cancel
Showing results for 
Search instead for 
Did you mean: 

How can I generate an arbitrary interrupt from software?

arnold_w
Senior
Posted on February 01, 2016 at 15:20

I want to generate an interrupt from software in order to execute things in a different ''thread'' than the main()-thread. In other Microcontroller-brands I've been previously working with this has been very easy to achieve, I would simply enable the interrupt and set the interrupt flag. When I try to do that with my STM32F04-microcontroller, nothing happens:

RCC->APB1ENR |= RCC_APB1ENR_TIM3EN;
TIM3->DIER |= TIM_DIER_UIE; // Update interrupt enable
HAL_NVIC_EnableIRQ(TIM3_IRQn); // Enable interrupts
TIM3->SR |= TIM_SR_UIF; // Set interrupt flag
void TIM3_IRQHandler(void)
{
UART1_TransmitNullTerminatedString(''\r\nTIM3_IRQHandler''); // This is never executed. Why?
}

What is the proper way to issue arbitrary interrups (TIM3_IRQHandler, CAN1_RX0_IRQHandler, DMA2_Stream6_IRQHandler or whatever) from software?
3 REPLIES 3
dthedens
Associate II
Posted on February 01, 2016 at 16:57

perhaps read up on SETPEND and STIR.

arnold_w
Senior
Posted on February 01, 2016 at 17:06

Thanks for your reply. The following works fine (in this example I want to issue a

CAN1_TX_IRQHandler-interrupt):

HAL_NVIC_EnableIRQ(CAN1_TX_IRQn);
NVIC->STIR = CAN1_TX_IRQn;

Walid FTITI_O
Senior II
Posted on February 02, 2016 at 10:57

Hi arnold_w,

To generate a Timer update event (UEV)by software, you set the UG bit the TIMx_EGR register. before that,you should ensure that the URS bit is already is reset (default value).

/* Reset the URS bit */ 
TIM1-> CR1 &= ~ TIM_CR1_URS; 
/* Enable UEV by setting UG bit */ 
TIM1->EGR |= TIM_EGR_UG; 

-Hannibal-