Source code for the SX126xDVK1xAS Dev Kit. This example code has only been tested on the Nucleo L476RG

Dependencies:   mbed DmTftLibrary SX126xLib

Committer:
mantoine
Date:
Mon Jan 07 23:02:45 2019 +0100
Revision:
3:c3ab10127815
Parent:
2:8e1b4210df6b
Updated erroneous path to SX126xLib library.

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