Skip to content

Commit d9633e8

Browse files
committed
chore(tim): add HAL v2 support
Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent 356addc commit d9633e8

7 files changed

Lines changed: 732 additions & 188 deletions

File tree

cores/arduino/wiring_analog.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ void analogWrite(pin_size_t pinNumber, int value)
215215
dac_write_value(p, value, do_init);
216216
} else
217217
#endif //HAL_DAC_MODULE_ENABLED && !HAL_DAC_MODULE_ONLY
218-
#if defined(HAL_TIM_MODULE_ENABLED) && !defined(HAL_TIM_MODULE_ONLY)
218+
#if !defined(HAL_TIM_MODULE_ONLY) &&\
219+
(defined(HAL_TIM_MODULE_ENABLED) || (defined(USE_HAL_TIM_MODULE) && (USE_HAL_TIM_MODULE == 1)))
219220
if (pin_in_pinmap(p, PinMap_TIM)) {
220221
if (is_pin_configured(p, g_anOutputPinConfigured) == false) {
221222
set_pin_configured(p, g_anOutputPinConfigured);

libraries/SrcWrapper/inc/HardwareTimer.h

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
#include "timer.h"
3333
#include "stm32yyxx_ll_tim.h"
3434

35-
#if defined(HAL_TIM_MODULE_ENABLED) && !defined(HAL_TIM_MODULE_ONLY)
35+
#if !defined(HAL_TIM_MODULE_ONLY) &&\
36+
(defined(HAL_TIM_MODULE_ENABLED) || (defined(USE_HAL_TIM_MODULE) && (USE_HAL_TIM_MODULE == 1)))
3637

3738
#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
3839

@@ -113,6 +114,14 @@ typedef enum {
113114
FILTER_DTS32_N8, // Sampling rate is DTS/32, n=8 events
114115
} ChannelInputFilter_t;
115116

117+
typedef enum {
118+
DISABLE_IT, // default
119+
ENABLE_IT,
120+
CLEAR_IT,
121+
CLEAR_AND_ENABLE_IT,
122+
IS_ENABLE_IT,
123+
} ChannelITConfig_t;
124+
116125
#ifdef __cplusplus
117126

118127
#include <functional>
@@ -171,19 +180,29 @@ class HardwareTimer {
171180

172181
uint32_t getTimerClkFreq(); // return timer clock frequency in Hz.
173182

183+
#if defined(USE_HALV2_DRIVER)
184+
static void captureCompareCallback(hal_tim_handle_t *htim, hal_tim_channel_t hal_channel); // Generic Capture and Compare callback which will call user callback
185+
static void updateCallback(hal_tim_handle_t *htim); // Generic Update (rollover) callback which will call user callback
186+
#else
174187
static void captureCompareCallback(TIM_HandleTypeDef *htim); // Generic Capture and Compare callback which will call user callback
175188
static void updateCallback(TIM_HandleTypeDef *htim); // Generic Update (rollover) callback which will call user callback
176-
189+
#endif
177190
void updateRegistersIfNotRunning(TIM_TypeDef *TIMx); // Take into account registers update immediately if timer is not running,
178191

179192
bool isRunning(); // return true if HardwareTimer is running
180193
bool isRunningChannel(uint32_t channel); // return true if channel is running
181194

182195
// The following function(s) are available for more advanced timer options
196+
#if defined(USE_HALV2_DRIVER)
197+
hal_tim_handle_t *getHandle(); // return the handle address for HAL related configuration
198+
hal_tim_channel_t getChannel(uint32_t channel);
199+
#else
183200
TIM_HandleTypeDef *getHandle(); // return the handle address for HAL related configuration
184201
uint32_t getChannel(uint32_t channel);
202+
#endif
185203
uint32_t getLLChannel(uint32_t channel);
186-
uint32_t getIT(uint32_t channel);
204+
205+
bool manageIT(uint32_t channel, ChannelITConfig_t config = DISABLE_IT);
187206
uint32_t getAssociatedChannel(uint32_t channel);
188207

189208
private:

libraries/SrcWrapper/inc/analog.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ void dac_write_value(PinName pin, uint32_t value, bool do_init);
7474
void dac_stop(PinName pin);
7575
#endif
7676
#endif /* !HAL_DAC_MODULE_ONLY */
77-
#if defined(HAL_TIM_MODULE_ENABLED) && !defined(HAL_TIM_MODULE_ONLY)
77+
#if !defined(HAL_TIM_MODULE_ONLY) &&\
78+
(defined(HAL_TIM_MODULE_ENABLED) || (defined(USE_HAL_TIM_MODULE) && (USE_HAL_TIM_MODULE == 1)))
7879
void pwm_start(PinName pin, uint32_t clock_freq, uint32_t value, TimerCompareFormat_t resolution);
7980
void pwm_stop(PinName pin);
8081
#endif

libraries/SrcWrapper/inc/timer.h

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
#ifdef __cplusplus
2323
extern "C" {
2424
#endif
25-
#if defined(HAL_TIM_MODULE_ENABLED) && !defined(HAL_TIM_MODULE_ONLY)
26-
25+
#if !defined(HAL_TIM_MODULE_ONLY) &&\
26+
(defined(HAL_TIM_MODULE_ENABLED) || (defined(USE_HAL_TIM_MODULE) && (USE_HAL_TIM_MODULE == 1)))
2727
/* Exported constants --------------------------------------------------------*/
2828
#ifndef TIM_IRQ_PRIO
2929
#if (__CORTEX_M == 0x00U)
@@ -65,6 +65,9 @@ extern "C" {
6565
defined(STM32WBxx) || defined(STM32WBAxx) ||defined(STM32WLxx)
6666
#define TIM1_IRQn TIM1_UP_IRQn
6767
#define TIM1_IRQHandler TIM1_UP_IRQHandler
68+
#elif defined(STM32C5xx)
69+
#define TIM1_IRQn TIM1_UPD_IRQn
70+
#define TIM1_IRQHandler TIM1_UPD_IRQHandler
6871
#endif
6972
#endif
7073

@@ -86,9 +89,9 @@ extern "C" {
8689
#if defined(STM32G0xx) || defined(STM32U0xx)
8790
#define TIM6_IRQn TIM6_DAC_LPTIM1_IRQn
8891
#define TIM6_IRQHandler TIM6_DAC_LPTIM1_IRQHandler
89-
#elif !defined(STM32F1xx) && !defined(STM32H5xx) && !defined(STM32L1xx) &&\
90-
!defined(STM32L5xx) && !defined(STM32MP1xx) && !defined(STM32U3xx) &&\
91-
!defined(STM32U5xx)
92+
#elif !defined(STM32C5xx) && !defined(STM32F1xx) && !defined(STM32H5xx) &&\
93+
!defined(STM32L1xx) && !defined(STM32L5xx) && !defined(STM32MP1xx) &&\
94+
!defined(STM32U3xx) && !defined(STM32U5xx)
9295
#define TIM6_IRQn TIM6_DAC_IRQn
9396
#define TIM6_IRQHandler TIM6_DAC_IRQHandler
9497
#endif
@@ -115,6 +118,9 @@ extern "C" {
115118
defined(STM32U5xx)
116119
#define TIM8_IRQn TIM8_UP_IRQn
117120
#define TIM8_IRQHandler TIM8_UP_IRQHandler
121+
#elif defined(STM32C5xx)
122+
#define TIM8_IRQn TIM8_UPD_IRQn
123+
#define TIM8_IRQHandler TIM8_UPD_IRQHandler
118124
#endif
119125
#endif
120126

@@ -276,25 +282,36 @@ typedef enum {
276282
typedef struct {
277283
// Those 2 first fields must remain in this order at the beginning of the structure
278284
void *__this;
285+
#if defined(USE_HALV2_DRIVER)
286+
hal_tim_handle_t handle;
287+
#else
279288
TIM_HandleTypeDef handle;
289+
#endif
290+
TIM_TypeDef *instance;
280291
uint32_t preemptPriority;
281292
uint32_t subPriority;
282293
} timerObj_t;
283294

284295
/* Exported functions ------------------------------------------------------- */
296+
#if defined(USE_HALV2_DRIVER)
297+
timerObj_t *get_timer_obj(hal_tim_handle_t *htim);
298+
#else
285299
timerObj_t *get_timer_obj(TIM_HandleTypeDef *htim);
286-
287-
void enableTimerClock(TIM_HandleTypeDef *htim);
288-
void disableTimerClock(TIM_HandleTypeDef *htim);
300+
#endif
301+
void enableTimerClock(TIM_TypeDef *instance);
302+
void disableTimerClock(TIM_TypeDef *instance);
289303

290304
uint32_t getTimerIrq(TIM_TypeDef *tim);
291305
uint8_t getTimerClkSrc(TIM_TypeDef *tim);
292306

293307
IRQn_Type getTimerUpIrq(TIM_TypeDef *tim);
294308
IRQn_Type getTimerCCIrq(TIM_TypeDef *tim);
295309

310+
#if defined(USE_HALV2_DRIVER)
311+
hal_tim_channel_t getTimerChannel(PinName pin);
312+
#else
296313
uint32_t getTimerChannel(PinName pin);
297-
314+
#endif
298315
#endif /* HAL_TIM_MODULE_ENABLED && !HAL_TIM_MODULE_ONLY */
299316

300317
#ifdef __cplusplus

0 commit comments

Comments
 (0)