pico_flash_param
Release 1.0.1
#pragma once
#include "FlashParam.h"
struct ConfigParam : FlashParamNs::FlashParam {
static ConfigParam& instance() // Singleton
{
static ConfigParam instance;
return instance;
}
static constexpr uint32_t ID_BASE = FlashParamNs::CFG_ID_BASE;
// Parameter<T> instance id name default size
FlashParamNs::Parameter<std::string> P_CFG_STRING {ID_BASE + 0, "CFG_STRING", "abcdefg", 16}; // std::string needs size
FlashParamNs::Parameter<bool> P_CFG_BOOL {ID_BASE + 1, "CFG_BOOL", false};
FlashParamNs::Parameter<uint8_t> P_CFG_UINT8 {ID_BASE + 2, "CFG_UINT8", 23};
FlashParamNs::Parameter<uint16_t> P_CFG_UINT16 {ID_BASE + 3, "CFG_UINT16", 4096};
FlashParamNs::Parameter<uint32_t> P_CFG_UINT32 {ID_BASE + 4, "CFG_UINT32", 65535*4};
FlashParamNs::Parameter<uint64_t> P_CFG_UINT64 {ID_BASE + 5, "CFG_UINT64", 1ULL<<40};
FlashParamNs::Parameter<int8_t> P_CFG_INT8 {ID_BASE + 6, "CFG_INT8", -16};
FlashParamNs::Parameter<int16_t> P_CFG_INT16 {ID_BASE + 7, "CFG_INT16", -2047};
FlashParamNs::Parameter<int32_t> P_CFG_INT32 {ID_BASE + 8, "CFG_INT32", -65536*5};
FlashParamNs::Parameter<int64_t> P_CFG_INT64 {ID_BASE + 9, "CFG_INT64", -(1LL<<35)};
FlashParamNs::Parameter<float> P_CFG_FLOAT {ID_BASE + 10, "CFG_FLOAT", 3.326f};
FlashParamNs::Parameter<double> P_CFG_DOUBLE {ID_BASE + 11, "CFG_DOUBLE", -1.056e-8};
};
ConfigParam cfgParam& = ConfigParam.instance();
cfgParam.initialize();
cfgParam.finalize();
cfgParam.loadDefault();
cfgParam.printInfo();
=== UserFlash ===
FlashSize: 0x200000 (2097152d)
SectorSize: 0x1000 (4096d)
PageSize: 0x100 (256d)
UserReqSize: 0x400 (1024d)
EraseSize: 0x1000 (4096d)
PageProgSize: 0x400 (1024d)
UserFlashOfs: 0x1ff000
UserFlashReadAddr: 0x101ff000
=== FlashParam ===
0x0000 CFG_MAP_HASH: 3015833569d (0xb3c1f7e1)
0x0004 CFG_STORE_COUNT: 67d (0x43)
0x0008 CFG_STRING: abcdefg
0x0018 CFG_BOOL: false
0x0019 CFG_UINT8: 23d (0x17)
0x001a CFG_UINT16: 4096d (0x1000)
0x001c CFG_UINT32: 262140d (0x3fffc)
0x0020 CFG_UINT64: 1099511627776d (0x10000000000)
0x0028 CFG_INT8: 240d (0xf0)
0x0029 CFG_INT16: -2047d (0xf801)
0x002b CFG_INT32: -327680d (0xfffb0000)
0x002f CFG_INT64: -34359738368d (0xfffffff800000000)
0x0037 CFG_FLOAT: 3.3260 (3.3260e+00)
0x003b CFG_DOUBLE: -0.0000 (-1.0560e-08)
uint16_t في الحالة التاليةset() ، ومع ذلك ، لم يتم تخزينها بعد إلى الفلاش حتى يتم استدعاء () cfgParam.P_CFG_UINT16.set(0x89abcdef);
const auto& value = cfgParam.P_CFG_UINT16.get();
setValue<T>() ، ومع ذلك ، لم يتم تخزينها بعد حتى يتم استدعاءها حتى يتم استدعاء () cfgParam.setValue<uint16_t>(cfgParam.ID_BASE + 3, 0x0123);
const auto& value = cfgParam.getValue<uint16_t>(cfgParam.ID_BASE + 3);
هناك نوعان من المعلمات في المكتبة. عادةً ما يتم إنشاء هذه القيم تلقائيًا أو تحديثها في المكتبة.
finalize() . flash_safe_execute_core_init() من Core1 لإخطار حالة آمنة للبرمجةcfgParam.finalize() بسبب faulure of UserFlash::program() ...
#include "pico/flash.h"
#include "pico/multicore.h"
static void core1_process() {
flash_safe_execute_core_init(); // notify core0 that there's no access to flash on core1
...
}
int main() {
...
multicore_launch_core1(core1_process);
...
}
> git clone -b 2.0.0 https://github.com/raspberrypi/pico-sdk.git
> cd pico-sdk
> git submodule update -i
> cd ..
> git clone -b sdk-2.0.0 https://github.com/raspberrypi/pico-examples.git
>
> git clone -b sdk-2.0.0 https://github.com/raspberrypi/pico-extras.git
>
> git clone -b main https://github.com/elehobica/pico_user_flash.git
> cd pico_user_flash
> cd samplesxxxxx # target sample project
> cd ..
> mkdir build && cd build
> cmake -G "NMake Makefiles" ..
> nmake
$ mkdir build && cd build
$ cmake ..
$ make -j4