Skip to content

Timer pull request #447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
Closed

Timer pull request #447

wants to merge 10 commits into from

Conversation

Tjeerdie
Copy link
Contributor

Adding on timer to make channel 1..4 IRQ callbacks possible

The timer.c and timer.h are modified such that you can now attach
interrupt callbacks to all channels of the hardware timers. This feature
should be fully backwards compatible with the previous implementation.

The addition is done to make an arduino core implementation of
HardwareTimers possible (Next step). That would be inline with what other
arduino stm32 cores offer.

This PR starts implementation of the following bugs/features
See issue #146

@Tjeerdie
Copy link
Contributor Author

Tjeerdie commented Feb 18, 2019

Example ino to check function

//
/*
 * Hardware timer interrupt 
 * Overflow example and channel example
 *
 * Setup the timers and call interrupt routines
 *
 * This example code is in the public domain.
 */
 
volatile int counterCH1;
volatile int counterCH2;
volatile int counterCH3;
volatile int counterCH4;
volatile int counterOC;
volatile int timertrig_channel;
volatile int channel_nr;
stimer_t _timer;

extern void IRQcallback_TIM2OC(stimer_t *Timer, uint32_t channel)
{
    counterOC++;
//    digitalWrite(PA6, !digitalRead(PA6));
//    Serial.println(__channel);
    
}

extern void IRQcallback_TIM2CH1()
{
    counterCH1++;
    digitalWrite(PA6, !digitalRead(PA6));
//    Serial.println(__channel);
    
}
extern void IRQcallback_TIM2CH2()
{
    counterCH2++;
    digitalWrite(PA6, !digitalRead(PA6));
//    Serial.println(__channel);
    
}
extern void IRQcallback_TIM2CH3()
{
    counterCH3++;
    digitalWrite(PA6, !digitalRead(PA6));
//    Serial.println(__channel);
    
}
extern void IRQcallback_TIM2CH4()
{
    counterCH4++;
    digitalWrite(PA6, !digitalRead(PA6));
//    Serial.println(__channel);
    
}

extern void IRQcallback_TIM2(stimer_t *Timer)
{
    timertrig_channel++;
    digitalWrite(PA6, !digitalRead(PA6));
    
}


void setup() {
  counterCH1 = 0;
  counterCH2 = 0;
  counterCH3 = 0;
  counterCH4 = 0;
  counterOC = 0;

  //begin serial for debug info.
  Serial.begin(115200);

  //attach timer to struct
  _timer.timer = TIM2;

  //led/pin output to see result
  //results can only be seen with logic analyzer/oscilloscoop by monitoring this pin
  //Result is showing the different phases the intrupts occur at. 
  pinMode(PA6, OUTPUT);

  Serial.println("--- Start timer init ---");
      
  TimerHandleInit(&_timer, 2000, 168);
  attachIntHandle(&_timer, IRQcallback_TIM2);

  TimerPulseInit(&_timer, 2000, 500, IRQcallback_TIM2OC);
  attachIntHandleOC(&_timer, IRQcallback_TIM2CH1, 1, 500);
  attachIntHandleOC(&_timer, IRQcallback_TIM2CH2, 2, 250);
  attachIntHandleOC(&_timer, IRQcallback_TIM2CH3, 3, 880);
  attachIntHandleOC(&_timer, IRQcallback_TIM2CH4, 4, 100);

  Serial.println("--- Finish timer init ---");
  

}

void loop() {
  // put your main code here, to run repeatedly:
          Serial.print("Counter_1: ");
          Serial.println(counterCH1);
          Serial.print("Counter_2: ");
          Serial.println(counterCH2);
          Serial.print("Counter_3: ");
          Serial.println(counterCH3);
          Serial.print("Counter_4: ");
          Serial.println(counterCH4);
          Serial.print("Channel_OC: ");
          Serial.println(counterOC);
          Serial.print("Channel: ");
          Serial.println(timertrig_channel);
           
          delay(1000);

}

@fpistm
Copy link
Member

fpistm commented Feb 19, 2019

Thanks @Tjeerdie
I will review this soon and maybe the last part of the implementations. 😉
About astyle issue, I guess you use astyle without format config.
It is available here: https://github.com/stm32duino/Arduino_Core_STM32/blob/master/CI/astyle/.astylerc

@fpistm fpistm added the enhancement New feature or request label Feb 19, 2019
@Tjeerdie
Copy link
Contributor Author

When i get home i try to fix the Astyle issue.

@Tjeerdie
Copy link
Contributor Author

@fpistm Did you already start with a HardwareTimer implementation or is there nothing implemented yet? I was considering using the STM32GERNERIC core implementation as a starting point for this. Because it is also based on the ST HAL. But i do not want to do redundant work if not necessary.

@fpistm
Copy link
Member

fpistm commented Feb 20, 2019

@Tjeerdie
In fact not really, as I would study all current implementation and request from user.
I guess the one from STM32Generic is a good starting point if I well remember.
I will try to check soon, but I think I could not give you a feedback before the next week.

@Tjeerdie
Copy link
Contributor Author

Tjeerdie commented Mar 4, 2019

@fpistm Any news if this is going to be accepted like it is? Or does it need more work before that?

@fpistm
Copy link
Member

fpistm commented Mar 4, 2019

@Tjeerdie Sorry I didn't have time to check.
Will try to review it this week but I could not not guarantee it as I'm very busy on several stuff. 😭

@fpistm fpistm self-requested a review March 4, 2019 16:34
@noisymime
Copy link

noisymime commented Mar 7, 2019

This would be a great addition. Currently using the stimer arrangement, there's no way at all to utilise any compare channel except 1, which makes the implementation very limited.

The PR allows use of these extra channels without any breakage to current use.

The only alternative to getting the equivalent functionality to this PR would be to move the stm32generic HardwareTimer implementation over.

@BennehBoy
Copy link
Contributor

BennehBoy commented Mar 7, 2019 via email

Copy link
Member

@fpistm fpistm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First review:

  • Several commits needs to be squash and commit messages to review following contributing guidelines.
    Ex: 2 commits:

[Timer] Add get/set prescaler register function
[Timer] Add channels support

  • Rebase on top of the master
  • Some enhancement could be performed to avoid lot of return or factorize code

@fpistm
Copy link
Member

fpistm commented Mar 15, 2019

@Tjeerdie I will try to provide a branch updated this afternoon, then you will be able to test and give feedback --> done in #473

@fpistm fpistm mentioned this pull request Mar 15, 2019
@Tjeerdie
Copy link
Contributor Author

@fpistm i will check this as soon as i have time. Hopefully this will be tomorrow.

@fpistm fpistm added abandoned No more work on this and removed Review on going labels Apr 3, 2019
@fpistm
Copy link
Member

fpistm commented Apr 3, 2019

Replace by #473

@fpistm fpistm closed this Apr 3, 2019
fpistm added a commit that referenced this pull request Apr 3, 2019
benwaffle pushed a commit to benwaffle/Arduino_Core_STM32 that referenced this pull request Apr 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
abandoned No more work on this enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants