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

STM32F103 Nucleo boards e.g. STM Nucleo F103RB
mailhouse
Posts: 26
Joined: Tue Nov 01, 2016 12:19 am

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

Postby 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?

Code: Select all

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");
  }
}




using the HAL library calls has the same effect.

Code: Select all

#ifdef __cplusplus
extern "C"
#endif

TIM_HandleTypeDef s_TimerInstance = {
    .Instance = TIM2
};

void InitializeTimer()
{
    __TIM2_CLK_ENABLE();
    s_TimerInstance.Init.Prescaler = 36000;
    s_TimerInstance.Init.Period = 2000;
    s_TimerInstance.Init.CounterMode = TIM_COUNTERMODE_UP;
    s_TimerInstance.Init.RepetitionCounter = 0;
    s_TimerInstance.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
    HAL_NVIC_SetPriority(TIM2_IRQn, 0, 0);
    //HAL_NVIC_EnableIRQ(TIM2_IRQn);
    HAL_TIM_Base_Init(&s_TimerInstance);
    HAL_TIM_Base_Start_IT(&s_TimerInstance); 
}

void InitializeLED()
{
    __GPIOA_CLK_ENABLE();
    GPIO_InitTypeDef GPIO_InitStructure;

    GPIO_InitStructure.Pin = GPIO_PIN_5;
    GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
    GPIO_InitStructure.Pull = GPIO_NOPULL;
    HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
}


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect.
  }
   
    HAL_Init();
    Serial.print("HAL Version 0x");
    Serial.println(HAL_GetHalVersion(), HEX);
    Serial.print("Device ID ");
    Serial.println(HAL_GetDEVID());
   
    InitializeLED();
    InitializeTimer();

}

void loop() {
  // put your main code here, to run repeatedly:
       
        int timerValue = __HAL_TIM_GET_COUNTER(&s_TimerInstance);
        ///*
        if (timerValue == 1950)
            HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);
        if (timerValue == 2000)
            HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);
        //*/
        //Serial.println(timerValue);
       


        /*
        if (__HAL_TIM_GET_FLAG(&s_TimerInstance, TIM_FLAG_UPDATE) != RESET)
        {
            __HAL_TIM_CLEAR_IT(&s_TimerInstance, TIM_IT_UPDATE);
            HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
            //Serial.println("Update event");
        }
        */
       
}



User avatar
RogerClark
Posts: 5470
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

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

Postby RogerClark » Tue Nov 01, 2016 2:13 am

Which core are you using, the one in the stm32duino github account ?

mailhouse
Posts: 26
Joined: Tue Nov 01, 2016 12:19 am

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

Postby mailhouse » Tue Nov 01, 2016 2:22 am

yes the github ones STM32F1 and STM32L4. should i be using something else?

User avatar
RogerClark
Posts: 5470
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

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

Postby 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

User avatar
RogerClark
Posts: 5470
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

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

Postby 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
Posts: 26
Joined: Tue Nov 01, 2016 12:19 am

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

Postby mailhouse » Tue Nov 01, 2016 1:54 pm

before i go reporting bugs, can someone else repeat the behavior?

User avatar
RogerClark
Posts: 5470
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

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

Postby 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
Posts: 26
Joined: Tue Nov 01, 2016 12:19 am

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

Postby 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.

User avatar
RogerClark
Posts: 5470
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

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

Postby 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.


I don't think there are that many members of the forum that use the HAL, as until fairly recently the only Arduino STM core we had was the one written by Leaflabs (LibMaple) , which doesn't use the HAL.

You could try posting to STM's own official forum, which has lots of HAL users and one of them may be able to help.


Effectively what is missing from the STM Arduino core is Hardware Timer support.

We have this in LibMaple, as an internal implementation, but what the STM core needs is something like the AVR Arduino "Timer1" etc
http://playground.arduino.cc/Code/Timer1

But as this is not an internal Arduino library, I don't think it would be on STM's To Do list, as AFIK they only intend to support internal Arduino libraries

danieleff
Posts: 147
Joined: Thu Sep 01, 2016 8:52 pm
Location: Hungary
Contact:

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

Postby danieleff » Wed Nov 02, 2016 6:03 am

There is timer interrupt in timer.c, for example:

Code: Select all

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

It is not exactly what you want, but check out that code.


Return to “STM Nucleo boards”

Who is online

Users browsing this forum: No registered users and 1 guest