Hi Huan,
The FTFL write and erase sector functions do not translate the FlexNVM 32-bit address to 24-bit address. To access the FlexNVM/bank1 flash bit-23 of the write_addr used in the command_array[1] needs to be set.
I added simple address check and translation as shown below.
From the ftfl_flash_erase_sector()
write_addr = (_mem_size) from_ptr;
#if 1 //DES 1=test,0=default code
if(write_addr & 0x10000000) //DES Hack that looks at address and if in the 0x10000000 range we assume access is for FlexNVM/bank1 flash block and we set bit 23 to gain access
write_addr |= 0x00800000;
#endif
From the ftfl_flash_write_sector()
write_addr = (_mem_size) to_ptr; //DES??? should this have check of dev_ptr->FLAGS to translate address to NVM/bank1 by setting bit 23?
#if 1 //DES 1=test,0=default code
if(write_addr & 0x10000000) //DES Hack that looks at address and if in the 0x10000000 range we assume access is for FlexNVM/bank1 flash block and we set bit 23 to gain access
write_addr |= 0x00800000;
#endif
From my comments above I was thinking that a “better” solution would be to use the dev_ptr->FLAGS but your expertise probably can do better than that.
So know the attached is ZIP with all files I touched and project working for both program and data flash space.
Terminal Output:
MQX Flash Example
Flash file flashx:bank0 opened
Size of the flash file: 0x40000 Bytes
Flash sector cache enabled.
Reading last 32 Bytes.
Bytes are blank.
Type a string to be written to the end of file (32 chars max.):flashx:bank0 test
Data written to the flash.
Now you can power down and power up your device
and then retry the test to see if the string was written correctly.
Flash example finished.
MQX NVM Flash Example
Flash file flashx_nvm:bank1 opened
Size of the flash file: 0x8000 Bytes
Flash sector cache enabled.
Reading last 32 Bytes.
Bytes are blank.
Type a string to be written to the end of file (32 chars max.):
Type a string to be written to the end of file (32 chars max.):flashx_nvm:bank1 test
Data written to the flash.
Now you can power down and power up your device
and then retry the test to see if the string was written correctly.
Flash example finished.
MQX Flash Example
Flash file flashx:bank0 opened
Size of the flash file: 0x40000 Bytes
Flash sector cache enabled.
Reading last 32 Bytes.
String found: flashx:bank0 test
Type a string to be written to the end of file (32 chars max.):MQX Flash Example
Data written to the flash.
Now you can power down and power up your device
and then retry the test to see if the string was written correctly.
Flash example finished.
MQX NVM Flash Example
Flash file flashx_nvm:bank1 opened
Size of the flash file: 0x8000 Bytes
Flash sector cache enabled.
Reading last 32 Bytes.
String found: flashx_nvm:bank1 test
Type a string to be written to the end of file (32 chars max.):
Type a string to be written to the end of file (32 chars max.):MQX NVM Flash Example
Data written to the flash.
Now you can power down and power up your device
and rthen retry the test to see if the string was written correctly.
Flash example finished.
MQX Flash Example
Flash file flashx:bank0 opened
Size of the flash file: 0x40000 Bytes
Flash sector cache enabled.
Reading last 32 Bytes.
String found: MQX Flash Example
Type a string to be written to the end of file (32 chars max.):Good Bye bank0
Data written to the flash.
Now you can power down and power up your device
and then retry the test to see if the string was written correctly.
Flash example finished.
MQX NVM Flash Example
Flash file flashx_nvm:bank1 opened
Size of the flash file: 0x8000 Bytes
Flash sector cache enabled.
Reading last 32 Bytes.
String found: MQX NVM Flash Example
Type a string to be written to the end of file (32 chars max.):
Type a string to be written to the end of file (32 chars max.):Good Bye bank1
Data written to the flash.
Now you can power down and power up your device
and then retry the test to see if the string was written correctly.
Flash example finished.
I've forwarded my results to our MQX Development team for improving this solution.
Regards,
David
PS
This was done with MQX4.0 (I have early release).