[Solved]Problem with tone() and new STM32 core

Please post bugs and enhancements for the STM core here
Post Reply
User avatar
Rick Kimball
Posts: 1043
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

[Solved]Problem with tone() and new STM32 core

Post by Rick Kimball » Sat Jun 10, 2017 11:51 pm

I'm trying to add a variant to the https://github.com/stm32duino/Arduino_Core_STM32. However, I'm having issue with the tone function. It seems to run at half the frequency I'd expect. Has anyone measured the tone output with an existing supported board to see if the frequency is accurate? I tested with the toneMelody demo sketch. However, all the notes play at half the frequency of what they should be.

If i modify stm32/timer.c

Code: Select all

$ git diff stm32/timer.c
diff --git a/cores/arduino/stm32/timer.c b/cores/arduino/stm32/timer.c
index c45ba3e..fd0d028 100644
--- a/cores/arduino/stm32/timer.c
+++ b/cores/arduino/stm32/timer.c
@@ -704,7 +704,7 @@ void TimerPinInit(stimer_t *obj, uint32_t frequency, uint32_t duration)
 
   if((period < 0xFFFF) && (prescaler < 0xFFFF)) {
     obj->irqHandle = HAL_TIMx_PeriodElapsedCallback;
-    TimerHandleInit(obj, period, prescaler-1);
+    TimerHandleInit(obj, period/2, prescaler-1);
   }
   else {
     TimerHandleDeinit(obj);
$ 
With the above change, I can use tone to generate valid frequencies from about 40 -> 65535 (my chip max speed is 48MHz)

So has anyone tried it?
Last edited by Rick Kimball on Sun Jun 11, 2017 3:34 pm, edited 4 times in total.
-rick

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

Re: Issue with tone() and new STM32 core

Post by RogerClark » Sun Jun 11, 2017 12:00 am

Probably best to raise an issue on Github if you haven't already done so.


BTW. Which MCU are you using for this? Did you make your own F103 version?

User avatar
Rick Kimball
Posts: 1043
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: Issue with tone() and new STM32 core

Post by Rick Kimball » Sun Jun 11, 2017 12:10 am

I have a nucleo-f030r8 so I thought that might be interesting to get it working. There is another thread where I described what I have changed.

I didn't really want to raise an issue before I got confirmation that it works with an existing board.
-rick

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

Re: Issue with tone() and new STM32 core

Post by RogerClark » Sun Jun 11, 2017 12:32 am

Sorry Rick,

I've not tried that, and I'm in the middle of debugging some other code, otherwise I'd get a board out and try it

User avatar
Rick Kimball
Posts: 1043
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: Issue with tone() and new STM32 core

Post by Rick Kimball » Sun Jun 11, 2017 12:40 am

No problem Roger. I just don't have any of the supported boards.
-rick

fpiSTM
Posts: 227
Joined: Fri Sep 16, 2016 12:33 pm
Location: Le Mans, France

Re: Problem with tone() and new STM32 core

Post by fpiSTM » Mon Jun 12, 2017 6:58 am

Hi Rick,

Sorry do not saw this post this week end.
You're right there is an issue on the frequency.

Some correction has been done last week around that but it seem I missed this init: :roll:
https://github.com/stm32duino/Arduino_C ... /issues/18

Now, corrected with:
https://github.com/stm32duino/Arduino_C ... /issues/27

Post Reply