Use external NOR flash to move CPP object file
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
