Trouble writing FlexNVM on MK70FX512

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Trouble writing FlexNVM on MK70FX512

498 Views
gpontis
Contributor IV

Try as I might, I've not been able to write data to FlexNVM. I'm working with MQX 4.1.1.

In my specific case I was trying to write data to 0x1007F000, the last sector of block 3. First thing, I found that I needed to create some new arrays to initialize the flashx driver. This is because the example file for the twr K70 board is set up for the FN CPU, which does not have the FlexNVM. Also there is a gap between banks 1 and 2 on the K70FX, which is not compatible with the twr K70 board. It looks like this in init_bsp.c:

#if BSPCFG_ENABLE_FLASHX

// Customization specific to the MK70FX512, which has FlexNVM for blocks 2,3 and they are not contiguous with blocks 0,1

#define MK70FX512_BANK0_START ((uint32_t) BSP_INTERNAL_FLASH_BASE)
#define MK70FX512_BANK1_START ((uint32_t) BSP_INTERNAL_FLASH_BASE + BSP_INTERNAL_FLASH_SIZE / 4)
#define MK70FX512_BANK2_START ((uint32_t) BSP_INTERNAL_FLASH_BASE + 0x10000000)
#define MK70FX512_BANK3_START ((uint32_t) BSP_INTERNAL_FLASH_BASE + BSP_INTERNAL_FLASH_SIZE / 4 + 0x10000000)

// fields are: number of sectors, physical start address, sector size
static const FLASHX_BLOCK_INFO_STRUCT _flashx_MK70FX512_block_map[] = {
    { BSP_INTERNAL_FLASH_SIZE / BSP_INTERNAL_FLASH_SECTOR_SIZE / 4, MK70FX512_BANK0_START, BSP_INTERNAL_FLASH_SECTOR_SIZE },
    { BSP_INTERNAL_FLASH_SIZE / BSP_INTERNAL_FLASH_SECTOR_SIZE / 4, MK70FX512_BANK1_START, BSP_INTERNAL_FLASH_SECTOR_SIZE },
    { BSP_INTERNAL_FLASH_SIZE / BSP_INTERNAL_FLASH_SECTOR_SIZE / 4, MK70FX512_BANK2_START, BSP_INTERNAL_FLASH_SECTOR_SIZE },
    { BSP_INTERNAL_FLASH_SIZE / BSP_INTERNAL_FLASH_SECTOR_SIZE / 4, MK70FX512_BANK3_START, BSP_INTERNAL_FLASH_SECTOR_SIZE },
    { 0, 0, 0 }
};

static const FLASHX_FILE_BLOCK _bsp_flashx_MK70FX512_file_blocks[] = {
    { "bank0",      MK70FX512_BANK0_START, MK70FX512_BANK0_START + (BSP_INTERNAL_FLASH_SIZE / 4) - 1 },
    { "bank1",      MK70FX512_BANK1_START, MK70FX512_BANK1_START + (BSP_INTERNAL_FLASH_SIZE / 4) - 1 },
    { "bank2",      MK70FX512_BANK2_START, MK70FX512_BANK2_START + (BSP_INTERNAL_FLASH_SIZE / 4) - 1 },
    { "bank3",      MK70FX512_BANK3_START, MK70FX512_BANK3_START + (BSP_INTERNAL_FLASH_SIZE / 4) - 1 },
// swap file definition according to the default value of BSPCFG_SWAP_INDICATOR_ADDR and sector size
    { "swap0",      BSP_INTERNAL_FLASH_BASE,                                        BSP_INTERNAL_FLASH_BASE + (BSP_INTERNAL_FLASH_SIZE / 2) - (1 + BSP_INTERNAL_FLASH_SECTOR_SIZE) },
    { "swap1",      BSP_INTERNAL_FLASH_BASE + (BSP_INTERNAL_FLASH_SIZE / 2),        BSP_INTERNAL_FLASH_BASE + (BSP_INTERNAL_FLASH_SIZE    ) - (1 + BSP_INTERNAL_FLASH_SECTOR_SIZE) },
// flash space used by application
    { "code",       BSP_INTERNAL_FLASH_BASE,                                        (uint32_t)__FLASHX_START_ADDR - 1 },
// remaining free flash space
    { "",           (uint32_t)__FLASHX_START_ADDR,                                  (uint32_t)__FLASHX_END_ADDR },
    { NULL,         0,                                                              0 }
};


static const FLASHX_INIT_STRUCT _bsp_flashx_MK70FX512_init = {
    0x00000000, /* BASE_ADDR should be 0 for internal flashes */
    _flashx_MK70FX512_block_map, /* HW block map for MK70FX512 devices */
    _bsp_flashx_MK70FX512_file_blocks, /* Files on the device defined by the BSP */
    &_flashx_ftfe_if, /* Interface for low level driver */
    32, /* For external devices, data lines for the flash. Not used for internal flash devices. */
    1,  /* Number of parallel external flash devices. Not used for internal flash devices. */
    0,  /* 0 if the write verify is requested, non-zero otherwise */
    NULL /* low level driver specific data */
};

_io_flashx_install("flashx:", &_bsp_flashx_MK70FX512_init);
#endif

I might mention that for this processor, BSP_INTERNAL_FLASH_BASE is 0x00100000. My code seems to execute without error, but there is nothing written into the flash. It opens flashx:bank3 and writes data to 0x3f000. Tracing through the code I verified that this is translated to the expected physical address of 0x1007f000. I watched one flash operation execute and the status register showed command completion and no errors. The same code works fine writing to the top of bank 1 at physical address 7f000. Where to look next ?

George

1 Reply

284 Views
RadekS
NXP Employee
NXP Employee

I checked you modifications and I found potential issue:

Since you used "flashx:" (file ""), area for programming is defined by __FLASHX_START_ADDR and __FLASHX_END_ADDR. Please check definitions of these macros. In default settings __FLASHX_START_ADDR  points to end of your code and __FLASHX_END_ADDR points to BSP_INTERNAL_FLASH_BASE+BSP_INTERNAL_FLASH_SIZE. So, you should change both these values to FlexNVM addresses or at least modify __FLASHX_END_ADDR to half size (512kB, BSP_INTERNAL_FLASH_BASE+BSP_INTERNAL_FLASH_SIZE/2 - 1) and declare FlexNVM as separate file.

I would like to recommend define "" file as:

{ "", (uint32_t) MK70FX512_BANK2_START, (uint32_t)( MK70FX512_BANK2_START + BSP_INTERNAL_FLASH_SIZE/2 - 1) },

Or rather create it directly under some specific file name in _bsp_flashx_MK70FX512_file_blocks which will points to FlexNVM memory for example "d-flash".

So, if your file definitions will contain:

{ "code", BSP_INTERNAL_FLASH_BASE, (uint32_t)__FLASHX_START_ADDR - 1 }, //your code in P-Flash

{ "p-flash", (uint32_t)__FLASHX_START_ADDR, (uint32_t)__FLASHX_END_ADDR }, //rest of P-Flash

{ "d-flash", (uint32_t) MK70FX512_BANK2_START, (uint32_t)( MK70FX512_BANK2_START + BSP_INTERNAL_FLASH_SIZE/2 - 1) }, // D-Flash

In that case you should use _io_flashx_install("flashx:d-flash", &_bsp_flashx_MK70FX512_init);

Notes:

  1. Since you have MK70FX512, you cannot use swapping, therefore swap0 and swap1 files are useless.
  2. BSP_INTERNAL_FLASH_BASE has to be defined as 0x00000000 otherwise you declaration has no sense. Please check your definition of BSP_INTERNAL_FLASH_BASE.


Have a great day,
RadekS

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------