cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CUBEIDE code run extern flash

Sunwaz
Associate III

I'm using the STM32H7B0, but I want to place the executable file compiled from a certain file in the project into the external flash for execution. For example, the `BSP/led/led.c` file.

I've modified the linker script (ld file), added the address of the external flash, and created a new section for the external flash.

MEMORY {

ITCMRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 64K

FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 128K

DTCMRAM1 (xrw) : ORIGIN = 0x20000000, LENGTH = 64K

DTCMRAM2 (xrw) : ORIGIN = 0x20010000, LENGTH = 64K

RAM (xrw) : ORIGIN = 0x24000000, LENGTH = 1024K

RAM_CD (xrw) : ORIGIN = 0x30000000, LENGTH = 128K

RAM_SRD (xrw) : ORIGIN = 0x38000000, LENGTH = 32K

SPI_FLASH (rx) : ORIGIN = 0x90000000, LENGTH = 8192K

}

 

.usart_in_spi_flash :

{

. = ALIGN(4);

BSP/led/led.o(.text*) /* Place .text section of usart.o into SPI_FLASH */

BSP/led/led.o(.rodata*) /* Place .rodata section of usart.o into SPI_FLASH */

BSP/led/led.o(.data*) /* Place .data section of usart.o into SPI_FLASH */

BSP/led/led.o(.bss*) /* Place .bss section of usart.o into SPI_FLASH */

. = ALIGN(4);

} >SPI_FLASH

 

 

However, when compiling, a "multiple definition" error occurs.

../BSP/led/led.c:11: multiple definition of `led_open';

1 ACCEPTED SOLUTION

Accepted Solutions
Sunwaz
Associate III

After modifying the code as follows, the problem can be solved.

But it feels that there is no MDK convenience in function.

It would be nice if the excess code could be automatically extended to external flash.

 

	.externFlash :
	{
	    . = ALIGN(4);
	    *led.o(.text .text*)
	   	. = ALIGN(4);
	    _eQSPI = .;
	} >SPI_FLASH

 

View solution in original post

5 REPLIES 5
Sunwaz
Associate III

This is my ld linker file.

Sunwaz
Associate III

I need help~~

>>However, when compiling, a "multiple definition" error occurs.  ../BSP/led/led.c:11: multiple definition of `led_open';

When COMPILING or LINKING?

Provide the whole build log.

Check for circular #include files

Check for multiple instances of the same source code in the project.

Check for #include's with SOURCE in them rather than definitions or macros

Find-in-Files for led_open

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

Hi Tesla

       Thank you for your reply. This problem has been bothering me for a long time.

        The attachment contains the build log file of CubeIDE and the compiled map file.

        In my linker script (ld file), I placed `led.o` in the external flash area. However, according to the map file, it is located at the address 0x080005dc. So, I think there is a problem with the linking process.

 

When COMPILING or LINKING?

    I think it is during the linking process.

Check for circular #include files.

Check for multiple instances of the same source code in the project.

Check for #include's with SOURCE in them rather than definitions or macros

    This is just a very simple test code.Call the `led_open` function inside the `main` function.

/*
 * led.c
 *
 *  Created on: Feb 7, 2025
 *      Author: Sunwaz
 */
#include "led.h"

uint8_t ledCnt = 0;

void led_open( void ){

	HAL_Delay(100);
	ledCnt++;
}
/*
 * led.h
 *
 *  Created on: Feb 7, 2025
 *      Author: Sunwaz
 */

#ifndef LED_LED_H_
#define LED_LED_H_

#include "main.h"


void led_open( void );
#endif /* LED_LED_H_ */

 

Sunwaz
Associate III

After modifying the code as follows, the problem can be solved.

But it feels that there is no MDK convenience in function.

It would be nice if the excess code could be automatically extended to external flash.

 

	.externFlash :
	{
	    . = ALIGN(4);
	    *led.o(.text .text*)
	   	. = ALIGN(4);
	    _eQSPI = .;
	} >SPI_FLASH