RTEMS 7.0-rc1
Loading...
Searching...
No Matches
hal.h
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/*
4 * Copyright (C) 2020 embedded brains GmbH & Co. KG
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#ifndef LIBBSP_ARM_STM32H7_STM32H7_HAL_H
29#define LIBBSP_ARM_STM32H7_STM32H7_HAL_H
30
31#include <stm32h7xx_hal.h>
32
33#include <rtems/termiostypes.h>
34#include <dev/spi/spi.h>
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40typedef enum {
41 STM32H7_MODULE_INVALID,
42 STM32H7_MODULE_GPIOA,
43 STM32H7_MODULE_GPIOB,
44 STM32H7_MODULE_GPIOC,
45 STM32H7_MODULE_GPIOD,
46 STM32H7_MODULE_GPIOE,
47 STM32H7_MODULE_GPIOF,
48 STM32H7_MODULE_GPIOG,
49 STM32H7_MODULE_GPIOH,
50 STM32H7_MODULE_GPIOI,
51 STM32H7_MODULE_GPIOJ,
52 STM32H7_MODULE_GPIOK,
53 STM32H7_MODULE_USART1,
54 STM32H7_MODULE_USART2,
55 STM32H7_MODULE_USART3,
56 STM32H7_MODULE_UART4,
57 STM32H7_MODULE_UART5,
58 STM32H7_MODULE_USART6,
59 STM32H7_MODULE_UART7,
60 STM32H7_MODULE_UART8,
61 STM32H7_MODULE_UART9,
62 STM32H7_MODULE_USART10,
63 STM32H7_MODULE_RNG,
64 STM32H7_MODULE_ETH1MAC,
65 STM32H7_MODULE_ETH1TX,
66 STM32H7_MODULE_ETH1RX,
67 STM32H7_MODULE_USB1_OTG,
68 STM32H7_MODULE_USB1_OTG_ULPI,
69 STM32H7_MODULE_USB2_OTG,
70 STM32H7_MODULE_USB2_OTG_ULPI,
71 STM32H7_MODULE_SDMMC1,
72 STM32H7_MODULE_SDMMC2,
73 STM32H7_MODULE_SPI1,
74 STM32H7_MODULE_SPI2,
75 STM32H7_MODULE_SPI3,
76 STM32H7_MODULE_SPI4,
77 STM32H7_MODULE_SPI5,
78 STM32H7_MODULE_SPI6,
79 STM32H7_MODULE_DMA1,
80 STM32H7_MODULE_DMA2,
81} stm32h7_module_index;
82
83stm32h7_module_index stm32h7_get_module_index(const void *regs);
84
85void stm32h7_clk_enable(stm32h7_module_index index);
86
87void stm32h7_clk_disable(stm32h7_module_index index);
88
89void stm32h7_clk_low_power_enable(stm32h7_module_index index);
90
91void stm32h7_clk_low_power_disable(stm32h7_module_index index);
92
93typedef struct {
94 GPIO_TypeDef *regs;
95 GPIO_InitTypeDef config;
97
98void stm32h7_gpio_init(const stm32h7_gpio_config *config);
99
100typedef struct {
103 uint8_t device_index;
105
106typedef struct {
107 UART_HandleTypeDef uart;
108 bool transmitting;
110 const stm32h7_uart_config *config;
112
113static inline stm32h7_uart_context *stm32h7_uart_get_context(
115)
116{
117 return RTEMS_CONTAINER_OF(base, stm32h7_uart_context, device);
118}
119
120void stm32h7_uart_polled_write(rtems_termios_device_context *base, char c);
121
122int stm32h7_uart_polled_read(rtems_termios_device_context *base);
123
124extern stm32h7_uart_context stm32h7_usart1_instance;
125
126extern const stm32h7_uart_config stm32h7_usart1_config;
127
128extern stm32h7_uart_context stm32h7_usart2_instance;
129
130extern const stm32h7_uart_config stm32h7_usart2_config;
131
132extern stm32h7_uart_context stm32h7_usart3_instance;
133
134extern const stm32h7_uart_config stm32h7_usart3_config;
135
136extern stm32h7_uart_context stm32h7_uart4_instance;
137
138extern const stm32h7_uart_config stm32h7_uart4_config;
139
140extern stm32h7_uart_context stm32h7_uart5_instance;
141
142extern const stm32h7_uart_config stm32h7_uart5_config;
143
144extern stm32h7_uart_context stm32h7_usart6_instance;
145
146extern const stm32h7_uart_config stm32h7_usart6_config;
147
148extern stm32h7_uart_context stm32h7_uart7_instance;
149
150extern const stm32h7_uart_config stm32h7_uart7_config;
151
152extern stm32h7_uart_context stm32h7_uart8_instance;
153
154extern const stm32h7_uart_config stm32h7_uart8_config;
155
156extern stm32h7_uart_context stm32h7_uart9_instance;
157
158extern const stm32h7_uart_config stm32h7_uart9_config;
159
160extern stm32h7_uart_context stm32h7_usart10_instance;
161
162extern const stm32h7_uart_config stm32h7_usart10_config;
163
164extern const uint32_t stm32h7_config_pwr_regulator_voltagescaling;
165
166extern const RCC_OscInitTypeDef stm32h7_config_oscillator;
167
168extern const RCC_ClkInitTypeDef stm32h7_config_clocks;
169
170extern const uint32_t stm32h7_config_flash_latency;
171
172extern const RCC_PeriphCLKInitTypeDef stm32h7_config_peripheral_clocks;
173
174#define STM32H7_NUM_SOFT_CS 4
175
176typedef struct {
177 /*
178 * Some SPI peripheral configurations require multiple GPIO blocks, so
179 * configure each pin separately.
180 */
181 stm32h7_gpio_config sck_gpio;
182 stm32h7_gpio_config miso_gpio;
183 stm32h7_gpio_config mosi_gpio;
184 stm32h7_gpio_config cs_gpio[STM32H7_NUM_SOFT_CS];
185 /*
186 * This is expected to be the maximum speed of the output clock which is a
187 * factor of 2 less than the input clock.
188 */
189 uint32_t max_speed_hz;
191
192typedef struct {
193 spi_bus bus;
194 SPI_HandleTypeDef spi;
195 bool transmitting;
196 const stm32h7_spi_config *config;
198#ifdef STM32H7_SPI_USE_INTERRUPTS
199 rtems_interrupt_entry spi_irq_entry;
201 int error;
202#endif
204
205extern stm32h7_spi_context stm32h7_spi1_instance;
206
207extern const stm32h7_spi_config stm32h7_spi1_config;
208
209extern stm32h7_spi_context stm32h7_spi2_instance;
210
211extern const stm32h7_spi_config stm32h7_spi2_config;
212
213extern stm32h7_spi_context stm32h7_spi3_instance;
214
215extern const stm32h7_spi_config stm32h7_spi3_config;
216
217extern stm32h7_spi_context stm32h7_spi4_instance;
218
219extern const stm32h7_spi_config stm32h7_spi4_config;
220
221extern stm32h7_spi_context stm32h7_spi5_instance;
222
223extern const stm32h7_spi_config stm32h7_spi5_config;
224
225extern stm32h7_spi_context stm32h7_spi6_instance;
226
227extern const stm32h7_spi_config stm32h7_spi6_config;
228
229
230#ifdef __cplusplus
231}
232#endif
233
234#endif /* LIBBSP_ARM_STM32H7_STM32H7_HAL_H */
Serial Peripheral Interface (SPI) Driver API.
#define RTEMS_CONTAINER_OF(_m, _type, _member_name)
Gets the container of a member.
Definition: basedefs.h:306
ISR_Vector_number rtems_vector_number
This integer type represents interrupt vector numbers.
Definition: intr.h:102
General Purpose I/O.
Definition: stm32u5g9xx.h:747
Definition: thread.h:280
This structure represents an interrupt entry.
Definition: intr.h:1070
Termios device context.
Definition: termiosdevice.h:68
SPI bus control.
Definition: spi.h:80
Definition: hal.h:93
Definition: hal.h:176
Definition: hal.h:192
Definition: hal.h:100
Definition: hal.h:106