drv_usart.h 1.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * Copyright (c) 2006-2018, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2018.10.30     SummerGift   change to new framework
 */

#ifndef __DRV_USART_H__
#define __DRV_USART_H__

#include <rtthread.h>
#include "rtdevice.h"
#include <rthw.h>
#include <drv_common.h>
18
#include "drv_dma.h"
19 20 21

int rt_hw_usart_init(void);

22
#if defined(SOC_SERIES_STM32F0) || defined(SOC_SERIES_STM32F1) || defined(SOC_SERIES_STM32L4)
23
#define DMA_INSTANCE_TYPE              DMA_Channel_TypeDef
24
#elif defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7)
25 26 27
#define DMA_INSTANCE_TYPE              DMA_Stream_TypeDef
#endif /*  defined(SOC_SERIES_STM32F1) || defined(SOC_SERIES_STM32L4) */

28 29 30 31 32 33
#if defined(SOC_SERIES_STM32F1) || defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32F4)
#define UART_INSTANCE_CLEAR_FUNCTION    __HAL_UART_CLEAR_FLAG
#elif defined(SOC_SERIES_STM32F7) || defined(SOC_SERIES_STM32F0)
#define UART_INSTANCE_CLEAR_FUNCTION    __HAL_UART_CLEAR_IT
#endif

34 35 36 37 38 39
/* stm32 config class */
struct stm32_uart_config
{
    const char *name;
    USART_TypeDef *Instance;
    IRQn_Type irq_type;
40
    struct dma_config *dma_rx;
41 42 43 44 45 46
};

/* stm32 uart dirver class */
struct stm32_uart
{
    UART_HandleTypeDef handle;
47
    struct stm32_uart_config *config;
48
    
49
#ifdef RT_SERIAL_USING_DMA
50 51 52 53 54 55
    struct
    {
        DMA_HandleTypeDef handle;
        rt_size_t last_index;
    } dma;
#endif
56
    rt_uint8_t uart_dma_flag;
57 58 59 60
    struct rt_serial_device serial;
};

#endif  /* __DRV_USART_H__ */