rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
board.c
Go to the documentation of this file.
1/**
2 * @file boards/subaru_eg33/board.c
3 *
4 * @date Feb 06, 2021
5 * @author Andrey Gusakov, 2021
6 */
7
8#include "hal.h"
9#include "stm32_gpio.h"
10#include "unused.h"
11
12#include "board_io.h"
13
14/* drivers */
15
16/*==========================================================================*/
17/* Driver local definitions. */
18/*==========================================================================*/
19
20/*==========================================================================*/
21/* Driver exported variables. */
22/*==========================================================================*/
23
24/*==========================================================================*/
25/* Driver local variables and types. */
26/*==========================================================================*/
27
28/**
29 * @brief Type of STM32 GPIO port setup.
30 */
31typedef struct {
32 uint32_t moder;
33 uint32_t otyper;
34 uint32_t ospeedr;
35 uint32_t pupdr;
36 uint32_t odr;
37 uint32_t afrl;
38 uint32_t afrh;
39} gpio_setup_t;
40
41/**
42 * @brief Type of STM32 GPIO initialization data.
43 */
44typedef struct {
45 gpio_setup_t PAData;
46 gpio_setup_t PBData;
47 gpio_setup_t PCData;
48 gpio_setup_t PDData;
49 gpio_setup_t PEData;
50 gpio_setup_t PFData;
51 gpio_setup_t PGData;
52 gpio_setup_t PHData;
53 gpio_setup_t PIData;
54} gpio_config_t;
55
56/**
57 * @brief STM32 GPIO static initialization data.
58 */
59static const gpio_config_t gpio_default_config = {
60 {VAL_GPIOA_MODER, VAL_GPIOA_OTYPER, VAL_GPIOA_OSPEEDR, VAL_GPIOA_PUPDR,
61 VAL_GPIOA_ODR, VAL_GPIOA_AFRL, VAL_GPIOA_AFRH},
62 {VAL_GPIOB_MODER, VAL_GPIOB_OTYPER, VAL_GPIOB_OSPEEDR, VAL_GPIOB_PUPDR,
63 VAL_GPIOB_ODR, VAL_GPIOB_AFRL, VAL_GPIOB_AFRH},
64 {VAL_GPIOC_MODER, VAL_GPIOC_OTYPER, VAL_GPIOC_OSPEEDR, VAL_GPIOC_PUPDR,
65 VAL_GPIOC_ODR, VAL_GPIOC_AFRL, VAL_GPIOC_AFRH},
66 {VAL_GPIOD_MODER, VAL_GPIOD_OTYPER, VAL_GPIOD_OSPEEDR, VAL_GPIOD_PUPDR,
67 VAL_GPIOD_ODR, VAL_GPIOD_AFRL, VAL_GPIOD_AFRH},
68 {VAL_GPIOE_MODER, VAL_GPIOE_OTYPER, VAL_GPIOE_OSPEEDR, VAL_GPIOE_PUPDR,
69 VAL_GPIOE_ODR, VAL_GPIOE_AFRL, VAL_GPIOE_AFRH},
70 {VAL_GPIOF_MODER, VAL_GPIOF_OTYPER, VAL_GPIOF_OSPEEDR, VAL_GPIOF_PUPDR,
71 VAL_GPIOF_ODR, VAL_GPIOF_AFRL, VAL_GPIOF_AFRH},
72 {VAL_GPIOG_MODER, VAL_GPIOG_OTYPER, VAL_GPIOG_OSPEEDR, VAL_GPIOG_PUPDR,
73 VAL_GPIOG_ODR, VAL_GPIOG_AFRL, VAL_GPIOG_AFRH},
74 {VAL_GPIOH_MODER, VAL_GPIOH_OTYPER, VAL_GPIOH_OSPEEDR, VAL_GPIOH_PUPDR,
75 VAL_GPIOH_ODR, VAL_GPIOH_AFRL, VAL_GPIOH_AFRH},
76 {VAL_GPIOI_MODER, VAL_GPIOI_OTYPER, VAL_GPIOI_OSPEEDR, VAL_GPIOI_PUPDR,
77 VAL_GPIOI_ODR, VAL_GPIOI_AFRL, VAL_GPIOI_AFRH},
78};
79
80/*==========================================================================*/
81/* Driver local functions. */
82/*==========================================================================*/
83
84static void gpio_init(stm32_gpio_t *gpiop, const gpio_setup_t *config) {
85
86 gpiop->OTYPER = config->otyper;
87 gpiop->OSPEEDR = config->ospeedr;
88 gpiop->PUPDR = config->pupdr;
89 gpiop->ODR = config->odr;
90 gpiop->AFRL = config->afrl;
91 gpiop->AFRH = config->afrh;
92 gpiop->MODER = config->moder;
93}
94
95static void stm32_gpio_init(void) {
96
97 /* Enabling GPIO-related clocks, the mask comes from the
98 * registry header file.*/
99 rccResetAHB1(STM32_GPIO_EN_MASK);
100 rccEnableAHB1(STM32_GPIO_EN_MASK, true);
101
102 /* Initializing all the defined GPIO ports.*/
103 gpio_init(GPIOA, &gpio_default_config.PAData);
104 gpio_init(GPIOB, &gpio_default_config.PBData);
105 gpio_init(GPIOC, &gpio_default_config.PCData);
106 gpio_init(GPIOD, &gpio_default_config.PDData);
107 gpio_init(GPIOE, &gpio_default_config.PEData);
108 gpio_init(GPIOF, &gpio_default_config.PFData);
109 gpio_init(GPIOG, &gpio_default_config.PGData);
110 gpio_init(GPIOH, &gpio_default_config.PHData);
111 gpio_init(GPIOI, &gpio_default_config.PIData);
112}
113
114/*==========================================================================*/
115/* Driver interrupt handlers. */
116/*==========================================================================*/
117
118/*==========================================================================*/
119/* Driver exported functions. */
120/*==========================================================================*/
121
122/**
123 * @brief Early initialization code.
124 * @details GPIO ports and system clocks are initialized before everything
125 * else.
126 */
127void __early_init(void)
128{
129 /* allow debug in all low-power modes */
130 DBGMCU->CR |= DBGMCU_CR_DBG_SLEEP | DBGMCU_CR_DBG_STOP | DBGMCU_CR_DBG_STANDBY;
131
133 stm32_clock_init();
134}
135
136#if HAL_USE_SDC || defined(__DOXYGEN__)
137/**
138 * @brief SDC card detection.
139 */
140bool sdc_lld_is_card_inserted(SDCDriver *sdcp)
141{
142 UNUSED(sdcp);
143 /* TODO: Fill the implementation.*/
144 return true;
145}
146
147/**
148 * @brief SDC card write protection detection.
149 */
150bool sdc_lld_is_write_protected(SDCDriver *sdcp)
151{
152 UNUSED(sdcp);
153 /* TODO: Fill the implementation.*/
154 return false;
155}
156#endif /* HAL_USE_SDC */
157
158#if HAL_USE_MMC_SPI || defined(__DOXYGEN__)
159/**
160 * @brief MMC_SPI card detection.
161 */
162bool mmc_lld_is_card_inserted(MMCDriver *mmcp)
163{
164 UNUSED(mmcp);
165 /* TODO: Fill the implementation.*/
166 return true;
167}
168
169/**
170 * @brief MMC_SPI card write protection detection.
171 */
172bool mmc_lld_is_write_protected(MMCDriver *mmcp)
173{
174 UNUSED(mmcp);
175 /* TODO: Fill the implementation.*/
176 return false;
177}
178#endif
void __early_init(void)
Definition board.c:21
static constexpr persistent_config_s * config
bool sdc_lld_is_write_protected(SDCDriver *sdcp)
SDC card write protection detection.
Definition board.c:394
bool mmc_lld_is_card_inserted(MMCDriver *mmcp)
MMC_SPI card detection.
Definition board.c:406
bool mmc_lld_is_write_protected(MMCDriver *mmcp)
MMC_SPI card write protection detection.
Definition board.c:416
static void stm32_gpio_init(void)
Definition board.c:181
static void gpio_init(stm32_gpio_t *gpiop, const gpio_setup_t *config)
Definition board.c:170
static const gpio_config_t gpio_default_config
STM32 GPIO static initialization data.
Definition board.c:119
bool sdc_lld_is_card_inserted(SDCDriver *sdcp)
SDC card detection.
Definition board.c:384
UNUSED(samplingTimeSeconds)