RTEMS 6.1-rc4
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_index;
80
81stm32h7_module_index stm32h7_get_module_index(const void *regs);
82
83void stm32h7_clk_enable(stm32h7_module_index index);
84
85void stm32h7_clk_disable(stm32h7_module_index index);
86
87void stm32h7_clk_low_power_enable(stm32h7_module_index index);
88
89void stm32h7_clk_low_power_disable(stm32h7_module_index index);
90
91typedef struct {
92 GPIO_TypeDef *regs;
95
96void stm32h7_gpio_init(const stm32h7_gpio_config *config);
97
98typedef struct {
101 uint8_t device_index;
103
104typedef struct {
106 bool transmitting;
110
111static inline stm32h7_uart_context *stm32h7_uart_get_context(
113)
114{
115 return RTEMS_CONTAINER_OF(base, stm32h7_uart_context, device);
116}
117
118void stm32h7_uart_polled_write(rtems_termios_device_context *base, char c);
119
120int stm32h7_uart_polled_read(rtems_termios_device_context *base);
121
122extern stm32h7_uart_context stm32h7_usart1_instance;
123
124extern const stm32h7_uart_config stm32h7_usart1_config;
125
126extern stm32h7_uart_context stm32h7_usart2_instance;
127
128extern const stm32h7_uart_config stm32h7_usart2_config;
129
130extern stm32h7_uart_context stm32h7_usart3_instance;
131
132extern const stm32h7_uart_config stm32h7_usart3_config;
133
134extern stm32h7_uart_context stm32h7_uart4_instance;
135
136extern const stm32h7_uart_config stm32h7_uart4_config;
137
138extern stm32h7_uart_context stm32h7_uart5_instance;
139
140extern const stm32h7_uart_config stm32h7_uart5_config;
141
142extern stm32h7_uart_context stm32h7_usart6_instance;
143
144extern const stm32h7_uart_config stm32h7_usart6_config;
145
146extern stm32h7_uart_context stm32h7_uart7_instance;
147
148extern const stm32h7_uart_config stm32h7_uart7_config;
149
150extern stm32h7_uart_context stm32h7_uart8_instance;
151
152extern const stm32h7_uart_config stm32h7_uart8_config;
153
154extern stm32h7_uart_context stm32h7_uart9_instance;
155
156extern const stm32h7_uart_config stm32h7_uart9_config;
157
158extern stm32h7_uart_context stm32h7_usart10_instance;
159
160extern const stm32h7_uart_config stm32h7_usart10_config;
161
162extern const uint32_t stm32h7_config_pwr_regulator_voltagescaling;
163
164extern const RCC_OscInitTypeDef stm32h7_config_oscillator;
165
166extern const RCC_ClkInitTypeDef stm32h7_config_clocks;
167
168extern const uint32_t stm32h7_config_flash_latency;
169
170extern const RCC_PeriphCLKInitTypeDef stm32h7_config_peripheral_clocks;
171
172#define STM32H7_NUM_SOFT_CS 4
173
174typedef struct {
175 /*
176 * Some SPI peripheral configurations require multiple GPIO blocks, so
177 * configure each pin separately.
178 */
179 stm32h7_gpio_config sck_gpio;
180 stm32h7_gpio_config miso_gpio;
181 stm32h7_gpio_config mosi_gpio;
182 stm32h7_gpio_config cs_gpio[STM32H7_NUM_SOFT_CS];
183 /*
184 * This is expected to be the maximum speed of the output clock which is a
185 * factor of 2 less than the input clock.
186 */
187 uint32_t max_speed_hz;
189
190typedef struct {
191 spi_bus bus;
193 bool transmitting;
196#ifdef STM32H7_SPI_USE_INTERRUPTS
197 rtems_interrupt_entry spi_irq_entry;
199 int error;
200#endif
202
203extern stm32h7_spi_context stm32h7_spi1_instance;
204
205extern const stm32h7_spi_config stm32h7_spi1_config;
206
207extern stm32h7_spi_context stm32h7_spi2_instance;
208
209extern const stm32h7_spi_config stm32h7_spi2_config;
210
211extern stm32h7_spi_context stm32h7_spi3_instance;
212
213extern const stm32h7_spi_config stm32h7_spi3_config;
214
215extern stm32h7_spi_context stm32h7_spi4_instance;
216
217extern const stm32h7_spi_config stm32h7_spi4_config;
218
219extern stm32h7_spi_context stm32h7_spi5_instance;
220
221extern const stm32h7_spi_config stm32h7_spi5_config;
222
223extern stm32h7_spi_context stm32h7_spi6_instance;
224
225extern const stm32h7_spi_config stm32h7_spi6_config;
226
227
228#ifdef __cplusplus
229}
230#endif
231
232#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
This file contains all the functions prototypes for the HAL module driver.
GPIO Init structure definition.
Definition: stm32h7xx_hal_gpio.h:48
General Purpose I/O.
Definition: stm32h723xx.h:1066
RCC System, AHB and APB busses clock configuration structure definition.
Definition: stm32h7xx_hal_rcc.h:124
RCC Internal/External Oscillator (HSE, HSI, CSI, LSE and LSI) configuration structure definition.
Definition: stm32h7xx_hal_rcc.h:86
RCC extended clocks structure definition.
Definition: stm32h7xx_hal_rcc_ex.h:142
SPI handle Structure definition.
Definition: stm32h7xx_hal_spi.h:171
UART handle Structure definition.
Definition: stm32h7xx_hal_uart.h:224
Definition: deflate.c:114
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:91
Definition: hal.h:174
Definition: hal.h:190
Definition: hal.h:98
Definition: hal.h:104