Added support for storing settings in FLASH.

master
marcel 3 years ago
parent b6eec82d6c
commit cc24f9d531
  1. 18
      CHANGELOG.md
  2. 22
      build/src/CMakeFiles/main.dir/CXX.includecache
  3. 3
      build/src/CMakeFiles/main.dir/depend.internal
  4. 3
      build/src/CMakeFiles/main.dir/depend.make
  5. BIN
      build/src/CMakeFiles/main.dir/main.cpp.obj
  6. BIN
      build/src/main.bin
  7. 52495
      build/src/main.dis
  8. BIN
      build/src/main.elf
  9. 1678
      build/src/main.elf.map
  10. 7562
      build/src/main.hex
  11. BIN
      build/src/main.uf2
  12. 18
      src/Config.h
  13. 74
      src/main.cpp

@ -0,0 +1,18 @@
# Changelog
All notable changes to this project will be documented in this file.
Added : for new features.
Changed : for changes in existing functionality.
Deprecated: for soon-to-be removed features.
Removed : for now removed features.
Fixed : for any bug fixes.
Security : in case of vulnerabilities.
## [1.0.0] - pre 2022-05-12
First (more or less) working version.
## [1.0.1] - 2022-05-12
### Added
- Support for saving settings to internal FLASH

@ -148,6 +148,16 @@ pico.h
hardware/regs/addressmap.h
../pico-sdk/src/rp2_common/hardware_base/include/hardware/hardware/regs/addressmap.h
../pico-sdk/src/rp2_common/hardware_claim/include/hardware/claim.h
pico.h
../pico-sdk/src/rp2_common/hardware_claim/include/hardware/pico.h
hardware/sync.h
../pico-sdk/src/rp2_common/hardware_claim/include/hardware/hardware/sync.h
../pico-sdk/src/rp2_common/hardware_flash/include/hardware/flash.h
pico.h
../pico-sdk/src/rp2_common/hardware_flash/include/hardware/pico.h
../pico-sdk/src/rp2_common/hardware_gpio/include/hardware/gpio.h
pico.h
../pico-sdk/src/rp2_common/hardware_gpio/include/hardware/pico.h
@ -166,6 +176,14 @@ hardware/structs/spi.h
hardware/regs/dreq.h
../pico-sdk/src/rp2_common/hardware_spi/include/hardware/hardware/regs/dreq.h
../pico-sdk/src/rp2_common/hardware_sync/include/hardware/sync.h
pico.h
../pico-sdk/src/rp2_common/hardware_sync/include/hardware/pico.h
hardware/address_mapped.h
../pico-sdk/src/rp2_common/hardware_sync/include/hardware/hardware/address_mapped.h
hardware/regs/sio.h
../pico-sdk/src/rp2_common/hardware_sync/include/hardware/hardware/regs/sio.h
../pico-sdk/src/rp2_common/hardware_timer/include/hardware/timer.h
pico.h
../pico-sdk/src/rp2_common/hardware_timer/include/hardware/pico.h
@ -237,12 +255,16 @@ pico/stdlib.h
/home/marcel/Documents/electronische_projecten/lora_aprs_node_pico/src/pico/stdlib.h
pico/binary_info.h
/home/marcel/Documents/electronische_projecten/lora_aprs_node_pico/src/pico/binary_info.h
hardware/flash.h
/home/marcel/Documents/electronische_projecten/lora_aprs_node_pico/src/hardware/flash.h
LoRa-RP2040.h
/home/marcel/Documents/electronische_projecten/lora_aprs_node_pico/src/LoRa-RP2040.h
Config.h
/home/marcel/Documents/electronische_projecten/lora_aprs_node_pico/src/Config.h
KISS.h
/home/marcel/Documents/electronische_projecten/lora_aprs_node_pico/src/KISS.h
hardware/claim.h
/home/marcel/Documents/electronische_projecten/lora_aprs_node_pico/src/hardware/claim.h
generated/pico_base/pico/config_autogen.h
/home/marcel/Documents/electronische_projecten/lora_aprs_node_pico/pico-sdk/src/boards/include/boards/pico.h

@ -2162,8 +2162,11 @@ src/CMakeFiles/main.dir/main.cpp.obj
../pico-sdk/src/rp2040/hardware_structs/include/hardware/structs/timer.h
../pico-sdk/src/rp2040/hardware_structs/include/hardware/structs/uart.h
../pico-sdk/src/rp2_common/hardware_base/include/hardware/address_mapped.h
../pico-sdk/src/rp2_common/hardware_claim/include/hardware/claim.h
../pico-sdk/src/rp2_common/hardware_flash/include/hardware/flash.h
../pico-sdk/src/rp2_common/hardware_gpio/include/hardware/gpio.h
../pico-sdk/src/rp2_common/hardware_spi/include/hardware/spi.h
../pico-sdk/src/rp2_common/hardware_sync/include/hardware/sync.h
../pico-sdk/src/rp2_common/hardware_timer/include/hardware/timer.h
../pico-sdk/src/rp2_common/hardware_uart/include/hardware/uart.h
../pico-sdk/src/rp2_common/pico_platform/include/pico/platform.h

@ -2161,8 +2161,11 @@ src/CMakeFiles/main.dir/main.cpp.obj: ../pico-sdk/src/rp2040/hardware_structs/in
src/CMakeFiles/main.dir/main.cpp.obj: ../pico-sdk/src/rp2040/hardware_structs/include/hardware/structs/timer.h
src/CMakeFiles/main.dir/main.cpp.obj: ../pico-sdk/src/rp2040/hardware_structs/include/hardware/structs/uart.h
src/CMakeFiles/main.dir/main.cpp.obj: ../pico-sdk/src/rp2_common/hardware_base/include/hardware/address_mapped.h
src/CMakeFiles/main.dir/main.cpp.obj: ../pico-sdk/src/rp2_common/hardware_claim/include/hardware/claim.h
src/CMakeFiles/main.dir/main.cpp.obj: ../pico-sdk/src/rp2_common/hardware_flash/include/hardware/flash.h
src/CMakeFiles/main.dir/main.cpp.obj: ../pico-sdk/src/rp2_common/hardware_gpio/include/hardware/gpio.h
src/CMakeFiles/main.dir/main.cpp.obj: ../pico-sdk/src/rp2_common/hardware_spi/include/hardware/spi.h
src/CMakeFiles/main.dir/main.cpp.obj: ../pico-sdk/src/rp2_common/hardware_sync/include/hardware/sync.h
src/CMakeFiles/main.dir/main.cpp.obj: ../pico-sdk/src/rp2_common/hardware_timer/include/hardware/timer.h
src/CMakeFiles/main.dir/main.cpp.obj: ../pico-sdk/src/rp2_common/hardware_uart/include/hardware/uart.h
src/CMakeFiles/main.dir/main.cpp.obj: ../pico-sdk/src/rp2_common/pico_platform/include/pico/platform.h

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

@ -60,14 +60,18 @@
const uint8_t SIG_SYNCED = 0x02;
const uint8_t RX_ONGOING = 0x04;
// The size of this struc should be a exactly 256 bytes, which is the FLASH_PAGE_SIZE of the RPi pico's flash memory
struct aprssettings {
uint8_t MyCall[10] = { 'P','E','1','R','X','F','-','5', 0} ;
uint8_t ServerCall[10] = { 'P','E','1','R','X','F','-','3', 0} ;
uint8_t Destination[10] = { 'A','P','Z','M','D','M', 0} ;
uint8_t Path1[10] = { 0,'I','D','E','1','-', '1', 0} ;
uint8_t Path2[10] = { 0,'I','D','E','2','-', '2', 0} ;
uint8_t FirmwareVersion[20] = { 'V','1',',','C','o','n','t','r', 'o','l','l','e','r',' ','0','1', 0} ;
uint8_t ValidFlashData = 0x5A; // Indicates flash contains valid data - 1 bytes
uint8_t MyCall[10] = { 'N','O','C','A','L','L','-','2', 0} ; // 10 bytes
uint8_t ServerCall[10] = { 'N','O','C','A','L','L','-','1', 0} ; // 10 bytes
uint8_t Destination[10] = { 'A','P','Z','M','D','M', 0} ; // 10 bytes
uint8_t Path1[10] = { 0,'I','D','E','1','-', '1', 0} ; // 10 bytes
uint8_t Path2[10] = { 0,'I','D','E','2','-', '2', 0} ; // 10 bytes
uint8_t FirmwareVersion[20] = { 'V','1',',','C','o','n','t','r', 'o','l','l','e','r',' ','0','1', 0} ; // 20 bytes
// 71 bytes total
uint8_t FillerData[256-71];
} AprsSettings;
struct status {

@ -3,12 +3,13 @@
#include <time.h>
#include "pico/stdlib.h"
#include "pico/binary_info.h"
#include "hardware/flash.h"
#include "LoRa-RP2040.h"
#include "Config.h"
#include "KISS.h"
#include "hardware/claim.h"
bool startRadio();
bool LoadSettings();
void getPacketData(int packetLength);
int compare_strings(uint8_t a[], uint8_t b[]);
bool is_message_for_me (uint8_t data[], uint8_t mycall[]);
@ -27,14 +28,49 @@ const uint PowerSupply5VControl = 4;
const uint RelayOffControl = 2;
const uint RelayOnControl = 3;
int main() {
// We're going to use a region 256k from the start of flash as non volatile storage for our settings.
// We can access this at XIP_BASE + 256k.
#define FLASH_TARGET_OFFSET (512 * 1024)
const uint8_t *flash_target_contents = (const uint8_t *) (XIP_BASE + FLASH_TARGET_OFFSET);
uint8_t ReadSettingsFromFlash(void)
{
uint16_t ServerCommand = 0;
uint16_t TxDelay = 0;
/* Among others, this initializes the USB-serial port at 115200bps 8N1 */
// If byte zero of flash contains 0x5A we assume the data to be valid, otherwise we fill the flash with default values.
if (flash_target_contents[0] != 0x5A)
{
printf( "No valid data found in FLASH memory.\n" );
memset(AprsSettings.FillerData, 0, sizeof(AprsSettings.FillerData));
uint32_t ints = save_and_disable_interrupts();
// First we erase the FLASH sector we need. After that we can store new values.
// Note that a whole number of sectors must be erased at a time.
// Sector size is 4kB, so this is way bigger than the needed 256 bytes for storing the settings.
printf("Erasing FLASH region...");
flash_range_erase(FLASH_TARGET_OFFSET, FLASH_SECTOR_SIZE);
printf("done\n");
printf("Writing default values to FLASH...");
flash_range_program(FLASH_TARGET_OFFSET, (uint8_t*)&AprsSettings, FLASH_PAGE_SIZE);
printf("done\n");
restore_interrupts (ints);
} else {
// Read settings stored in flash memory
printf("Found valid settings in FLASH memory.\n");
}
memcpy((uint8_t*)&AprsSettings, flash_target_contents, FLASH_PAGE_SIZE);
printf("APRS settings:\n");
printf("My call: %s\n", AprsSettings.MyCall);
printf("Server call: %s\n", AprsSettings.ServerCall);
printf("Firmware: %s\n",AprsSettings.FirmwareVersion);
}
void setup(void)
{
/* Among others, this initializes the USB-serial port at 115200bps 8N1 */
stdio_init_all();
// Buffers
memset(rxBuffer, 0, sizeof(rxBuffer));
memset(txBuffer, 0, sizeof(txBuffer));
@ -63,12 +99,20 @@ int main() {
gpio_put(RelayOffControl, 0);
gpio_put(RelayOnControl, 0);
Status.ControlRelay = OFF;
sleep_ms(5000);
LoadSettings();
ReadSettingsFromFlash();
startRadio();
}
int main() {
uint16_t ServerCommand = 0;
uint16_t TxDelay = 0;
setup();
while (1) {
int packetSize = LoRa.parsePacket();
@ -196,16 +240,6 @@ int main() {
return 0;
}
/*
* Load settings from EEPROM
*/
bool LoadSettings()
{
printf("APRS settings:\n");
printf("My call: %s\n", AprsSettings.MyCall);
printf("Server call: %s\n", AprsSettings.ServerCall);
}
/*
* Initializes the LoRa module with the parameters set in config.h
*/

Loading…
Cancel
Save