Skip to content

Commit 1dc90c1

Browse files
committed
[TIM] Allow to enable HAL module only
Define `HAL_TIM_MODULE_ONLY` in `build_opt.h` or `hal_conf_extra.h` allow HAL TIM module usage without any usage by the core. Fixes #697 Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent 399d63c commit 1dc90c1

File tree

9 files changed

+22
-22
lines changed

9 files changed

+22
-22
lines changed

cores/arduino/HardwareTimer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include "Arduino.h"
2727
#include "HardwareTimer.h"
2828

29-
#ifdef HAL_TIM_MODULE_ENABLED
29+
#if defined(HAL_TIM_MODULE_ENABLED) && !defined(HAL_TIM_MODULE_ONLY)
3030

3131
/* Private Defines */
3232
#define PIN_NOT_USED 0xFF
@@ -1427,4 +1427,4 @@ extern "C" {
14271427
#endif //TIM22_BASE
14281428
}
14291429

1430-
#endif // HAL_TIM_MODULE_ENABLED
1430+
#endif // HAL_TIM_MODULE_ENABLED && !HAL_TIM_MODULE_ONLY

cores/arduino/HardwareTimer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
/* Includes ------------------------------------------------------------------*/
3131
#include "timer.h"
3232

33-
#ifdef HAL_TIM_MODULE_ENABLED
33+
#if defined(HAL_TIM_MODULE_ENABLED) && !defined(HAL_TIM_MODULE_ONLY)
3434

3535
#define TIMER_CHANNELS 4 // channel5 and channel 6 are not considered here has they don't have gpio output and they don't have interrupt
3636

@@ -153,5 +153,5 @@ extern timer_index_t get_timer_index(TIM_TypeDef *htim);
153153

154154
#endif /* __cplusplus */
155155

156-
#endif // HAL_TIM_MODULE_ENABLED
156+
#endif // HAL_TIM_MODULE_ENABLED && !HAL_TIM_MODULE_ONLY
157157
#endif // HARDWARETIMER_H_

cores/arduino/Tone.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "Arduino.h"
2323
#include "HardwareTimer.h"
2424

25-
#if defined(HAL_TIM_MODULE_ENABLED) && defined(TIMER_TONE)
25+
#if defined(HAL_TIM_MODULE_ENABLED) && defined(TIMER_TONE) && !defined(HAL_TIM_MODULE_ONLY)
2626

2727
#define MAX_FREQ 65535
2828

@@ -143,4 +143,4 @@ void noTone(uint8_t _pin)
143143
{
144144
UNUSED(_pin);
145145
}
146-
#endif /* HAL_TIM_MODULE_ENABLED && TIMER_TONE */
146+
#endif /* HAL_TIM_MODULE_ENABLED && TIMER_TONE && !HAL_TIM_MODULE_ONLY*/

cores/arduino/stm32/analog.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ static uint32_t get_adc_internal_channel(PinName pin)
271271
}
272272
#endif /* HAL_ADC_MODULE_ENABLED */
273273

274-
#ifdef HAL_TIM_MODULE_ENABLED
274+
#if defined(HAL_TIM_MODULE_ENABLED) && !defined(HAL_TIM_MODULE_ONLY)
275275
uint32_t get_pwm_channel(PinName pin)
276276
{
277277
uint32_t function = pinmap_function(pin, PinMap_PWM);
@@ -295,7 +295,7 @@ uint32_t get_pwm_channel(PinName pin)
295295
}
296296
return channel;
297297
}
298-
#endif /* HAL_TIM_MODULE_ENABLED */
298+
#endif /* HAL_TIM_MODULE_ENABLED && !HAL_TIM_MODULE_ONLY */
299299

300300
#ifdef HAL_DAC_MODULE_ENABLED
301301
static uint32_t get_dac_channel(PinName pin)
@@ -979,7 +979,7 @@ uint16_t adc_read_value(PinName pin)
979979
}
980980
#endif /* HAL_ADC_MODULE_ENABLED */
981981

982-
#ifdef HAL_TIM_MODULE_ENABLED
982+
#if defined(HAL_TIM_MODULE_ENABLED) && !defined(HAL_TIM_MODULE_ONLY)
983983
////////////////////////// PWM INTERFACE FUNCTIONS /////////////////////////////
984984

985985
/**
@@ -1029,7 +1029,7 @@ void pwm_stop(PinName pin)
10291029
HT = NULL;
10301030
}
10311031
}
1032-
#endif /* HAL_TIM_MODULE_ENABLED */
1032+
#endif /* HAL_TIM_MODULE_ENABLED && !HAL_TIM_MODULE_ONLY */
10331033

10341034
#ifdef __cplusplus
10351035
}

cores/arduino/stm32/timer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#ifdef __cplusplus
1818
extern "C" {
1919
#endif
20-
#ifdef HAL_TIM_MODULE_ENABLED
20+
#if defined(HAL_TIM_MODULE_ENABLED) && !defined(HAL_TIM_MODULE_ONLY)
2121

2222
/* Private Functions */
2323

@@ -705,7 +705,7 @@ uint8_t getTimerClkSrc(TIM_TypeDef *tim)
705705
}
706706

707707

708-
#endif /* HAL_TIM_MODULE_ENABLED */
708+
#endif /* HAL_TIM_MODULE_ENABLED && !HAL_TIM_MODULE_ONLY */
709709

710710
#ifdef __cplusplus
711711
}

cores/arduino/stm32/timer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#ifdef __cplusplus
2323
extern "C" {
2424
#endif
25-
#ifdef HAL_TIM_MODULE_ENABLED
25+
#if defined(HAL_TIM_MODULE_ENABLED) && !defined(HAL_TIM_MODULE_ONLY)
2626

2727
/* Exported constants --------------------------------------------------------*/
2828
#ifndef TIM_IRQ_PRIO
@@ -242,7 +242,7 @@ uint8_t getTimerClkSrc(TIM_TypeDef *tim);
242242
IRQn_Type getTimerUpIrq(TIM_TypeDef *tim);
243243
IRQn_Type getTimerCCIrq(TIM_TypeDef *tim);
244244

245-
#endif /* HAL_TIM_MODULE_ENABLED */
245+
#endif /* HAL_TIM_MODULE_ENABLED && !HAL_TIM_MODULE_ONLY */
246246

247247
#ifdef __cplusplus
248248
}

cores/arduino/wiring_analog.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
extern "C" {
2424
#endif
2525

26-
#if defined(HAL_DAC_MODULE_ENABLED) || defined(HAL_TIM_MODULE_ENABLED)
26+
#if defined(HAL_DAC_MODULE_ENABLED) || (defined(HAL_TIM_MODULE_ENABLED) && !defined(HAL_TIM_MODULE_ONLY))
2727
//This is the list of the IOs configured
2828
uint32_t g_anOutputPinConfigured[MAX_NB_PORT] = {0};
2929
#endif
@@ -109,15 +109,15 @@ void analogWrite(uint32_t ulPin, uint32_t ulValue)
109109
dac_write_value(p, ulValue, do_init);
110110
} else
111111
#endif //HAL_DAC_MODULE_ENABLED
112-
#ifdef HAL_TIM_MODULE_ENABLED
112+
#if defined(HAL_TIM_MODULE_ENABLED) && !defined(HAL_TIM_MODULE_ONLY)
113113
if (pin_in_pinmap(p, PinMap_PWM)) {
114114
if (is_pin_configured(p, g_anOutputPinConfigured) == false) {
115115
set_pin_configured(p, g_anOutputPinConfigured);
116116
}
117117
ulValue = mapResolution(ulValue, _writeResolution, PWM_RESOLUTION);
118118
pwm_start(p, _writeFreq, ulValue);
119119
} else
120-
#endif /* HAL_TIM_MODULE_ENABLED */
120+
#endif /* HAL_TIM_MODULE_ENABLED && !HAL_TIM_MODULE_ONLY */
121121
{
122122
//DIGITAL PIN ONLY
123123
// Defaults to digital write

cores/arduino/wiring_digital.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@ void pinMode(uint32_t ulPin, uint32_t ulMode)
3232

3333
if (p != NC) {
3434
// If the pin that support PWM or DAC output, we need to turn it off
35-
#if defined(HAL_DAC_MODULE_ENABLED) || defined(HAL_TIM_MODULE_ENABLED)
35+
#if defined(HAL_DAC_MODULE_ENABLED) || (defined(HAL_TIM_MODULE_ENABLED) && !defined(HAL_TIM_MODULE_ONLY))
3636
if (is_pin_configured(p, g_anOutputPinConfigured)) {
3737
#ifdef HAL_DAC_MODULE_ENABLED
3838
if (pin_in_pinmap(p, PinMap_DAC)) {
3939
dac_stop(p);
4040
} else
4141
#endif //HAL_DAC_MODULE_ENABLED
42-
#ifdef HAL_TIM_MODULE_ENABLED
42+
#if defined(HAL_TIM_MODULE_ENABLED) && !defined(HAL_TIM_MODULE_ONLY)
4343
if (pin_in_pinmap(p, PinMap_PWM)) {
4444
pwm_stop(p);
4545
}
46-
#endif //HAL_TIM_MODULE_ENABLED
46+
#endif //HAL_TIM_MODULE_ENABLED && !HAL_TIM_MODULE_ONLY
4747
{
4848
reset_pin_configured(p, g_anOutputPinConfigured);
4949
}

libraries/Servo/src/stm32/Servo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <Servo.h>
2323
#include <HardwareTimer.h>
2424

25-
#if defined(HAL_TIM_MODULE_ENABLED) && defined(TIMER_SERVO)
25+
#if defined(HAL_TIM_MODULE_ENABLED) && defined(TIMER_SERVO) && !defined(HAL_TIM_MODULE_ONLY)
2626

2727
static servo_t servos[MAX_SERVOS]; // static array of servo structures
2828
static volatile int8_t timerChannel[_Nbr_16timers] = {-1}; // counter for the servo being pulsed for each timer (or -1 if refresh interval)
@@ -231,6 +231,6 @@ int Servo::readMicroseconds()
231231
}
232232
bool Servo::attached() {}
233233

234-
#endif /* HAL_TIM_MODULE_ENABLED && TIMER_SERVO */
234+
#endif /* HAL_TIM_MODULE_ENABLED && TIMER_SERVO & !HAL_TIM_MODULE_ONLY */
235235

236236
#endif // ARDUINO_ARCH_STM32

0 commit comments

Comments
 (0)