Skip to main content
Senior
February 20, 2026
Solved

Use external NOR flash to move CPP object file

  • February 20, 2026
  • 4 replies
  • 419 views

Hello,

I have STM32F7 controller, using Free RTOS, trying to interface external NOR flash, S29GL128S10TFIV13.

I have one source file say testCode.cpp, which I want to move completely in external NOR flash, but every time I ran then code it give Hardfault.

MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 512K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 2048K
EXT_FLASH (rx) : ORIGIN = 0x64000000, LENGTH = 16M
EXT_SRAM_HEAP (xrw) : ORIGIN = 0x60000000, LENGTH = 256K
EXT_SRAM_STACK (rw) : ORIGIN = 0x60040000, LENGTH = 256K
}
 
SECTIONS
{
 .isr_vector :
 {
 . = ALIGN(4);
 KEEP(*(.isr_vector)) /* Startup code */
 . = ALIGN(4);
 } >FLASH

.ext_flash_code :
 {
 . = ALIGN(4);
 _sextflash_run = .;
 *(.ext_flash_data*)
 *(.ext_flash_data*)
 . = ALIGN(4);
 _eextflash_run = .;
 } > EXT_FLASH

 /* 2. SECTION FOR MANUAL ATTRIBUTES (For Arrays) */
 .ext_flash_data :
 {
 . = ALIGN(4);
 *(.ext_flash_data) /* Targets __attribute__((section(".ext_flash_data"))) */
 *(.ext_flash_data*)
 . = ALIGN(4);
 } > EXT_FLASH
}

 

Below function I was trying to call from thread,

main()
{
 testCodeTaskHandle = osThreadNew(testCodeWrapper, NULL, &testCodeTask_attributes);
}

extern "C" 
__attribute__((section(".ext_flash_code")))
void testCodeWrapper(void *argument)
{
 testCode* obj = testCode::getInstance();
 obj->run();
}

Now it gets stuck at first line of this function and then jump to Hardfault.

Note: I have tried to read QRY from flash as test and it PASSED, so flash is integrated correctly.

In .map file it is clearly seen that the function moves to external flash address.

Below init details

 hnor2.Instance = FMC_NORSRAM_DEVICE;
 hnor2.Extended = FMC_NORSRAM_EXTENDED_DEVICE;
 /* hnor2.Init */
 hnor2.Init.NSBank = FMC_NORSRAM_BANK2;
 hnor2.Init.DataAddressMux = FMC_DATA_ADDRESS_MUX_DISABLE;
 hnor2.Init.MemoryType = FMC_MEMORY_TYPE_NOR;
 hnor2.Init.MemoryDataWidth = FMC_NORSRAM_MEM_BUS_WIDTH_16;
 hnor2.Init.BurstAccessMode = FMC_BURST_ACCESS_MODE_DISABLE;
 hnor2.Init.WaitSignalPolarity = FMC_WAIT_SIGNAL_POLARITY_LOW;
 hnor2.Init.WaitSignalActive = FMC_WAIT_TIMING_BEFORE_WS;
 hnor2.Init.WriteOperation = FMC_WRITE_OPERATION_ENABLE;
 hnor2.Init.WaitSignal = FMC_WAIT_SIGNAL_DISABLE;
 hnor2.Init.ExtendedMode = FMC_EXTENDED_MODE_DISABLE;
 hnor2.Init.AsynchronousWait = FMC_ASYNCHRONOUS_WAIT_DISABLE;
 hnor2.Init.WriteBurst = FMC_WRITE_BURST_DISABLE;
 hnor2.Init.ContinuousClock = FMC_CONTINUOUS_CLOCK_SYNC_ONLY;
 hnor2.Init.WriteFifo = FMC_WRITE_FIFO_ENABLE;
 hnor2.Init.PageSize = FMC_PAGE_SIZE_NONE;
 /* Timing */
 Timing.AddressSetupTime = 15;
 Timing.AddressHoldTime = 15;
 Timing.DataSetupTime = 255;
 Timing.BusTurnAroundDuration = 15;
 Timing.CLKDivision = 16;
 Timing.DataLatency = 17;
 Timing.AccessMode = FMC_ACCESS_MODE_A;


Help me to understand what is missing here?
Thanks,

Nitin

 

Best answer by npatil15

Hello,

As we decided here, I have worked and resolve these 2 issues

External Flash Read/Write: Solved: Re: External NOR Flash Read address line instead o... - STMicroelectronics Community

Move Object to external SRAM: Solved: Re: Move object (.obj) to external SRAM - STMicroelectronics Community

Now everything has works, but additionally as discussed in above thread, I need to work on external Loader application, found support here (https://github.com/STMicroelectronics/stm32-external-loader.git) which has FMC related Loader examples, make sure you correctly configure the pin of FMC for external Loader application as per you project requirements.

Now you have four things to manage:

1. Create a project with external loader and make sure this works using STM32CubeProgrammer, try to edit, delete, read, multi write/read operations on external Flash.

2. Integrate external Loader program to STM32CubeIDE or vscode in main application project, find the reference you can easily find.

"serverArgs": [
 "-m", "0",
 "-el", "${workspaceFolder}/Loader/testLoader.stldr"
 ],

3. In main application, to access external memory without any limitations (i.e., globally or locally), make sure you initialize FMC and its GPIO inside "SystemInit()" function, that function run at very first stage which make FMC ready for anything.

4. Now, to perform external SRAM operation, you need to copy external/internal FLASH to external SRAM (specifically which execute before main), then make sure you copy external memory to external SRAM and memset to '.bss' sections. And initialize Heap section as mentioned here (Solved: Re: Move object (.obj) to external SRAM - Page 2 - STMicroelectronics Community) So that everything should be ready to run. And that way, it will easily show breakpoint on main(). If you missed anything then you will definitely cause Hard fault before main runs.

Hope my finding helps.

Thanks,

Nitin

4 replies

mƎALLEm
Technical Moderator
February 20, 2026

Hello,

What about this post: External NOR Flash Read address line instead of data?

You need to ensure the read/write is performed without issue to that NOR memory.

"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."
npatil15Author
Senior
February 20, 2026

Hello,
This post External NOR Flash Read address line instead of data? is to simply read/write the flash, and it was failing as explain in that post. But I have tried to read QRY from flash it success, so flash is configure correctly, the only part of flash read/write logic was failing. \

And the current post is about the moving complete object file to external flash, which was also failing.

mƎALLEm
Technical Moderator
February 20, 2026

@npatil15 wrote:

Hello,
This post External NOR Flash Read address line instead of data? is to simply read/write the flash, and it was failing as explain in that post. But I have tried to read QRY from flash it success, so flash is configure correctly, the only part of flash read/write logic was failing. \

And the current post is about the moving complete object file to external flash, which was also failing.


So how you could continue with this thread if the previous is not solved? 

"Now it gets stuck at first line of this function and then jump to Hardfault."

How do you expect to not getting a HardFault while you didn't succeed to read/write to the external NOR flash?

"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."
Andrew Neil
Super User
February 20, 2026

Did you solve your similar issue: Move object (.obj) to external SRAM ?

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
npatil15Author
Senior
February 20, 2026

Hello,

This is my post only where I was trying to move object in external SRAM, but I didn't get any success.

Andrew Neil
Super User
February 20, 2026

@npatil15 wrote:

This is my post only where I was trying to move object in external SRAM, but I didn't get any success.


So why not concentrate on getting that working first?

As far as the Linker is concerned, the process would be the same.

 

As @mƎALLEm said, there are 2 separate issues here:

  1. Getting the physical memory working;
  2. Configuring the Linker to place code as required.
A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Andrew Neil
Super User
February 20, 2026

Some GCC Linker resources here.

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
npatil15AuthorBest answer
Senior
April 6, 2026

Hello,

As we decided here, I have worked and resolve these 2 issues

External Flash Read/Write: Solved: Re: External NOR Flash Read address line instead o... - STMicroelectronics Community

Move Object to external SRAM: Solved: Re: Move object (.obj) to external SRAM - STMicroelectronics Community

Now everything has works, but additionally as discussed in above thread, I need to work on external Loader application, found support here (https://github.com/STMicroelectronics/stm32-external-loader.git) which has FMC related Loader examples, make sure you correctly configure the pin of FMC for external Loader application as per you project requirements.

Now you have four things to manage:

1. Create a project with external loader and make sure this works using STM32CubeProgrammer, try to edit, delete, read, multi write/read operations on external Flash.

2. Integrate external Loader program to STM32CubeIDE or vscode in main application project, find the reference you can easily find.

"serverArgs": [
 "-m", "0",
 "-el", "${workspaceFolder}/Loader/testLoader.stldr"
 ],

3. In main application, to access external memory without any limitations (i.e., globally or locally), make sure you initialize FMC and its GPIO inside "SystemInit()" function, that function run at very first stage which make FMC ready for anything.

4. Now, to perform external SRAM operation, you need to copy external/internal FLASH to external SRAM (specifically which execute before main), then make sure you copy external memory to external SRAM and memset to '.bss' sections. And initialize Heap section as mentioned here (Solved: Re: Move object (.obj) to external SRAM - Page 2 - STMicroelectronics Community) So that everything should be ready to run. And that way, it will easily show breakpoint on main(). If you missed anything then you will definitely cause Hard fault before main runs.

Hope my finding helps.

Thanks,

Nitin