zephyr: Flash memory partitions not being initialized correctly by settings_subsys_init()
I believe this to be related to #19880
Describe the bug I am attempting to implement the CANopenNode library in Zephyr into my project, but is having issues creating the NVS needed for the EEPROM part. My device is the stm32f4_disco, and I have added the following to the device tree file:
&flash0 {
/* FLASH memory layout in reference manual Table 5. */
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
/*
* Used by CANopen for the Object Dictionary.
* 32 kB at sectors 0 and 1 (each 16 kB large).
* Two sectors must be used for NVS.
*/
storage_partition: partition@800000 {
label = "storage";
reg = <0x800000 0x00008000>;
};
};
};
and is using a prj.conf with these relevant parameters (inspired by the CANopen examples):
# CAN Settings
CONFIG_CAN=y
CONFIG_CAN_MAX_FILTER=13
# Memory settings, used for CANopen
CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_NVS=y
CONFIG_SETTINGS=y
CONFIG_SETTINGS_NVS=y
CONFIG_MPU_ALLOW_FLASH_WRITE=y
# CANopen settings
CONFIG_CANOPEN=y
CONFIG_CANOPEN_SYNC_THREAD=y
CONFIG_CANOPEN_STORAGE=y
The project compiles but when running settings_subsys_init() I get error -EDOM.
This seems to be because hw_flash_sector does not get updated with values during the call to rc = flash_area_get_sectors(DT_FLASH_AREA_STORAGE_ID, §or_cnt, &hw_flash_sector);
int flash_area_get_sectors(int idx, u32_t *cnt, struct flash_sector *ret)
{
struct layout_data data;
return flash_area_layout(idx, cnt, ret, get_sectors_cb, &data);
}
Where an inaccessible layout_data does get populated with data matching my setup in the dts file.
It seems as if the data stored in layout_data should instead be stored in hw_flash_sector (ret), as this is the one getting checked for sector size.
nvs_sector_size = CONFIG_SETTINGS_NVS_SECTOR_SIZE_MULT *
hw_flash_sector.fs_size;
if (nvs_sector_size > UINT16_MAX) {
return -EDOM;
}
Expected behavior
settings_subsys_init() returns 0.
Impact Annoyance. I can just not check if the subsys initialization worked, but that seems rather risky…
Environment (please complete the following information):
- OS: Fedora 31
- Toolchain: Zephyr SDK managed by platformio
- Zephyr v2.2
Additional context
When debugging this, I can see that the Object Dictionary provided is indeed correct, but is stored completely in SRAM. I am unsure if this is due to the initialization not completing.
Additionally it seems that
CONFIG_SETTINGS_NVS_SECTOR_SIZE_MULT = 1
About this issue
- Original URL
- State: open
- Created 4 years ago
- Comments: 31
I was reading the STM32H7A3/B3 and B0 manual, for the STM32H742/743/753 devices the sector size indeed seems to be 128kB.
Slack access isn’t limited, there is an open invite linked on this page. https://docs.zephyrproject.org/latest/guides/getting-help.html
Actual invite link https://tinyurl.com/y5glwylp
I am unable to sign in to this slack, as I am not affiliated with any of the listed companies.