AnsweredAssumed Answered

Trouble writing FlexNVM on MK70FX512

Question asked by George Pontis on Nov 19, 2014
Latest reply on Nov 24, 2014 by Radek Sestak

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

Outcomes