1 /*!
2 * \file eeprom-board.c
3 *
4 * \brief Target board EEPROM driver implementation
5 *
6 * \copyright Revised BSD License, see section \ref LICENSE.
7 *
8 * \code
9 * ______ _
10 * / _____) _ | |
11 * ( (____ _____ ____ _| |_ _____ ____| |__
12 * \____ \| ___ | (_ _) ___ |/ ___) _ \
13 * _____) ) ____| | | || |_| ____( (___| | | |
14 * (______/|_____)_|_|_| \__)_____)\____)_| |_|
15 * (C)2013-2017 Semtech
16 *
17 * \endcode
18 *
19 * \author Miguel Luis ( Semtech )
20 *
21 * \author Gregory Cristian ( Semtech )
22 */
23 #include "stm32l1xx.h"
24 #include "utilities.h"
25 #include "eeprom-board.h"
26
EepromMcuWriteBuffer(uint16_t addr,uint8_t * buffer,uint16_t size)27 LmnStatus_t EepromMcuWriteBuffer( uint16_t addr, uint8_t *buffer, uint16_t size )
28 {
29 LmnStatus_t status = LMN_STATUS_ERROR;
30
31 assert_param( ( FLASH_EEPROM_BASE + addr ) >= FLASH_EEPROM_BASE );
32 assert_param( buffer != NULL );
33 assert_param( size < ( FLASH_EEPROM_END - FLASH_EEPROM_BASE ) );
34
35 if( HAL_FLASHEx_DATAEEPROM_Unlock( ) == HAL_OK )
36 {
37 CRITICAL_SECTION_BEGIN( );
38 for( uint16_t i = 0; i < size; i++ )
39 {
40 if( HAL_FLASHEx_DATAEEPROM_Program( FLASH_TYPEPROGRAMDATA_BYTE,
41 ( FLASH_EEPROM_BASE + addr + i ),
42 buffer[i] ) != HAL_OK )
43 {
44 // Failed to write EEPROM
45 break;
46 }
47
48 }
49 CRITICAL_SECTION_END( );
50 status = LMN_STATUS_OK;
51 }
52
53 HAL_FLASHEx_DATAEEPROM_Lock( );
54 return status;
55 }
56
EepromMcuReadBuffer(uint16_t addr,uint8_t * buffer,uint16_t size)57 LmnStatus_t EepromMcuReadBuffer( uint16_t addr, uint8_t *buffer, uint16_t size )
58 {
59 assert_param( ( FLASH_EEPROM_BASE + addr ) >= FLASH_EEPROM_BASE );
60 assert_param( buffer != NULL );
61 assert_param( size < ( FLASH_EEPROM_END - FLASH_EEPROM_BASE ) );
62
63 memcpy1( buffer, ( uint8_t* )( FLASH_EEPROM_BASE + addr ), size );
64 return LMN_STATUS_OK;
65 }
66
EepromMcuSetDeviceAddr(uint8_t addr)67 void EepromMcuSetDeviceAddr( uint8_t addr )
68 {
69 assert_param( LMN_STATUS_ERROR );
70 }
71
EepromMcuGetDeviceAddr(void)72 LmnStatus_t EepromMcuGetDeviceAddr( void )
73 {
74 assert_param( LMN_STATUS_ERROR );
75 return 0;
76 }
77