[SOLVED] tone() not working on F072-Discovery

Please post bugs and enhancements for the STM core here
User avatar
ekawahyu
Posts: 107
Joined: Wed Apr 13, 2016 6:17 am

[SOLVED] tone() not working on F072-Discovery

Post by ekawahyu » Sat Sep 23, 2017 4:24 am

Here is my latest feature to add STM32F072 Discovery into one of the variants. Everything seems to work just fine, except for tone(). I have followed all steps in the wiki, what else should I look (or I have missed?)

I have tried with TIM15 and TIM14 for TIMER_TONE with no luck!

Link to my work is here: https://github.com/ekawahyu/Arduino_Cor ... ry-variant
Last edited by ekawahyu on Tue Sep 26, 2017 7:11 pm, edited 2 times in total.

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

Re: tone() not working on F072-Discovery

Post by fpiSTM » Sat Sep 23, 2017 7:21 am

Ok. I will have a look.

User avatar
ekawahyu
Posts: 107
Joined: Wed Apr 13, 2016 6:17 am

Re: tone() not working on F072-Discovery

Post by ekawahyu » Sat Sep 23, 2017 8:52 am

I added Makefiles and OpenOCD with debugging support on Eclipse, cause there is nothing I can do to find where it goes wrong with only Arduino IDE.

The Makefile and OpenOCD features can be found in here: https://github.com/ekawahyu/Arduino_Cor ... nd-openocd

So far, what I can tell, the code seems to get stuck once the timer interrupt is enabled:

Code: Select all

   /* Enable the TIM Update interrupt */
   __HAL_TIM_ENABLE_IT(htim, TIM_IT_UPDATE);
Will look further tomorrow, it's already past midnight here. :roll:

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

Re: tone() not working on F072-Discovery

Post by fpiSTM » Sat Sep 23, 2017 9:56 am

Your variant seems ok. nice job.
After checking the STM32F072 specification:
http://www.st.com/content/ccc/resource/ ... 090510.pdf
TIM14
This timer is based on a 16-bit auto-reload upcounter and a 16-bit prescaler.
TIM14 features one single channel for input capture/output compare, PWM or one-pulse
mode output.
Its counter can be frozen in debug mode.
TIM15, TIM16 and TIM17
These timers are based on a 16-bit auto-reload upcounter and a 16-bit prescaler.
So, I think there is an issue with the core management of the timer.
Probably value set is not correct then the counter is very small then probably IT is raised a lot...
I will try to reproduce on an other boards. Not reproduce on my F7. I will try on minday with your variant on the discovery F072.
Have you tried with TIM2 or TIM3.

Which sketch you used? ToneMelody?

User avatar
ekawahyu
Posts: 107
Joined: Wed Apr 13, 2016 6:17 am

Re: tone() not working on F072-Discovery

Post by ekawahyu » Sat Sep 23, 2017 4:51 pm

Confirmed that TIM3 works for tone(), but I don't have the oscilloscope to test frequency correctness. The temporary fix is available in here:

https://github.com/ekawahyu/Arduino_Cor ... /tone-tim3

ToneMelody is the sketch I am testing with.

By now, I merged everything back into branch develop, but it does not include the TIM3 temporary fix. I do hope to use TIM14 or TIM15 to generate the tone before merging into branch develop. Thank you.

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

Re: tone() not working on F072-Discovery

Post by Rick Kimball » Sat Sep 23, 2017 5:09 pm

You could wire the tone output pin to another pin and use pulseIn() to measure.
-rick

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

Re: tone() not working on F072-Discovery

Post by fpiSTM » Sat Sep 23, 2017 7:27 pm

Ok I will do some tests on monday.
Could you submit an issue on the Arduino_Core_STM32 to track this issue and add the link to this post. please?

User avatar
ekawahyu
Posts: 107
Joined: Wed Apr 13, 2016 6:17 am

Re: tone() not working on F072-Discovery

Post by ekawahyu » Sat Sep 23, 2017 8:23 pm

Rick Kimball wrote:
Sat Sep 23, 2017 5:09 pm
You could wire the tone output pin to another pin configure to do a pulseIn() to measure.
Will do it soon, thanks for pointing that out. I have never used pulseIn() before
fpiSTM wrote:
Sat Sep 23, 2017 7:27 pm
Ok I will do some tests on monday.
Could you submit an issue on the Arduino_Core_STM32 to track this issue and add the link to this post. please?
Done!

User avatar
ekawahyu
Posts: 107
Joined: Wed Apr 13, 2016 6:17 am

Re: tone() not working on F072-Discovery

Post by ekawahyu » Sun Sep 24, 2017 8:25 am

So it is confirmed that the tone() frequency is correct with TIM3. I used pulseIn() to measure the time per Rick suggestion. Looking forward to the fix for TIM14 and TIM15.

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

Re: tone() not working on F072-Discovery

Post by fpiSTM » Sun Sep 24, 2017 1:38 pm

Thanks ekawahyu

One question about your repo, why adding some CMSIS header file?
https://github.com/ekawahyu/Arduino_Cor ... 3d342b8730
They are already available in the CMSIS 4.5.0 arduino package?
This is for the opeOCD and Makefile need?

Post Reply