Skip to main content
Explorer
April 29, 2024
Solved

Not able to jump from internal memory boot code to QSPI external memory application code.

  • April 29, 2024
  • 4 replies
  • 5919 views

I am working on NUCLEO-H563ZI evaluation board interfacing with QSPI external memory. I have done below steps,

I am able to do read and write.

I have created the external loader file.

I am able to run application code in external memory with debugger support.

Now i am trying to run application code from external memory with bootloader code but i am always ending up with code crash. Could anybody give a clue how to debug this issue?

 

Note: I have flashed the application code in external memory using cube programmer with external loader.

         I have enabled the memory mapped mode in boot up code and able to see the app code in Ext memory.

          I have written jump code like below and changed linker script also,

 

/* Disable Systick interrupt */

SysTick->CTRL = 0;

 

/* Jump to application */

jumpToApplication = (pFunction)(*(__IO uint32_t*)(APPLICATION_ADDRESS + 4));

__set_MSP(*(__IO uint32_t*)APPLICATION_ADDRESS);

jumpToApplication();

 

 

    This topic has been closed for replies.
    Best answer by Tesla DeLorean

    You'd need to split the data into TWO .BIN covering the individual regions which are otherwise a long way apart, resulting in a file that's 2GB in size, and clearly not going to fit within a device with a fraction of that capacity.

    A .HEX or .ELF can be sparse

    4 replies

    Technical Moderator
    April 30, 2024

    Hello @Nagarajan ,

    ->but i am always ending up with code crash. 

    Could you please precise the exact line of code or function where the code crashes?

    I recommend you to take a look at AN5188, this application note provides details on how to boot from internal Flash memory, and then jump to user-application execution from an external memory. 

    May be the  ExtMem_Boot example can help you.

     

    NagarajanAuthor
    Explorer
    April 30, 2024

    I followed exactly the same instruction given in AN5188 and written Boot and app code like example code you given for STM32H7 only, but when i execute the jumpToApplication(); line, i am always getting Hard fault error.

    Before executing jumpToApplication(); line, i am able to see the actual external memory data like below,

    Nagarajan_0-1714470638388.png

     

    After executing jumpToApplication(); line, i am seeing corrupted data in external memory like below, but the data is not corrupted actually.

    Nagarajan_1-1714470801893.png

     

     

    Graduate II
    April 30, 2024

    Don't repeat the clock and memory initialization in the application code.

    Get the loader code to bring up the system in the desired configuration, at least the key settings for clock, plls, pins, external memories. Other pins/peripherals you can defer until later. Teardown any other interrupts you have going before transferring control.

    Watch HAL_Init() and don't be doing SystemClock_Config() for a second time.

    Watch also what SystemInit() is doing with SCB->VTOR, I'd use a linker symbol over a define, but make sure the vector table is pointing at your new location.

    Technical Moderator
    April 30, 2024

    Hi @Nagarajan ,

    Is ICache enabled?

    If the ICache is enabled, I recommend you to take a look at How to avoid a hard fault when ICACHE is enabled on the STM32H5 series. 

    This article presents a quick guidance on how to prevent hard fault occurrences when the ICACHE is enabled on the STM32H5 MCU. 

    I hope this help you.

    Kaouthar

    NagarajanAuthor
    Explorer
    May 2, 2024

    Both iCache and Dcache are disabled in boot code as well as application code. Is it mandatory to enable it in app code?

    Below is the MPU configuration for boot code, Please let me know if i need to change anything in that.

    void MPU_Config(void)
    {
    MPU_Region_InitTypeDef MPU_InitStruct = {0};
    MPU_Attributes_InitTypeDef MPU_AttributesInit = {0};

    /* Disables the MPU */
    HAL_MPU_Disable();

    /** Initializes and configures the Region and the memory to be protected
    */
    MPU_InitStruct.Enable = MPU_REGION_ENABLE;
    MPU_InitStruct.Number = MPU_REGION_NUMBER0;
    MPU_InitStruct.BaseAddress = 0x90000000;
    MPU_InitStruct.LimitAddress = 0x90FFFFFF;
    MPU_InitStruct.AttributesIndex = MPU_ATTRIBUTES_NUMBER0;
    MPU_InitStruct.AccessPermission = MPU_REGION_ALL_RW;
    MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
    MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;

    HAL_MPU_ConfigRegion(&MPU_InitStruct);
    MPU_AttributesInit.Number = MPU_REGION_NUMBER0;
    MPU_AttributesInit.Attributes = MPU_DEVICE_GRE | MPU_WRITE_THROUGH
    | MPU_TRANSIENT | MPU_NO_ALLOCATE;

    HAL_MPU_ConfigMemoryAttributes(&MPU_AttributesInit);
    /* Enables the MPU */
    HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);

    }

    NagarajanAuthor
    Explorer
    May 6, 2024

    I am able to download the entire code in external QSPI flash with the help of external loader but if i want to keep particular section alone in external memory, i am getting the below error while downloading. Could you please help me to find the reason for this issue. I attached linker script with this chat.

     

    This below variable only i want to move to external memory,

    uint8_t buff[10] __attribute__((section(".extflash")));

     

    Nagarajan_0-1714983545071.png

     

    Note: As i couldnt upload the .ld file directly, i just changed as a .c file.

     

     

    Graduate II
    May 6, 2024

    Use STM32 Cube Programmer, show complete error, ideally with adequate logging to be able to get some clue as to what is happening.

    Show whole memory map for the built file, only see internal FLASH addresses in your screen shot

    NagarajanAuthor
    Explorer
    May 7, 2024

    If i download it through cube programmer, it stuck up with the below page itself. it's not even start downloading at all. Attached map and linker file for your reference.

     

    Nagarajan_0-1715062483355.png

     

    Nagarajan_1-1715062770619.png

     

    NagarajanAuthor
    Explorer
    May 9, 2024

    Is it possible to download code to internal as well as external memory at the same time using cube programmer?

    If yes, which address should i give as start address?

    With cube IDE i am able to download but cube programmer i am seeing the hang like below.

    Nagarajan_0-1715257875531.png

     

    Graduate II
    May 9, 2024

    You'd need to split the data into TWO .BIN covering the individual regions which are otherwise a long way apart, resulting in a file that's 2GB in size, and clearly not going to fit within a device with a fraction of that capacity.

    A .HEX or .ELF can be sparse

    NagarajanAuthor
    Explorer
    May 10, 2024

    Is there any tool to download .hex file into STM32H5 microcontroller?