cancel
Showing results for 
Search instead for 
Did you mean: 

Firmware (with FreeRTOS) does not run when nDBoot is enabled

lealmicael
Associate II

Hello, everyone!

MCU: STM32F765ZIT.

FLASH size: 2MB.

I have a problem when running my firmware, with FreeRTOS, with or without a debugger.

My code is crashing in the HAL_Init() function when nDBoot¹ is enabled.

When I initialize the code through the debugger, it enters the HAL_Init()² function and crashes when trying to execute the HAL_MspInit() line, but I suspect that the problem actually occurs in the previous function, HAL_InitTick(TICK_INT_PRIORITY)³.

My function uses Timer 7 as the default for the FreeRTOS tick, as recommended by ST itself when using this middleware.

For testing purposes, I modified the HAL_InitTick function so that it would be similar to the HAL default⁴.

Even after this modification, it did not work.

So, after further testing, I decided to disable nDBoot (setting it as checked by STM32CubeProgrammer) and then the code worked perfectly. nDBank remained unchecked.

The problem is that now, without nDBoot enabled, I can no longer use dual boot mode and switch banks.

If anyone can help me, I will be very grateful

-------------------------------------------------------------------------------------------

¹ I needed to enable nDBoot and nDBank (set as unchecked by STM32CubeProgrammer) because I am working with Dual Boot, and I have a firmware recorded in each bank.

-------------------------------------------------------------------------------------------

² My HAL_Init function:

HAL_StatusTypeDef HAL_Init(void)
{
/* Configure Instruction cache through ART accelerator */
#if (ART_ACCLERATOR_ENABLE != 0)
__HAL_FLASH_ART_ENABLE(); #endif /* ART_ACCLERATOR_ENABLE */ /* Configure Flash prefetch */ #if (PREFETCH_ENABLE != 0U) __HAL_FLASH_PREFETCH_BUFFER_ENABLE();
#endif /* PREFETCH_ENABLE */ /* Set Interrupt Group Priority */ HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);

/* Use systick as time base source and configure 1ms tick (default clock after Reset is HSI) */ HAL_InitTick(TICK_INT_PRIORITY);

/* Init the low level hardware */ HAL_MspInit();

/* Return function status */ return HAL_OK;
}

-------------------------------------------------------------------------------------------

³ My function HAL_InitTick(TICK_INT_PRIORITY):

HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) {

RCC_ClkInitTypeDef clkconfig;
uint32_t uwTimclock = 0;
uint32_t uwPrescalerValue = 0;
uint32_t pFLatency;
/*Configure the TIM7 IRQ priority */ HAL_NVIC_SetPriority(TIM7_IRQn, TickPriority ,0);

/* Enable the TIM7 global Interrupt */ HAL_NVIC_EnableIRQ(TIM7_IRQn);
/* Enable TIM7 clock */ __HAL_RCC_TIM7_CLK_ENABLE();

/* Get clock configuration */ HAL_RCC_GetClockConfig(&clkconfig, &pFLatency);

/* Compute TIM7 clock */ uwTimclock = 2*HAL_RCC_GetPCLK1Freq();
/* Compute the prescaler value to have TIM7 counter clock equal to 1MHz */ uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U);

/* Initialize TIM7 */ htim7.Instance = TIM7;

/* Initialize TIMx peripheral as follow: + Period = [(TIM7CLK/1000) - 1]. to have a (1/1000) s base time.
+ Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock.
+ ClockDivision = 0 + Counter direction = Up */ htim7.Init.Period = (1000000U / 1000U) - 1U;
htim7.Init.Prescaler = uwPrescalerValue;
htim7.Init.ClockDivision = 0;
htim7.Init.CounterMode = TIM_COUNTERMODE_UP;
if(HAL_TIM_Base_Init(&htim7) == HAL_OK) { /* Start the TIM time Base generation in interrupt mode */ return HAL_TIM_Base_Start_IT(&htim7);
} /* Return function status */ return HAL_ERROR;
}

--------------------------------------------------------------------------------------------

⁴ Default HAL_InitTick function:

__weak HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) {

/* Configure the SysTick to have interrupt in 1ms time basis*/ if (HAL_SYSTICK_Config(SystemCoreClock / (1000U / uwTickFreq)) > 0U) return HAL_ERROR;
} /* Configure the SysTick IRQ priority */ if (TickPriority < (1UL << __NVIC_PRIO_BITS)) { HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority, 0U);
uwTickPrio = TickPriority;
} else { return HAL_ERROR;
} /* Return function status */ return HAL_OK;
}
1 ACCEPTED SOLUTION

Accepted Solutions
lealmicael
Associate II

Guys, I'm just here to tell you how I solved my problem.

Basically, it was a problem related to VTOR (Vector Table Offset). When initializing the code, the value contained in VTOR was always 0x100000 (system memory bootloader address).

What I hadn't realized was that my SystemInit function (system_stm32f7xx.c file) wasn't making the following assignment:

SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET;

This was happening because USER_VECT_TAB_ADDRESS was not defined at the beginning of the file.

So, I just uncommented the line #define USER_VECT_TAB_ADDRESS and everything worked perfectly!

Here's the log to help anyone who needs it.

View solution in original post

4 REPLIES 4
Sarra.S
ST Employee

Hello @lealmicael, welcome to the Community, 

Could you share your project to try and reproduce and debug on our side? I'm not sure HAL_InitTick(TICK_INT_PRIORITY) is the faulty instruction, we have to get more details 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hello @Sarra.S, sorry for the delay.

Here is the zipped file of the project.

As I said before, this project works normally when nDBoot is checked. But when unchecked it crashes in HAL_Init().

In my tests nDBank is always unchecked.

lealmicael_0-1726076508456.png

lealmicael
Associate II

Guys, I'm just here to tell you how I solved my problem.

Basically, it was a problem related to VTOR (Vector Table Offset). When initializing the code, the value contained in VTOR was always 0x100000 (system memory bootloader address).

What I hadn't realized was that my SystemInit function (system_stm32f7xx.c file) wasn't making the following assignment:

SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET;

This was happening because USER_VECT_TAB_ADDRESS was not defined at the beginning of the file.

So, I just uncommented the line #define USER_VECT_TAB_ADDRESS and everything worked perfectly!

Here's the log to help anyone who needs it.

StevenF
Associate

Thank you so much @lealmicael! I was having this exact same problem.

@Sarra.S Can this information please be added to an2606?