cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L431 bootloader Not switching to application

harshel
Associate

I am working on STM32L431RCT6 microcontroller. Similar changes tried on STM32L053C8T6 also.

Using custom hardware for product development and hardware is validated.

 

I facing issue, bootloader not jumping to application. Instead it's creating hardfault: HardFault_Handler() after JumpToApplication().

 

Please let me know what can be made OR what's missing to switch to application successfully.

Here is sample code provided for reference.

 

Bootloader and Application code changes:

 

1. Linker file *.ld changes:

MEMORY

{

RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 48K

RAM2 (xrw) : ORIGIN = 0x10000000, LENGTH = 16K

FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 16K

}

 

2. Bootloader jump application code

 

#define ADDRESS_START_APP 0x08004000U

 

#define BOOTLOADER_WAIT_TIME 5000

 

typedef void (*pFunction)(void);

 

pFunction JumpToApplication;

 

uint32_t* pAddrApp = NULL;

uint32_t* pAddrStack = NULL;

 

void SwitchToApplication(void)

{

pAddrApp = ADDRESS_START_APP + 0x4U;

pAddrStack = ADDRESS_START_APP;

 

JumpToApplication = (pFunction) *pAddrApp;

 

HAL_RCC_DeInit();

HAL_DeInit();

/* reset all interrupts to default */

__disable_irq();

SysTick->CTRL = 0;

SysTick->LOAD = 0;

SysTick->VAL = 0;

 

__set_MSP(*pAddrStack);

 

JumpToApplication();

}

 

Application Firmware changes:

 

1. Linker file *.ld changes:

MEMORY

{

RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 48K

RAM2 (xrw) : ORIGIN = 0x10000000, LENGTH = 16K

FLASH (rx) : ORIGIN = 0x8004000, LENGTH = 240K

}

 

2. system_stm32l4xx.c changes

 

#define USER_VECT_TAB_ADDRESS

 

#if defined(USER_VECT_TAB_ADDRESS)

/*!< Uncomment the following line if you need to relocate your vector Table

in Sram else user remap will be done in Flash. */

/* #define VECT_TAB_SRAM */

 

#if defined(VECT_TAB_SRAM)

#define VECT_TAB_BASE_ADDRESS SRAM1_BASE /*!< Vector Table base address field.

This value must be a multiple of 0x200. */

#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.

This value must be a multiple of 0x200. */

#else

#define VECT_TAB_BASE_ADDRESS FLASH_BASE /*!< Vector Table base address field.

This value must be a multiple of 0x200. */

#define VECT_TAB_OFFSET 0x00004000U /*!< Vector Table base offset field.

This value must be a multiple of 0x200. */

#endif /* VECT_TAB_SRAM */

#endif /* USER_VECT_TAB_ADDRESS */

 

void SystemInit(void)

{

#if defined(USER_VECT_TAB_ADDRESS)

/* Configure the Vector Table location -------------------------------------*/

SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET;

#endif

 

/* FPU settings ------------------------------------------------------------*/

#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)

SCB->CPACR |= ((3UL << 20U)|(3UL << 22U)); /* set CP10 and CP11 Full Access */

#endif

}

 

3. main.c

 

while (1)

{

/* USER CODE END WHILE */

 

/* USER CODE BEGIN 3 */

HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_11);

HAL_Delay(1000);

}

 

 Thank you.

 

2 REPLIES 2

Dear Pavel,

Thank you for suggestion.

I have referred sample programs and based on tried many more.

I didn't get any satisfied solution, hence need support to find best and reliable solution along with technical reason.