Write error to last sector of RT1604 flash on HAB

cancel
Showing results for 
Search instead for 
Did you mean: 

Write error to last sector of RT1604 flash on HAB

Jump to solution
394 Views
namsu_mun
Contributor II

HI, I could not write data to the last sector (0x3ff000) of internal flash of RT1604 on HAB closed mode. RT1604 was hang after writing flash.  I have used flexspi_nor_flash_erase() and flexspi_nor_flash_page_program() in "RT1064 Users Manual" regarding FlexSPI NOR API. Is there any restrict of memory map on HAB? Please tell me how to debug it?

Regards,

Labels (1)
0 Kudos
1 Solution
212 Views
jeremyzhou
NXP TechSupport
NXP TechSupport

Hi Namsu Mun,

Thank you for your interest in NXP Semiconductor products and
for the opportunity to serve you.
Before answering the question, I'd like to get more information about it.
In your statement, does the HAB closed mode means the authentic boot which demonstrated in the AN1079?
Whether you tried the  flexspi_nor_flash_erase() and flexspi_nor_flash_page_program() under without secuity mode, does it works or not?

TIC

 

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

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

View solution in original post

0 Kudos
8 Replies
213 Views
jeremyzhou
NXP TechSupport
NXP TechSupport

Hi Namsu Mun,

Thank you for your interest in NXP Semiconductor products and
for the opportunity to serve you.
Before answering the question, I'd like to get more information about it.
In your statement, does the HAB closed mode means the authentic boot which demonstrated in the AN1079?
Whether you tried the  flexspi_nor_flash_erase() and flexspi_nor_flash_page_program() under without secuity mode, does it works or not?

TIC

 

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

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

View solution in original post

0 Kudos
212 Views
namsu_mun
Contributor II

Hi Jeremy,

Thank you for fast reply. Yes, HAB closed mode is authentic boot which is in AN1079. I have burned SRK and image file using NXP-MCUBootutility-master, and flexspi_nor_flash_page_program() have no problem under without security mode.

Regards,

0 Kudos
212 Views
jeremyzhou
NXP TechSupport
NXP TechSupport

Hi Namsu Mun,

Thanks for your reply.
Whether you can upload the demo code, in further, please clarify the mean of 'RT1604 was hang after writing flash', do you mean the MCU encounter the hard fault interrupt or other things?

TIC

 

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

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
212 Views
namsu_mun
Contributor II

Hi Jeremyzhou,

Unfortunately, I don't know whether RT1604 encounter the hard fault interrupt or not, because have used serial terminal for debugging. In flexspi_nor_flash_page_program(), writing flash and verifying had no problem. Just after flexspi_nor_flash_page_program() program was stopped.

Regards,

0 Kudos
212 Views
jeremyzhou
NXP TechSupport
NXP TechSupport

Hi Namsu Mun,

Thanks for your reply.
I was wondering can upload the demo code, it can help me to figure this issue out.

TIC

 

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

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
212 Views
namsu_mun
Contributor II

Hi Jeremyzhou,

Sorry for late reply. It was not HAB problem. My demo code is as following;

------------------------------------------

reference demo code: evkmimxrt1064_dev_hid_generic_bm

#if 1 // nsmoon@191028
#define FLASH_SECT_SIZE 0x1000
#define FLASH_PAGE_SIZE 0x100 //256
#define PROGRAM_ADDRESS 0x3ff000

static flexspi_nor_config_t config;
static serial_nor_config_option_t option;
static uint32_t address;
static uint8_t prog_buffer[FLASH_SECT_SIZE];
static uint8_t read_buffer[FLASH_SECT_SIZE];
static uint32_t instance; // Should identify NOR memory instance

static status_t flash_init()
{
    status_t status = kStatus_Success;
    PRINTF("Start testIAP()..\r\n");
    address = PROGRAM_ADDRESS;
    instance = 1;
    option.option0.U = 0xC0000008; // QuadSPI NOR, Frequency: 133MHz

    status = flexspi_nor_get_config(instance, &config, &option);
    if (status != kStatus_Success) {
        PRINTF("ERROR! flexspi_nor_get_config().. %d\r\n", status);
    return status;
    }
    return status;
}
#endif

#if defined(__CC_ARM) || (defined(__ARMCC_VERSION)) || defined(__GNUC__)
int main(void)
#else
void main(void)
#endif
{
    BOARD_ConfigMPU();

    BOARD_InitPins();
    BOARD_BootClockRUN();
    BOARD_InitDebugConsole();

    USB_DeviceApplicationInit();
#if 1 //nsmoon@19102
    status_t status;
    status = flash_init();
#endif

    while (1U)
    {
#if USB_DEVICE_CONFIG_USE_TASK
    USB_DeviceTaskFn(g_UsbDeviceHidGeneric.deviceHandle);
#endif
#if 1 //nsmoon@191028
    uint32_t mem_address = 0x70000000 + address;
    uint32_t test_data = 1;

    //static uint32_t test_data = 1;

#if 0 //FIXME!! should called every time?

    option.option0.U = 0xC0000008; // QuadSPI NOR, Frequency: 133MHz

    PRINTF("Config flash.. %x %x\r\n", mem_address, FLASH_SECT_SIZE);
    status = flexspi_nor_flash_init(instance, &config);
    if (status != kStatus_Success) {
        PRINTF("ERROR! flexspi_nor_flash_init().. %d\r\n", status);
        goto _main_error;
   }

#endif


#if 1 //FIXME
    PRINTF("Read flash.. %x %x\r\n", mem_address, FLASH_PAGE_SIZE);
    memcpy((void*)&prog_buffer[0], (void*)mem_address, FLASH_PAGE_SIZE);

    //SCB_InvalidateDCache();
#endif


    PRINTF("Erase flash.. %x %x\r\n", mem_address, FLASH_SECT_SIZE);
    __disable_irq();
    status = flexspi_nor_flash_erase(instance, &config, address , 1); // Erase 1 sector
    __enable_irq();
    if (status != kStatus_Success) {
        PRINTF("ERROR! flexspi_nor_flash_erase().. %d\r\n", status);
    goto _main_error;
    }

    // Fill data into the sect_buffer;
    for (uint32_t i = 0; i < FLASH_PAGE_SIZE; i++) {
        prog_buffer[i] = (uint8_t)(i * test_data);
    }
    test_data++;

    // Program data to destination (256 bytes)
    PRINTF("Program flash.. %x %x\r\n", mem_address, FLASH_PAGE_SIZE);
    __disable_irq();
    status = flexspi_nor_flash_page_program(instance, &config, address, (uint32_t *)&prog_buffer[0]); // program 1 page
    __enable_irq();
    if (status != kStatus_Success) {
        PRINTF("ERROR! flexspi_nor_flash_page_program().. %d\r\n", status);
    goto _main_error;
    }

    SCB_CleanDCache();
    // Do cache maintenance here if the D-Cache is enabled
    // Use memory mapped access to verify whether data are programmed into Flash correctly
#if 1 //for test
    memcpy((void*)&read_buffer[0], (void*)mem_address, FLASH_PAGE_SIZE);
    if (0 == memcmp((void*)&read_buffer[0], (void*)&prog_buffer[0], FLASH_PAGE_SIZE))
#else
    if (0 == memcmp((void*)mem_address, (void*)&prog_buffer[0], FLASH_PAGE_SIZE))
#endif
    {
        PRINTF("Success!!\r\n");
    } else {
        PRINTF("Failed!!\r\n");
    }

_main_error:
    USB_delay(5000000);
    }

#endif
}

I have three questions. First, should call flexspi_nor_flash_init() before every  flexspi_nor_flash_erase(). Seond, if use SCB_InvalidateDCache(), MCU is hang up on HAB closed. The others, could not update cache for flash memory, so the verification was failed.

Please check whether this code is correct or not.

Thank you.

0 Kudos
212 Views
jeremyzhou
NXP TechSupport
NXP TechSupport

Hi Namsu Mun,,

Thanks for your reply.
1) Should call flexspi_nor_flash_init() before every  flexspi_nor_flash_erase()?
-- Yes.
 1) If use SCB_InvalidateDCache(), MCU is hang up on HAB closed?
-- I think it's related to the attribute of the memory area, I'd like to suggest you refer to the AN12042.
1) Could not update the cache for flash memory, so the verification was failed?
-- Please refer to the AN12042 to learn the cache feature, in further, I've attached a FlexSPI ROM API demo for you to refer to.

TIC

 

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

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
212 Views
namsu_mun
Contributor II

Hi,

Sorry for late reply. Thank you for AN12042. I have changed this memory region from "not share" to "share" in BOARD_ConfigMPU() of demo code. And then, the problem is cleared. I think it's temporary solution. I am still looking for proper way to manipulate data cache. Thanks.

Namsu

0 Kudos