2025-06-08 12:02 AM - edited 2025-06-08 12:09 AM
Hi,
I'm working on STM32H7A3NIH6
Firmware Package: STM32Cube FW_H7 V1.11.2
I have a very interesting issue with bootloader jumping.
According to the file "an2606-stm32-microcontroller-system-memory-boot-mode-stmicroelectronics", the bootloader address is 0x1FF0A000.
The issue:
Sometime its works (succeed to jump into the bootloader, and succeed to program by STM32CubeProgrammer), and sometime is not.
After investigation, I found that when it is not works, it is because the jumping function stuck in HAL function named SCB_DisableDCache().
In SCB_DisableDCache(), there is a while loop that reduce a variable named "sets", and when it came to be zero, the loop is done, and the jumping is continue.
The variable "sets" value starting with some value, 127 for example, and sometime without any reason it changed to a non-reasonable number (605028303), and the loop is continued and continued.
SCB_DisableDCache() is a pure HAL function.
I'm using this function in the bootloader jumping function because I'm using SCB_EnableICache() & SCB_EnableDCache() in the main.
BTW, I noted, that if I'm jump before the function SCB_EnableDCache(), there is no issues.
Maybe there is something in the D cache?
tnx!
my jumping function:
void jumpToBootloader()
{
volatile uint32_t BOOTLOADER_ADDRESS = 0x1FF0A000;
// Prepare the micro controller for the jump.
// Reset all interrupts
__disable_irq();
for (uint16_t i = 0; i < sizeof(NVIC->ICER) / sizeof(NVIC->ICER[0]); ++i)
{
NVIC->ICER[i] = 0xFFFFFFFF;
NVIC->ICPR[i] = 0xFFFFFFFF;
}
//clean all caches.
//note!! the Disable performs also clean & invalidate.
SCB_DisableDCache();
SCB_DisableICache();
// disable SysTick timer
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
__enable_irq();
// peripherals if necessary
HAL_RCC_DeInit();
HAL_DeInit();
SCB->VTOR = BOOTLOADER_ADDRESS;
// Set main stack pointer (MSP) to the bootloader's MSP.
__set_MSP(*(uint32_t*)(BOOTLOADER_ADDRESS));
// Get the bootloader's reset vector address and jump to it.
void (*SysMemBootJump)(void);
SysMemBootJump = (void (*)(void))(*(uint32_t*)(BOOTLOADER_ADDRESS + 4));
SysMemBootJump();
//the program should not get here, it should be in bootloader mode.
}
My Main (pure HAL, only added jumpToBootloader() at line 18, for tests):
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MPU Configuration--------------------------------------------------------*/
MPU_Config();
/* Enable the CPU Cache */
/* Enable I-Cache---------------------------------------------------------*/
SCB_EnableICache();
/* Enable D-Cache---------------------------------------------------------*/
SCB_EnableDCache();
jumpToBootloader(); // for tests
/* 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();
/* Configure the peripherals common clocks */
PeriphCommonClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_OCTOSPI1_Init();
MX_USART1_UART_Init();
MX_ADC2_Init();
MX_I2C4_Init();
MX_TIM8_Init();
MX_USART3_UART_Init();
MX_SPI4_Init();
MX_SPI5_Init();
MX_SPI6_Init();
MX_DAC1_Init();
MX_UART4_Init();
MX_I2C2_Init();
MX_SPI1_Init();
MX_ADC1_Init();
MX_I2C1_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Init scheduler */
osKernelInitialize();
/* Call init function for freertos objects (in cmsis_os2.c) */
MX_FREERTOS_Init();
/* Start scheduler */
osKernelStart();
/* We should never get here as control is now taken by the scheduler */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
2025-06-08 6:29 AM - edited 2025-06-08 6:30 AM
Solved: Problems using the Cache and SCB_DisableDCache in ... - STMicroelectronics Community
Note that SCB_DisableDCache is a CMSIS function, not HAL.
Seems to be fixed in CMSIS but not adopted by ST's CMSIS.
Fix the endless loop issue with GCC O0. · ARM-software/CMSIS_5@36bd54f
2025-06-09 1:14 AM
Tnx!
So, how can I take the solution?
there is any Firmware Package with this fix?