wave spectrum / Mbed 2 deprecated SX126xDevKit

Dependencies:   mbed SX126xLib

Committer:
wavespectrum
Date:
Thu Feb 11 18:41:12 2021 +0000
Revision:
5:136f7396c552
Parent:
2:8e1b4210df6b
Child:
8:cdb739697925
ticker timer used;

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