Skip to content

Commit b10696d

Browse files
committed
[TIM] Able to build without HAL module
Signed-off-by: Frederic.Pillon <[email protected]>
1 parent 0e1f5a7 commit b10696d

File tree

7 files changed

+48
-6
lines changed

7 files changed

+48
-6
lines changed

Diff for: cores/arduino/Tone.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include "Arduino.h"
2323

2424
PinName g_lastPin = NC;
25+
26+
#ifdef HAL_TIM_MODULE_ENABLED
2527
static stimer_t _timer;
2628

2729
// frequency (in hertz) and duration (in milliseconds).
@@ -47,3 +49,16 @@ void noTone(uint8_t _pin)
4749
g_lastPin = NC;
4850
}
4951
}
52+
#else
53+
void tone(uint8_t _pin, unsigned int frequency, unsigned long duration)
54+
{
55+
UNUSED(_pin);
56+
UNUSED(frequency);
57+
UNUSED(duration);
58+
}
59+
60+
void noTone(uint8_t _pin)
61+
{
62+
UNUSED(_pin);
63+
}
64+
#endif /* HAL_TIM_MODULE_ENABLED */

Diff for: cores/arduino/stm32/analog.c

+7
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ extern "C" {
4646

4747

4848
/* Private_Variables */
49+
#if defined(HAL_ADC_MODULE_ENABLED) || defined(HAL_DAC_MODULE_ENABLED) ||\
50+
defined(HAL_TIM_MODULE_ENABLED)
4951
static PinName g_current_pin = NC;
52+
#endif
5053

5154
/* Private_Defines */
5255
#ifdef HAL_ADC_MODULE_ENABLED
@@ -160,6 +163,7 @@ static uint32_t get_adc_channel(PinName pin)
160163
}
161164
#endif /* HAL_ADC_MODULE_ENABLED */
162165

166+
#ifdef HAL_TIM_MODULE_ENABLED
163167
static uint32_t get_pwm_channel(PinName pin)
164168
{
165169
uint32_t function = pinmap_function(pin, PinMap_PWM);
@@ -183,6 +187,7 @@ static uint32_t get_pwm_channel(PinName pin)
183187
}
184188
return channel;
185189
}
190+
#endif /* HAL_TIM_MODULE_ENABLED */
186191

187192
#ifdef HAL_DAC_MODULE_ENABLED
188193
static uint32_t get_dac_channel(PinName pin)
@@ -647,6 +652,7 @@ uint16_t adc_read_value(PinName pin)
647652
}
648653
#endif /* HAL_ADC_MODULE_ENABLED */
649654

655+
#ifdef HAL_TIM_MODULE_ENABLED
650656
////////////////////////// PWM INTERFACE FUNCTIONS /////////////////////////////
651657

652658

@@ -780,6 +786,7 @@ void pwm_stop(PinName pin)
780786

781787
HAL_TIM_PWM_DeInit(&timHandle);
782788
}
789+
#endif /* HAL_TIM_MODULE_ENABLED */
783790

784791
#ifdef __cplusplus
785792
}

Diff for: cores/arduino/stm32/stm32yyxx_hal_conf.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#define HAL_GPIO_MODULE_ENABLED
1212
#define HAL_PWR_MODULE_ENABLED
1313
#define HAL_RCC_MODULE_ENABLED
14-
#define HAL_TIM_MODULE_ENABLED
1514

1615
/*
1716
* Optional HAL modules, can be enabled/disabled using
@@ -44,6 +43,12 @@
4443
#undef HAL_SPI_MODULE_ENABLED
4544
#endif
4645

46+
#if !defined(HAL_TIM_MODULE_DISABLED)
47+
#define HAL_TIM_MODULE_ENABLED
48+
#else
49+
#undef HAL_TIM_MODULE_ENABLED
50+
#endif
51+
4752
/*
4853
* Not defined by default
4954
*/

Diff for: cores/arduino/stm32/timer.c

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#ifdef __cplusplus
4343
extern "C" {
4444
#endif
45+
#ifdef HAL_TIM_MODULE_ENABLED
4546

4647
/* Private Variables */
4748
typedef enum {
@@ -1507,6 +1508,7 @@ void TIM22_IRQHandler(void)
15071508
}
15081509
}
15091510
#endif //TIM22_BASE
1511+
#endif /* HAL_TIM_MODULE_ENABLED */
15101512

15111513
#ifdef __cplusplus
15121514
}

Diff for: cores/arduino/stm32/timer.h

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#ifdef __cplusplus
4747
extern "C" {
4848
#endif
49+
#ifdef HAL_TIM_MODULE_ENABLED
4950

5051
/* Exported types ------------------------------------------------------------*/
5152
#define OFFSETOF(type, member) ((uint32_t) (&(((type *)(0))->member)))
@@ -233,6 +234,7 @@ uint32_t getTimerClkFreq(TIM_TypeDef *tim);
233234

234235
void attachIntHandle(stimer_t *obj, void (*irqHandle)(stimer_t *));
235236
void attachIntHandleOC(stimer_t *obj, void (*irqHandle)(void), uint16_t timChannel, uint16_t pulseWidth);
237+
#endif /* HAL_TIM_MODULE_ENABLED */
236238

237239
#ifdef __cplusplus
238240
}

Diff for: cores/arduino/wiring_analog.c

+9-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@
2323
extern "C" {
2424
#endif
2525

26-
26+
#if defined(HAL_DAC_MODULE_ENABLED) || defined(HAL_TIM_MODULE_ENABLED)
2727
//This is the list of the IOs configured
2828
uint32_t g_anOutputPinConfigured[MAX_NB_PORT] = {0};
29+
#endif
2930

3031
static int _readResolution = 10;
3132
static int _writeResolution = 8;
@@ -87,8 +88,9 @@ void analogOutputInit(void)
8788
// to digital output.
8889
void analogWrite(uint32_t ulPin, uint32_t ulValue)
8990
{
90-
91+
#if defined(HAL_DAC_MODULE_ENABLED) || defined(HAL_TIM_MODULE_ENABLED)
9192
uint8_t do_init = 0;
93+
#endif
9294
PinName p = digitalPinToPinName(ulPin);
9395
if (p != NC) {
9496
#ifdef HAL_DAC_MODULE_ENABLED
@@ -101,6 +103,7 @@ void analogWrite(uint32_t ulPin, uint32_t ulValue)
101103
dac_write_value(p, ulValue, do_init);
102104
} else
103105
#endif //HAL_DAC_MODULE_ENABLED
106+
#ifdef HAL_TIM_MODULE_ENABLED
104107
if (pin_in_pinmap(p, PinMap_PWM)) {
105108
if (is_pin_configured(p, g_anOutputPinConfigured) == false) {
106109
do_init = 1;
@@ -110,7 +113,10 @@ void analogWrite(uint32_t ulPin, uint32_t ulValue)
110113
pwm_start(p, _writeFreq * PWM_MAX_DUTY_CYCLE,
111114
PWM_MAX_DUTY_CYCLE,
112115
ulValue, do_init);
113-
} else { //DIGITAL PIN ONLY
116+
} else
117+
#endif /* HAL_TIM_MODULE_ENABLED */
118+
{
119+
//DIGITAL PIN ONLY
114120
// Defaults to digital write
115121
pinMode(ulPin, OUTPUT);
116122
ulValue = mapResolution(ulValue, _writeResolution, 8);

Diff for: cores/arduino/wiring_digital.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,23 @@ 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)
3536
if (is_pin_configured(p, g_anOutputPinConfigured)) {
3637
#ifdef HAL_DAC_MODULE_ENABLED
3738
if (pin_in_pinmap(p, PinMap_DAC)) {
3839
dac_stop(p);
3940
} else
4041
#endif //HAL_DAC_MODULE_ENABLED
42+
#ifdef HAL_TIM_MODULE_ENABLED
4143
if (pin_in_pinmap(p, PinMap_PWM)) {
4244
pwm_stop(p);
4345
}
44-
reset_pin_configured(p, g_anOutputPinConfigured);
46+
#endif //HAL_TIM_MODULE_ENABLED
47+
{
48+
reset_pin_configured(p, g_anOutputPinConfigured);
49+
}
4550
}
46-
51+
#endif
4752
switch (ulMode) {
4853
case INPUT: /* INPUT_FLOATING */
4954
pin_function(p, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));

0 commit comments

Comments
 (0)