Hello,
I'am trying to write data to external Flash.
First, the code below works well to write code to flash
void NVDATA_Write() {
memset(wr_buf, 0xFF, 512*sizeof(uint8_t));
FLASH_page_program(FLEXSPI, (uint32_t)0x100000, (void *)wr_buf, 512));
}
However, in case of getting parameter of function, I does not work well.
void NVDATA_Write(uint8_t* data) {
memset(wr_buf, 0xFF, 512*sizeof(uint8_t));
memset(wr_buf, data, 16*sizeof(uint8_t));
FLASH_page_program(FLEXSPI, (uint32_t)0x100000, (void *)wr_buf, 512));
}
Please let me know why it doesn't work well
Hi YongJin
probably there is confusion as function void NVDATA_Write(uint8_t* data) implies passing
pointer to data, so if you are expecting to pass data it should be as (uint8_t data) .
You can inspect data value in more details using debugging.
Best regards
igor
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Thank you for your reply
Hmmmm,
in first case, I sets wr_buf as {0x5A, 0x5A, 0xFF, 0xFF,.... }
uint8_t wr_buf[512];
void NVDATA_Write() {
memset(wr_buf, 0xFF, 512*sizeof(uint8_t));
memset(wr_buf, 0x5A, 2*sizeof(uint8_t))
flexspi_nor_flash_page_program(FLEXSPI, (uint32_t)0x100000, (void *)wr_buf, 512));
FLEXSPI_SoftwareReset(EXAMPLE_FLEXSPI);
}
and after writing it to flash I saw that it had a value of 0xFFFF5A5A when the address 0x60100000 was dumped
It does work well.
However, in second case, I make a code as below
uint8_t wr_buf[512];
void NVDATA_Write(uint8_t* data) {
memset(wr_buf, 0xFF, 512*sizeof(uint8_t));
memset(wr_buf, data, 2*sizeof(uint8_t))
flexspi_nor_flash_page_program(FLEXSPI, (uint32_t)0x100000, (void *)wr_buf, 512));
FLEXSPI_SoftwareReset(EXAMPLE_FLEXSPI);
}
and I call NVDATA_Write() function as below
uint8_t buffer[2] = {0x5A, 0x5A}
NVDATA_Write(buffer);
And with mcuxpresso debugger, I saw that wr_buf was set to {0x5A, 0x5A, 0xFF, 0xFF,.... }
But after writing it to flash I saw that it had a value of 0xFFFF5E7A when the address 0x60100000 was dumped
It doesn't work well
I don't know what difference is.
Could you tell me why it is different?
what board used in the case, could you try latest MCUXpresso SDK
with nxp EVK reference board
Welcome | MCUXpresso SDK Builder
Best regards
igor
I used RT1050 EVKB board with hyperflash and latest SDK
And I used external flash as below. I'm trying to write data into EXT_FLASH_NV section.
In linkerscript
MEMORY
{
/* Define each memory region */
EXT_FLASH (rx) : ORIGIN = 0x60000000, LENGTH = 0x100000 /* 1M bytes (alias Flash) */
EXT_FLASH_NV (rw) : ORIGIN = 0x60100000, LENGTH = 0x80000 /* 512K bytes (alias Flash2) */
EX_FLASH_RES (r) : ORIGIN = 0x60180000, LENGTH = 0x3e80000 /* 64000K bytes (alias Flash3) */
In board.c
MPU->RBAR = ARM_MPU_RBAR(region_idx++, 0x60000000U);
MPU->RASR = ARM_MPU_RASR(0, ARM_MPU_AP_FULL, 1, 0, 1, 1, 0, ARM_MPU_REGION_SIZE_1MB);
MPU->RBAR = ARM_MPU_RBAR(region_idx++, 0x60100000U);
MPU->RASR = ARM_MPU_RASR(1, ARM_MPU_AP_FULL, 0, 0, 1, 1, 0, ARM_MPU_REGION_SIZE_512KB);
MPU->RBAR = ARM_MPU_RBAR(region_idx++, 0x60180000U);
MPU->RASR = ARM_MPU_RASR(1, ARM_MPU_AP_FULL, 1, 1, 0, 0, 0, ARM_MPU_REGION_SIZE_64MB);
please check hyperflash timings with logic analyzer or oscilloscope both
good and not good cases and check if issue is caused by flash wrong timings or
MCUXpresso sends wrong data.