SX126xDevKit

Dependencies:   mbed DmTftLibrary SX126xLib

Committer:
GregCr
Date:
Tue Sep 05 08:15:37 2017 +0000
Revision:
0:e5420f1a8a1a
Child:
1:b96176a4ccb8
Candidate Release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
GregCr 0:e5420f1a8a1a 1 /*
GregCr 0:e5420f1a8a1a 2 ______ _
GregCr 0:e5420f1a8a1a 3 / _____) _ | |
GregCr 0:e5420f1a8a1a 4 ( (____ _____ ____ _| |_ _____ ____| |__
GregCr 0:e5420f1a8a1a 5 \____ \| ___ | (_ _) ___ |/ ___) _ \
GregCr 0:e5420f1a8a1a 6 _____) ) ____| | | || |_| ____( (___| | | |
GregCr 0:e5420f1a8a1a 7 (______/|_____)_|_|_| \__)_____)\____)_| |_|
GregCr 0:e5420f1a8a1a 8 (C)2016 Semtech
GregCr 0:e5420f1a8a1a 9
GregCr 0:e5420f1a8a1a 10 Description: EEPROM routines
GregCr 0:e5420f1a8a1a 11
GregCr 0:e5420f1a8a1a 12 Maintainer: Gregory Cristian & Gilbert Menth
GregCr 0:e5420f1a8a1a 13 */
GregCr 0:e5420f1a8a1a 14
GregCr 0:e5420f1a8a1a 15 #include "mbed.h"
GregCr 0:e5420f1a8a1a 16 #include "string.h"
GregCr 0:e5420f1a8a1a 17 #include "Eeprom.h"
GregCr 0:e5420f1a8a1a 18 #include "Menu.h"
GregCr 0:e5420f1a8a1a 19 #include "DemoApplication.h"
GregCr 0:e5420f1a8a1a 20 #include "sx126x.h"
GregCr 0:e5420f1a8a1a 21 #if defined( TARGET_NUCLEO_L476RG )
GregCr 0:e5420f1a8a1a 22 #include "stm32l4xx_hal_flash.h"
GregCr 0:e5420f1a8a1a 23 #elif defined( TARGET_NUCLEO_L152RE )
GregCr 0:e5420f1a8a1a 24 #include "stm32l1xx_hal_flash.h"
GregCr 0:e5420f1a8a1a 25 #else
GregCr 0:e5420f1a8a1a 26 #error "Please define include file"
GregCr 0:e5420f1a8a1a 27 #endif
GregCr 0:e5420f1a8a1a 28
GregCr 0:e5420f1a8a1a 29
GregCr 0:e5420f1a8a1a 30
GregCr 0:e5420f1a8a1a 31 #include "DisplayDriver.h"
GregCr 0:e5420f1a8a1a 32
GregCr 0:e5420f1a8a1a 33
GregCr 0:e5420f1a8a1a 34 /*!
GregCr 0:e5420f1a8a1a 35 * \brief Define address of Emulated EEPROM (in fact region of Flash)
GregCr 0:e5420f1a8a1a 36 */
GregCr 0:e5420f1a8a1a 37 #if defined( TARGET_NUCLEO_L476RG )
GregCr 0:e5420f1a8a1a 38 #define DATA_EEPROM_BASE ( ( uint32_t )0x0807F800U )
GregCr 0:e5420f1a8a1a 39 #define DATA_EEPROM_END ( ( uint32_t )DATA_EEPROM_BASE + 2048 )
GregCr 0:e5420f1a8a1a 40 #elif defined( TARGET_NUCLEO_L152RE )
GregCr 0:e5420f1a8a1a 41 #define DATA_EEPROM_BASE ( ( uint32_t )0x08080000U )
GregCr 0:e5420f1a8a1a 42 #define DATA_EEPROM_END ( ( uint32_t )0x080807FFU )
GregCr 0:e5420f1a8a1a 43 #else
GregCr 0:e5420f1a8a1a 44 #error "Please define EEPROM base address and size for your board "
GregCr 0:e5420f1a8a1a 45 #endif
GregCr 0:e5420f1a8a1a 46
GregCr 0:e5420f1a8a1a 47
GregCr 0:e5420f1a8a1a 48 /*!
GregCr 0:e5420f1a8a1a 49 * \brief CRC of EEPROM buffer and its valid status
GregCr 0:e5420f1a8a1a 50 */
GregCr 0:e5420f1a8a1a 51 typedef struct
GregCr 0:e5420f1a8a1a 52 {
GregCr 0:e5420f1a8a1a 53 uint16_t Value;
GregCr 0:e5420f1a8a1a 54 bool Valid;
GregCr 0:e5420f1a8a1a 55 }MemTestStruct_t;
GregCr 0:e5420f1a8a1a 56
GregCr 0:e5420f1a8a1a 57 /*!
GregCr 0:e5420f1a8a1a 58 * \brief Local copy of Eeprom.
GregCr 0:e5420f1a8a1a 59 */
GregCr 0:e5420f1a8a1a 60 Eeprom_t Eeprom;
GregCr 0:e5420f1a8a1a 61
GregCr 0:e5420f1a8a1a 62
GregCr 0:e5420f1a8a1a 63 // Check CRC of local copy of Eeprom (Buffer). This update Valid & Value
GregCr 0:e5420f1a8a1a 64 static MemTestStruct_t EepromDataCheckSum( void );
GregCr 0:e5420f1a8a1a 65 uint8_t EepromMcuWriteBuffer( uint16_t addr, uint8_t *buffer, uint16_t size );
GregCr 0:e5420f1a8a1a 66
GregCr 0:e5420f1a8a1a 67 void EepromInit( uint8_t deviceConnected )
GregCr 0:e5420f1a8a1a 68 {
GregCr 0:e5420f1a8a1a 69 MemTestStruct_t memTestStruct;
GregCr 0:e5420f1a8a1a 70
GregCr 0:e5420f1a8a1a 71 if( deviceConnected == 0xFF )
GregCr 0:e5420f1a8a1a 72 {
GregCr 0:e5420f1a8a1a 73 EepromSetDefaultSettings( deviceConnected );
GregCr 0:e5420f1a8a1a 74 }
GregCr 0:e5420f1a8a1a 75
GregCr 0:e5420f1a8a1a 76 EepromMcuReadBuffer( 0, Eeprom.Buffer, EEPROM_BUFFER_SIZE );
GregCr 0:e5420f1a8a1a 77 EepromLoadGeneralSettings( );
GregCr 0:e5420f1a8a1a 78
GregCr 0:e5420f1a8a1a 79 memTestStruct = EepromDataCheckSum( );
GregCr 0:e5420f1a8a1a 80 if( !( memTestStruct.Valid ) || ( Eeprom.EepromData.DemoSettings.LastDeviceConnected != deviceConnected ) )
GregCr 0:e5420f1a8a1a 81 {
GregCr 0:e5420f1a8a1a 82 #ifdef ADV_DEBUG
GregCr 0:e5420f1a8a1a 83 printf("EepromDataCheckSum failed\n\r");
GregCr 0:e5420f1a8a1a 84 #endif
GregCr 0:e5420f1a8a1a 85 EepromSetDefaultSettings( deviceConnected );
GregCr 0:e5420f1a8a1a 86 }
GregCr 0:e5420f1a8a1a 87 EepromLoadSettings( ( RadioPacketTypes_t ) Eeprom.EepromData.DemoSettings.ModulationType );
GregCr 0:e5420f1a8a1a 88 }
GregCr 0:e5420f1a8a1a 89
GregCr 0:e5420f1a8a1a 90 void EepromSaveSettings( EepromDataSet_t dataSet)
GregCr 0:e5420f1a8a1a 91 {
GregCr 0:e5420f1a8a1a 92 MemTestStruct_t memTestStruct;
GregCr 0:e5420f1a8a1a 93
GregCr 0:e5420f1a8a1a 94 switch( dataSet )
GregCr 0:e5420f1a8a1a 95 {
GregCr 0:e5420f1a8a1a 96 case RADIO_LORA_PARAMS:
GregCr 0:e5420f1a8a1a 97 Eeprom.EepromData.ModulationParams.Params.LoRa.SpreadingFactor = ( RadioLoRaSpreadingFactors_t ) Eeprom.EepromData.DemoSettings.ModulationParam1;
GregCr 0:e5420f1a8a1a 98 Eeprom.EepromData.ModulationParams.Params.LoRa.Bandwidth = ( RadioLoRaBandwidths_t ) Eeprom.EepromData.DemoSettings.ModulationParam2;
GregCr 0:e5420f1a8a1a 99 Eeprom.EepromData.ModulationParams.Params.LoRa.CodingRate = ( RadioLoRaCodingRates_t ) Eeprom.EepromData.DemoSettings.ModulationParam3;
GregCr 0:e5420f1a8a1a 100
GregCr 0:e5420f1a8a1a 101 Eeprom.EepromData.PacketParams.Params.LoRa.PreambleLength = Eeprom.EepromData.DemoSettings.PacketParam1;
GregCr 0:e5420f1a8a1a 102 Eeprom.EepromData.PacketParams.Params.LoRa.HeaderType = ( RadioLoRaPacketLengthsMode_t )Eeprom.EepromData.DemoSettings.PacketParam2;
GregCr 0:e5420f1a8a1a 103 Eeprom.EepromData.PacketParams.Params.LoRa.PayloadLength = Eeprom.EepromData.DemoSettings.PacketParam3;
GregCr 0:e5420f1a8a1a 104 Eeprom.EepromData.PacketParams.Params.LoRa.CrcMode = ( RadioLoRaCrcModes_t ) Eeprom.EepromData.DemoSettings.PacketParam4;
GregCr 0:e5420f1a8a1a 105 Eeprom.EepromData.PacketParams.Params.LoRa.InvertIQ = ( RadioLoRaIQModes_t ) Eeprom.EepromData.DemoSettings.PacketParam5;
GregCr 0:e5420f1a8a1a 106
GregCr 0:e5420f1a8a1a 107 memcpy( Eeprom.Buffer + MOD_LORA_SPREADF_EEPROM_ADDR, &( Eeprom.EepromData.ModulationParams.Params.LoRa.SpreadingFactor ), 1 );
GregCr 0:e5420f1a8a1a 108 memcpy( Eeprom.Buffer + MOD_LORA_BW_EEPROM_ADDR, &( Eeprom.EepromData.ModulationParams.Params.LoRa.Bandwidth ), 1 );
GregCr 0:e5420f1a8a1a 109 memcpy( Eeprom.Buffer + MOD_LORA_CODERATE_EEPROM_ADDR, &( Eeprom.EepromData.ModulationParams.Params.LoRa.CodingRate ), 1 );
GregCr 0:e5420f1a8a1a 110 memcpy( Eeprom.Buffer + PAK_LORA_PREAMBLE_LEN_EEPROM_ADDR, &( Eeprom.EepromData.PacketParams.Params.LoRa.PreambleLength ), 1 );
GregCr 0:e5420f1a8a1a 111 memcpy( Eeprom.Buffer + PAK_LORA_HEADERTYPE_EEPROM_ADDR, &( Eeprom.EepromData.PacketParams.Params.LoRa.HeaderType ), 1 );
GregCr 0:e5420f1a8a1a 112 memcpy( Eeprom.Buffer + PAK_LORA_PL_LEN_EEPROM_ADDR, &( Eeprom.EepromData.PacketParams.Params.LoRa.PayloadLength ), 1 );
GregCr 0:e5420f1a8a1a 113 memcpy( Eeprom.Buffer + PAK_LORA_CRC_MODE_EEPROM_ADDR, &( Eeprom.EepromData.PacketParams.Params.LoRa.CrcMode ), 1 );
GregCr 0:e5420f1a8a1a 114 memcpy( Eeprom.Buffer + PAK_LORA_IQ_INV_EEPROM_ADDR, &( Eeprom.EepromData.PacketParams.Params.LoRa.InvertIQ ), 1 );
GregCr 0:e5420f1a8a1a 115 #ifdef ADV_DEBUG
GregCr 0:e5420f1a8a1a 116 printf("Saved RADIO_LoRa_PARAMS\n\r");
GregCr 0:e5420f1a8a1a 117 #endif
GregCr 0:e5420f1a8a1a 118 break;
GregCr 0:e5420f1a8a1a 119
GregCr 0:e5420f1a8a1a 120 case RADIO_GFSK_PARAMS:
GregCr 0:e5420f1a8a1a 121 Eeprom.EepromData.ModulationParams.Params.Gfsk.BitRate = Eeprom.EepromData.DemoSettings.ModulationParam1;
GregCr 0:e5420f1a8a1a 122 Eeprom.EepromData.ModulationParams.Params.Gfsk.Fdev = Eeprom.EepromData.DemoSettings.ModulationParam2;
GregCr 0:e5420f1a8a1a 123 Eeprom.EepromData.ModulationParams.Params.Gfsk.ModulationShaping = ( RadioModShapings_t ) Eeprom.EepromData.DemoSettings.ModulationParam3;
GregCr 0:e5420f1a8a1a 124 Eeprom.EepromData.ModulationParams.Params.Gfsk.Bandwidth = ( RadioRxBandwidth_t ) Eeprom.EepromData.DemoSettings.ModulationParam4;
GregCr 0:e5420f1a8a1a 125 Eeprom.EepromData.PacketParams.Params.Gfsk.PreambleLength = Eeprom.EepromData.DemoSettings.PacketParam1;
GregCr 0:e5420f1a8a1a 126 Eeprom.EepromData.PacketParams.Params.Gfsk.PreambleMinDetect = ( RadioPreambleDetection_t )Eeprom.EepromData.DemoSettings.PacketParam2;
GregCr 0:e5420f1a8a1a 127 Eeprom.EepromData.PacketParams.Params.Gfsk.SyncWordLength = Eeprom.EepromData.DemoSettings.PacketParam3;
GregCr 0:e5420f1a8a1a 128 Eeprom.EepromData.PacketParams.Params.Gfsk.AddrComp = ( RadioAddressComp_t ) Eeprom.EepromData.DemoSettings.PacketParam4;
GregCr 0:e5420f1a8a1a 129 Eeprom.EepromData.PacketParams.Params.Gfsk.HeaderType = ( RadioPacketLengthModes_t )Eeprom.EepromData.DemoSettings.PacketParam5;
GregCr 0:e5420f1a8a1a 130 Eeprom.EepromData.PacketParams.Params.Gfsk.PayloadLength = Eeprom.EepromData.DemoSettings.PacketParam6;
GregCr 0:e5420f1a8a1a 131
GregCr 0:e5420f1a8a1a 132 Eeprom.EepromData.PacketParams.Params.Gfsk.CrcLength = ( RadioCrcTypes_t ) Eeprom.EepromData.DemoSettings.PacketParam7;
GregCr 0:e5420f1a8a1a 133 Eeprom.EepromData.PacketParams.Params.Gfsk.DcFree = ( RadioDcFree_t ) Eeprom.EepromData.DemoSettings.PacketParam8;
GregCr 0:e5420f1a8a1a 134
GregCr 0:e5420f1a8a1a 135 memcpy( Eeprom.Buffer + MOD_GFSK_BR_EEPROM_ADDR, &( Eeprom.EepromData.ModulationParams.Params.Gfsk.BitRate ), 4 );
GregCr 0:e5420f1a8a1a 136 memcpy( Eeprom.Buffer + MOD_GFSK_FDEV_EEPROM_ADDR, &( Eeprom.EepromData.ModulationParams.Params.Gfsk.Fdev ), 4 );
GregCr 0:e5420f1a8a1a 137 memcpy( Eeprom.Buffer + MOD_GFSK_MOD_SHAPE_EEPROM_ADDR, &( Eeprom.EepromData.ModulationParams.Params.Gfsk.ModulationShaping ), 1 );
GregCr 0:e5420f1a8a1a 138 memcpy( Eeprom.Buffer + MOD_GFSK_BW_EEPROM_ADDR, &( Eeprom.EepromData.ModulationParams.Params.Gfsk.Bandwidth ), 1 );
GregCr 0:e5420f1a8a1a 139 memcpy( Eeprom.Buffer + PAK_GFSK_PREAMBLE_LEN_EEPROM_ADDR, &( Eeprom.EepromData.PacketParams.Params.Gfsk.PreambleLength ), 1 );
GregCr 0:e5420f1a8a1a 140 memcpy( Eeprom.Buffer + PAK_GFSK_PR_MIN_DET_EEPROM_ADDR, &( Eeprom.EepromData.PacketParams.Params.Gfsk.PreambleMinDetect ), 1 );
GregCr 0:e5420f1a8a1a 141 memcpy( Eeprom.Buffer + PAK_GFSK_SYNC_LEN_EEPROM_ADDR, &( Eeprom.EepromData.PacketParams.Params.Gfsk.SyncWordLength ), 1 );
GregCr 0:e5420f1a8a1a 142 memcpy( Eeprom.Buffer + PAK_GFSK_HEADERTYPE_EEPROM_ADDR, &( Eeprom.EepromData.PacketParams.Params.Gfsk.HeaderType ), 1 );
GregCr 0:e5420f1a8a1a 143 memcpy( Eeprom.Buffer + PAK_GFSK_PL_LEN_EEPROM_ADDR, &( Eeprom.EepromData.PacketParams.Params.Gfsk.PayloadLength ), 1 );
GregCr 0:e5420f1a8a1a 144 memcpy( Eeprom.Buffer + PAK_GFSK_ADDR_COMP_EEPROM_ADDR, &( Eeprom.EepromData.PacketParams.Params.Gfsk.AddrComp ), 1 );
GregCr 0:e5420f1a8a1a 145 memcpy( Eeprom.Buffer + PAK_GFSK_CRC_LEN_EEPROM_ADDR, &( Eeprom.EepromData.PacketParams.Params.Gfsk.CrcLength ), 1 );
GregCr 0:e5420f1a8a1a 146 memcpy( Eeprom.Buffer + PAK_GFSK_DC_FREE_EEPROM_ADDR, &( Eeprom.EepromData.PacketParams.Params.Gfsk.DcFree ), 1 );
GregCr 0:e5420f1a8a1a 147
GregCr 0:e5420f1a8a1a 148 #ifdef ADV_DEBUG
GregCr 0:e5420f1a8a1a 149 printf("Saved RADIO_GFSK_PARAMS\n\r");
GregCr 0:e5420f1a8a1a 150 #endif
GregCr 0:e5420f1a8a1a 151 break;
GregCr 0:e5420f1a8a1a 152
GregCr 0:e5420f1a8a1a 153 case DEMO_SETTINGS:
GregCr 0:e5420f1a8a1a 154 memcpy( Eeprom.Buffer + APP_ENTITY_EEPROM_ADDR, &( Eeprom.EepromData.DemoSettings.Entity ), 1 );
GregCr 0:e5420f1a8a1a 155 memcpy( Eeprom.Buffer + APP_RADIO_BOOSTED_RX_EEPROM_ADDR, &( Eeprom.EepromData.DemoSettings.BoostedRx ), 1 );
GregCr 0:e5420f1a8a1a 156 memcpy( Eeprom.Buffer + APP_FREQ_EEPROM_ADDR, &( Eeprom.EepromData.DemoSettings.Frequency ), 4 );
GregCr 0:e5420f1a8a1a 157 memcpy( Eeprom.Buffer + APP_TXPWR_EEPROM_ADDR, &( Eeprom.EepromData.DemoSettings.TxPower ), 1 );
GregCr 0:e5420f1a8a1a 158 memcpy( Eeprom.Buffer + APP_MOD_TYPE_EEPROM_ADDR, &( Eeprom.EepromData.DemoSettings.ModulationType ), 1 );
GregCr 0:e5420f1a8a1a 159 memcpy( Eeprom.Buffer + APP_PER_NPAK_MAX_EEPROM_ADDR, &( Eeprom.EepromData.DemoSettings.MaxNumPacket ), 4 );
GregCr 0:e5420f1a8a1a 160 memcpy( Eeprom.Buffer + APP_RADIO_POWER_MODE_EEPROM_ADDR, &( Eeprom.EepromData.DemoSettings.RadioPowerMode ), 1 );
GregCr 0:e5420f1a8a1a 161 memcpy( Eeprom.Buffer + MOD_PKET_TYPE_EEPROM_ADDR, &( Eeprom.EepromData.DemoSettings.ModulationType ), 1 );
GregCr 0:e5420f1a8a1a 162 memcpy( Eeprom.Buffer + PAK_PKET_TYPE_EEPROM_ADDR, &( Eeprom.EepromData.DemoSettings.ModulationType ), 1 );
GregCr 0:e5420f1a8a1a 163 memcpy( Eeprom.Buffer + EEPROM_LAST_DEVICE_CONNECTED, &( Eeprom.EepromData.DemoSettings.LastDeviceConnected ), 1 );
GregCr 0:e5420f1a8a1a 164
GregCr 0:e5420f1a8a1a 165 #ifdef ADV_DEBUG
GregCr 0:e5420f1a8a1a 166 printf("Saved DEMO_SETTINGS\n\r");
GregCr 0:e5420f1a8a1a 167 #endif
GregCr 0:e5420f1a8a1a 168 break;
GregCr 0:e5420f1a8a1a 169
GregCr 0:e5420f1a8a1a 170 case SCREEN_DATA:
GregCr 0:e5420f1a8a1a 171 memcpy( Eeprom.Buffer + SCR_CAL_FLAG_EEPROM_ADDR, &( Eeprom.EepromData.MenuSettings.ScreenCalibrated ), 1 );
GregCr 0:e5420f1a8a1a 172 memcpy( Eeprom.Buffer + SCR_CAL_POSA_EEPROM_ADDR, &( Eeprom.EepromData.MenuSettings.Calibration.a ), 4 );
GregCr 0:e5420f1a8a1a 173 memcpy( Eeprom.Buffer + SCR_CAL_POSB_EEPROM_ADDR, &( Eeprom.EepromData.MenuSettings.Calibration.b ), 4 );
GregCr 0:e5420f1a8a1a 174 memcpy( Eeprom.Buffer + SCR_CAL_POSC_EEPROM_ADDR, &( Eeprom.EepromData.MenuSettings.Calibration.c ), 4 );
GregCr 0:e5420f1a8a1a 175 memcpy( Eeprom.Buffer + SCR_CAL_POSD_EEPROM_ADDR, &( Eeprom.EepromData.MenuSettings.Calibration.d ), 4 );
GregCr 0:e5420f1a8a1a 176 memcpy( Eeprom.Buffer + SCR_CAL_POSE_EEPROM_ADDR, &( Eeprom.EepromData.MenuSettings.Calibration.e ), 4 );
GregCr 0:e5420f1a8a1a 177 memcpy( Eeprom.Buffer + SCR_CAL_POSF_EEPROM_ADDR, &( Eeprom.EepromData.MenuSettings.Calibration.f ), 4 );
GregCr 0:e5420f1a8a1a 178 break;
GregCr 0:e5420f1a8a1a 179
GregCr 0:e5420f1a8a1a 180 default:
GregCr 0:e5420f1a8a1a 181 #ifdef ADV_DEBUG
GregCr 0:e5420f1a8a1a 182 printf("data not saved\n\r");
GregCr 0:e5420f1a8a1a 183 #endif
GregCr 0:e5420f1a8a1a 184 break;
GregCr 0:e5420f1a8a1a 185 }
GregCr 0:e5420f1a8a1a 186
GregCr 0:e5420f1a8a1a 187 memTestStruct = EepromDataCheckSum( );
GregCr 0:e5420f1a8a1a 188 memcpy( Eeprom.Buffer + EEPROM_CRC_EEPROM_ADDR, &( memTestStruct.Value ), 2 );
GregCr 0:e5420f1a8a1a 189
GregCr 0:e5420f1a8a1a 190 EepromMcuWriteBuffer( 0, Eeprom.Buffer, EEPROM_BUFFER_SIZE );
GregCr 0:e5420f1a8a1a 191 }
GregCr 0:e5420f1a8a1a 192
GregCr 0:e5420f1a8a1a 193 void EepromLoadGeneralSettings( void )
GregCr 0:e5420f1a8a1a 194 {
GregCr 0:e5420f1a8a1a 195 printf("Load General Settings\n\r");
GregCr 0:e5420f1a8a1a 196 memcpy( &( Eeprom.EepromData.MenuSettings.ScreenCalibrated ), Eeprom.Buffer + SCR_CAL_FLAG_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 197 memcpy( &( Eeprom.EepromData.MenuSettings.Calibration.a ), Eeprom.Buffer + SCR_CAL_POSA_EEPROM_ADDR, 4 );
GregCr 0:e5420f1a8a1a 198 memcpy( &( Eeprom.EepromData.MenuSettings.Calibration.b ), Eeprom.Buffer + SCR_CAL_POSB_EEPROM_ADDR, 4 );
GregCr 0:e5420f1a8a1a 199 memcpy( &( Eeprom.EepromData.MenuSettings.Calibration.c ), Eeprom.Buffer + SCR_CAL_POSC_EEPROM_ADDR, 4 );
GregCr 0:e5420f1a8a1a 200 memcpy( &( Eeprom.EepromData.MenuSettings.Calibration.d ), Eeprom.Buffer + SCR_CAL_POSD_EEPROM_ADDR, 4 );
GregCr 0:e5420f1a8a1a 201 memcpy( &( Eeprom.EepromData.MenuSettings.Calibration.e ), Eeprom.Buffer + SCR_CAL_POSE_EEPROM_ADDR, 4 );
GregCr 0:e5420f1a8a1a 202 memcpy( &( Eeprom.EepromData.MenuSettings.Calibration.f ), Eeprom.Buffer + SCR_CAL_POSF_EEPROM_ADDR, 4 );
GregCr 0:e5420f1a8a1a 203
GregCr 0:e5420f1a8a1a 204 memcpy( &( Eeprom.EepromData.DemoSettings.Entity ), Eeprom.Buffer + APP_ENTITY_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 205 memcpy( &( Eeprom.EepromData.DemoSettings.BoostedRx ), Eeprom.Buffer + APP_RADIO_BOOSTED_RX_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 206 memcpy( &( Eeprom.EepromData.DemoSettings.Frequency ), Eeprom.Buffer + APP_FREQ_EEPROM_ADDR, 4 );
GregCr 0:e5420f1a8a1a 207 memcpy( &( Eeprom.EepromData.DemoSettings.RadioPowerMode ), Eeprom.Buffer + APP_RADIO_POWER_MODE_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 208 memcpy( &( Eeprom.EepromData.DemoSettings.TxPower ), Eeprom.Buffer + APP_TXPWR_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 209 memcpy( &( Eeprom.EepromData.DemoSettings.ModulationType ), Eeprom.Buffer + APP_MOD_TYPE_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 210 memcpy( &( Eeprom.EepromData.DemoSettings.MaxNumPacket ), Eeprom.Buffer + APP_PER_NPAK_MAX_EEPROM_ADDR, 4 );
GregCr 0:e5420f1a8a1a 211 memcpy( &( Eeprom.EepromData.DemoSettings.LastDeviceConnected ), Eeprom.Buffer + EEPROM_LAST_DEVICE_CONNECTED, 1 );
GregCr 0:e5420f1a8a1a 212
GregCr 0:e5420f1a8a1a 213 memcpy( &( Eeprom.EepromData.ModulationParams.PacketType ), Eeprom.Buffer + MOD_PKET_TYPE_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 214
GregCr 0:e5420f1a8a1a 215 memcpy( &( Eeprom.EepromData.ModulationParams.Params.Gfsk.BitRate ), Eeprom.Buffer + MOD_GFSK_BR_EEPROM_ADDR, 4 );
GregCr 0:e5420f1a8a1a 216 memcpy( &( Eeprom.EepromData.ModulationParams.Params.Gfsk.Fdev ), Eeprom.Buffer + MOD_GFSK_FDEV_EEPROM_ADDR, 4 );
GregCr 0:e5420f1a8a1a 217 memcpy( &( Eeprom.EepromData.ModulationParams.Params.Gfsk.ModulationShaping ), Eeprom.Buffer + MOD_GFSK_MOD_SHAPE_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 218 memcpy( &( Eeprom.EepromData.ModulationParams.Params.Gfsk.Bandwidth ), Eeprom.Buffer + MOD_GFSK_BW_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 219
GregCr 0:e5420f1a8a1a 220 memcpy( &( Eeprom.EepromData.ModulationParams.Params.LoRa.SpreadingFactor ), Eeprom.Buffer + MOD_LORA_SPREADF_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 221 memcpy( &( Eeprom.EepromData.ModulationParams.Params.LoRa.Bandwidth ), Eeprom.Buffer + MOD_LORA_BW_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 222 memcpy( &( Eeprom.EepromData.ModulationParams.Params.LoRa.CodingRate ), Eeprom.Buffer + MOD_LORA_CODERATE_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 223
GregCr 0:e5420f1a8a1a 224 memcpy( &( Eeprom.EepromData.PacketParams.PacketType ), Eeprom.Buffer + PAK_PKET_TYPE_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 225 memcpy( &( Eeprom.EepromData.PacketParams.Params.Gfsk.PreambleLength ), Eeprom.Buffer + PAK_GFSK_PREAMBLE_LEN_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 226 memcpy( &( Eeprom.EepromData.PacketParams.Params.Gfsk.PreambleMinDetect ), Eeprom.Buffer + PAK_GFSK_PR_MIN_DET_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 227 memcpy( &( Eeprom.EepromData.PacketParams.Params.Gfsk.SyncWordLength ), Eeprom.Buffer + PAK_GFSK_SYNC_LEN_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 228 memcpy( &( Eeprom.EepromData.PacketParams.Params.Gfsk.HeaderType ), Eeprom.Buffer + PAK_GFSK_HEADERTYPE_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 229 memcpy( &( Eeprom.EepromData.PacketParams.Params.Gfsk.PayloadLength ), Eeprom.Buffer + PAK_GFSK_PL_LEN_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 230 memcpy( &( Eeprom.EepromData.PacketParams.Params.Gfsk.AddrComp ), Eeprom.Buffer + PAK_GFSK_ADDR_COMP_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 231 memcpy( &( Eeprom.EepromData.PacketParams.Params.Gfsk.CrcLength ), Eeprom.Buffer + PAK_GFSK_CRC_LEN_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 232 memcpy( &( Eeprom.EepromData.PacketParams.Params.Gfsk.DcFree ), Eeprom.Buffer + PAK_GFSK_DC_FREE_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 233
GregCr 0:e5420f1a8a1a 234 memcpy( &( Eeprom.EepromData.PacketParams.Params.LoRa.PreambleLength ), Eeprom.Buffer + PAK_LORA_PREAMBLE_LEN_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 235 memcpy( &( Eeprom.EepromData.PacketParams.Params.LoRa.HeaderType ), Eeprom.Buffer + PAK_LORA_HEADERTYPE_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 236 memcpy( &( Eeprom.EepromData.PacketParams.Params.LoRa.PayloadLength ), Eeprom.Buffer + PAK_LORA_PL_LEN_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 237 memcpy( &( Eeprom.EepromData.PacketParams.Params.LoRa.CrcMode ), Eeprom.Buffer + PAK_LORA_CRC_MODE_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 238 memcpy( &( Eeprom.EepromData.PacketParams.Params.LoRa.InvertIQ ), Eeprom.Buffer + PAK_LORA_IQ_INV_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 239 }
GregCr 0:e5420f1a8a1a 240
GregCr 0:e5420f1a8a1a 241 void EepromLoadSettings( RadioPacketTypes_t modulation )
GregCr 0:e5420f1a8a1a 242 {
GregCr 0:e5420f1a8a1a 243 if( modulation == PACKET_TYPE_LORA )
GregCr 0:e5420f1a8a1a 244 {
GregCr 0:e5420f1a8a1a 245 printf("Load Settings PACKET_TYPE_LORA\n\r");
GregCr 0:e5420f1a8a1a 246 memcpy( &( Eeprom.EepromData.ModulationParams.Params.LoRa.SpreadingFactor ), Eeprom.Buffer + MOD_LORA_SPREADF_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 247 memcpy( &( Eeprom.EepromData.ModulationParams.Params.LoRa.Bandwidth ), Eeprom.Buffer + MOD_LORA_BW_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 248 memcpy( &( Eeprom.EepromData.ModulationParams.Params.LoRa.CodingRate ), Eeprom.Buffer + MOD_LORA_CODERATE_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 249 memcpy( &( Eeprom.EepromData.PacketParams.Params.LoRa.PreambleLength ), Eeprom.Buffer + PAK_LORA_PREAMBLE_LEN_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 250 memcpy( &( Eeprom.EepromData.PacketParams.Params.LoRa.HeaderType ), Eeprom.Buffer + PAK_LORA_HEADERTYPE_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 251 memcpy( &( Eeprom.EepromData.PacketParams.Params.LoRa.PayloadLength ), Eeprom.Buffer + PAK_LORA_PL_LEN_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 252 memcpy( &( Eeprom.EepromData.PacketParams.Params.LoRa.CrcMode ), Eeprom.Buffer + PAK_LORA_CRC_MODE_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 253 memcpy( &( Eeprom.EepromData.PacketParams.Params.LoRa.InvertIQ ), Eeprom.Buffer + PAK_LORA_IQ_INV_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 254
GregCr 0:e5420f1a8a1a 255 Eeprom.EepromData.ModulationParams.PacketType = PACKET_TYPE_LORA;
GregCr 0:e5420f1a8a1a 256 Eeprom.EepromData.PacketParams.PacketType = PACKET_TYPE_LORA;
GregCr 0:e5420f1a8a1a 257 Eeprom.EepromData.DemoSettings.ModulationParam1 = Eeprom.EepromData.ModulationParams.Params.LoRa.SpreadingFactor;
GregCr 0:e5420f1a8a1a 258 Eeprom.EepromData.DemoSettings.ModulationParam2 = Eeprom.EepromData.ModulationParams.Params.LoRa.Bandwidth;
GregCr 0:e5420f1a8a1a 259 Eeprom.EepromData.DemoSettings.ModulationParam3 = Eeprom.EepromData.ModulationParams.Params.LoRa.CodingRate;
GregCr 0:e5420f1a8a1a 260
GregCr 0:e5420f1a8a1a 261 Eeprom.EepromData.DemoSettings.PacketParam1 = Eeprom.EepromData.PacketParams.Params.LoRa.PreambleLength;
GregCr 0:e5420f1a8a1a 262 Eeprom.EepromData.DemoSettings.PacketParam2 = Eeprom.EepromData.PacketParams.Params.LoRa.HeaderType;
GregCr 0:e5420f1a8a1a 263 Eeprom.EepromData.DemoSettings.PacketParam3 = Eeprom.EepromData.PacketParams.Params.LoRa.PayloadLength;
GregCr 0:e5420f1a8a1a 264 Eeprom.EepromData.DemoSettings.PacketParam4 = Eeprom.EepromData.PacketParams.Params.LoRa.CrcMode;
GregCr 0:e5420f1a8a1a 265 Eeprom.EepromData.DemoSettings.PacketParam5 = Eeprom.EepromData.PacketParams.Params.LoRa.InvertIQ;
GregCr 0:e5420f1a8a1a 266 Eeprom.EepromData.DemoSettings.PacketParam6 = 0x00;
GregCr 0:e5420f1a8a1a 267 Eeprom.EepromData.DemoSettings.PacketParam7 = 0x00;
GregCr 0:e5420f1a8a1a 268 }
GregCr 0:e5420f1a8a1a 269 else// if( modulation == PACKET_TYPE_GFSK )
GregCr 0:e5420f1a8a1a 270 {
GregCr 0:e5420f1a8a1a 271 printf("Load Settings PACKET_TYPE_GFSK\n\r");
GregCr 0:e5420f1a8a1a 272 memcpy( &( Eeprom.EepromData.ModulationParams.Params.Gfsk.BitRate ), Eeprom.Buffer + MOD_GFSK_BR_EEPROM_ADDR, 4 );
GregCr 0:e5420f1a8a1a 273 memcpy( &( Eeprom.EepromData.ModulationParams.Params.Gfsk.Fdev ), Eeprom.Buffer + MOD_GFSK_FDEV_EEPROM_ADDR, 4 );
GregCr 0:e5420f1a8a1a 274 memcpy( &( Eeprom.EepromData.ModulationParams.Params.Gfsk.ModulationShaping ), Eeprom.Buffer + MOD_GFSK_MOD_SHAPE_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 275 memcpy( &( Eeprom.EepromData.ModulationParams.Params.Gfsk.Bandwidth ), Eeprom.Buffer + MOD_GFSK_BW_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 276
GregCr 0:e5420f1a8a1a 277 memcpy( &( Eeprom.EepromData.PacketParams.Params.Gfsk.PreambleLength ), Eeprom.Buffer + PAK_GFSK_PREAMBLE_LEN_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 278 memcpy( &( Eeprom.EepromData.PacketParams.Params.Gfsk.PreambleMinDetect ), Eeprom.Buffer + PAK_GFSK_PR_MIN_DET_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 279 memcpy( &( Eeprom.EepromData.PacketParams.Params.Gfsk.SyncWordLength ), Eeprom.Buffer + PAK_GFSK_SYNC_LEN_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 280 memcpy( &( Eeprom.EepromData.PacketParams.Params.Gfsk.HeaderType ), Eeprom.Buffer + PAK_GFSK_HEADERTYPE_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 281 memcpy( &( Eeprom.EepromData.PacketParams.Params.Gfsk.PayloadLength ), Eeprom.Buffer + PAK_GFSK_PL_LEN_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 282 memcpy( &( Eeprom.EepromData.PacketParams.Params.Gfsk.AddrComp ), Eeprom.Buffer + PAK_GFSK_ADDR_COMP_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 283 memcpy( &( Eeprom.EepromData.PacketParams.Params.Gfsk.CrcLength ), Eeprom.Buffer + PAK_GFSK_CRC_LEN_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 284 memcpy( &( Eeprom.EepromData.PacketParams.Params.Gfsk.DcFree ), Eeprom.Buffer + PAK_GFSK_DC_FREE_EEPROM_ADDR, 1 );
GregCr 0:e5420f1a8a1a 285
GregCr 0:e5420f1a8a1a 286 Eeprom.EepromData.ModulationParams.PacketType = PACKET_TYPE_GFSK;
GregCr 0:e5420f1a8a1a 287 Eeprom.EepromData.PacketParams.PacketType = PACKET_TYPE_GFSK;
GregCr 0:e5420f1a8a1a 288 Eeprom.EepromData.DemoSettings.ModulationParam1 = Eeprom.EepromData.ModulationParams.Params.Gfsk.BitRate;
GregCr 0:e5420f1a8a1a 289 Eeprom.EepromData.DemoSettings.ModulationParam2 = Eeprom.EepromData.ModulationParams.Params.Gfsk.Fdev;
GregCr 0:e5420f1a8a1a 290 Eeprom.EepromData.DemoSettings.ModulationParam3 = Eeprom.EepromData.ModulationParams.Params.Gfsk.ModulationShaping;
GregCr 0:e5420f1a8a1a 291 Eeprom.EepromData.DemoSettings.ModulationParam4 = Eeprom.EepromData.ModulationParams.Params.Gfsk.Bandwidth;
GregCr 0:e5420f1a8a1a 292
GregCr 0:e5420f1a8a1a 293 Eeprom.EepromData.DemoSettings.PacketParam1 = Eeprom.EepromData.PacketParams.Params.Gfsk.PreambleLength;
GregCr 0:e5420f1a8a1a 294 Eeprom.EepromData.DemoSettings.PacketParam2 = Eeprom.EepromData.PacketParams.Params.Gfsk.PreambleMinDetect;
GregCr 0:e5420f1a8a1a 295 Eeprom.EepromData.DemoSettings.PacketParam3 = Eeprom.EepromData.PacketParams.Params.Gfsk.SyncWordLength;
GregCr 0:e5420f1a8a1a 296 Eeprom.EepromData.DemoSettings.PacketParam4 = Eeprom.EepromData.PacketParams.Params.Gfsk.AddrComp;
GregCr 0:e5420f1a8a1a 297 Eeprom.EepromData.DemoSettings.PacketParam5 = Eeprom.EepromData.PacketParams.Params.Gfsk.HeaderType;
GregCr 0:e5420f1a8a1a 298 Eeprom.EepromData.DemoSettings.PacketParam6 = Eeprom.EepromData.PacketParams.Params.Gfsk.PayloadLength;
GregCr 0:e5420f1a8a1a 299
GregCr 0:e5420f1a8a1a 300 Eeprom.EepromData.DemoSettings.PacketParam7 = Eeprom.EepromData.PacketParams.Params.Gfsk.CrcLength;
GregCr 0:e5420f1a8a1a 301 Eeprom.EepromData.DemoSettings.PacketParam8 = Eeprom.EepromData.PacketParams.Params.Gfsk.DcFree;
GregCr 0:e5420f1a8a1a 302 }
GregCr 0:e5420f1a8a1a 303
GregCr 0:e5420f1a8a1a 304 Eeprom.EepromData.DemoSettings.ModulationType = modulation;
GregCr 0:e5420f1a8a1a 305 }
GregCr 0:e5420f1a8a1a 306
GregCr 0:e5420f1a8a1a 307 void EepromSetDefaultSettings( uint8_t deviceConnected )
GregCr 0:e5420f1a8a1a 308 {
GregCr 0:e5420f1a8a1a 309 Eeprom.EepromData.MenuSettings.ScreenCalibrated = false;
GregCr 0:e5420f1a8a1a 310
GregCr 0:e5420f1a8a1a 311 printf("Set Default Settings\n\r");
GregCr 0:e5420f1a8a1a 312 EepromSaveSettings( SCREEN_DATA );
GregCr 0:e5420f1a8a1a 313
GregCr 0:e5420f1a8a1a 314 Eeprom.EepromData.DemoSettings.ModulationType = PACKET_TYPE_LORA;
GregCr 0:e5420f1a8a1a 315 Eeprom.EepromData.ModulationParams.PacketType = PACKET_TYPE_LORA;
GregCr 0:e5420f1a8a1a 316 Eeprom.EepromData.PacketParams.PacketType = PACKET_TYPE_LORA;
GregCr 0:e5420f1a8a1a 317
GregCr 0:e5420f1a8a1a 318 Eeprom.EepromData.DemoSettings.ModulationParam1 = LORA_SF7;
GregCr 0:e5420f1a8a1a 319 Eeprom.EepromData.DemoSettings.ModulationParam2 = LORA_BW_500;
GregCr 0:e5420f1a8a1a 320 Eeprom.EepromData.DemoSettings.ModulationParam3 = LORA_CR_4_5;
GregCr 0:e5420f1a8a1a 321 Eeprom.EepromData.DemoSettings.ModulationParam4 = 0x00;
GregCr 0:e5420f1a8a1a 322
GregCr 0:e5420f1a8a1a 323 Eeprom.EepromData.DemoSettings.PacketParam1 = 8; // PreambleLength
GregCr 0:e5420f1a8a1a 324 Eeprom.EepromData.DemoSettings.PacketParam2 = LORA_PACKET_VARIABLE_LENGTH;
GregCr 0:e5420f1a8a1a 325 Eeprom.EepromData.DemoSettings.PacketParam3 = 16; // PayloadLength
GregCr 0:e5420f1a8a1a 326 Eeprom.EepromData.DemoSettings.PacketParam4 = LORA_CRC_ON;
GregCr 0:e5420f1a8a1a 327 Eeprom.EepromData.DemoSettings.PacketParam5 = LORA_IQ_NORMAL;
GregCr 0:e5420f1a8a1a 328
GregCr 0:e5420f1a8a1a 329 EepromSaveSettings( RADIO_LORA_PARAMS );
GregCr 0:e5420f1a8a1a 330
GregCr 0:e5420f1a8a1a 331 Eeprom.EepromData.DemoSettings.ModulationType = PACKET_TYPE_GFSK;
GregCr 0:e5420f1a8a1a 332 Eeprom.EepromData.ModulationParams.PacketType = PACKET_TYPE_GFSK;
GregCr 0:e5420f1a8a1a 333 Eeprom.EepromData.PacketParams.PacketType = PACKET_TYPE_GFSK;
GregCr 0:e5420f1a8a1a 334
GregCr 0:e5420f1a8a1a 335 Eeprom.EepromData.DemoSettings.ModulationParam1 = 19200;
GregCr 0:e5420f1a8a1a 336 Eeprom.EepromData.DemoSettings.ModulationParam2 = 5000;
GregCr 0:e5420f1a8a1a 337 Eeprom.EepromData.DemoSettings.ModulationParam3 = MOD_SHAPING_G_BT_1;
GregCr 0:e5420f1a8a1a 338 Eeprom.EepromData.DemoSettings.ModulationParam4 = RX_BW_39000;
GregCr 0:e5420f1a8a1a 339
GregCr 0:e5420f1a8a1a 340 Eeprom.EepromData.DemoSettings.PacketParam1 = 40;
GregCr 0:e5420f1a8a1a 341 Eeprom.EepromData.DemoSettings.PacketParam2 = RADIO_PREAMBLE_DETECTOR_08_BITS;
GregCr 0:e5420f1a8a1a 342 Eeprom.EepromData.DemoSettings.PacketParam3 = 4;
GregCr 0:e5420f1a8a1a 343 Eeprom.EepromData.DemoSettings.PacketParam4 = RADIO_ADDRESSCOMP_FILT_OFF;
GregCr 0:e5420f1a8a1a 344 Eeprom.EepromData.DemoSettings.PacketParam5 = RADIO_PACKET_VARIABLE_LENGTH;
GregCr 0:e5420f1a8a1a 345 Eeprom.EepromData.DemoSettings.PacketParam6 = 16; // PayloadLength
GregCr 0:e5420f1a8a1a 346 Eeprom.EepromData.DemoSettings.PacketParam7 = RADIO_CRC_2_BYTES_CCIT;
GregCr 0:e5420f1a8a1a 347 Eeprom.EepromData.DemoSettings.PacketParam8 = RADIO_DC_FREE_OFF;
GregCr 0:e5420f1a8a1a 348
GregCr 0:e5420f1a8a1a 349 EepromSaveSettings( RADIO_GFSK_PARAMS );
GregCr 0:e5420f1a8a1a 350
GregCr 0:e5420f1a8a1a 351 Eeprom.EepromData.DemoSettings.Entity = SLAVE;
GregCr 0:e5420f1a8a1a 352 Eeprom.EepromData.DemoSettings.BoostedRx = 0x00;
GregCr 0:e5420f1a8a1a 353 if( deviceConnected == SX1261 )
GregCr 0:e5420f1a8a1a 354 {
GregCr 0:e5420f1a8a1a 355 Eeprom.EepromData.DemoSettings.LastDeviceConnected = deviceConnected;
GregCr 0:e5420f1a8a1a 356 Eeprom.EepromData.DemoSettings.RadioPowerMode = USE_DCDC;
GregCr 0:e5420f1a8a1a 357 Eeprom.EepromData.DemoSettings.Frequency = DEMO_CENTRAL_FREQ_PRESET1;
GregCr 0:e5420f1a8a1a 358 Eeprom.EepromData.DemoSettings.TxPower = SX1261_POWER_TX_MAX;
GregCr 0:e5420f1a8a1a 359 }
GregCr 0:e5420f1a8a1a 360 else
GregCr 0:e5420f1a8a1a 361 {
GregCr 0:e5420f1a8a1a 362 Eeprom.EepromData.DemoSettings.LastDeviceConnected = deviceConnected;
GregCr 0:e5420f1a8a1a 363 Eeprom.EepromData.DemoSettings.RadioPowerMode = USE_LDO;
GregCr 0:e5420f1a8a1a 364 Eeprom.EepromData.DemoSettings.Frequency = DEMO_CENTRAL_FREQ_PRESET2;
GregCr 0:e5420f1a8a1a 365 Eeprom.EepromData.DemoSettings.TxPower = SX1262_POWER_TX_MAX;
GregCr 0:e5420f1a8a1a 366 }
GregCr 0:e5420f1a8a1a 367 Eeprom.EepromData.DemoSettings.MaxNumPacket = 0x00;
GregCr 0:e5420f1a8a1a 368 Eeprom.EepromData.DemoSettings.ModulationType = PACKET_TYPE_LORA;
GregCr 0:e5420f1a8a1a 369
GregCr 0:e5420f1a8a1a 370 EepromSaveSettings( DEMO_SETTINGS );
GregCr 0:e5420f1a8a1a 371 }
GregCr 0:e5420f1a8a1a 372
GregCr 0:e5420f1a8a1a 373 /*!
GregCr 0:e5420f1a8a1a 374 * \brief Erase a page of Flash. Here used to Erase EEPROM region.
GregCr 0:e5420f1a8a1a 375 *
GregCr 0:e5420f1a8a1a 376 * \param [in] page address of page to erase
GregCr 0:e5420f1a8a1a 377 * \param [in] banks address of banks to erase
GregCr 0:e5420f1a8a1a 378 */
GregCr 0:e5420f1a8a1a 379 void FlashPageErase( uint32_t page, uint32_t banks )
GregCr 0:e5420f1a8a1a 380 {
GregCr 0:e5420f1a8a1a 381 // Check the parameters
GregCr 0:e5420f1a8a1a 382 assert_param( IS_FLASH_PAGE( page ) );
GregCr 0:e5420f1a8a1a 383 assert_param( IS_FLASH_BANK_EXCLUSIVE( banks ) );
GregCr 0:e5420f1a8a1a 384
GregCr 0:e5420f1a8a1a 385 if( ( banks & FLASH_BANK_1 ) != RESET )
GregCr 0:e5420f1a8a1a 386 {
GregCr 0:e5420f1a8a1a 387 CLEAR_BIT( FLASH->CR, FLASH_CR_BKER );
GregCr 0:e5420f1a8a1a 388 }
GregCr 0:e5420f1a8a1a 389 else
GregCr 0:e5420f1a8a1a 390 {
GregCr 0:e5420f1a8a1a 391 SET_BIT( FLASH->CR, FLASH_CR_BKER );
GregCr 0:e5420f1a8a1a 392 }
GregCr 0:e5420f1a8a1a 393
GregCr 0:e5420f1a8a1a 394 // Proceed to erase the page
GregCr 0:e5420f1a8a1a 395 MODIFY_REG( FLASH->CR, FLASH_CR_PNB, ( page << 3 ) );
GregCr 0:e5420f1a8a1a 396 SET_BIT( FLASH->CR, FLASH_CR_PER );
GregCr 0:e5420f1a8a1a 397 SET_BIT( FLASH->CR, FLASH_CR_STRT );
GregCr 0:e5420f1a8a1a 398 }
GregCr 0:e5420f1a8a1a 399
GregCr 0:e5420f1a8a1a 400 /*!
GregCr 0:e5420f1a8a1a 401 * \brief Write Eeprom to emulated EEPROM (in fact in Flash " higher address).
GregCr 0:e5420f1a8a1a 402 *
GregCr 0:e5420f1a8a1a 403 * \param [in] addr address of data (EEPROM offset not to be include)
GregCr 0:e5420f1a8a1a 404 * \param [in] buffer buffer to use for copy
GregCr 0:e5420f1a8a1a 405 * \param [in] size size of data to copy
GregCr 0:e5420f1a8a1a 406 *
GregCr 0:e5420f1a8a1a 407 * \retval status Status of operation (SUCCESS, ..)
GregCr 0:e5420f1a8a1a 408 */
GregCr 0:e5420f1a8a1a 409 uint8_t EepromMcuWriteBuffer( uint16_t addr, uint8_t *buffer, uint16_t size )
GregCr 0:e5420f1a8a1a 410 {
GregCr 0:e5420f1a8a1a 411 uint64_t *flash = ( uint64_t* )buffer;
GregCr 0:e5420f1a8a1a 412
GregCr 0:e5420f1a8a1a 413 // assert_param( addr >= DATA_EEPROM_BASE );
GregCr 0:e5420f1a8a1a 414 assert_param( buffer != NULL );
GregCr 0:e5420f1a8a1a 415 assert_param( size < ( DATA_EEPROM_END - DATA_EEPROM_BASE ) );
GregCr 0:e5420f1a8a1a 416
GregCr 0:e5420f1a8a1a 417 HAL_FLASH_Unlock( );
GregCr 0:e5420f1a8a1a 418
GregCr 0:e5420f1a8a1a 419 FlashPageErase( 255, 1 );
GregCr 0:e5420f1a8a1a 420
GregCr 0:e5420f1a8a1a 421 WRITE_REG( FLASH->CR, 0x40000000 );
GregCr 0:e5420f1a8a1a 422
GregCr 0:e5420f1a8a1a 423 for( uint32_t i = 0; i < size; i++ )
GregCr 0:e5420f1a8a1a 424 {
GregCr 0:e5420f1a8a1a 425 HAL_FLASH_Program( FLASH_TYPEPROGRAM_DOUBLEWORD, DATA_EEPROM_BASE + \
GregCr 0:e5420f1a8a1a 426 ( 8 * i ), flash[i] );
GregCr 0:e5420f1a8a1a 427 }
GregCr 0:e5420f1a8a1a 428
GregCr 0:e5420f1a8a1a 429 HAL_FLASH_Lock( );
GregCr 0:e5420f1a8a1a 430
GregCr 0:e5420f1a8a1a 431 return SUCCESS;
GregCr 0:e5420f1a8a1a 432 }
GregCr 0:e5420f1a8a1a 433
GregCr 0:e5420f1a8a1a 434 uint8_t EepromMcuReadBuffer( uint16_t addr, uint8_t *buffer, uint16_t size )
GregCr 0:e5420f1a8a1a 435 {
GregCr 0:e5420f1a8a1a 436 assert_param( buffer != NULL );
GregCr 0:e5420f1a8a1a 437
GregCr 0:e5420f1a8a1a 438 // assert_param( addr >= DATA_EEPROM_BASE );
GregCr 0:e5420f1a8a1a 439 assert_param( buffer != NULL );
GregCr 0:e5420f1a8a1a 440 assert_param( size < ( DATA_EEPROM_END - DATA_EEPROM_BASE ) );
GregCr 0:e5420f1a8a1a 441
GregCr 0:e5420f1a8a1a 442 memcpy( buffer, ( uint8_t* )DATA_EEPROM_BASE, size );
GregCr 0:e5420f1a8a1a 443 return SUCCESS;
GregCr 0:e5420f1a8a1a 444 }
GregCr 0:e5420f1a8a1a 445
GregCr 0:e5420f1a8a1a 446 static MemTestStruct_t EepromDataCheckSum( void )
GregCr 0:e5420f1a8a1a 447 {
GregCr 0:e5420f1a8a1a 448 MemTestStruct_t memTestStruct;
GregCr 0:e5420f1a8a1a 449 uint8_t x;
GregCr 0:e5420f1a8a1a 450 uint8_t i;
GregCr 0:e5420f1a8a1a 451 uint16_t crcBuf;
GregCr 0:e5420f1a8a1a 452 memTestStruct.Value = 0xFFFF;
GregCr 0:e5420f1a8a1a 453
GregCr 0:e5420f1a8a1a 454 for( i = 0; i < EEPROM_BUFFER_SIZE - sizeof( uint16_t ); i++ )
GregCr 0:e5420f1a8a1a 455 {
GregCr 0:e5420f1a8a1a 456 x = memTestStruct.Value >> 8 ^ Eeprom.Buffer[i];
GregCr 0:e5420f1a8a1a 457 x ^= x >> 4;
GregCr 0:e5420f1a8a1a 458 memTestStruct.Value = ( memTestStruct.Value << 8 ) ^ \
GregCr 0:e5420f1a8a1a 459 ( ( uint16_t )( x << 12 ) ) ^ \
GregCr 0:e5420f1a8a1a 460 ( ( uint16_t )( x << 5 ) ) ^ \
GregCr 0:e5420f1a8a1a 461 ( ( uint16_t )x );
GregCr 0:e5420f1a8a1a 462 }
GregCr 0:e5420f1a8a1a 463 memcpy( &crcBuf, Eeprom.Buffer + EEPROM_CRC_EEPROM_ADDR, 2 );
GregCr 0:e5420f1a8a1a 464 memTestStruct.Valid = ( crcBuf == memTestStruct.Value );
GregCr 0:e5420f1a8a1a 465
GregCr 0:e5420f1a8a1a 466 return memTestStruct;
GregCr 0:e5420f1a8a1a 467 }