Hello,
I've recently been porting a program over to Zephyr and hoping someone here might be able to shed some insight on this issue.
I can't seem to get flash_write to actually write anything even though it returns successful.
Here is my device tree section,
/* Flash Layout
* Bootloader 0x00000 - 0x10000 (Size 0x10000 65536 Bytes)
* Code 0x10000 - 0xFC000 (Size 0xEC000 966656 Bytes)
* NVM Data 0xFC000 - 0x100000 (Size 0x4000 16384 Bytes)
*/
&flash0 {
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
code_partition: partition@10000 {
label = "code";
reg = <0x10000 0xEC000>;
read-only;
};
datapt_partition: partition@EC000 {
label = "datapt";
reg = <0xEC000 0x4000>;
};
};
};
And KConfig,
# Flash CONFIG_FLASH=y CONFIG_FLASH_PAGE_LAYOUT=y CONFIG_SOC_FLASH_NRF=y CONFIG_MPU_ALLOW_FLASH_WRITE=y
And finally the code,
#define FLASH_ADDR FLASH_AREA_OFFSET(datapt)
#define FLASH_SPACE FLASH_AREA_SIZE(datapt)
void flash_Init() {
flash_device = device_get_binding(DT_CHOSEN_ZEPHYR_FLASH_CONTROLLER_LABEL);
if (!flash_device) {
serialWrite("**No flash controller found!**\r\n");
serialWrite("Run set_device <name> to specify one before using other commands.\r\n");
return;
}
serialWrite("Found flash controller %s.\r\n");
serialWrite(DT_CHOSEN_ZEPHYR_FLASH_CONTROLLER_LABEL);
serialWrite("Flash I/O commands can be run.\r\n");
}
int writeFlash(const char *datain, int len)
{
if(!flash_device)
return -1;
// Don't let other flash get overwritten
if(len > FLASH_SPACE)
return -1;
// Erase flash space, enough for all settings. JSON formatted
printf("HT: Flash Address %#10x \r\n", FLASH_ADDR);
printf("HT: Flash Space %d\r\n", FLASH_SPACE);
if(flash_erase(flash_device, FLASH_ADDR, FLASH_SPACE) != 0) {
printf("HT: Flash Erase Failed");
return -1;
}
printf("HT: Flash Space Erased (%d bytes)\r\n", FLASH_SPACE);
int rv = flash_write(flash_device, FLASH_ADDR, datain, len);
if(!rv) {
printf("HT: Flash Write Failure %d\r\n", rv);
return -1;
}
return 0;
}
When I call write flash it returns success, but if I examine the memory after at 0xEC000 it's still all erased at 0xFF
Did I do something wrong here? Not sure if this is a Zephyr specific thing or part of Nordics driver.. so I'm asking here first.
Thank you for any help