Skip to content
Merged
Show file tree
Hide file tree
Changes from 70 commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
6dbc6b3
Refactored F4 timer to use configuations
ActuallyTaylor Mar 4, 2025
3c10c42
Fixed timer IDs that were missing for f3
ActuallyTaylor Mar 20, 2025
22ea911
Cleaned up a little
ActuallyTaylor Mar 20, 2025
07efb79
F3 PWM to new timer framework
ActuallyTaylor Mar 20, 2025
c6088ac
f4 compiling
ActuallyTaylor Mar 29, 2025
e6685eb
Most timers working, advanced timers do not
ActuallyTaylor Apr 11, 2025
0cc7944
All wokring f4 timers
ActuallyTaylor Apr 12, 2025
3a7ecd1
ADC for f4 using new timers
ActuallyTaylor Apr 12, 2025
cc7cebb
Timer1 working
ActuallyTaylor Apr 22, 2025
7ce8ad6
bork
ActuallyTaylor Apr 22, 2025
f955bf1
Merge branch 'main' into feature/actuallytaylor/timer_refactor
ActuallyTaylor Aug 25, 2025
e09c08f
Fixed f3 tim1 & 16
ActuallyTaylor Aug 28, 2025
ddeb259
Make PWM a subclass of TimerF3xx
ActuallyTaylor Sep 19, 2025
12635a8
Fixed warning
ActuallyTaylor Sep 19, 2025
a4f2ac2
Working f334 PWM
ActuallyTaylor Sep 26, 2025
6cd0fb9
Validated for f302
ActuallyTaylor Oct 2, 2025
28d82d8
Added a macro that allows the user to define code to be called before…
aclowmclaughlin Mar 25, 2025
ffd9a86
Commenting :3
aclowmclaughlin Mar 31, 2025
e0f0e62
more commenting.
aclowmclaughlin Mar 31, 2025
e858026
Changes to bulk initialize, now the debug failure messages contain th…
aclowmclaughlin Apr 5, 2025
ac19f66
Update GPIO.hpp
tmb5932 Aug 10, 2025
5316636
Update time.hpp
tmb5932 Aug 10, 2025
a65e33c
Update GPIO.hpp
tmb5932 Aug 10, 2025
cbaaa14
Update GPIO.hpp
tmb5932 Aug 10, 2025
b896af9
Applied Formatting Changes During GitHub Build
Aug 10, 2025
972a3d6
Update GPIO.hpp
tmb5932 Aug 10, 2025
553d7a1
Updating list of what F446 supports.
tmb5932 Aug 28, 2025
47b10e9
Update README.md
tmb5932 Aug 28, 2025
36144d7
CMAKE improvements
mjh9585 Aug 23, 2025
d19317c
VScode configs
mjh9585 Aug 24, 2025
524abae
Make all fixes
mjh9585 Aug 24, 2025
af0e3d1
Applied Formatting Changes During GitHub Build
Aug 25, 2025
eb8b8ec
paths and vars
mjh9585 Aug 27, 2025
a11e614
Better default settings management
mjh9585 Aug 27, 2025
f231994
Removed other files
mjh9585 Aug 29, 2025
db2aaee
Updated default settings extension and move settings to .default files
mjh9585 Sep 1, 2025
a7d9a62
Remove linker file changes
mjh9585 Sep 11, 2025
eb129db
Fixed rebae issues
ActuallyTaylor Oct 2, 2025
bd7d36d
Merge branch 'main' into feature/actuallytaylor/timer_refactor
ActuallyTaylor Oct 2, 2025
6e4122f
Added documentation
ActuallyTaylor Oct 3, 2025
fad8212
removed <ctime>, ordered MCUTimers
ActuallyTaylor Oct 16, 2025
6ab1fbf
Updated RTC Timer
ActuallyTaylor Oct 16, 2025
c0d1d2c
Update include/core/dev/Timer.hpp
ActuallyTaylor Oct 16, 2025
9a431aa
Removed old PWMTimerF3xx, removed unused imports.
ActuallyTaylor Oct 16, 2025
b94cb1a
Removed logger, fixed core::time being removed
ActuallyTaylor Oct 16, 2025
812923c
Update src/core/dev/platform/f3xx/Timerf3xx.cpp
ActuallyTaylor Oct 16, 2025
4edfee8
Update src/core/dev/platform/f3xx/Timerf3xx.cpp
ActuallyTaylor Oct 16, 2025
6cdb446
Update libs/HALf3/src/system_stm32f3xx.c
ActuallyTaylor Oct 16, 2025
628b430
Added #endif and #if comments
ActuallyTaylor Oct 16, 2025
2638d1d
Fixed my typos
ActuallyTaylor Oct 16, 2025
62ab432
Fixed canopen_rpdo
ActuallyTaylor Oct 16, 2025
d7f49f7
fix canopen_sample
ActuallyTaylor Oct 17, 2025
e2d4dca
Fixed canopen_tpdo
ActuallyTaylor Oct 17, 2025
b3527b8
Applied Formatting Changes During GitHub Build
Oct 17, 2025
bbe2224
Fix comments for clock prescaler & add (void) pres
ActuallyTaylor Oct 23, 2025
68951bd
Applied Formatting Changes During GitHub Build
Oct 23, 2025
4d2c368
Move around timer getting
ActuallyTaylor Oct 23, 2025
ce77f08
Update include/core/dev/platform/f3xx/Timerf3xx.hpp
ActuallyTaylor Oct 23, 2025
b56450f
Added _t to TimerConfiguration. More const params
ActuallyTaylor Oct 23, 2025
d49eedb
Adds default configurations.
ActuallyTaylor Oct 23, 2025
45d34dd
Makes PRESCALER a uint32_t
ActuallyTaylor Oct 23, 2025
5044e74
Added a comment about me being dumb and making -1 a uint32
ActuallyTaylor Oct 23, 2025
f7f133d
Fixed build
ActuallyTaylor Oct 24, 2025
732c897
inline getTIM to make the compiler stop complaining
ActuallyTaylor Oct 24, 2025
f3d32c7
Applied Formatting Changes During GitHub Build
Oct 24, 2025
a9aa6f0
Default config template for `getTim`
ActuallyTaylor Nov 3, 2025
ece7812
Applied Formatting Changes During GitHub Build
Nov 3, 2025
c9ac850
Formatted
ActuallyTaylor Nov 3, 2025
2b7e571
Applied Formatting Changes During GitHub Build
Nov 3, 2025
63931d7
Merge branch 'main' into feature/actuallytaylor/timer_refactor
ActuallyTaylor Nov 7, 2025
7cacb57
Added context void * for interrupt handlers.
ActuallyTaylor Nov 8, 2025
d7ea9b5
Fix RTC timer having period
ActuallyTaylor Nov 8, 2025
70f0b0c
Documented AUTO_PRESCALER better
ActuallyTaylor Nov 8, 2025
54a9524
Documented why getTIM uses inline.
ActuallyTaylor Nov 8, 2025
f933cef
Updated Timer Init docs
ActuallyTaylor Nov 8, 2025
a156271
Alter subclasses to inherit docs.
ActuallyTaylor Nov 8, 2025
105a7a7
Fix RTC build.
ActuallyTaylor Nov 10, 2025
498b67d
replace inline
ActuallyTaylor Nov 10, 2025
5e3e705
Fixed my sample
ActuallyTaylor Nov 10, 2025
e6a4276
Applied Formatting Changes During GitHub Build
Nov 10, 2025
2c998eb
Add return descriptor & default argument.
ActuallyTaylor Nov 10, 2025
ad7c2cf
Use class enums instead of board specific defs
ActuallyTaylor Nov 11, 2025
97af051
Wrote docs for why TimerTypes exists
ActuallyTaylor Nov 11, 2025
5a4e925
More comments in TimerTypes + name change of enum.
ActuallyTaylor Nov 11, 2025
5da5b6a
Started commenting TimerClockSource.
ActuallyTaylor Nov 11, 2025
b5b2db1
Update docs for TimerClockSource.
ActuallyTaylor Nov 17, 2025
eec1679
Adds docs for TimerMasterModeSelection
ActuallyTaylor Nov 18, 2025
d99fd04
Fix timer sample
ActuallyTaylor Nov 18, 2025
94ef1aa
Applied Formatting Changes During GitHub Build
Nov 18, 2025
0bf362f
Merge branch 'main' into feature/actuallytaylor/timer_refactor
ActuallyTaylor Jan 18, 2026
7f05866
Applied Formatting Changes During GitHub Build
Jan 18, 2026
26b018e
Quick fixes for some includes & comments
ActuallyTaylor Jan 21, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ if(COMPDEFS MATCHES "(.*)STM32F3xx(.*)")
src/core/io/platform/f3xx/UARTf3xx.cpp
src/core/io/platform/f3xx/SPIf3xx.cpp
src/core/dev/platform/f3xx/IWDGf3xx.cpp
src/core/dev/platform/f3xx/RTCf3xx.cpp)
src/core/dev/platform/f3xx/RTCf3xx.cpp
)
elseif(COMPDEFS MATCHES "(.*)STM32F4xx(.*)")
target_sources(${PROJECT_NAME} PRIVATE
src/core/utils/platform/f4xx/timef4xx.cpp
Expand Down
31 changes: 13 additions & 18 deletions include/core/dev/MCUTimer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,38 @@
#endif

namespace core::dev {

/**
* Enum for all the hardware timers available on the current MCU
*/
enum class MCUTimer {
#if defined(STM32F302x8)
Timer1,
Timer2,
Timer6,
Timer15,
Timer16,
Timer17,
#elif defined(STM32F334x8)
Timer1,
Timer2,
Timer3,
Timer6,
Timer7,
Timer15,
Timer16,
Timer17,
#elif defined(STM32F446xx)
Timer1,
Timer2,
Timer3,
Timer4,
Timer5,
Timer8,
Timer9,
Timer10,
Timer11,
Timer12,
Timer13,
Timer14,
#endif
None
};

/**
Expand All @@ -50,7 +49,7 @@ enum class MCUTimer {
* @param mcuTimer MCUTimer of which to get the HAL equivalent
* @return HAL equivalent of mcuTimer
*/
TIM_TypeDef* getTIM(MCUTimer mcuTimer) {
inline TIM_TypeDef* getTIM(const MCUTimer mcuTimer) {
Comment thread
ActuallyTaylor marked this conversation as resolved.
TIM_TypeDef* timPeriph;
switch (mcuTimer) {
#if defined(STM32F302x8)
Expand All @@ -60,9 +59,6 @@ TIM_TypeDef* getTIM(MCUTimer mcuTimer) {
case MCUTimer::Timer2:
timPeriph = TIM2;
break;
case MCUTimer::Timer6:
timPeriph = TIM6;
break;
case MCUTimer::Timer15:
timPeriph = TIM15;
break;
Expand All @@ -82,12 +78,6 @@ TIM_TypeDef* getTIM(MCUTimer mcuTimer) {
case MCUTimer::Timer3:
timPeriph = TIM3;
break;
case MCUTimer::Timer6:
timPeriph = TIM6;
break;
case MCUTimer::Timer7:
timPeriph = TIM7;
break;
case MCUTimer::Timer15:
timPeriph = TIM15;
break;
Expand All @@ -98,10 +88,9 @@ TIM_TypeDef* getTIM(MCUTimer mcuTimer) {
timPeriph = TIM17;
break;
#elif defined(STM32F446xx)
/*
* Timers 1 and 8 are advanced timers
* so they are not included in this switch statement
*/
case MCUTimer::Timer1:
timPeriph = TIM1;
break;
case MCUTimer::Timer2:
timPeriph = TIM2;
break;
Expand All @@ -114,6 +103,9 @@ TIM_TypeDef* getTIM(MCUTimer mcuTimer) {
case MCUTimer::Timer5:
timPeriph = TIM5;
break;
case MCUTimer::Timer8:
timPeriph = TIM8;
break;
case MCUTimer::Timer9:
timPeriph = TIM9;
break;
Expand All @@ -132,6 +124,9 @@ TIM_TypeDef* getTIM(MCUTimer mcuTimer) {
case MCUTimer::Timer14:
timPeriph = TIM14;
break;
default:
timPeriph = TIM1;
break;
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion include/core/dev/RTCTimer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class RTCTimer : public Timer {

void reloadTimer() override;

void setPeriod(uint32_t clock) override;
void setPeriod(uint32_t clock, uint32_t clockPrescaler) override;

/**
* Gets the time since the RTC clock began in seconds
Expand Down
69 changes: 63 additions & 6 deletions include/core/dev/Timer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,68 @@

#include <cstdint>

namespace core::dev {
/**
* If AUTO_PRESCALER is sent as a prescaler the timer will calculate its own Prescaler.
Comment thread
ActuallyTaylor marked this conversation as resolved.
Outdated
* Yes, this is a negative in an uint32_t, but it ends up just causing an underflow, and making it the max of an
Comment thread
ActuallyTaylor marked this conversation as resolved.
* uint32_t.
*/
#define AUTO_PRESCALER uint32_t(-1)

namespace core::dev {
/**
* This class will represent an internal general purpose timer device for the STM32.
* It is capable of triggering interrupts with a given frequency
* @brief A timer configuration provides a timer with all configuration variables needed to be set up..
*/
typedef struct {
/**
* Specifies how the timer will count.
* This parameter can be a value of @ref TIM_Counter_Mode
* Maps to a timer's @ref TIM_Base_InitTypeDef:CounterMode
*/
uint32_t counterMode{};
Comment thread
ActuallyTaylor marked this conversation as resolved.
Outdated

/**
* Specifies the clock division.
* This parameter can be a value of @ref TIM_ClockDivision
* Maps to a timer's @ref TIM_Base_InitTypeDef:ClockDivision
*/
uint32_t clockDivision{};

/**
* Specifies the auto reload preload value, which controls whether @ref TIMx_ARR is buffered or not.
* This parameter can be a value of @ref TIM_AutoReloadPreload
* Maps to a timer's @ref TIM_Base_InitTypeDef:AutoReloadPreload
*/
uint32_t autoReloadPreload{};

/**
* Timer clock source
* This parameter can be a value of @ref TIM_Clock_Source
* Maps to @ref TIM_ClockConfigTypeDef:ClockSource
*/
uint32_t clockSource{};

/**
* Trigger output (TRGO) selection.
* This parameter can be a value of @ref TIM_Master_Mode_Selection
* Maps to @ref TIM_MasterConfigTypeDef:MasterOutputTrigger
*/
uint32_t masterOutputTrigger{};

/**
* Master/slave mode selection.
* This parameter can be a value of @ref TIM_Master_Slave_Mode
* Maps to @ref TIM_MasterConfigTypeDef:MasterSlaveMode
*/
uint32_t masterSlaveMode{};
} TimerConfiguration_t;

class Timer {
public:
/**
* Virtual destructor required by C++.
*/
virtual ~Timer() = default;

/**
* Starts the given timer and registers the given interrupt pointer to trigger when the timer overflows
* @param[in] irqHandler The IRQ Handler function pointer. Sets a new interrupt handler function
Expand All @@ -36,11 +90,14 @@ class Timer {
* Set the clock period for the timer. Will stop the timer, re-initialize the device with the updated period.
* You must call startTimer again to continue timer operation.
*
* @param[in] clockPeriod the clock period in ms. An interrupt will be triggered at that frequency.
* @param[in] clockPeriod the clock period in ticks (ms when using AUTO_PRESCALER). An interrupt will be triggered
* at that frequency.
* @param [in] clockPrescaler the prescaler used by the timer. Divides the system clock frequency to get it within
* an acceptable range for use with the required period. If set to @ref AUTO_PRESCALER, the function implementation
* will calculate its own prescaler.
*/
virtual void setPeriod(uint32_t clockPeriod) = 0;
virtual void setPeriod(uint32_t clockPeriod, uint32_t clockPrescaler = AUTO_PRESCALER) = 0;
};

} // namespace core::dev

#endif // EVT_TIMER_HPP
74 changes: 63 additions & 11 deletions include/core/dev/platform/f3xx/Timerf3xx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,20 @@
namespace core::dev {

/**
* Implementation of the Timer class for STM32f3xx MCUs
* Concrete implementation of the Timer class for STM32f3xx MCUs.
*/
class Timerf3xx : public Timer {
class TimerF3xx : public Timer {
public:
/**
* The default configuration for an F3 timer.
*/
static constexpr TimerConfiguration_t defaultConfig = {TIM_COUNTERMODE_UP,
TIM_CLOCKDIVISION_DIV1,
TIM_AUTORELOAD_PRELOAD_ENABLE,
TIM_CLOCKSOURCE_INTERNAL,
TIM_TRGO_RESET,
TIM_MASTERSLAVEMODE_DISABLE};

/**
* Will initialize the timer device on the STM with the given period and the given IRQ Handler
* that triggers with the given period. Starts the timer
Expand All @@ -22,34 +32,76 @@ class Timerf3xx : public Timer {
* do not occur.
Comment thread
ActuallyTaylor marked this conversation as resolved.
Outdated
*
* @param[in] timerPeripheral The timer to use
* @param[in] clockPeriod the clock period in ms. An interrupt will be triggered at that frequency.
* @param[in] clockPeriod the clock period in ticks (ms when using AUTO_PRESCALER). An interrupt will be triggered
* at this frequency.
* @param[in] configuration the configuration tells the timer how to configure itself. Defaults to @ref
* TimerF3xx::defaultConfig.
* @param[in] clockPrescaler the prescaler that the clock will use. If clockPrescaler is set to @ref AUTO_PRESCALER,
* this function will calculate its own prescaler value.
*/
explicit Timerf3xx(TIM_TypeDef* timerPeripheral, uint32_t clockPeriod);
explicit TimerF3xx(TIM_TypeDef* timerPeripheral, uint32_t clockPeriod,
const TimerConfiguration_t& configuration = defaultConfig,
uint32_t clockPrescaler = AUTO_PRESCALER);

/**
* Starts the given timer and registers the given interrupt pointer to trigger when the timer overflows
* @param[in] irqHandler The IRQ Handler function pointer. Sets a new interrupt handler function
*/
void startTimer(void (*irqHandler)(void* htim)) override;

/**
* Starts the given timer using the IRQ Handler already assigned to that timer.
*/
void startTimer() override;

/**
* Stops the current timer from running. Does not complete its current counting sequence.
*/
void stopTimer() override;

/**
* Resets the timer counter.
*/
void reloadTimer() override;

void setPeriod(uint32_t clockPeriod) override;
/**
* Set the clock period for the timer. Will stop the timer, re-initialize the device with the updated period.
* You must call startTimer again to continue timer operation.
*
* @param[in] clockPeriod the clock period in ticks (ms when using AUTO_PRESCALER). An interrupt will be triggered
* at that frequency.
* @param [in] clockPrescaler the prescaler used by the clock. Divides the system clock frequency to get it within
* an acceptable range for clocking. If set to @ref AUTO_PRESCALER, the function implementation should calculate its
* own prescaler.
*/
void setPeriod(uint32_t clockPeriod, uint32_t clockPrescaler = AUTO_PRESCALER) override;
Comment thread
ActuallyTaylor marked this conversation as resolved.

private:
// Pointer to the halTimer struct stored in the global array in Timerf3xx.cpp
protected:
/**
* Pointer to the halTimer struct stored in the global array in Timerf4xx.cpp
*/
TIM_HandleTypeDef* halTimer;

// Timer clock period
uint32_t clockPeriod;
/**
* Timer clock period
*/
uint32_t clockPeriod{};

/**
* The configuration that this timer will use.
*/
TimerConfiguration_t configuration;

/**
* Handles the initialization of the timer module. Actually configures the device and enables it.
* @param[in] timerPeripheral The timer peripheral to configure. Possible options for this board are
* TIM2, TIM15, TIM16, TIM17. It is up to the user to verify that resource conflicts do not occur.
* @param[in] clockPeriod the clock period in ms. An interrupt will be triggered at that frequency.
* @param[in] clockPeriod the clock period in ticks (ms when using AUTO_PRESCALER). An interrupt will be triggered
* at that frequency.
* @param[in] clockPrescaler the prescaler that the clock will use. If clockPrescaler is set to @ref AUTO_PRESCALER,
* this function will calculate its own prescaler value.
*/
void initTimer(TIM_TypeDef* timerPeripheral, uint32_t clockPeriod);
void initTimer(TIM_TypeDef* timerPeripheral, uint32_t clockPeriod, uint32_t clockPrescaler);
};

} // namespace core::dev
Expand Down
Loading