2024-04-14 07:32 AM
I'm learning to port FreeRTOS to my STM32F407, but I'm running into problems with HAL initializing TIM2.
After HAL_OK the program is supposed to enable TIM2IRQ via NVIC_EnableIRQ(), but the operation of writing to NVIC->ISER doesn't seem to work.
NVIC->ISER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
So I followed this post and modified 'CMSIS\Include\core_cm4.h', but again it didn't work.
uint32_t data;
uint32_t index;
if ((int32_t)(IRQn) >= 0)
{
__COMPILER_BARRIER();
index = ((uint32_t)IRQn) >> 5UL;
data = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
NVIC->ISER[index] = data;
__COMPILER_BARRIER();
}
My debugger won't continue after this expression, any ideas?
2024-04-14 08:21 AM
I have no idea what how to config NVIC register...
2024-04-14 08:35 AM
Why you are trying to fix good function? Ptoblem seems to be in another place. NVIC can be probably edited only in privilage mode or something, or...
Search problem in Your code,
2024-04-14 02:24 PM
@Jemegen Please, show the actual code. What means "after HAL_OK"?
2024-04-14 06:26 PM
HAL_OK is the return value of HAL_TIM_Base_Init() in HAL_InitTick()
Core\Src\stm32f4xx_hal_timebase_tim.c:
htim2.Init.Period = (1000000U / 1000U) - 1U;
htim2.Init.Prescaler = uwPrescalerValue;
htim2.Init.ClockDivision = 0;
htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
status = HAL_TIM_Base_Init(&htim2);
if (status == HAL_OK)
{
/* Start the TIM time Base generation in interrupt mode */
status = HAL_TIM_Base_Start_IT(&htim2);
if (status == HAL_OK)
{
/* Enable the TIM2 global Interrupt */
HAL_NVIC_EnableIRQ(TIM2_IRQn);
/* Configure the SysTick IRQ priority */
if (TickPriority < (1UL << __NVIC_PRIO_BITS))
{
/* Configure the TIM IRQ priority */
HAL_NVIC_SetPriority(TIM2_IRQn, TickPriority, 0U);
uwTickPrio = TickPriority;
}
else
{
status = HAL_ERROR;
}
}
}
/* Return function status */
return status;
HAL_NVIC_EnableIRQ(TIM2_IRQn) calls NVIC_EnableIRQ(), which is __NVIC_EnableIRQ()
Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_cortex.c:
void HAL_NVIC_EnableIRQ(IRQn_Type IRQn)
{
/* Check the parameters */
assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
/* Enable interrupt */
//NVIC_SetVector(TIM2_IRQn, TIM2_BASE);
NVIC_EnableIRQ(IRQn);
}
These are the code generated by HAL and I don't understand what is wrong. HAL_Init() in main() is the first to perform peripheral initialization.
Core\Src\main.c:
int main(void)
{
TaskHandle_t task1_handler;
TaskHandle_t task2_handler;
BaseType_t status;
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
//NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 );
status = xTaskCreate(task1_handler,"Task1",100,NULL,2,&task1_handler);
configASSERT( status == pdPASS);
status = xTaskCreate(task2_handler,"Task2",100,NULL,2,&task2_handler);
configASSERT( status == pdPASS);
vTaskStartScheduler();
while (1)
{
}
}