cancel
Showing results for 
Search instead for 
Did you mean: 

custom bootloader/linker script issue when converting from SW --> CubeIDE

DSala.18
Associate

So we currently have a project where 1 single binary runs on different type of PCB boards (with the same MCU (stm32f303rct6) but is connected to different peripherals - for example, we have a motorboard, a solenoidboard, a powerboard, a sensorsboard. All these boards run the same binary, and a flag in a certain section in the FLASH determines which HAL/MSP Init functions it should run.

The above mentioned project is called f3_application, which is ± 112K. To support firmware flashing through the uart port, we have also reserved 112K for an incoming new firmware.

We also have a f3_bootloader project which upon startup checks if it should copy the new firmware to the application section, and then starts the application by overriding the vector table offset, set the application stack pointer, and then running the application at that address.

This above has worked perfectly in Eclipse 2019 AC6 System Workbench.

Now, we have to add a new MCU to this codebase, but we still want to use the same library etc, so I started converting this project to a CubeIDE project but I already encounter strange bugs here...

Bootloader Linker file:

/* Entry Point */
 
ENTRY(Reset_Handler)
/* Highest address of the user mode stack */ 
_estack = 0x2000A000; /* end of "RAM" Ram type memory */
   
_Min_Heap_Size = 0x200; /* required amount of heap */ 
_Min_Stack_Size = 0x400; /* required amount of stack */ 
 
/* Memories definition */ 
MEMORY 
{ 
 CCMRAM (xrw)  : ORIGIN = 0x10000000, LENGTH = 8K
 RAM  (xrw) : ORIGIN = 0x20000000, LENGTH = 40K 
 FLASH (rx)  : ORIGIN = 0x08000000, LENGTH = 24K 
 DATA (rx)  : ORIGIN = 0x08006000, LENGTH = 8K
}
 
[..]

main.c (excerpt)

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{
  [..]
  pFunction appEntry;
  uint32_t appStack;
 
  // APPLICATION_ADDRESS 0x08008000
 
  /* Get the application stack pointer (First entry in the application vector table) */
  appStack = (uint32_t) *((__IO uint32_t*) APPLICATION_ADDRESS);
 
  /* Get the application entry point (Second entry in the application vector table) */
  appEntry = (pFunction) *(__IO uint32_t*) (APPLICATION_ADDRESS + 4);
 
  /* Reconfigure vector table offset register to match the application location */
  SCB->VTOR = APPLICATION_ADDRESS;
 
  /* Set the application stack pointer */
  __set_MSP(appStack);
 
  /* Start the application */
  appEntry();
 
  /* USER CODE END 2 */
 
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
	  HAL_Delay(100);
	  HAL_GPIO_TogglePin(OutputBoard_State_DataBus_GPIO_Port, OutputBoard_State_DataBus_Pin);
  }
  /* USER CODE END 3 */
}

 When I run this, it crashes on line 14 when I assign appEntry:

0693W00000aIv1GQAS.png 

If I comment all this code and let it go into the while loop, it functions normally.

So I know it has to do something with the memory addresses - but I am unsure how to continue from here.

How do I make this project working again in CubeIDE, and preferably without re-flashing all existing boards with a new bootloader (if this is possible: a bootloader built with SW6 that starts the application built with CubeIDE)

So total memory is divided as follows:

CCMRAM (xrw): ORIGIN = 0x10000000, LENGTH = 8K
RAM (xrw)   : ORIGIN = 0x20000000, LENGTH = 40K
FLASH (rx)  : ORIGIN = 0x08000000, LENGTH = 24K  (bootloader)
DATA (rwx)  : ORIGIN = 0x08006000, LENGTH = 8K   (shared flash memory)
FLASH (rwx) : ORIGIN = 0x08008000, LENGTH = 112K (application)
IMAGE (rwx) : ORIGIN = 0x08024000, LENGTH = 112K (new firmware)

2 REPLIES 2

Watch what address it is actually using. Look at generated code.

Watch for changing the stack frame and how that will impact auto/local variables in the current scope.

Suggest letting the Reset_Handler in the app code set its own initial SP value, negating the need to do it here.​

Have a HardFault_Handler that does something useful.

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

> it crashes on line 14 

It's the time to get acquainted with the hardfault analyzer of CubeIDE. (does SW3STM32 have this tool too?)

When you change VTOR in line 20, the next systick interrupt will arrive there.