Skip to content

Commit a7420eb

Browse files
committed
Tone: uninit pin when frequency is 0
Fix stm32duino#187 Signed-off-by: Frederic.Pillon <frederic.pillon@st.com>
1 parent 37f55c3 commit a7420eb

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

cores/arduino/Tone.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ void noTone(uint8_t _pin)
4444
PinName p = digitalPinToPinName(_pin);
4545
if(p != NC) {
4646
TimerPinDeinit(&_timer);
47-
digitalWrite(_pin, 0);
4847
g_lastPin = NC;
4948
}
5049
}

cores/arduino/stm32/timer.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,8 +558,10 @@ uint32_t getTimerIrq(TIM_TypeDef* tim)
558558
*/
559559
void TimerHandleDeinit(stimer_t *obj)
560560
{
561-
HAL_TIM_Base_DeInit(&(obj->handle));
562-
HAL_TIM_Base_Stop_IT(&(obj->handle));
561+
if(obj != NULL) {
562+
HAL_TIM_Base_DeInit(&(obj->handle));
563+
HAL_TIM_Base_Stop_IT(&(obj->handle));
564+
}
563565
}
564566

565567
/**
@@ -923,6 +925,11 @@ void TimerPinInit(stimer_t *obj, uint32_t frequency, uint32_t duration)
923925
obj->timer = TIMER_TONE;
924926
obj->pinInfo.state = 0;
925927

928+
if(frequency == 0) {
929+
TimerPinDeinit(obj);
930+
return;
931+
}
932+
926933
//Calculate the toggle count
927934
if (duration > 0) {
928935
obj->pinInfo.count = ((timFreq * duration) / 1000);
@@ -962,6 +969,7 @@ void TimerPinInit(stimer_t *obj, uint32_t frequency, uint32_t duration)
962969
void TimerPinDeinit(stimer_t *obj)
963970
{
964971
TimerHandleDeinit(obj);
972+
digital_io_init(obj->pin, GPIO_MODE_INPUT, GPIO_NOPULL);
965973
}
966974

967975
/**

0 commit comments

Comments
 (0)