2016-03-03 15:33:20 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Open-RnD Sp. z o.o.
|
2016-11-14 11:53:52 +01:00
|
|
|
* Copyright (c) 2016 Linaro Limited.
|
2016-03-03 15:33:20 +01:00
|
|
|
*
|
2017-01-19 02:01:01 +01:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2016-03-03 15:33:20 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2018-03-20 18:44:45 +01:00
|
|
|
* @brief Driver for UART port on STM32 family processor.
|
2019-03-15 19:51:09 +01:00
|
|
|
* @note LPUART and U(S)ART have the same base and
|
|
|
|
* majority of operations are performed the same way.
|
|
|
|
* Please validate for newly added series.
|
2016-03-03 15:33:20 +01:00
|
|
|
*/
|
|
|
|
|
2016-12-04 21:59:37 +01:00
|
|
|
#include <kernel.h>
|
2016-03-03 15:33:20 +01:00
|
|
|
#include <arch/cpu.h>
|
2019-06-26 16:33:39 +02:00
|
|
|
#include <sys/__assert.h>
|
2018-10-31 18:44:45 +01:00
|
|
|
#include <soc.h>
|
2016-03-03 15:33:20 +01:00
|
|
|
#include <init.h>
|
2019-06-25 21:54:01 +02:00
|
|
|
#include <drivers/uart.h>
|
2019-06-25 21:53:47 +02:00
|
|
|
#include <drivers/clock_control.h>
|
2016-03-03 15:33:20 +01:00
|
|
|
|
2017-06-17 17:30:47 +02:00
|
|
|
#include <linker/sections.h>
|
2020-01-25 12:34:53 +01:00
|
|
|
#include <drivers/clock_control/stm32_clock_control.h>
|
2016-03-03 15:33:20 +01:00
|
|
|
#include "uart_stm32.h"
|
|
|
|
|
2019-11-12 16:13:03 +01:00
|
|
|
#include <logging/log.h>
|
|
|
|
LOG_MODULE_REGISTER(uart_stm32);
|
|
|
|
|
2016-03-03 15:33:20 +01:00
|
|
|
/* convenience defines */
|
|
|
|
#define DEV_CFG(dev) \
|
2016-10-06 20:47:13 +02:00
|
|
|
((const struct uart_stm32_config * const)(dev)->config->config_info)
|
2016-03-03 15:33:20 +01:00
|
|
|
#define DEV_DATA(dev) \
|
|
|
|
((struct uart_stm32_data * const)(dev)->driver_data)
|
|
|
|
#define UART_STRUCT(dev) \
|
2016-11-14 11:53:52 +01:00
|
|
|
((USART_TypeDef *)(DEV_CFG(dev))->uconf.base)
|
2016-03-03 15:33:20 +01:00
|
|
|
|
2016-11-14 11:53:52 +01:00
|
|
|
#define TIMEOUT 1000
|
2016-03-03 15:33:20 +01:00
|
|
|
|
2019-01-07 22:52:24 +01:00
|
|
|
static inline void uart_stm32_set_baudrate(struct device *dev, u32_t baud_rate)
|
|
|
|
{
|
|
|
|
const struct uart_stm32_config *config = DEV_CFG(dev);
|
|
|
|
struct uart_stm32_data *data = DEV_DATA(dev);
|
|
|
|
USART_TypeDef *UartInstance = UART_STRUCT(dev);
|
2019-05-20 17:15:02 +02:00
|
|
|
|
2019-01-07 22:52:24 +01:00
|
|
|
u32_t clock_rate;
|
|
|
|
|
|
|
|
/* Get clock rate */
|
2019-11-12 16:13:03 +01:00
|
|
|
if (clock_control_get_rate(data->clock,
|
2019-01-07 22:52:24 +01:00
|
|
|
(clock_control_subsys_t *)&config->pclken,
|
2019-11-12 16:13:03 +01:00
|
|
|
&clock_rate) < 0) {
|
|
|
|
LOG_ERR("Failed call clock_control_get_rate");
|
|
|
|
return;
|
|
|
|
}
|
2019-05-20 17:15:02 +02:00
|
|
|
|
|
|
|
|
2019-01-07 22:52:24 +01:00
|
|
|
#ifdef CONFIG_LPUART_1
|
|
|
|
if (IS_LPUART_INSTANCE(UartInstance)) {
|
2019-05-20 17:15:02 +02:00
|
|
|
LL_LPUART_SetBaudRate(UartInstance,
|
|
|
|
clock_rate,
|
|
|
|
#ifdef USART_PRESC_PRESCALER
|
|
|
|
LL_USART_PRESCALER_DIV1,
|
|
|
|
#endif
|
|
|
|
baud_rate);
|
2019-01-07 22:52:24 +01:00
|
|
|
} else {
|
2019-05-20 17:15:02 +02:00
|
|
|
#endif /* CONFIG_LPUART_1 */
|
|
|
|
|
|
|
|
LL_USART_SetBaudRate(UartInstance,
|
|
|
|
clock_rate,
|
|
|
|
#ifdef USART_PRESC_PRESCALER
|
|
|
|
LL_USART_PRESCALER_DIV1,
|
|
|
|
#endif
|
|
|
|
#ifdef USART_CR1_OVER8
|
|
|
|
LL_USART_OVERSAMPLING_16,
|
2019-01-07 22:52:24 +01:00
|
|
|
#endif
|
2019-05-20 17:15:02 +02:00
|
|
|
baud_rate);
|
|
|
|
|
|
|
|
#ifdef CONFIG_LPUART_1
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_LPUART_1 */
|
2019-01-07 22:52:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void uart_stm32_set_parity(struct device *dev, u32_t parity)
|
|
|
|
{
|
|
|
|
USART_TypeDef *UartInstance = UART_STRUCT(dev);
|
|
|
|
|
|
|
|
LL_USART_SetParity(UartInstance, parity);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u32_t uart_stm32_get_parity(struct device *dev)
|
|
|
|
{
|
|
|
|
USART_TypeDef *UartInstance = UART_STRUCT(dev);
|
|
|
|
|
|
|
|
return LL_USART_GetParity(UartInstance);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void uart_stm32_set_stopbits(struct device *dev, u32_t stopbits)
|
|
|
|
{
|
|
|
|
USART_TypeDef *UartInstance = UART_STRUCT(dev);
|
|
|
|
|
|
|
|
LL_USART_SetStopBitsLength(UartInstance, stopbits);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u32_t uart_stm32_get_stopbits(struct device *dev)
|
|
|
|
{
|
|
|
|
USART_TypeDef *UartInstance = UART_STRUCT(dev);
|
|
|
|
|
|
|
|
return LL_USART_GetStopBitsLength(UartInstance);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void uart_stm32_set_databits(struct device *dev, u32_t databits)
|
|
|
|
{
|
|
|
|
USART_TypeDef *UartInstance = UART_STRUCT(dev);
|
|
|
|
|
|
|
|
LL_USART_SetDataWidth(UartInstance, databits);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u32_t uart_stm32_get_databits(struct device *dev)
|
|
|
|
{
|
|
|
|
USART_TypeDef *UartInstance = UART_STRUCT(dev);
|
|
|
|
|
|
|
|
return LL_USART_GetDataWidth(UartInstance);
|
|
|
|
}
|
|
|
|
|
2019-03-15 19:51:09 +01:00
|
|
|
static inline void uart_stm32_set_hwctrl(struct device *dev, u32_t hwctrl)
|
|
|
|
{
|
|
|
|
USART_TypeDef *UartInstance = UART_STRUCT(dev);
|
|
|
|
|
|
|
|
LL_USART_SetHWFlowCtrl(UartInstance, hwctrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u32_t uart_stm32_get_hwctrl(struct device *dev)
|
|
|
|
{
|
|
|
|
USART_TypeDef *UartInstance = UART_STRUCT(dev);
|
|
|
|
|
|
|
|
return LL_USART_GetHWFlowCtrl(UartInstance);
|
|
|
|
}
|
|
|
|
|
2019-01-07 22:52:24 +01:00
|
|
|
static inline u32_t uart_stm32_cfg2ll_parity(enum uart_config_parity parity)
|
|
|
|
{
|
|
|
|
switch (parity) {
|
|
|
|
case UART_CFG_PARITY_ODD:
|
|
|
|
return LL_USART_PARITY_ODD;
|
|
|
|
case UART_CFG_PARITY_EVEN:
|
|
|
|
return LL_USART_PARITY_EVEN;
|
|
|
|
case UART_CFG_PARITY_NONE:
|
|
|
|
default:
|
|
|
|
return LL_USART_PARITY_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline enum uart_config_parity uart_stm32_ll2cfg_parity(u32_t parity)
|
|
|
|
{
|
|
|
|
switch (parity) {
|
|
|
|
case LL_USART_PARITY_ODD:
|
|
|
|
return UART_CFG_PARITY_ODD;
|
|
|
|
case LL_USART_PARITY_EVEN:
|
|
|
|
return UART_CFG_PARITY_EVEN;
|
|
|
|
case LL_USART_PARITY_NONE:
|
|
|
|
default:
|
|
|
|
return UART_CFG_PARITY_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u32_t uart_stm32_cfg2ll_stopbits(enum uart_config_stop_bits sb)
|
|
|
|
{
|
|
|
|
switch (sb) {
|
|
|
|
/* Some MCU's don't support 0.5 stop bits */
|
|
|
|
#ifdef LL_USART_STOPBITS_0_5
|
|
|
|
case UART_CFG_STOP_BITS_0_5:
|
|
|
|
return LL_USART_STOPBITS_0_5;
|
|
|
|
#endif /* LL_USART_STOPBITS_0_5 */
|
|
|
|
case UART_CFG_STOP_BITS_1:
|
|
|
|
return LL_USART_STOPBITS_1;
|
|
|
|
/* Some MCU's don't support 1.5 stop bits */
|
|
|
|
#ifdef LL_USART_STOPBITS_1_5
|
|
|
|
case UART_CFG_STOP_BITS_1_5:
|
|
|
|
return LL_USART_STOPBITS_1_5;
|
|
|
|
#endif /* LL_USART_STOPBITS_1_5 */
|
|
|
|
case UART_CFG_STOP_BITS_2:
|
|
|
|
default:
|
|
|
|
return LL_USART_STOPBITS_2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline enum uart_config_stop_bits uart_stm32_ll2cfg_stopbits(u32_t sb)
|
|
|
|
{
|
|
|
|
switch (sb) {
|
|
|
|
/* Some MCU's don't support 0.5 stop bits */
|
|
|
|
#ifdef LL_USART_STOPBITS_0_5
|
|
|
|
case LL_USART_STOPBITS_0_5:
|
|
|
|
return UART_CFG_STOP_BITS_0_5;
|
|
|
|
#endif /* LL_USART_STOPBITS_0_5 */
|
|
|
|
case LL_USART_STOPBITS_1:
|
|
|
|
return UART_CFG_STOP_BITS_1;
|
|
|
|
/* Some MCU's don't support 1.5 stop bits */
|
|
|
|
#ifdef LL_USART_STOPBITS_1_5
|
|
|
|
case LL_USART_STOPBITS_1_5:
|
|
|
|
return UART_CFG_STOP_BITS_1_5;
|
|
|
|
#endif /* LL_USART_STOPBITS_1_5 */
|
|
|
|
case LL_USART_STOPBITS_2:
|
|
|
|
default:
|
|
|
|
return UART_CFG_STOP_BITS_2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u32_t uart_stm32_cfg2ll_databits(enum uart_config_data_bits db)
|
|
|
|
{
|
|
|
|
switch (db) {
|
2019-03-22 14:19:57 +01:00
|
|
|
/* Some MCU's don't support 7B or 9B datawidth */
|
2019-01-07 22:52:24 +01:00
|
|
|
#ifdef LL_USART_DATAWIDTH_7B
|
|
|
|
case UART_CFG_DATA_BITS_7:
|
|
|
|
return LL_USART_DATAWIDTH_7B;
|
|
|
|
#endif /* LL_USART_DATAWIDTH_7B */
|
2019-03-22 14:19:57 +01:00
|
|
|
#ifdef LL_USART_DATAWIDTH_9B
|
|
|
|
case UART_CFG_DATA_BITS_9:
|
|
|
|
return LL_USART_DATAWIDTH_9B;
|
|
|
|
#endif /* LL_USART_DATAWIDTH_9B */
|
2019-01-07 22:52:24 +01:00
|
|
|
case UART_CFG_DATA_BITS_8:
|
|
|
|
default:
|
|
|
|
return LL_USART_DATAWIDTH_8B;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline enum uart_config_data_bits uart_stm32_ll2cfg_databits(u32_t db)
|
|
|
|
{
|
|
|
|
switch (db) {
|
2019-03-22 14:19:57 +01:00
|
|
|
/* Some MCU's don't support 7B or 9B datawidth */
|
2019-01-07 22:52:24 +01:00
|
|
|
#ifdef LL_USART_DATAWIDTH_7B
|
|
|
|
case LL_USART_DATAWIDTH_7B:
|
|
|
|
return UART_CFG_DATA_BITS_7;
|
|
|
|
#endif /* LL_USART_DATAWIDTH_7B */
|
2019-03-22 14:19:57 +01:00
|
|
|
#ifdef LL_USART_DATAWIDTH_9B
|
|
|
|
case LL_USART_DATAWIDTH_9B:
|
|
|
|
return UART_CFG_DATA_BITS_9;
|
|
|
|
#endif /* LL_USART_DATAWIDTH_9B */
|
2019-01-07 22:52:24 +01:00
|
|
|
case LL_USART_DATAWIDTH_8B:
|
|
|
|
default:
|
|
|
|
return UART_CFG_DATA_BITS_8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-15 19:51:09 +01:00
|
|
|
/**
|
|
|
|
* @brief Get LL hardware flow control define from
|
|
|
|
* Zephyr hardware flow control option.
|
|
|
|
* @note Supports only UART_CFG_FLOW_CTRL_RTS_CTS.
|
|
|
|
* @param fc: Zephyr hardware flow control option.
|
|
|
|
* @retval LL_USART_HWCONTROL_RTS_CTS, or LL_USART_HWCONTROL_NONE.
|
|
|
|
*/
|
|
|
|
static inline u32_t uart_stm32_cfg2ll_hwctrl(enum uart_config_flow_control fc)
|
|
|
|
{
|
|
|
|
if (fc == UART_CFG_FLOW_CTRL_RTS_CTS) {
|
|
|
|
return LL_USART_HWCONTROL_RTS_CTS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return LL_USART_HWCONTROL_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-02-06 19:36:03 +01:00
|
|
|
* @brief Get Zephyr hardware flow control option from
|
2019-03-15 19:51:09 +01:00
|
|
|
* LL hardware flow control define.
|
|
|
|
* @note Supports only LL_USART_HWCONTROL_RTS_CTS.
|
2020-02-06 19:36:03 +01:00
|
|
|
* @param fc: LL hardware flow control definition.
|
2020-02-06 18:30:05 +01:00
|
|
|
* @retval UART_CFG_FLOW_CTRL_RTS_CTS, or UART_CFG_FLOW_CTRL_NONE.
|
2019-03-15 19:51:09 +01:00
|
|
|
*/
|
|
|
|
static inline enum uart_config_flow_control uart_stm32_ll2cfg_hwctrl(u32_t fc)
|
|
|
|
{
|
|
|
|
if (fc == LL_USART_HWCONTROL_RTS_CTS) {
|
|
|
|
return UART_CFG_FLOW_CTRL_RTS_CTS;
|
|
|
|
}
|
|
|
|
|
2020-02-06 18:30:05 +01:00
|
|
|
return UART_CFG_FLOW_CTRL_NONE;
|
2019-03-15 19:51:09 +01:00
|
|
|
}
|
|
|
|
|
2019-01-07 22:52:24 +01:00
|
|
|
static int uart_stm32_configure(struct device *dev,
|
|
|
|
const struct uart_config *cfg)
|
|
|
|
{
|
|
|
|
struct uart_stm32_data *data = DEV_DATA(dev);
|
|
|
|
USART_TypeDef *UartInstance = UART_STRUCT(dev);
|
|
|
|
const u32_t parity = uart_stm32_cfg2ll_parity(cfg->parity);
|
|
|
|
const u32_t stopbits = uart_stm32_cfg2ll_stopbits(cfg->stop_bits);
|
|
|
|
const u32_t databits = uart_stm32_cfg2ll_databits(cfg->data_bits);
|
2019-03-15 19:51:09 +01:00
|
|
|
const u32_t flowctrl = uart_stm32_cfg2ll_hwctrl(cfg->flow_ctrl);
|
2019-01-07 22:52:24 +01:00
|
|
|
|
|
|
|
/* Hardware doesn't support mark or space parity */
|
|
|
|
if ((UART_CFG_PARITY_MARK == cfg->parity) ||
|
|
|
|
(UART_CFG_PARITY_SPACE == cfg->parity)) {
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(LL_USART_STOPBITS_0_5) && defined(CONFIG_LPUART_1)
|
|
|
|
if (IS_LPUART_INSTANCE(UartInstance) &&
|
|
|
|
UART_CFG_STOP_BITS_0_5 == cfg->stop_bits) {
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (UART_CFG_STOP_BITS_0_5 == cfg->stop_bits) {
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(LL_USART_STOPBITS_1_5) && defined(CONFIG_LPUART_1)
|
|
|
|
if (IS_LPUART_INSTANCE(UartInstance) &&
|
|
|
|
UART_CFG_STOP_BITS_1_5 == cfg->stop_bits) {
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (UART_CFG_STOP_BITS_1_5 == cfg->stop_bits) {
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-03-22 14:19:57 +01:00
|
|
|
/* Driver doesn't support 5 or 6 databits and potentially 7 or 9 */
|
2019-01-07 22:52:24 +01:00
|
|
|
if ((UART_CFG_DATA_BITS_5 == cfg->data_bits) ||
|
|
|
|
(UART_CFG_DATA_BITS_6 == cfg->data_bits)
|
|
|
|
#ifndef LL_USART_DATAWIDTH_7B
|
|
|
|
|| (UART_CFG_DATA_BITS_7 == cfg->data_bits)
|
|
|
|
#endif /* LL_USART_DATAWIDTH_7B */
|
2019-03-22 14:19:57 +01:00
|
|
|
#ifndef LL_USART_DATAWIDTH_9B
|
|
|
|
|| (UART_CFG_DATA_BITS_9 == cfg->data_bits)
|
|
|
|
#endif /* LL_USART_DATAWIDTH_9B */
|
2019-01-07 22:52:24 +01:00
|
|
|
) {
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|
|
|
|
|
2019-03-15 19:51:09 +01:00
|
|
|
/* Driver supports only RTS CTS flow control */
|
2019-01-07 22:52:24 +01:00
|
|
|
if (UART_CFG_FLOW_CTRL_NONE != cfg->flow_ctrl) {
|
2019-03-15 19:51:09 +01:00
|
|
|
if (!IS_UART_HWFLOW_INSTANCE(UartInstance) ||
|
|
|
|
UART_CFG_FLOW_CTRL_RTS_CTS != cfg->flow_ctrl) {
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|
2019-01-07 22:52:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
LL_USART_Disable(UartInstance);
|
|
|
|
|
|
|
|
if (parity != uart_stm32_get_parity(dev)) {
|
|
|
|
uart_stm32_set_parity(dev, parity);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stopbits != uart_stm32_get_stopbits(dev)) {
|
|
|
|
uart_stm32_set_stopbits(dev, stopbits);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (databits != uart_stm32_get_databits(dev)) {
|
|
|
|
uart_stm32_set_databits(dev, databits);
|
|
|
|
}
|
|
|
|
|
2019-03-15 19:51:09 +01:00
|
|
|
if (flowctrl != uart_stm32_get_hwctrl(dev)) {
|
|
|
|
uart_stm32_set_hwctrl(dev, flowctrl);
|
|
|
|
}
|
|
|
|
|
2019-01-07 22:52:24 +01:00
|
|
|
if (cfg->baudrate != data->baud_rate) {
|
|
|
|
uart_stm32_set_baudrate(dev, cfg->baudrate);
|
|
|
|
data->baud_rate = cfg->baudrate;
|
|
|
|
}
|
|
|
|
|
|
|
|
LL_USART_Enable(UartInstance);
|
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int uart_stm32_config_get(struct device *dev, struct uart_config *cfg)
|
|
|
|
{
|
|
|
|
struct uart_stm32_data *data = DEV_DATA(dev);
|
|
|
|
|
|
|
|
cfg->baudrate = data->baud_rate;
|
|
|
|
cfg->parity = uart_stm32_ll2cfg_parity(uart_stm32_get_parity(dev));
|
|
|
|
cfg->stop_bits = uart_stm32_ll2cfg_stopbits(
|
|
|
|
uart_stm32_get_stopbits(dev));
|
|
|
|
cfg->data_bits = uart_stm32_ll2cfg_databits(
|
|
|
|
uart_stm32_get_databits(dev));
|
2019-03-15 19:51:09 +01:00
|
|
|
cfg->flow_ctrl = uart_stm32_ll2cfg_hwctrl(
|
|
|
|
uart_stm32_get_hwctrl(dev));
|
2019-01-07 22:52:24 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-03-03 15:33:20 +01:00
|
|
|
static int uart_stm32_poll_in(struct device *dev, unsigned char *c)
|
|
|
|
{
|
2017-09-21 15:20:53 +02:00
|
|
|
USART_TypeDef *UartInstance = UART_STRUCT(dev);
|
2016-03-03 15:33:20 +01:00
|
|
|
|
2018-11-02 14:34:56 +01:00
|
|
|
/* Clear overrun error flag */
|
|
|
|
if (LL_USART_IsActiveFlag_ORE(UartInstance)) {
|
|
|
|
LL_USART_ClearFlag_ORE(UartInstance);
|
|
|
|
}
|
|
|
|
|
2017-09-21 15:20:53 +02:00
|
|
|
if (!LL_USART_IsActiveFlag_RXNE(UartInstance)) {
|
2016-03-03 15:33:20 +01:00
|
|
|
return -1;
|
|
|
|
}
|
2017-09-21 15:20:53 +02:00
|
|
|
|
|
|
|
*c = (unsigned char)LL_USART_ReceiveData8(UartInstance);
|
|
|
|
|
|
|
|
return 0;
|
2016-03-03 15:33:20 +01:00
|
|
|
}
|
|
|
|
|
2018-11-27 01:43:46 +01:00
|
|
|
static void uart_stm32_poll_out(struct device *dev,
|
2016-03-03 15:33:20 +01:00
|
|
|
unsigned char c)
|
|
|
|
{
|
2017-09-21 15:20:53 +02:00
|
|
|
USART_TypeDef *UartInstance = UART_STRUCT(dev);
|
2016-03-03 15:33:20 +01:00
|
|
|
|
2017-09-21 15:20:53 +02:00
|
|
|
/* Wait for TXE flag to be raised */
|
2019-06-04 16:52:23 +02:00
|
|
|
while (!LL_USART_IsActiveFlag_TXE(UartInstance)) {
|
|
|
|
}
|
2017-09-21 15:20:53 +02:00
|
|
|
|
|
|
|
LL_USART_ClearFlag_TC(UartInstance);
|
|
|
|
|
|
|
|
LL_USART_TransmitData8(UartInstance, (u8_t)c);
|
2016-03-03 15:33:20 +01:00
|
|
|
}
|
|
|
|
|
2019-02-14 10:50:19 +01:00
|
|
|
static int uart_stm32_err_check(struct device *dev)
|
|
|
|
{
|
|
|
|
USART_TypeDef *UartInstance = UART_STRUCT(dev);
|
|
|
|
u32_t err = 0U;
|
|
|
|
|
|
|
|
/* Check for errors, but don't clear them here.
|
|
|
|
* Some SoC clear all error flags when at least
|
|
|
|
* one is cleared. (e.g. F4X, F1X, and F2X)
|
|
|
|
*/
|
|
|
|
if (LL_USART_IsActiveFlag_ORE(UartInstance)) {
|
|
|
|
err |= UART_ERROR_OVERRUN;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (LL_USART_IsActiveFlag_PE(UartInstance)) {
|
|
|
|
err |= UART_ERROR_PARITY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (LL_USART_IsActiveFlag_FE(UartInstance)) {
|
|
|
|
err |= UART_ERROR_FRAMING;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err & UART_ERROR_OVERRUN) {
|
|
|
|
LL_USART_ClearFlag_ORE(UartInstance);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err & UART_ERROR_PARITY) {
|
|
|
|
LL_USART_ClearFlag_PE(UartInstance);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err & UART_ERROR_FRAMING) {
|
|
|
|
LL_USART_ClearFlag_FE(UartInstance);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear noise error as well,
|
|
|
|
* it is not represented by the errors enum
|
|
|
|
*/
|
|
|
|
LL_USART_ClearFlag_NE(UartInstance);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2016-03-03 15:33:20 +01:00
|
|
|
static inline void __uart_stm32_get_clock(struct device *dev)
|
|
|
|
{
|
2016-11-14 11:53:52 +01:00
|
|
|
struct uart_stm32_data *data = DEV_DATA(dev);
|
2016-03-03 15:33:20 +01:00
|
|
|
struct device *clk =
|
|
|
|
device_get_binding(STM32_CLOCK_CONTROL_NAME);
|
|
|
|
|
|
|
|
__ASSERT_NO_MSG(clk);
|
|
|
|
|
2016-11-14 11:53:52 +01:00
|
|
|
data->clock = clk;
|
2016-03-03 15:33:20 +01:00
|
|
|
}
|
|
|
|
|
2016-03-13 19:37:25 +01:00
|
|
|
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
|
|
|
|
2017-04-21 17:03:20 +02:00
|
|
|
static int uart_stm32_fifo_fill(struct device *dev, const u8_t *tx_data,
|
2016-03-13 19:37:25 +01:00
|
|
|
int size)
|
|
|
|
{
|
2017-09-21 15:20:53 +02:00
|
|
|
USART_TypeDef *UartInstance = UART_STRUCT(dev);
|
2018-11-29 20:12:22 +01:00
|
|
|
u8_t num_tx = 0U;
|
2016-11-14 11:53:52 +01:00
|
|
|
|
2017-09-21 15:20:53 +02:00
|
|
|
while ((size - num_tx > 0) &&
|
|
|
|
LL_USART_IsActiveFlag_TXE(UartInstance)) {
|
2019-02-06 23:31:24 +01:00
|
|
|
/* TXE flag will be cleared with byte write to DR|RDR register */
|
2016-11-14 11:53:52 +01:00
|
|
|
|
|
|
|
/* Send a character (8bit , parity none) */
|
2017-09-21 15:20:53 +02:00
|
|
|
LL_USART_TransmitData8(UartInstance, tx_data[num_tx++]);
|
2016-03-13 19:37:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return num_tx;
|
|
|
|
}
|
|
|
|
|
2017-04-21 17:03:20 +02:00
|
|
|
static int uart_stm32_fifo_read(struct device *dev, u8_t *rx_data,
|
2016-03-13 19:37:25 +01:00
|
|
|
const int size)
|
|
|
|
{
|
2017-09-21 15:20:53 +02:00
|
|
|
USART_TypeDef *UartInstance = UART_STRUCT(dev);
|
2018-11-29 20:12:22 +01:00
|
|
|
u8_t num_rx = 0U;
|
2016-11-14 11:53:52 +01:00
|
|
|
|
2017-09-21 15:20:53 +02:00
|
|
|
while ((size - num_rx > 0) &&
|
|
|
|
LL_USART_IsActiveFlag_RXNE(UartInstance)) {
|
2019-02-06 23:31:24 +01:00
|
|
|
/* RXNE flag will be cleared upon read from DR|RDR register */
|
2016-11-14 11:53:52 +01:00
|
|
|
|
|
|
|
/* Receive a character (8bit , parity none) */
|
2017-09-21 15:20:53 +02:00
|
|
|
rx_data[num_rx++] = LL_USART_ReceiveData8(UartInstance);
|
2018-11-02 14:34:56 +01:00
|
|
|
|
|
|
|
/* Clear overrun error flag */
|
|
|
|
if (LL_USART_IsActiveFlag_ORE(UartInstance)) {
|
|
|
|
LL_USART_ClearFlag_ORE(UartInstance);
|
|
|
|
}
|
2016-03-13 19:37:25 +01:00
|
|
|
}
|
2019-02-06 23:31:24 +01:00
|
|
|
|
2016-03-13 19:37:25 +01:00
|
|
|
return num_rx;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void uart_stm32_irq_tx_enable(struct device *dev)
|
|
|
|
{
|
2017-09-21 15:20:53 +02:00
|
|
|
USART_TypeDef *UartInstance = UART_STRUCT(dev);
|
2016-03-13 19:37:25 +01:00
|
|
|
|
2017-09-21 15:20:53 +02:00
|
|
|
LL_USART_EnableIT_TC(UartInstance);
|
2016-03-13 19:37:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void uart_stm32_irq_tx_disable(struct device *dev)
|
|
|
|
{
|
2017-09-21 15:20:53 +02:00
|
|
|
USART_TypeDef *UartInstance = UART_STRUCT(dev);
|
2016-03-13 19:37:25 +01:00
|
|
|
|
2017-09-21 15:20:53 +02:00
|
|
|
LL_USART_DisableIT_TC(UartInstance);
|
2016-03-13 19:37:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int uart_stm32_irq_tx_ready(struct device *dev)
|
|
|
|
{
|
2017-09-21 15:20:53 +02:00
|
|
|
USART_TypeDef *UartInstance = UART_STRUCT(dev);
|
2016-03-13 19:37:25 +01:00
|
|
|
|
2017-09-21 15:20:53 +02:00
|
|
|
return LL_USART_IsActiveFlag_TXE(UartInstance);
|
2016-03-13 19:37:25 +01:00
|
|
|
}
|
|
|
|
|
2017-05-11 16:57:29 +02:00
|
|
|
static int uart_stm32_irq_tx_complete(struct device *dev)
|
2016-03-13 19:37:25 +01:00
|
|
|
{
|
2017-09-21 15:20:53 +02:00
|
|
|
USART_TypeDef *UartInstance = UART_STRUCT(dev);
|
2016-03-13 19:37:25 +01:00
|
|
|
|
2019-09-25 19:57:35 +02:00
|
|
|
return LL_USART_IsActiveFlag_TC(UartInstance);
|
2016-03-13 19:37:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void uart_stm32_irq_rx_enable(struct device *dev)
|
|
|
|
{
|
2017-09-21 15:20:53 +02:00
|
|
|
USART_TypeDef *UartInstance = UART_STRUCT(dev);
|
2016-03-13 19:37:25 +01:00
|
|
|
|
2017-09-21 15:20:53 +02:00
|
|
|
LL_USART_EnableIT_RXNE(UartInstance);
|
2016-03-13 19:37:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void uart_stm32_irq_rx_disable(struct device *dev)
|
|
|
|
{
|
2017-09-21 15:20:53 +02:00
|
|
|
USART_TypeDef *UartInstance = UART_STRUCT(dev);
|
2016-03-13 19:37:25 +01:00
|
|
|
|
2017-09-21 15:20:53 +02:00
|
|
|
LL_USART_DisableIT_RXNE(UartInstance);
|
2016-03-13 19:37:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int uart_stm32_irq_rx_ready(struct device *dev)
|
|
|
|
{
|
2017-09-21 15:20:53 +02:00
|
|
|
USART_TypeDef *UartInstance = UART_STRUCT(dev);
|
2016-03-13 19:37:25 +01:00
|
|
|
|
2017-09-21 15:20:53 +02:00
|
|
|
return LL_USART_IsActiveFlag_RXNE(UartInstance);
|
2016-03-13 19:37:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void uart_stm32_irq_err_enable(struct device *dev)
|
|
|
|
{
|
2017-09-21 15:20:53 +02:00
|
|
|
USART_TypeDef *UartInstance = UART_STRUCT(dev);
|
2016-11-14 11:53:52 +01:00
|
|
|
|
|
|
|
/* Enable FE, ORE interruptions */
|
2017-09-21 15:20:53 +02:00
|
|
|
LL_USART_EnableIT_ERROR(UartInstance);
|
2018-03-29 18:40:00 +02:00
|
|
|
#if !defined(CONFIG_SOC_SERIES_STM32F0X) || defined(USART_LIN_SUPPORT)
|
2016-11-14 11:53:52 +01:00
|
|
|
/* Enable Line break detection */
|
2018-03-29 18:40:00 +02:00
|
|
|
if (IS_UART_LIN_INSTANCE(UartInstance)) {
|
|
|
|
LL_USART_EnableIT_LBD(UartInstance);
|
|
|
|
}
|
2017-08-09 11:23:04 +02:00
|
|
|
#endif
|
2016-11-14 11:53:52 +01:00
|
|
|
/* Enable parity error interruption */
|
2017-09-21 15:20:53 +02:00
|
|
|
LL_USART_EnableIT_PE(UartInstance);
|
2016-03-13 19:37:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void uart_stm32_irq_err_disable(struct device *dev)
|
|
|
|
{
|
2017-09-21 15:20:53 +02:00
|
|
|
USART_TypeDef *UartInstance = UART_STRUCT(dev);
|
|
|
|
|
2018-03-29 18:40:00 +02:00
|
|
|
/* Disable FE, ORE interruptions */
|
2017-09-21 15:20:53 +02:00
|
|
|
LL_USART_DisableIT_ERROR(UartInstance);
|
2018-03-29 18:40:00 +02:00
|
|
|
#if !defined(CONFIG_SOC_SERIES_STM32F0X) || defined(USART_LIN_SUPPORT)
|
|
|
|
/* Disable Line break detection */
|
|
|
|
if (IS_UART_LIN_INSTANCE(UartInstance)) {
|
|
|
|
LL_USART_DisableIT_LBD(UartInstance);
|
|
|
|
}
|
2017-08-09 11:23:04 +02:00
|
|
|
#endif
|
2018-03-29 18:40:00 +02:00
|
|
|
/* Disable parity error interruption */
|
2017-09-21 15:20:53 +02:00
|
|
|
LL_USART_DisableIT_PE(UartInstance);
|
2016-03-13 19:37:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int uart_stm32_irq_is_pending(struct device *dev)
|
|
|
|
{
|
2017-09-21 15:20:53 +02:00
|
|
|
USART_TypeDef *UartInstance = UART_STRUCT(dev);
|
2016-03-13 19:37:25 +01:00
|
|
|
|
2017-12-05 20:46:13 +01:00
|
|
|
return ((LL_USART_IsActiveFlag_RXNE(UartInstance) &&
|
|
|
|
LL_USART_IsEnabledIT_RXNE(UartInstance)) ||
|
2018-11-13 15:26:06 +01:00
|
|
|
(LL_USART_IsActiveFlag_TC(UartInstance) &&
|
|
|
|
LL_USART_IsEnabledIT_TC(UartInstance)));
|
2016-03-13 19:37:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int uart_stm32_irq_update(struct device *dev)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void uart_stm32_irq_callback_set(struct device *dev,
|
2018-07-16 20:12:26 +02:00
|
|
|
uart_irq_callback_user_data_t cb,
|
|
|
|
void *cb_data)
|
2016-03-13 19:37:25 +01:00
|
|
|
{
|
|
|
|
struct uart_stm32_data *data = DEV_DATA(dev);
|
|
|
|
|
|
|
|
data->user_cb = cb;
|
2018-07-16 20:12:26 +02:00
|
|
|
data->user_data = cb_data;
|
2016-03-13 19:37:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void uart_stm32_isr(void *arg)
|
|
|
|
{
|
|
|
|
struct device *dev = arg;
|
|
|
|
struct uart_stm32_data *data = DEV_DATA(dev);
|
|
|
|
|
|
|
|
if (data->user_cb) {
|
2018-07-16 20:12:26 +02:00
|
|
|
data->user_cb(data->user_data);
|
2016-03-13 19:37:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
|
|
|
|
|
2016-10-24 09:38:49 +02:00
|
|
|
static const struct uart_driver_api uart_stm32_driver_api = {
|
2016-03-03 15:33:20 +01:00
|
|
|
.poll_in = uart_stm32_poll_in,
|
|
|
|
.poll_out = uart_stm32_poll_out,
|
2019-02-14 10:50:19 +01:00
|
|
|
.err_check = uart_stm32_err_check,
|
2019-01-07 22:52:24 +01:00
|
|
|
.configure = uart_stm32_configure,
|
|
|
|
.config_get = uart_stm32_config_get,
|
2016-03-13 19:37:25 +01:00
|
|
|
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
|
|
|
.fifo_fill = uart_stm32_fifo_fill,
|
|
|
|
.fifo_read = uart_stm32_fifo_read,
|
|
|
|
.irq_tx_enable = uart_stm32_irq_tx_enable,
|
|
|
|
.irq_tx_disable = uart_stm32_irq_tx_disable,
|
|
|
|
.irq_tx_ready = uart_stm32_irq_tx_ready,
|
2017-05-11 16:57:29 +02:00
|
|
|
.irq_tx_complete = uart_stm32_irq_tx_complete,
|
2016-03-13 19:37:25 +01:00
|
|
|
.irq_rx_enable = uart_stm32_irq_rx_enable,
|
|
|
|
.irq_rx_disable = uart_stm32_irq_rx_disable,
|
|
|
|
.irq_rx_ready = uart_stm32_irq_rx_ready,
|
|
|
|
.irq_err_enable = uart_stm32_irq_err_enable,
|
|
|
|
.irq_err_disable = uart_stm32_irq_err_disable,
|
|
|
|
.irq_is_pending = uart_stm32_irq_is_pending,
|
|
|
|
.irq_update = uart_stm32_irq_update,
|
|
|
|
.irq_callback_set = uart_stm32_irq_callback_set,
|
|
|
|
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
|
2016-03-03 15:33:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Initialize UART channel
|
|
|
|
*
|
|
|
|
* This routine is called to reset the chip in a quiescent state.
|
|
|
|
* It is assumed that this function is called only once per UART.
|
|
|
|
*
|
|
|
|
* @param dev UART device struct
|
|
|
|
*
|
|
|
|
* @return 0
|
|
|
|
*/
|
|
|
|
static int uart_stm32_init(struct device *dev)
|
|
|
|
{
|
2016-11-14 11:53:52 +01:00
|
|
|
const struct uart_stm32_config *config = DEV_CFG(dev);
|
2016-03-03 15:33:20 +01:00
|
|
|
struct uart_stm32_data *data = DEV_DATA(dev);
|
2017-09-21 15:20:53 +02:00
|
|
|
USART_TypeDef *UartInstance = UART_STRUCT(dev);
|
|
|
|
|
2016-03-03 15:33:20 +01:00
|
|
|
__uart_stm32_get_clock(dev);
|
|
|
|
/* enable clock */
|
2018-12-07 11:09:28 +01:00
|
|
|
if (clock_control_on(data->clock,
|
|
|
|
(clock_control_subsys_t *)&config->pclken) != 0) {
|
|
|
|
return -EIO;
|
|
|
|
}
|
2016-03-03 15:33:20 +01:00
|
|
|
|
2017-09-21 15:20:53 +02:00
|
|
|
LL_USART_Disable(UartInstance);
|
|
|
|
|
|
|
|
/* TX/RX direction */
|
|
|
|
LL_USART_SetTransferDirection(UartInstance,
|
|
|
|
LL_USART_DIRECTION_TX_RX);
|
|
|
|
|
|
|
|
/* 8 data bit, 1 start bit, 1 stop bit, no parity */
|
|
|
|
LL_USART_ConfigCharacter(UartInstance,
|
|
|
|
LL_USART_DATAWIDTH_8B,
|
|
|
|
LL_USART_PARITY_NONE,
|
|
|
|
LL_USART_STOPBITS_1);
|
|
|
|
|
2019-02-08 18:39:35 +01:00
|
|
|
if (config->hw_flow_control) {
|
|
|
|
uart_stm32_set_hwctrl(dev, LL_USART_HWCONTROL_RTS_CTS);
|
|
|
|
}
|
|
|
|
|
2019-01-07 22:52:24 +01:00
|
|
|
/* Set the default baudrate */
|
|
|
|
uart_stm32_set_baudrate(dev, data->baud_rate);
|
2017-09-21 15:20:53 +02:00
|
|
|
|
|
|
|
LL_USART_Enable(UartInstance);
|
2016-03-03 15:33:20 +01:00
|
|
|
|
2018-06-13 11:32:38 +02:00
|
|
|
#ifdef USART_ISR_TEACK
|
|
|
|
/* Wait until TEACK flag is set */
|
2019-06-04 16:52:23 +02:00
|
|
|
while (!(LL_USART_IsActiveFlag_TEACK(UartInstance))) {
|
|
|
|
}
|
2018-06-13 11:32:38 +02:00
|
|
|
#endif /* !USART_ISR_TEACK */
|
|
|
|
|
|
|
|
#ifdef USART_ISR_REACK
|
2018-06-18 18:01:06 +02:00
|
|
|
/* Wait until REACK flag is set */
|
2019-06-04 16:52:23 +02:00
|
|
|
while (!(LL_USART_IsActiveFlag_REACK(UartInstance))) {
|
|
|
|
}
|
2018-06-13 11:32:38 +02:00
|
|
|
#endif /* !USART_ISR_REACK */
|
2016-03-03 15:33:20 +01:00
|
|
|
|
2016-03-13 19:37:25 +01:00
|
|
|
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
2016-11-14 11:53:52 +01:00
|
|
|
config->uconf.irq_config_func(dev);
|
2016-03-13 19:37:25 +01:00
|
|
|
#endif
|
2016-03-03 15:33:20 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-03-13 19:37:25 +01:00
|
|
|
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
2020-02-28 14:54:37 +01:00
|
|
|
#define STM32_UART_IRQ_HANDLER_DECL(index) \
|
|
|
|
static void uart_stm32_irq_config_func_##index(struct device *dev)
|
|
|
|
#define STM32_UART_IRQ_HANDLER_FUNC(index) \
|
|
|
|
.irq_config_func = uart_stm32_irq_config_func_##index,
|
|
|
|
#define STM32_UART_IRQ_HANDLER(index) \
|
|
|
|
static void uart_stm32_irq_config_func_##index(struct device *dev) \
|
2017-05-01 15:21:52 +02:00
|
|
|
{ \
|
2020-02-28 14:54:37 +01:00
|
|
|
IRQ_CONNECT(DT_INST_##index##_ST_STM32_UART_IRQ_0, \
|
|
|
|
DT_INST_##index##_ST_STM32_UART_IRQ_0_PRIORITY, \
|
|
|
|
uart_stm32_isr, DEVICE_GET(uart_stm32_##index), \
|
2017-05-01 15:21:52 +02:00
|
|
|
0); \
|
2020-02-28 14:54:37 +01:00
|
|
|
irq_enable(DT_INST_##index##_ST_STM32_UART_IRQ_0); \
|
2016-03-13 19:37:25 +01:00
|
|
|
}
|
2017-01-23 17:55:57 +01:00
|
|
|
#else
|
2020-02-28 14:54:37 +01:00
|
|
|
#define STM32_UART_IRQ_HANDLER_DECL(index)
|
|
|
|
#define STM32_UART_IRQ_HANDLER_FUNC(index)
|
|
|
|
#define STM32_UART_IRQ_HANDLER(index)
|
2017-05-01 15:21:52 +02:00
|
|
|
#endif
|
2016-03-03 15:33:20 +01:00
|
|
|
|
2020-02-28 14:54:37 +01:00
|
|
|
#define STM32_UART_INIT(index) \
|
|
|
|
STM32_UART_IRQ_HANDLER_DECL(index); \
|
2017-05-01 15:21:52 +02:00
|
|
|
\
|
2020-02-28 14:54:37 +01:00
|
|
|
static const struct uart_stm32_config uart_stm32_cfg_##index = { \
|
2017-05-01 15:21:52 +02:00
|
|
|
.uconf = { \
|
2020-02-28 14:54:37 +01:00
|
|
|
.base = (u8_t *)DT_INST_##index##_ST_STM32_UART_BASE_ADDRESS,\
|
|
|
|
STM32_UART_IRQ_HANDLER_FUNC(index) \
|
2017-05-01 15:21:52 +02:00
|
|
|
}, \
|
2020-02-28 14:54:37 +01:00
|
|
|
.pclken = { .bus = DT_INST_##index##_ST_STM32_UART_CLOCK_BUS, \
|
|
|
|
.enr = DT_INST_##index##_ST_STM32_UART_CLOCK_BITS \
|
2018-11-08 14:38:48 +01:00
|
|
|
}, \
|
2020-02-28 14:54:37 +01:00
|
|
|
.hw_flow_control = DT_INST_##index##_ST_STM32_UART_HW_FLOW_CONTROL\
|
2017-05-01 15:21:52 +02:00
|
|
|
}; \
|
|
|
|
\
|
2020-02-28 14:54:37 +01:00
|
|
|
static struct uart_stm32_data uart_stm32_data_##index = { \
|
|
|
|
.baud_rate = DT_INST_##index##_ST_STM32_UART_CURRENT_SPEED \
|
2017-05-01 15:21:52 +02:00
|
|
|
}; \
|
|
|
|
\
|
2020-02-28 14:54:37 +01:00
|
|
|
DEVICE_AND_API_INIT(uart_stm32_##index, DT_INST_##index##_ST_STM32_UART_LABEL,\
|
2017-05-01 15:21:52 +02:00
|
|
|
&uart_stm32_init, \
|
2020-02-28 14:54:37 +01:00
|
|
|
&uart_stm32_data_##index, &uart_stm32_cfg_##index, \
|
2017-05-01 15:21:52 +02:00
|
|
|
PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \
|
|
|
|
&uart_stm32_driver_api); \
|
|
|
|
\
|
2020-02-28 14:54:37 +01:00
|
|
|
STM32_UART_IRQ_HANDLER(index)
|
2016-03-03 15:33:20 +01:00
|
|
|
|
2020-02-28 14:54:37 +01:00
|
|
|
#ifdef DT_INST_0_ST_STM32_UART
|
|
|
|
STM32_UART_INIT(0)
|
|
|
|
#endif /* DT_INST_0_ST_STM32_UART */
|
2018-03-20 18:50:57 +01:00
|
|
|
|
2020-02-28 14:54:37 +01:00
|
|
|
#ifdef DT_INST_1_ST_STM32_UART
|
|
|
|
STM32_UART_INIT(1)
|
|
|
|
#endif /* DT_INST_1_ST_STM32_UART */
|
2017-12-18 11:38:10 +01:00
|
|
|
|
2020-02-28 14:54:37 +01:00
|
|
|
#ifdef DT_INST_2_ST_STM32_UART
|
|
|
|
STM32_UART_INIT(2)
|
|
|
|
#endif /* DT_INST_2_ST_STM32_UART */
|
2017-12-18 11:38:10 +01:00
|
|
|
|
2020-02-28 14:54:37 +01:00
|
|
|
#ifdef DT_INST_3_ST_STM32_UART
|
|
|
|
STM32_UART_INIT(3)
|
|
|
|
#endif /* DT_INST_3_ST_STM32_UART */
|
2017-12-18 11:38:10 +01:00
|
|
|
|
2020-02-28 14:54:37 +01:00
|
|
|
#ifdef DT_INST_4_ST_STM32_UART
|
|
|
|
STM32_UART_INIT(4)
|
|
|
|
#endif /* DT_INST_4_ST_STM32_UART */
|
2018-11-08 14:52:02 +01:00
|
|
|
|
2020-02-28 14:54:37 +01:00
|
|
|
#ifdef DT_INST_5_ST_STM32_UART
|
|
|
|
STM32_UART_INIT(5)
|
|
|
|
#endif /* DT_INST_5_ST_STM32_UART */
|
2017-12-18 11:38:10 +01:00
|
|
|
|
2020-02-28 14:54:37 +01:00
|
|
|
#ifdef DT_INST_6_ST_STM32_UART
|
|
|
|
STM32_UART_INIT(6)
|
|
|
|
#endif /* DT_INST_6_ST_STM32_UART */
|
2017-12-18 11:38:10 +01:00
|
|
|
|
2020-02-28 14:54:37 +01:00
|
|
|
#ifdef DT_INST_7_ST_STM32_UART
|
|
|
|
STM32_UART_INIT(7)
|
|
|
|
#endif /* DT_INST_7_ST_STM32_UART */
|
2017-05-01 15:22:02 +02:00
|
|
|
|
2020-02-28 14:54:37 +01:00
|
|
|
#ifdef DT_INST_8_ST_STM32_UART
|
|
|
|
STM32_UART_INIT(8)
|
|
|
|
#endif /* DT_INST_8_ST_STM32_UART */
|
2017-05-01 15:22:02 +02:00
|
|
|
|
2020-02-28 14:54:37 +01:00
|
|
|
#ifdef DT_INST_9_ST_STM32_UART
|
|
|
|
STM32_UART_INIT(9)
|
|
|
|
#endif /* DT_INST_9_ST_STM32_UART */
|
2017-05-01 15:22:02 +02:00
|
|
|
|
2020-02-28 14:54:37 +01:00
|
|
|
#ifdef DT_INST_10_ST_STM32_UART
|
|
|
|
STM32_UART_INIT(10)
|
|
|
|
#endif /* DT_INST_10_ST_STM32_UART */
|