[Lianshengde W806 Hands-on Notes] 6. 7816/UART Controller

Publisher:不加糖的302Latest update time:2022-07-19 Source: csdnKeywords:UART  controller Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Windows 10 20H2

HLK-W806-V1.0-KIT

WM_SDK_W806_v0.6.0


       Excerpted from "W806 Chip Design Guide V1.0", "W806 MCU Chip Specification V2.0"


7816/UART Controller

The device side complies with the APB bus interface protocol

Support interrupt or polling working mode

Support DMA transfer mode, send and receive are stored in 32-byte FIFO

DMA can only operate on bytes, with a maximum of 16-burst byte DMA operations

insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here

insert image description hereinsert image description hereinsert image description here

Compatible with UART and 7816 interface functions


Serial port function

Programmable baud rate

5-8bit data length and parity polarity configurable

1 or 2 stop positions configurable

Support RTS/CTS flow control

Support Break frame sending and receiving

Overrun,parity error,frame error,rx break frame 中断指示


7816 Interface Function

Compatible with ISO-7816-3 T=0.T=1 mode

Compatible with EVM2000 protocol

Configurable guard time (11 ETU-267 ETU)

Forward/reverse convention software configurable

Support send/receive parity check and retransmission function

Supports 0.5 and 1.5 stop bit configurations


Download Port

       The W806 chip uses UART0 as the download port by default. When there is no firmware for the initial download, directly connect to the UART0 interface and download the firmware through the relevant download software. When there is firmware in the chip, enter the download mode again by pulling down BOOTMODE and then powering on to enter the download mode. After the download is complete, remove the operation of pulling down BOOTMODE and restart the firmware to run.


Library Functions

function

       Open wm_uart.h, there is the following function declaration:


// Initialize the baud rate, data bit, stop bit, check bit, mode, etc. of the serial port used

HAL_StatusTypeDef HAL_UART_Init(UART_HandleTypeDef *huart);


//Restore the serial port to the default state after initialization - the value of each register when it is reset

HAL_StatusTypeDef HAL_UART_DeInit(UART_HandleTypeDef *huart);


//Serial port sends data, using timeout management mechanism 

HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);


//Serial port receives data and uses timeout management mechanism

HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);


//Serial port interrupt mode sending  

HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);


/**

  * Receive data of a certain length in interrupt mode.

  * Note: The address pointed to by pData must have a space length greater than or equal to 32 bytes

  *   If Size is greater than 0, then receive data of sufficient length and execute HAL_UART_RxCpltCallback(huart);

  *   If Sized is 0, HAL_UART_RxCpltCallback(huart) will be executed once when receiving data of indefinite length;

  * In both cases, the data is stored in huart->pRxBuffPtr or pData, and the data length is stored in huart->RxXferCount

  */

HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);


//Serial port interrupt service function, used to respond to various serial port interrupts.

//The function entity has two functions, one is to clear the interrupt flag, the other is to call the corresponding callback function,

//如UART_Receive_IT、UART_Transmit_IT、UART_EndTransmit_IT

void HAL_UART_IRQHandler(UART_HandleTypeDef *huart);


//Serial port send interrupt callback function, called by UART_EndTransmit_IT

void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart);


//Serial port receive interrupt callback function, called by UART_Receive_IT

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart);


parameter

Structure and enumeration types

Seeing that STM32 can't hold it anymore


typedef struct

{

uint32_t BaudRate;                  /*!< This member configures the UART communication baud rate.

   The baud rate is computed using the following formula:

   - IntegerDivider = ((PCLKx) / (16 * (huart->Init.BaudRate)))

   - FractionalDivider = ((IntegerDivider - ((uint32_t) IntegerDivider)) * 16) + 0.5 */


uint32_t WordLength;                /*!< Specifies the number of data bits transmitted or received in a frame.

   This parameter can be a value of @ref UART_Word_Length */


uint32_t StopBits;                  /*!< Specifies the number of stop bits transmitted.

   This parameter can be a value of @ref UART_Stop_Bits */


uint32_t Parity;                    /*!< Specifies the parity mode.

   This parameter can be a value of @ref UART_Parity

   @note When parity is enabled, the computed parity is inserted

at the MSB position of the transmitted data (9th bit when

the word length is set to 9 data bits; 8th bit when the

word length is set to 8 data bits). */


uint32_t Mode;                      /*!< Specifies whether the Receive or Transmit mode is enabled or disabled.

   This parameter can be a value of @ref UART_Mode */


uint32_t HwFlowCtl;                 /*!< Specifies whether the hardware flow control mode is enabled or disabled.

   This parameter can be a value of @ref UART_Hardware_Flow_Control */


uint32_t OverSampling;              /*!< Specifies whether the Over sampling 8 is enabled or disabled, to achieve higher speed (up to fPCLK/8).

   This parameter can be a value of @ref UART_Over_Sampling. This feature is only available 

   on STM32F100xx family, so OverSampling parameter should always be set to 16. */

} UART_InitTypeDef;


typedef enum

{

HAL_UART_STATE_RESET             = 0x00U,    /*!< Peripheral is not yet Initialized

   Value is allowed for gState and RxState */

HAL_UART_STATE_READY             = 0x20U,    /*!< Peripheral Initialized and ready for use

   Value is allowed for gState and RxState */

HAL_UART_STATE_BUSY              = 0x24U,    /*!< an internal process is ongoing

   Value is allowed for gState only */

HAL_UART_STATE_BUSY_TX           = 0x21U,    /*!< Data Transmission process is ongoing

   Value is allowed for gState only */

HAL_UART_STATE_BUSY_RX           = 0x22U,    /*!< Data Reception process is ongoing

   Value is allowed for RxState only */

HAL_UART_STATE_BUSY_TX_RX        = 0x23U,    /*!< Data Transmission and Reception process is ongoing

   Not to be used for neither gState nor RxState.

   Value is result of combination (Or) between gState and RxState values */

HAL_UART_STATE_TIMEOUT           = 0xA0U,    /*!< Timeout state

   Value is allowed for gState only */

HAL_UART_STATE_ERROR             = 0xE0U     /*!< Error

   Value is allowed for gState only */

} HAL_UART_StateTypeDef;


typedef struct __UART_HandleTypeDef

{

USART_TypeDef                 *Instance;        /*!< UART registers base address        */


UART_InitTypeDef              Init;             /*!< UART communication parameters      */


uint8_t                       *pTxBuffPtr;      /*!< Pointer to UART Tx transfer Buffer */


uint16_t                      TxXferSize;       /*!< UART Tx Transfer size              */


__IO uint16_t                 TxXferCount;      /*!< UART Tx Transfer Counter           */


uint8_t                       *pRxBuffPtr;      /*!< Pointer to UART Rx transfer Buffer */


uint16_t                      RxXferSize;       /*!< UART Rx Transfer size              */


__IO uint16_t                 RxXferCount;      /*!< UART Rx Transfer Counter           */


HAL_LockTypeDef               Lock;             /*!< Locking object                     */


__IO HAL_UART_StateTypeDef    gState;           /*!< UART state information related to global Handle management

   and also related to Tx operations.

   This parameter can be a value of @ref HAL_UART_StateTypeDef */


__IO HAL_UART_StateTypeDef    RxState;          /*!< UART state information related to Rx operations.

   This parameter can be a value of @ref HAL_UART_StateTypeDef */


__IO uint32_t                 ErrorCode;        /*!< UART Error code                    */


}UART_HandleTypeDef;


typedef enum

{

UART_FIFO_TX_NOT_FULL,

UART_FIFO_TX_EMPTY,

UART_FIFO_RX_NOT_EMPTY,

} HAL_UART_WaitFlagDef;


Macro Parameters


#define UART0 ((USART_TypeDef *)UART0_BASE)

#define UART1 ((USART_TypeDef *)UART1_BASE)

#define UART2 ((USART_TypeDef *)UART2_BASE)

#define UART3 ((USART_TypeDef *)UART3_BASE)

#define UART4 ((USART_TypeDef *)UART4_BASE)

#define UART5 ((USART_TypeDef *)UART5_BASE)


#define UART_FIFO_FULL 32


#define HAL_UART_ERROR_NONE              0x00000000U   /*!< No error            */

#define HAL_UART_ERROR_FE                0x00000040U   /*!< Frame error         */

#define HAL_UART_ERROR_PE                0x00000080U   /*!< Parity error        */

#define HAL_UART_ERROR_ORE               0x00000100U   /*!< Overrun error       */


#define UART_WORDLENGTH_5B                  ((uint32_t)UART_LC_DATAL_5BIT)

#define UART_WORDLENGTH_6B                  ((uint32_t)UART_LC_DATAL_6BIT)

#define UART_WORDLENGTH_7B                  ((uint32_t)UART_LC_DATAL_7BIT)

#define UART_WORDLENGTH_8B                  ((uint32_t)UART_LC_DATAL_8BIT)


#define UART_STOPBITS_1                     0x00000000

#define UART_STOPBITS_2                     ((uint32_t)UART_LC_STOP)


#define UART_PARITY_NONE                    0x00000000

#define UART_PARITY_EVEN                    ((uint32_t)UART_LC_PCE)

#define UART_PARITY_ODD                     ((uint32_t)(UART_LC_PCE | UART_LC_PS))


#define UART_HWCONTROL_NONE                  0x00000000U

#define UART_HWCONTROL_RTS                   ((uint32_t)UART_FC_AFCE)

#define UART_HWCONTROL_CTS                   ((uint32_t)UART_FC_AFCE)

#define UART_HWCONTROL_RTS_CTS               ((uint32_t)UART_FC_AFCE)


#define UART_MODE_RX                        ((uint32_t)UART_LC_RE)

#define UART_MODE_TX                        ((uint32_t)UART_LC_TE)

#define UART_MODE_TX_RX                     ((uint32_t)(UART_LC_RE | UART_LC_TE))


#define UART_STATE_DISABLE                  0x00000000U

#define UART_STATE_ENABLE                   ((uint32_t)(UART_LC_RE | UART_LC_TE))


Macro

#define __HAL_UART_ENABLE(__HANDLE__)               ((__HANDLE__)->Instance->LC |= (UART_LC_RE | UART_LC_TE))


#define __HAL_UART_DISABLE(__HANDLE__)              ((__HANDLE__)->Instance->LC &= ~(UART_LC_RE | UART_LC_TE))

[1] [2]
Keywords:UART  controller Reference address:[Lianshengde W806 Hands-on Notes] 6. 7816/UART Controller

Previous article:[Lianshengde W806 Hands-on Notes] VII. I2C
Next article:[Lianshengde W806 Hands-on Notes] 5. TIM Timer

Recommended ReadingLatest update time:2024-11-16 12:51

S3C2440-5.Usage of UART
1. Introduction to UART in S3C2440 UART (universal asynchronous receive transmitter) is used to send and receive serial data and communicate in full-duplex mode. The level standard used by UART is TTL/CMOS. A frame of data usually contains a start bit, data bit, check bit, and stop bit. Both parties of UART transmissi
[Microcontroller]
S3C2440-5.Usage of UART
ARM7 microcontroller (learning) - (three), UART - 03
Today's experiment uses the FIFO interrupt of UART0~~ Receive data sent from the virtual terminal~~ Here the depth is set to 8~~ Then send it back~~ But~~I can't send it back~~Fuck~~ Let's leave this question for now~~ Let’s solve it together later~~ 3. UART Three - (03), send a string to the serial port and then send
[Microcontroller]
ARM7 microcontroller (learning) - (three), UART - 03
Learning records and usage experience about STM8S UART2 serial port
Preface This is my first time to use STM8S microcontroller, so I will record it for easy reference in the future. text As one of the standard serial ports of STM8S, Uart2 serial port is used to provide an external communication channel for STM8S microcontroller in the form of wired connection. initialization The f
[Microcontroller]
How does printf() "hook up" with the UART peripheral driver function?
This is definitely a good article. The print function is sometimes more useful than any debugging tool. The kernel print is an artifact among artifacts, but how is the printf function connected to the uart driver? This article will give you Answer, like, forward, save and read when needed. What I will share with you
[Microcontroller]
MSP430F249UART
//****************************************************************************** //   MSP430x24x Demo - USCI_A0, 9600 UART Echo ISR, DCO SMCLK // //   Description: Echo a received character, RX ISR used. Normal mode is LPM0. //   USCI_A0 RX interrupt triggers TX Echo. //   Baud rate divider with 1MHz = 1MHz/9600 = ~10
[Microcontroller]
UART, IrDA, SPI, I2C MSP430 learning
The first difference between SPI, IIC and UART is of course the name:        SPI (Serial Peripheral Interface);              I2C (INTER IC BUS)            UART (Universal Asynchronous Receiver Transmitter) Second, the difference is in the electrical signal line:        The SPI bus consists of three
[Microcontroller]
ARM7 microcontroller (learning) - (three), UART - 01
3. UART 3—(01) Introduction to UART related applications and registers~~ 1. UART0 (UART1 is the same as UART0, but with an additional modem interface~~ I will not introduce it~~ 1. Features: (I personally feel that understanding the features is the only way to get started~~ Especially the performance of FIFO~~ No one
[Microcontroller]
ARM7 microcontroller (learning) - (three), UART - 01
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号