Skip to main content
Visitor II
December 21, 2019
Question

STM32G4 IAP Bootloader Not Calling Application

  • December 21, 2019
  • 5 replies
  • 1368 views

Hi there,

I need an IAP bootloader via CAN interface with G431 MCU. Before I had developed for F446 and no problem, and it works properly, no problem, but not for G4.

The bootloader code has not called the application although set the stack pointer with __set_msp command and call the pointer function as shown in the example of st. Also, added the vector code command before HAL_Init function to the application main. During debugging the application already work properly. However, when it called in the bootloader, it doesn't work. I think there is a bug at CubeIDE or G4 MCU.

 I attached the code for the bootloader and linker file.

Bootloader code:

/* it's depending on the boot program and parameters */
#define k_ADDRESS_APP (12*1024UL)
 
int main(void)
{
 /* USER CODE BEGIN 1 */
 static volatile pf_application pfnc_jump_app = NULL;
 static volatile uint32_t dw_jump_app_address = 0;
 /* USER CODE END 1 */
 
 
 /* MCU Configuration--------------------------------------------------------*/
 
 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
 HAL_Init();
 
 /* USER CODE BEGIN Init */
 
 /* USER CODE END Init */
 
 /* Configure the system clock */
 SystemClock_Config();
 
 /* USER CODE BEGIN SysInit */
 
 /* USER CODE END SysInit */
 
 /* Initialize all configured peripherals */
 MX_GPIO_Init();
 /* USER CODE BEGIN 2 */
 /* Jump to user application */
 dw_jump_app_address = *(volatile uint32_t*)(k_ADDRESS_APP + 4);
 pfnc_jump_app = (pf_application)dw_jump_app_address;
 /* Initialize user application's Stack Pointer */
 __set_MSP(*(volatile uint32_t*)k_ADDRESS_APP);
 /* Jump to application */
 pfnc_jump_app();
}

Bootloader Linker File:

/* Memories definition */
MEMORY
{
 RAM	(xrw)	: ORIGIN = 0x20000000,	LENGTH = 32K
 FLASH	(rx)	: ORIGIN = 0x8000000,	LENGTH = 12K
}

The Application Code:

int main(void)
{
 /* USER CODE BEGIN 1 */
 SCB->VTOR = (FLASH_BASE | 0x3000);
 /* USER CODE END 1 */
 
 
 /* MCU Configuration--------------------------------------------------------*/
 
 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
 HAL_Init();
 
 /* USER CODE BEGIN Init */
 
 /* USER CODE END Init */
 
 /* Configure the system clock */
 SystemClock_Config();
...

and application linker:

/* Memories definition */
MEMORY
{
 RAM	(xrw)	: ORIGIN = 0x20000000,	LENGTH = 32K
 FLASH	(rx)	: ORIGIN = 0x8003000,	LENGTH = 116K
}

    This topic has been closed for replies.

    5 replies

    Graduate II
    December 21, 2019

    >> However, when it called in the bootloader, it doesn't work. I think there is a bug at CubeIDE or G4 MCU.

    Hard to say, you're going to need to debug better, review the generated code, and determine what exactly the MCU is doing and where it gets stuck.

    Visitor II
    December 23, 2019

    In bootloader code, after run the SystemClockConfig, not called the application code. 

    If this function is disabled, then the application works properly. Why the clock config is causing problems?

    Graduate II
    December 23, 2019

    Perhaps it makes assumptions about the clocks, and turns off the source it is clocking from?

    Should check current settings before tearing down and doing over.

    Shouldn't assume reset state, and using HSI, or whatever.​

    Graduate II
    December 24, 2019

    As with all ST's code, their solution is absolute crap. Here is a much better approach:

    https://community.st.com/s/question/0D50X0000AFpTmUSQV/using-nvicsystemreset-in-bootloaderapplication-jumps

    Visitor II
    April 1, 2020

    Adding HAL_DeInit() before jump function works for me. You can try that. I am working on stm32g474re