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 "stm32l0xx.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( ( DATA_EEPROM_BASE + addr ) >= DATA_EEPROM_BASE );
32     assert_param( buffer != NULL );
33     assert_param( size < ( DATA_EEPROM_BANK2_END - DATA_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                                                 ( DATA_EEPROM_BASE + addr + i ),
42                                                   buffer[i] ) != HAL_OK )
43             {
44                 // Failed to write EEPROM
45                 break;
46             }
47         }
48         CRITICAL_SECTION_END( );
49         status = LMN_STATUS_OK;
50     }
51 
52     HAL_FLASHEx_DATAEEPROM_Lock( );
53     return status;
54 }
55 
EepromMcuReadBuffer(uint16_t addr,uint8_t * buffer,uint16_t size)56 LmnStatus_t EepromMcuReadBuffer( uint16_t addr, uint8_t *buffer, uint16_t size )
57 {
58     assert_param( ( DATA_EEPROM_BASE + addr ) >= DATA_EEPROM_BASE );
59     assert_param( buffer != NULL );
60     assert_param( size < ( DATA_EEPROM_BANK2_END - DATA_EEPROM_BASE ) );
61 
62     memcpy1( buffer, ( uint8_t* )( DATA_EEPROM_BASE + addr ), size );
63     return LMN_STATUS_OK;
64 }
65 
EepromMcuSetDeviceAddr(uint8_t addr)66 void EepromMcuSetDeviceAddr( uint8_t addr )
67 {
68     assert_param( LMN_STATUS_ERROR );
69 }
70 
EepromMcuGetDeviceAddr(void)71 LmnStatus_t EepromMcuGetDeviceAddr( void )
72 {
73     assert_param( LMN_STATUS_ERROR );
74     return 0;
75 }
76