2022-09-09 02:28 AM
I have flashed bootloader code at 0x08000000 location.
Also, I have flashed application (2 cores) out of which
M7 core resides at 0x08040000 location &
M4 core resides at 0x08100000 location.
Now, in debug mode, the bootloader and the application is working together, i.e after reset bootloader code will be executed and from their application is booted. In order to verify the run state of application I toggle 1 LED in M7 core and 1 LED in M4 core. So, both are happening.
But, In free run mode, its not working the same. Instead after bootloader execution, its not jumping to application.
I am clueless why this is happening.
Following are my configurations done,
Bootloader_main.c:
static void goto_application(void)
{
printf("Gonna Jump to Application\n");
void (*app_reset_handler)(void) = (void*)(*((volatile uint32_t*) (0x08040000 + 4U)));
//__set_MSP(*(volatile uint32_t*) 0x08040000);
// Turn OFF the Green Led to tell the user that Bootloader is not running
HAL_GPIO_WritePin(LED_GREEN_BL_GPIO_Port, LED_GREEN_BL_Pin, GPIO_PIN_RESET ); //Green LED OFF
app_reset_handler(); //call the app reset handler
}
Application_CM7_STM32H757XIHX_FLASH.ld file:
/* Memories definition */
MEMORY
{
RAM_D1 (xrw) : ORIGIN = 0x24000000, LENGTH = 512K
FLASH (rx) : ORIGIN = 0x08040000, LENGTH = 512K
DTCMRAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
RAM_D2 (xrw) : ORIGIN = 0x30000000, LENGTH = 288K
RAM_D3 (xrw) : ORIGIN = 0x38000000, LENGTH = 64K
ITCMRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 64K
}
Application_CM4_STM32H757XIHX_FLASH.ld file:
MEMORY
{
FLASH (rx) : ORIGIN = 0x08100000, LENGTH = 1024K
RAM (xrw) : ORIGIN = 0x10000000, LENGTH = 288K
}
system_stm32h7xx_dualcore_boot_cm4_cm7.c
#elif defined(CORE_CM7)
#define VECT_TAB_OFFSET 0x00040000U
Let me know if I am missing anything in this.
2022-09-09 08:30 AM
Show bootloader main code more precise.
main
{
...
...
call go app
}
one example from git
__attribute__((noreturn)) static void boot_to(uint32_t addr)
{
const uint32_t *vtor = (uint32_t *)addr;
__disable_irq();
SCB_InvalidateDCache();
SCB_InvalidateICache();
NVIC->ICER[0] = 0xFFFFFFFF;
NVIC->ICER[1] = 0xFFFFFFFF;
NVIC->ICER[2] = 0xFFFFFFFF;
NVIC->ICER[3] = 0xFFFFFFFF;
NVIC->ICER[4] = 0xFFFFFFFF;
NVIC->ICER[5] = 0xFFFFFFFF;
NVIC->ICER[6] = 0xFFFFFFFF;
NVIC->ICER[7] = 0xFFFFFFFF;
NVIC->ICPR[0] = 0xFFFFFFFF;
NVIC->ICPR[1] = 0xFFFFFFFF;
NVIC->ICPR[2] = 0xFFFFFFFF;
NVIC->ICPR[3] = 0xFFFFFFFF;
NVIC->ICPR[4] = 0xFFFFFFFF;
NVIC->ICPR[5] = 0xFFFFFFFF;
NVIC->ICPR[6] = 0xFFFFFFFF;
NVIC->ICPR[7] = 0xFFFFFFFF;
SysTick->CTRL = 0;
SysTick->LOAD = 0; // Needed?
SysTick->VAL = 0; // Needed?
SCB->ICSR |= SCB_ICSR_PENDSTCLR_Msk;
SCB->SHCSR &= ~(SCB_SHCSR_USGFAULTENA_Msk | //
SCB_SHCSR_BUSFAULTENA_Msk | //
SCB_SHCSR_MEMFAULTENA_Msk);
SCB->VTOR = addr;
__set_MSP(vtor[0]);
__set_PSP(vtor[0]);
__set_CONTROL(0);
void (*entry)(void) __attribute__((noreturn)) = (void *)vtor[1];
entry();
for (;;)
;
}
2022-09-11 11:34 PM
Here is the code related to Bootloader,
Bootloader main:
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* USER CODE BEGIN Boot_Mode_Sequence_0 */
// int32_t timeout;
/* USER CODE END Boot_Mode_Sequence_0 */
/* USER CODE BEGIN Boot_Mode_Sequence_1 */
/* Wait until CPU2 boots and enters in stop mode or timeout*/
// timeout = 0xFFFF;
// while((__HAL_RCC_GET_FLAG(RCC_FLAG_D2CKRDY) != RESET) && (timeout-- > 0));
// if ( timeout < 0 )
// {
// Error_Handler();
// }
/* USER CODE END Boot_Mode_Sequence_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 Boot_Mode_Sequence_2 */
/* When system initialization is finished, Cortex-M7 will release Cortex-M4 by means of
HSEM notification */
/*HW semaphore Clock enable*/
__HAL_RCC_HSEM_CLK_ENABLE();
/*Take HSEM */
//HAL_HSEM_FastTake(HSEM_ID_0);
///*Release HSEM in order to notify the CPU2(CM4)*/
//HAL_HSEM_Release(HSEM_ID_0,0);
///* wait until CPU2 wakes up from stop mode */
//timeout = 0xFFFF;
//while((__HAL_RCC_GET_FLAG(RCC_FLAG_D2CKRDY) == RESET) && (timeout-- > 0));
//if ( timeout < 0 )
//{
//Error_Handler();
//}
/* USER CODE END Boot_Mode_Sequence_2 */
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART1_UART_Init();
/* USER CODE BEGIN 2 */
// Turn ON the Green Led to tell the user that Bootloader is running
HAL_GPIO_WritePin(LED_GREEN_BL_GPIO_Port, LED_GREEN_BL_Pin, GPIO_PIN_RESET ); //Green LED ON
printf("Starting Bootloader(%d.%d)\n", BL_Version[0], BL_Version[1] );
HAL_Delay(2000); //2sec delay for nothing
// Jump to application
goto_application();
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
// HAL_GPIO_TogglePin(LED_GREEN_BL_GPIO_Port, LED_GREEN_BL_Pin);
// HAL_Delay(1000);
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
Note: Here you may find some commented part, which is done is order to remove CM4 boot, only CM7 is there on bootloader code part.
static void goto_application(void)
{
printf("Gonna Jump to Application\n");
void (*app_reset_handler)(void) = (void*)(*((volatile uint32_t*) (0x08040000 + 4U)));
//__set_MSP(*(volatile uint32_t*) 0x08040000); //Do we need to uncomment this line???
// Turn OFF the Green Led to tell the user that Bootloader is not running
HAL_GPIO_WritePin(LED_GREEN_BL_GPIO_Port, LED_GREEN_BL_Pin, GPIO_PIN_RESET ); //Green LED OFF
app_reset_handler(); //call the app reset handler
}
Note: This code works fine when the application is having 1 core, but the same bootloader code doesn't work when the application is having 2 cores...