Generate Software Interrupt (SI) with STM32F· Discovery board with HAL drivers
Thanks for the answer diabolo, and sorry for not answering you earlier. I’ve read more information about FreeRTOS but I still couldn’t figure out how to make a timer properly. Now I’ve defined a timer of 1KHz frequency with the FreeRTOS API and a callback function like this:
/* Create the timer(s) */
/* definition and creation of myTimer01 */
osTimerDef(myTimer01, Callback01);
myTimer01Handle = osTimerCreate(osTimer(myTimer01), osTimerPeriodic, NULL);
/* USER CODE BEGIN RTOS_TIMERS */
/* start timers, add new ones, ... */
osTimerStart(myTimer01Handle,1);
/* USER CODE END RTOS_TIMERS */
/* Create the thread(s) */
/* definition and creation of defaultTask */
osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 128);
defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
In the callback I set a clock of 1KHz in a GPIO and every 100 ms I activate a SWI.
/* Callback01 function */
void Callback01(void const * argument)
{
/* USER CODE BEGIN Callback01 */
HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_1);
contador_timer++;
if (contador_timer == 100){
contador_timer = 0;
flag_SI = 1;
HAL_GPIO_TogglePin(GPIOE,GPIO_PIN_10);
//EXTI->SWIER |= EXTI_SWIER_SWIER0;
__HAL_GPIO_EXTI_GENERATE_SWIT(EXTI_SWIER_SWIER2);
}
/* USER CODE END Callback01 */
}
In the SWI I trie to set a GPIO and wait 200 ms until the next change of value, but the output change every 100 ms and I don’t know why.
void EXTI2_TSC_IRQHandler(void)
{
/* USER CODE BEGIN EXTI2_TSC_IRQn 0 */
if ((__HAL_GPIO_EXTI_GET_IT(EXTI_SWIER_SWIER2) != RESET) && (flag_SI == 1)){
//HAL_GPIO_WritePin(GPIOC,GPIO_PIN_2, GPIO_PIN_SET);
HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_2);
while(delay_SI > 0)
{
delay_SI = delay_SI - 1;
}
delay_SI = 200;
__HAL_GPIO_EXTI_CLEAR_IT(EXTI_SWIER_SWIER2);
flag_SI = 0;
}
/* USER CODE END EXTI2_TSC_IRQn 0 */
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_2);
/* USER CODE BEGIN EXTI2_TSC_IRQn 1 */
/* USER CODE END EXTI2_TSC_IRQn 1 */
}
There is some manual for the correct configuration of FreeRTOS for STM32CubeMX?
Thanks.