Skip to content

Commit 1423e87

Browse files
committed
stm32f469 bugfix not initializing clocks for gpio pins
1 parent 2bf3f08 commit 1423e87

3 files changed

Lines changed: 80 additions & 0 deletions

File tree

targets/chip/stm32f469/io/port.hpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ namespace klib::stm32f469::io::periph {
1818
// peripheral id (e.g gpio0, gpio1)
1919
constexpr static uint32_t id = 0;
2020

21+
// peripheral clock bit position
22+
constexpr static uint32_t clock_id = 0;
23+
2124
// port to the gpio hardware
2225
static inline GPIOA_Type *const port = GPIOA;
2326
};
@@ -26,6 +29,9 @@ namespace klib::stm32f469::io::periph {
2629
// peripheral id (e.g gpio0, gpio1)
2730
constexpr static uint32_t id = 1;
2831

32+
// peripheral clock bit position
33+
constexpr static uint32_t clock_id = 1;
34+
2935
// port to the gpio hardware
3036
static inline GPIOB_Type *const port = GPIOB;
3137
};
@@ -34,6 +40,9 @@ namespace klib::stm32f469::io::periph {
3440
// peripheral id (e.g gpio0, gpio1)
3541
constexpr static uint32_t id = 2;
3642

43+
// peripheral clock bit position
44+
constexpr static uint32_t clock_id = 2;
45+
3746
// port to the gpio hardware
3847
static inline GPIOK_Type *const port = GPIOC;
3948
};
@@ -42,6 +51,9 @@ namespace klib::stm32f469::io::periph {
4251
// peripheral id (e.g gpio0, gpio1)
4352
constexpr static uint32_t id = 3;
4453

54+
// peripheral clock bit position
55+
constexpr static uint32_t clock_id = 3;
56+
4557
// port to the gpio hardware
4658
static inline GPIOK_Type *const port = GPIOD;
4759
};
@@ -50,6 +62,9 @@ namespace klib::stm32f469::io::periph {
5062
// peripheral id (e.g gpio0, gpio1)
5163
constexpr static uint32_t id = 4;
5264

65+
// peripheral clock bit position
66+
constexpr static uint32_t clock_id = 4;
67+
5368
// port to the gpio hardware
5469
static inline GPIOK_Type *const port = GPIOE;
5570
};
@@ -58,6 +73,9 @@ namespace klib::stm32f469::io::periph {
5873
// peripheral id (e.g gpio0, gpio1)
5974
constexpr static uint32_t id = 5;
6075

76+
// peripheral clock bit position
77+
constexpr static uint32_t clock_id = 5;
78+
6179
// port to the gpio hardware
6280
static inline GPIOK_Type *const port = GPIOF;
6381
};
@@ -66,6 +84,9 @@ namespace klib::stm32f469::io::periph {
6684
// peripheral id (e.g gpio0, gpio1)
6785
constexpr static uint32_t id = 6;
6886

87+
// peripheral clock bit position
88+
constexpr static uint32_t clock_id = 6;
89+
6990
// port to the gpio hardware
7091
static inline GPIOK_Type *const port = GPIOG;
7192
};
@@ -74,6 +95,9 @@ namespace klib::stm32f469::io::periph {
7495
// peripheral id (e.g gpio0, gpio1)
7596
constexpr static uint32_t id = 7;
7697

98+
// peripheral clock bit position
99+
constexpr static uint32_t clock_id = 7;
100+
77101
// port to the gpio hardware
78102
static inline GPIOK_Type *const port = GPIOH;
79103
};
@@ -82,6 +106,9 @@ namespace klib::stm32f469::io::periph {
82106
// peripheral id (e.g gpio0, gpio1)
83107
constexpr static uint32_t id = 8;
84108

109+
// peripheral clock bit position
110+
constexpr static uint32_t clock_id = 8;
111+
85112
// port to the gpio hardware
86113
static inline GPIOK_Type *const port = GPIOI;
87114
};
@@ -90,6 +117,9 @@ namespace klib::stm32f469::io::periph {
90117
// peripheral id (e.g gpio0, gpio1)
91118
constexpr static uint32_t id = 9;
92119

120+
// peripheral clock bit position
121+
constexpr static uint32_t clock_id = 9;
122+
93123
// port to the gpio hardware
94124
static inline GPIOK_Type *const port = GPIOJ;
95125
};
@@ -98,6 +128,9 @@ namespace klib::stm32f469::io::periph {
98128
// peripheral id (e.g gpio0, gpio1)
99129
constexpr static uint32_t id = 10;
100130

131+
// peripheral clock bit position
132+
constexpr static uint32_t clock_id = 10;
133+
101134
// port to the gpio hardware
102135
static inline GPIOK_Type *const port = GPIOK;
103136
};
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#ifndef KLIB_STM_STM32F4XX_CLOCKS_HPP
2+
#define KLIB_STM_STM32F4XX_CLOCKS_HPP
3+
4+
#include <klib/klib.hpp>
5+
6+
namespace klib::core::stm32f4xx::io {
7+
class clocks {
8+
public:
9+
/**
10+
* @brief Set the global peripheral clock selection
11+
*
12+
*/
13+
template <typename P>
14+
static void set() {
15+
// get the clock id and make sure it is valid
16+
constexpr static uint32_t id = P::clock_id;
17+
static_assert(id < (5 * 32), "Invalid clock id");
18+
19+
// check what register to set
20+
if constexpr (id < (1 * 32)) {
21+
RCC->AHB1ENR |= (0x1 << P::clock_id);
22+
}
23+
else if constexpr (id < (2 * 32)) {
24+
RCC->AHB2ENR |= (0x1 << (P::clock_id - (1 * 32)));
25+
}
26+
else if constexpr (id < (3 * 32)) {
27+
RCC->AHB3ENR |= (0x1 << (P::clock_id - (2 * 32)));
28+
}
29+
else if constexpr (id < (4 * 32)) {
30+
RCC->APB1ENR |= (0x1 << (P::clock_id - (3 * 32)));
31+
}
32+
else if constexpr (id < (5 * 32)) {
33+
RCC->APB2ENR |= (0x1 << (P::clock_id - (4 * 32)));
34+
}
35+
}
36+
};
37+
}
38+
39+
#endif

targets/core/stm/stm32f4xx/port.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#include <klib/klib.hpp>
77

8+
#include <io/clocks.hpp>
9+
810
namespace klib::core::stm32f4xx::io::detail::alternate {
911
// alternate functions for all the gpio
1012
// default function (view reference manual for
@@ -277,6 +279,9 @@ namespace klib::core::stm32f4xx::io {
277279
*
278280
*/
279281
constexpr static void init() {
282+
// init the gpio port clock
283+
target::io::clocks::set<typename Pin::port>();
284+
280285
// set the pin to input mode
281286
detail::pins::set_direction_mode<Pin, detail::pins::direction_mode::input>();
282287
}
@@ -325,6 +330,9 @@ namespace klib::core::stm32f4xx::io {
325330
*
326331
*/
327332
constexpr static void init() {
333+
// init the gpio port clock
334+
target::io::clocks::set<typename Pin::port>();
335+
328336
// set the pin to output mode
329337
detail::pins::set_direction_mode<Pin, detail::pins::direction_mode::output>();
330338
}

0 commit comments

Comments
 (0)