2019-12-21 04:59 AM
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
}
2019-12-21 08:06 AM
>> 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.
2019-12-22 09:28 PM
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?
2019-12-23 04:36 AM
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.
2019-12-24 01:24 AM
As with all ST's code, their solution is absolute crap. Here is a much better approach:
2020-04-01 05:55 AM
Adding HAL_DeInit() before jump function works for me. You can try that. I am working on stm32g474re