Thanks RadekS! For sure it served me as nice inspiration!
Indeed there is something missing in your code that I found in this thread: Re: K20 FlexNVM with Flashx which was preventing it from work. The FTFE write AND erase functions require the FlexNVM 32-bit address to be translated to 24-bit address, so the following code is necessary on flash_ftfe.c erase and write sector functions.
| flash_ftfe.c (insert marked code on ftfe_flash_erase_sector and ftfe_flash_write_sector functions) |
|---|
write_addr = (_mem_size) from_ptr;
if (write_addr & 0x10000000) write_addr |= 0x00800000; |
I've not tested the FlexRAM+EEPROM functionality (after a lot of tests I realized that most of the sample code you supplied is not needed for FlexNVM D-flash usage only, but I kept it in my installation for the future).
I've also seen something that I can't quite understand in your code, also in the flash_ftfe.c file:
| flash_ftfe.c FLASHX_BLOCK_INFO_STRUCT |
|---|
const FLASHX_BLOCK_INFO_STRUCT _flashx_kinetisX_block_map[] = { { BSP_INTERNAL_FLASH_SIZE / BSP_INTERNAL_FLASH_SECTOR_SIZE / 2, (uint32_t) BSP_INTERNAL_FLASH_BASE, BSP_INTERNAL_FLASH_SECTOR_SIZE }, { BSP_INTERNAL_FLASH_SIZE / BSP_INTERNAL_FLASH_SECTOR_SIZE / 2, (uint32_t) BSP_INTERNAL_FLASH_BASE, BSP_INTERNAL_FLASH_SECTOR_SIZE }, { BSP_INTERNAL_FLASH_SIZE / BSP_INTERNAL_FLASH_SECTOR_SIZE, (uint32_t) __FLASHX_START_ADDR, BSP_INTERNAL_FLASH_SECTOR_SIZE }, // D-Flash blocks { 1, (uint32_t) BSP_INTERNAL_FLEXRAM_BASE, BSP_INTERNAL_FLEXRAM_SIZE }, { 0, 0, 0 } } |
Why two blocks defined to begin in the same place and with the same size in the internal flash?
In my code I've kept MQX defaults and configured two blocks in the internal flash. (from beginning to half and from half to end). I don't also undestand why two blocks on MQX as theoretically there is only one flash block on internal flash. I found contraditory information about this issue along Freescale documents.
So my FLASHX_BLOCK_INFO_STRUCT was configured as this:
| My FLASHX_BLOCK_INFO_STRUCT |
|---|
const FLASHX_BLOCK_INFO_STRUCT _flashx_kinetisX_block_map[] = { { BSP_INTERNAL_FLASH_SIZE / BSP_INTERNAL_FLASH_SECTOR_SIZE / 2, (uint32_t) BSP_INTERNAL_FLASH_BASE, BSP_INTERNAL_FLASH_SECTOR_SIZE }, { BSP_INTERNAL_FLASH_SIZE / BSP_INTERNAL_FLASH_SECTOR_SIZE / 2, (uint32_t) BSP_INTERNAL_FLASH_BASE + 1 * BSP_INTERNAL_FLASH_SIZE / 2, BSP_INTERNAL_FLASH_SECTOR_SIZE }, { BSP_INTERNAL_FLEXNVM_SIZE / BSP_INTERNAL_FLASH_SECTOR_SIZE, (uint32_t) BSP_INTERNAL_FLEXNVM_BASE, BSP_INTERNAL_FLASH_SECTOR_SIZE }, { 0, 0, 0 } } |
And it looks like it is working fine!
Thank you again!
Luiz Fernando