EEPROM for SX1272
Dependencies: X_NUCLEO_IKS01A1 driver_mbed_TH02 LoRaWAN-lib-v1_0_1 SX1272Lib mbed
Fork of Canada-SX1272-LoRaWAN-Bootcamp by
Revision 8:bca4f3d51eaa, committed 2018-01-24
- Comitter:
- terence304
- Date:
- Wed Jan 24 18:22:00 2018 +0000
- Parent:
- 7:1769f863fe49
- Child:
- 9:4c8f32a4044d
- Commit message:
- add eeprom read and write funcions
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/eeprom.cpp Wed Jan 24 18:22:00 2018 +0000 @@ -0,0 +1,46 @@ +#include "mbed.h" +#include "eeprom.h" + +#if defined( TARGET_NUCLEO_L476RG ) +#define DATA_EEPROM_BASE ( ( uint32_t )0x0807F800U ) +#define DATA_EEPROM_END ( ( uint32_t )DATA_EEPROM_BASE + 2048 ) +#elif defined( TARGET_NUCLEO_L152RE ) +#define DATA_EEPROM_BASE ( ( uint32_t )0x08080000U ) +#define DATA_EEPROM_END ( ( uint32_t )0x080807FFU ) +#else +#error "Please define EEPROM base address and size for your board " +#endif + +uint8_t EepromMcuReadBuffer( uint16_t addr, uint8_t *buffer, uint16_t size ) +{ + assert_param( buffer != NULL ); + + // assert_param( addr >= DATA_EEPROM_BASE ); + assert_param( buffer != NULL ); + assert_param( size < ( DATA_EEPROM_END - DATA_EEPROM_BASE ) ); + + memcpy( buffer, ( uint8_t* )DATA_EEPROM_BASE, size ); + + return SUCCESS; +} + +uint8_t EepromMcuWriteBuffer( uint16_t addr, uint8_t *buffer, uint16_t size ) +{ + int n = size / 4 + (size % 4 ? 1 : 0); + uint32_t *flash = ( uint32_t* )buffer; + + assert_param( buffer != NULL ); + assert_param( size < ( DATA_EEPROM_END - DATA_EEPROM_BASE ) ); + + HAL_FLASH_Unlock( ); + + for( uint32_t i = 0; i < n; i++ ) + { + HAL_FLASH_Program( 0x02U, DATA_EEPROM_BASE + \ + ( 4 * i ), flash[i] ); + } + + HAL_FLASH_Lock( ); + + return SUCCESS; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/eeprom.h Wed Jan 24 18:22:00 2018 +0000 @@ -0,0 +1,33 @@ +#ifndef EEPROM_H +#define EEPROM_H + +#include "stm32l1xx_hal_flash.h" + +/*! + * \brief Initialises the contents of EepromData + */ +void EepromInit( void ); + +/*! + * \brief Read Eeprom from emulated EEPROM (in fact in Flash " higher address). + * + * \param [in] addr address of data (EEPROM offset not to be include) + * \param [in] buffer buffer to use for copy + * \param [in] size size of data to copy + * + * \retval status Status of operation (SUCCESS, ..) + */ +uint8_t EepromMcuReadBuffer( uint16_t addr, uint8_t *buffer, uint16_t size ); + +/*! + * \brief Write Eeprom from emulated EEPROM (in fact in Flash " higher address). + * + * \param [in] addr address of data (EEPROM offset not to be include) + * \param [in] buffer buffer to use for copy + * \param [in] size size of data to copy + * + * \retval status Status of operation (SUCCESS, ..) + */ +uint8_t EepromMcuWriteBuffer( uint16_t addr, uint8_t *buffer, uint16_t size ); + +#endif //EEPROM_H \ No newline at end of file
--- a/app/main.cpp Wed Jan 24 01:50:38 2018 +0000 +++ b/app/main.cpp Wed Jan 24 18:22:00 2018 +0000 @@ -23,6 +23,7 @@ #include "LoRaDeviceStateProc.h" #include "LoRaEventProc.h" #include "LoRaApp.h" +#include "eeprom.h" /*! * Defines a random delay for application data transmission duty cycle. 1s, @@ -121,6 +122,17 @@ // Initialize Device state DeviceState = DEVICE_STATE_INIT; + // EEPROM + uint8_t buffer[8] = {'S', 'E', 'M', 'T', 'E', 'C', 'H', 0}; + uint8_t buffer2[8]; + + EepromMcuWriteBuffer(0, buffer, 8); + EepromMcuReadBuffer(0, buffer2, 8); + + for (int i = 0; i < 8; ++i) { + printf("data: %c\r\n", buffer2[i]); + } + while( 1 ) { if( IsNetworkJoinedStatusUpdate == true )