cancel
Showing results for 
Search instead for 
Did you mean: 

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

Nagarajan
Associate III

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();

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

21 REPLIES 21
KDJEM.1
ST Employee

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.

 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

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

 

 

KDJEM.1
ST Employee

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

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

I checked all initialization function, i didn't find any issue in that besides if i change into internal flash location, it jumps to that other internal flash location perfectly without any issue it works fine. When i change it to external memory location only iam facing issue. My doubt is when control jumps to external memory location how it holds the QSPI memory mapped mode in new location? because all QSPI initialization and memory mapped mode have done in boot code not in application code.

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);

}

Nagarajan
Associate III

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.

 

 

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

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