2020 */
2121
2222#include "string.h"
23- #include "fsl_device_registers.h"
24- #include "fsl_usart_cmsis.h"
2523#include "uart.h"
2624#include "util.h"
2725#include "cortex_m.h"
2826#include "circ_buf.h"
2927#include "settings.h" // for config_get_overflow_detect
30-
31- #define USART_INSTANCE (Driver_USART0)
32- #define USART_IRQ (FLEXCOMM0_IRQn)
33-
34- extern uint32_t SystemCoreClock ;
28+ #include "Driver_USART.h"
29+ #include "IO_Config.h"
3530
3631static void clear_buffers (void );
3732
@@ -64,18 +59,18 @@ int32_t uart_initialize(void)
6459{
6560 clear_buffers ();
6661 cb_buf .tx_size = 0 ;
67- USART_INSTANCE .Initialize (uart_handler );
68- USART_INSTANCE .PowerControl (ARM_POWER_FULL );
62+ CMSIS_UART_INSTANCE .Initialize (uart_handler );
63+ CMSIS_UART_INSTANCE .PowerControl (ARM_POWER_FULL );
6964
7065 return 1 ;
7166}
7267
7368int32_t uart_uninitialize (void )
7469{
75- USART_INSTANCE .Control (ARM_USART_CONTROL_RX , 0 );
76- USART_INSTANCE .Control (ARM_USART_ABORT_RECEIVE , 0U );
77- USART_INSTANCE .PowerControl (ARM_POWER_OFF );
78- USART_INSTANCE .Uninitialize ();
70+ CMSIS_UART_INSTANCE .Control (ARM_USART_CONTROL_RX , 0 );
71+ CMSIS_UART_INSTANCE .Control (ARM_USART_ABORT_RECEIVE , 0U );
72+ CMSIS_UART_INSTANCE .PowerControl (ARM_POWER_OFF );
73+ CMSIS_UART_INSTANCE .Uninitialize ();
7974 clear_buffers ();
8075 cb_buf .tx_size = 0 ;
8176
@@ -85,10 +80,10 @@ int32_t uart_uninitialize(void)
8580int32_t uart_reset (void )
8681{
8782 // disable interrupt
88- NVIC_DisableIRQ (USART_IRQ );
83+ NVIC_DisableIRQ (CMSIS_UART_IRQ );
8984 clear_buffers ();
9085 // enable interrupt
91- NVIC_EnableIRQ (USART_IRQ );
86+ NVIC_EnableIRQ (CMSIS_UART_IRQ );
9287
9388 return 1 ;
9489}
@@ -157,23 +152,23 @@ int32_t uart_set_configuration(UART_Configuration *config)
157152 break ;
158153 }
159154
160- NVIC_DisableIRQ (USART_IRQ );
155+ NVIC_DisableIRQ (CMSIS_UART_IRQ );
161156 clear_buffers ();
162157
163158 // If there was no Receive() call in progress aborting it is harmless.
164- USART_INSTANCE .Control (ARM_USART_CONTROL_RX , 0U );
165- USART_INSTANCE .Control (ARM_USART_ABORT_RECEIVE , 0U );
159+ CMSIS_UART_INSTANCE .Control (ARM_USART_CONTROL_RX , 0U );
160+ CMSIS_UART_INSTANCE .Control (ARM_USART_ABORT_RECEIVE , 0U );
166161
167- uint32_t r = USART_INSTANCE .Control (control , config -> Baudrate );
162+ uint32_t r = CMSIS_UART_INSTANCE .Control (control , config -> Baudrate );
168163 if (r != ARM_DRIVER_OK ) {
169164 return 0 ;
170165 }
171- USART_INSTANCE .Control (ARM_USART_CONTROL_TX , 1 );
172- USART_INSTANCE .Control (ARM_USART_CONTROL_RX , 1 );
173- USART_INSTANCE .Receive (& (cb_buf .rx ), 1 );
166+ CMSIS_UART_INSTANCE .Control (ARM_USART_CONTROL_TX , 1 );
167+ CMSIS_UART_INSTANCE .Control (ARM_USART_CONTROL_RX , 1 );
168+ CMSIS_UART_INSTANCE .Receive (& (cb_buf .rx ), 1 );
174169
175- NVIC_ClearPendingIRQ (USART_IRQ );
176- NVIC_EnableIRQ (USART_IRQ );
170+ NVIC_ClearPendingIRQ (CMSIS_UART_IRQ );
171+ NVIC_EnableIRQ (CMSIS_UART_IRQ );
177172
178173 return 1 ;
179174}
@@ -203,7 +198,7 @@ static void uart_start_tx_transfer() {
203198 }
204199 cb_buf .tx_size = tx_size ;
205200 if (tx_size ) {
206- USART_INSTANCE .Send (buf , tx_size );
201+ CMSIS_UART_INSTANCE .Send (buf , tx_size );
207202 }
208203}
209204
@@ -242,7 +237,7 @@ void uart_handler(uint32_t event) {
242237 } else {
243238 // Drop character
244239 }
245- USART_INSTANCE .Receive (& (cb_buf .rx ), 1 );
240+ CMSIS_UART_INSTANCE .Receive (& (cb_buf .rx ), 1 );
246241 }
247242
248243 if (event & ARM_USART_EVENT_SEND_COMPLETE ) {
0 commit comments