I already have a bare-metal code for timer working with ChibiOS which simply blinks an LED. However, when I try to use the HAL in ChibiOS, the LED stops blinking. Interestingly, if I put a breakpoint in callback function, the led actually lights up / turns off as I continue. However, when no break points present, LED does not seem to change state. Using the same ARR/PSC configuration in my bare metal code gives a 2Hz blinking rate, but the ChibiOS one does not work.
Code: Select all
void vTIM3Init(void) {
TIM_TypeDef *t = TIM3;
uint16_t tmpcr1 = 0;
RCC->APB1ENR |= RCC_APB1ENR_TIM3EN;
nvicEnableVector(STM32_TIM3_NUMBER, CORTEX_PRIORITY_MASK(STM32_GPT_TIM3_IRQ_PRIORITY));
tmpcr1 = t->CR1;
/* Auto reload buffer enabled.*/
tmpcr1 |= TIM_CR1_ARPE;
tmpcr1 &= ~(TIM_CR1_DIR | TIM_CR1_CMS);
t->CR1 = tmpcr1;
t->ARR = 24999;
/* Update Interrupt TIM3 */
t->DIER |= TIM_DIER_UIE;
/* Prescale CLKAPB / 1 */
t->PSC = 959;
t->EGR |= TIM_EGR_UG;
/* Update as TRGO */
t->CR2 &= ~TIM_CR2_MMS;
t->CR2 |= TIM_CR2_MMS_1;
/* Enable Timer */
t->CR1 |= TIM_CR1_CEN;
}
void STM32_TIM3_HANDLER(void) {
if (TIM3->SR & 0x0001) {
if (!ledval) {
GPIOA->BSRR.H.set = 1 << 5;
ledval = 1;
}
else {
GPIOA->BSRR.H.clear = 1 << 5;
ledval = 0;
}
}
TIM3->SR &= ~TIM_SR_UIF;
}
The followint is the ChibiOS code:
Code: Select all
static const GPTConfig xTIM3Config = {
50000,
cbTIM3
};
void vTIM3Config(void) {
gptStart(&GPTD3, &xTIM3Config);
gptStartContinuous(&GPTD3, 25000);
}
void cbTIM3(GPTDriver* gptp) {
/* (void) gptp; */
if (TIM3->SR & 0x0001) {
if (!ledval) {
GPIOA->BSRR.H.set = 1 << 5;
ledval = 1;
}
else {
GPIOA->BSRR.H.clear = 1 << 5;
ledval = 0;
}
}
TIM3->SR &= ~TIM_SR_UIF;
}