Interrupts in HAL core for STM32F1 broken or daft programmer??

mailhouse
Tue Nov 01, 2016 12:42 am
board is nucleo stm32f103rb, arduino.cc ide 1.6.12

any time i try to set an IRQ, the board crashes. comment out the IRQ assignment and it runs like a champ, albeit without interrupts. any help is appreciated.

if the NVIC_EnableIRQ is after the TIM_CR1_CEN, then it hangs on the NVIC assignment. as below, it hangs on the TIM_CR1_CEN.

what am i not getting?

void setup() {

// put your setup code here, to run once:
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect.
}

Serial.println("Setting up TIM2");

RCC->APB1ENR |= RCC_APB1ENR_TIM2EN;

TIM2->SR = 0; // Clear status register flags
TIM2->PSC = 2000; // Set prescaler
TIM2->ARR = 36000; // set auto-reload register
TIM2->DIER = TIM_DIER_UIE; // update interrupt

Serial.println("Enabling TIM2 IRQ");
NVIC_SetPriority(TIM2_IRQn, 0);
//NVIC_EnableIRQ(TIM2_IRQn);

Serial.println("Enabling TIM2");
TIM2->CR1 |= TIM_CR1_CEN; // set control register 1 enable flag
Serial.println(TIM2->SR, BIN);

Serial.println("TIM2 setup complete");
Serial.println(TIM2->SR, BIN);
pinMode(13, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
//Serial.println(TIM2->CNT);
if (TIM2->CNT == 35000)
digitalWrite(13, HIGH);
if (TIM2->CNT == 36000)
digitalWrite(13, LOW);
}

void TM2_IRQHandler(void)
{
if(TIM2->SR & TIM_SR_UIF) // if UIF flag is set
{
TIM2->SR &= ~TIM_SR_UIF; // clear UIF flag
Serial.println("TM3 Interrupt");
}
}


RogerClark
Tue Nov 01, 2016 2:13 am
Which core are you using, the one in the stm32duino github account ?

mailhouse
Tue Nov 01, 2016 2:22 am
yes the github ones STM32F1 and STM32L4. should i be using something else?

RogerClark
Tue Nov 01, 2016 2:43 am
Thats the new official STM core, which has been designed by STM for use with the Nucleo board.

We also have the old repo / core based on the original Leaflabs LibMaple code.

This also has support for the Nucleo F103RB bit not the L476 nucleo etc

https://github.com/rogerclarkmelbourne/Arduino_STM32

But the LibMaple based repo does not use HAL, its a clean room implementation by Leaflabs because of licence restrictions when they wrote it in 2012

Anyway, if there is a bug in the Official STM core, you really need to log it as a bug in GitHub, or possibly post to one of the threads on this forum dedicated to that core.

This is the best thread to post to

viewtopic.php?f=48&t=1413&start=50

Because its monitored by Wi6Labs who actually wrote the code for STM


RogerClark
Tue Nov 01, 2016 2:44 am
Actually, if you don’t have a github account, I will log the issue for you and reference this thread

mailhouse
Tue Nov 01, 2016 1:54 pm
before i go reporting bugs, can someone else repeat the behavior?

RogerClark
Tue Nov 01, 2016 7:39 pm
Is it possible it is a bug in your code?

Does the same code compiled and run in another enviromment than the Arduino core and Arduino IDE?


mailhouse
Tue Nov 01, 2016 11:17 pm
its entirely possible. im very new to stm32, and new to 32bit mcu in general. its why im asking here first.

RogerClark
Tue Nov 01, 2016 11:38 pm
mailhouse wrote:its entirely possible. im very new to stm32, and new to 32bit mcu in general. its why im asking here first.

danieleff
Wed Nov 02, 2016 6:03 am
There is timer interrupt in timer.c, for example:

void blink(timer_id_e timer, uint32_t counter) {
digitalWrite(13, !digitalRead(PB1));
}
void setup() {
pinMode(13, OUTPUT);
TimerPulseInit(TIM2_E, 36000, 1000, blink);
}


mailhouse
Sat Nov 12, 2016 2:24 am
danieleff wrote:There is timer interrupt in timer.c, for example:

void blink(timer_id_e timer, uint32_t counter) {
digitalWrite(13, !digitalRead(PB1));
}
void setup() {
pinMode(13, OUTPUT);
TimerPulseInit(TIM2_E, 36000, 1000, blink);
}


Leave a Reply

Your email address will not be published. Required fields are marked *