mirror of
https://github.com/thelsing/knx.git
synced 2025-08-22 13:46:21 +02:00
added support for EEPROM-Emulation / RAM-buffered Flash
improvements in RP2040 plattform
This commit is contained in:
parent
6ad8bd64e5
commit
fe5a542301
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#ifndef KNX_FLASH_SIZE
|
#ifndef KNX_FLASH_SIZE
|
||||||
#define KNX_FLASH_SIZE 1024
|
#define KNX_FLASH_SIZE 1024
|
||||||
|
#pragma warning "KNX_FLASH_SIZE not defined, using 1024"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
enum NvMemoryType
|
enum NvMemoryType
|
||||||
|
@ -10,10 +10,13 @@ by Earl E. Philhower III https://github.com/earlephilhower/arduino-pico V1.11.0
|
|||||||
RTTI must be set to enabled in the board options
|
RTTI must be set to enabled in the board options
|
||||||
|
|
||||||
Uses direct flash reading/writing.
|
Uses direct flash reading/writing.
|
||||||
Size ist defined by KNX_FLASH_SIZE (default 4k).
|
Size ist defined by KNX_FLASH_SIZE (default 4k) - must be a multiple of 4096.
|
||||||
Offset in Flash is defined by KNX_FLASH_OFFSET (default 1,5MiB / 0x180000).
|
Offset in Flash is defined by KNX_FLASH_OFFSET (default 1,5MiB / 0x180000) - must be a multiple of 4096.
|
||||||
|
|
||||||
EEPROM Emulation from arduino-pico core (max 4k) can be use by defining USE_RP2040_EEPROM_EMULATION
|
EEPROM Emulation from arduino-pico core (max 4k) can be use by defining USE_RP2040_EEPROM_EMULATION
|
||||||
|
|
||||||
|
A RAM-buffered Flash can be use by defining USE_RP2040_LARGE_EEPROM_EMULATION
|
||||||
|
|
||||||
|
|
||||||
----------------------------------------------------*/
|
----------------------------------------------------*/
|
||||||
|
|
||||||
@ -30,6 +33,16 @@ EEPROM Emulation from arduino-pico core (max 4k) can be use by defining USE_RP20
|
|||||||
#include <hardware/watchdog.h> // from Pico SDK
|
#include <hardware/watchdog.h> // from Pico SDK
|
||||||
#include <hardware/flash.h> // from Pico SDK
|
#include <hardware/flash.h> // from Pico SDK
|
||||||
|
|
||||||
|
#define FLASHPTR ((uint8_t*)XIP_BASE + KNX_FLASH_OFFSET)
|
||||||
|
|
||||||
|
#if KNX_FLASH_SIZE%4096
|
||||||
|
#error "KNX_FLASH_SIZE must be multiple of 4096"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if KNX_FLASH_SIZE%4096
|
||||||
|
#error "KNX_FLASH_OFFSET must be multiple of 4096"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
RP2040ArduinoPlatform::RP2040ArduinoPlatform()
|
RP2040ArduinoPlatform::RP2040ArduinoPlatform()
|
||||||
#ifndef KNX_NO_DEFAULT_UART
|
#ifndef KNX_NO_DEFAULT_UART
|
||||||
@ -82,6 +95,43 @@ void RP2040ArduinoPlatform::restart()
|
|||||||
|
|
||||||
#pragma warning "Using EEPROM Simulation"
|
#pragma warning "Using EEPROM Simulation"
|
||||||
|
|
||||||
|
#ifdef USE_RP2040_LARGE_EEPROM_EMULATION
|
||||||
|
|
||||||
|
uint8_t * RP2040ArduinoPlatform::getEepromBuffer(uint16_t size)
|
||||||
|
{
|
||||||
|
if(size%4096)
|
||||||
|
{
|
||||||
|
println("KNX_FLASH_SIZE must be a multiple of 4096");
|
||||||
|
fatalError();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!_rambuff_initialized)
|
||||||
|
{
|
||||||
|
memcpy(_rambuff, FLASHPTR, KNX_FLASH_SIZE);
|
||||||
|
_rambuff_initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _rambuff;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RP2040ArduinoPlatform::commitToEeprom()
|
||||||
|
{
|
||||||
|
noInterrupts();
|
||||||
|
rp2040.idleOtherCore();
|
||||||
|
|
||||||
|
//ToDo: write block-by-block to prevent writing of untouched blocks
|
||||||
|
if(memcmp(_rambuff, FLASHPTR, KNX_FLASH_SIZE))
|
||||||
|
{
|
||||||
|
flash_range_erase (KNX_FLASH_OFFSET, KNX_FLASH_SIZE);
|
||||||
|
flash_range_program(KNX_FLASH_OFFSET, _rambuff, KNX_FLASH_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
rp2040.resumeOtherCore();
|
||||||
|
interrupts();
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
uint8_t * RP2040ArduinoPlatform::getEepromBuffer(uint16_t size)
|
uint8_t * RP2040ArduinoPlatform::getEepromBuffer(uint16_t size)
|
||||||
{
|
{
|
||||||
if(size > 4096)
|
if(size > 4096)
|
||||||
@ -106,6 +156,8 @@ void RP2040ArduinoPlatform::commitToEeprom()
|
|||||||
EEPROM.commit();
|
EEPROM.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
size_t RP2040ArduinoPlatform::flashEraseBlockSize()
|
size_t RP2040ArduinoPlatform::flashEraseBlockSize()
|
||||||
|
@ -6,10 +6,11 @@
|
|||||||
|
|
||||||
#ifndef KNX_FLASH_OFFSET
|
#ifndef KNX_FLASH_OFFSET
|
||||||
#define KNX_FLASH_OFFSET 0x180000 // 1.5MiB
|
#define KNX_FLASH_OFFSET 0x180000 // 1.5MiB
|
||||||
|
#pragma warning "KNX_FLASH_OFFSET not defined, using 0x180000"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef KNX_FLASH_SIZE
|
#ifdef USE_RP2040_LARGE_EEPROM_EMULATION
|
||||||
#define KNX_FLASH_SIZE 1024
|
#define USE_RP2040_EEPROM_EMULATION
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@ -29,6 +30,11 @@ public:
|
|||||||
#ifdef USE_RP2040_EEPROM_EMULATION
|
#ifdef USE_RP2040_EEPROM_EMULATION
|
||||||
uint8_t* getEepromBuffer(uint16_t size);
|
uint8_t* getEepromBuffer(uint16_t size);
|
||||||
void commitToEeprom();
|
void commitToEeprom();
|
||||||
|
|
||||||
|
#ifdef USE_RP2040_LARGE_EEPROM_EMULATION
|
||||||
|
uint8_t _rambuff[KNX_FLASH_SIZE];
|
||||||
|
bool _rambuff_initialized = false;
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
|
|
||||||
// size of one EraseBlock in pages
|
// size of one EraseBlock in pages
|
||||||
|
Loading…
Reference in New Issue
Block a user