diff --git a/Ubiquitous/XiZi_IIoT/board/cortex-m7-emulator/third_party_driver/uart/Makefile b/Ubiquitous/XiZi_IIoT/board/cortex-m7-emulator/third_party_driver/uart/Makefile index aec03ad7d..f8c4610b9 100644 --- a/Ubiquitous/XiZi_IIoT/board/cortex-m7-emulator/third_party_driver/uart/Makefile +++ b/Ubiquitous/XiZi_IIoT/board/cortex-m7-emulator/third_party_driver/uart/Makefile @@ -1,3 +1,3 @@ -SRC_FILES := stdout_uart.c USART_V2M-MPS2.c connect_uart.c +SRC_FILES := connect_uart.c include $(KERNEL_ROOT)/compiler.mk diff --git a/Ubiquitous/XiZi_IIoT/board/cortex-m7-emulator/third_party_driver/uart/USART_V2M-MPS2.c b/Ubiquitous/XiZi_IIoT/board/cortex-m7-emulator/third_party_driver/uart/USART_V2M-MPS2.c deleted file mode 100644 index 7256b82a0..000000000 --- a/Ubiquitous/XiZi_IIoT/board/cortex-m7-emulator/third_party_driver/uart/USART_V2M-MPS2.c +++ /dev/null @@ -1,50 +0,0 @@ -/* ----------------------------------------------------------------------------- - * Copyright (c) 2016 - 2017 ARM Ltd. - * - * This software is provided 'as-is', without any express or implied warranty. - * In no event will the authors be held liable for any damages arising from - * the use of this software. Permission is granted to anyone to use this - * software for any purpose, including commercial applications, and to alter - * it and redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software in - * a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source distribution. - * - * - * $Date: 26. October 2017 - * $Revision: V1.0.3 - * - * Driver: Driver_USART0, Driver_USART1, Driver_USART2, Driver_USART3 - * - * Configured: via RTE_Device.h configuration file - * Project: UART Driver for ARM CMSDK_CM device - * -------------------------------------------------------------------------- - * Use the following configuration settings in the middleware component - * to connect to this driver. - * - * Configuration Setting Value UART Interface - * --------------------- ----- -------------- - * Connect to hardware via Driver_USART# = 0 use UART0 - * Connect to hardware via Driver_USART# = 1 use UART1 - * Connect to hardware via Driver_USART# = 2 use UART2 - * Connect to hardware via Driver_USART# = 3 use UART3 - * -------------------------------------------------------------------------- */ - -/* History: - * Version 1.0.0 - * Initial release - * Version 1.0.1 - * Removed ARMCLANG warnings - * Version 1.0.2 - * Removed ARMCLANG warnings - * Version 1.0.3 - * Removed race condition in USARTTX_IRQHandler - */ - diff --git a/Ubiquitous/XiZi_IIoT/board/cortex-m7-emulator/third_party_driver/uart/connect_uart.c b/Ubiquitous/XiZi_IIoT/board/cortex-m7-emulator/third_party_driver/uart/connect_uart.c index c1e379636..5f1a289ec 100644 --- a/Ubiquitous/XiZi_IIoT/board/cortex-m7-emulator/third_party_driver/uart/connect_uart.c +++ b/Ubiquitous/XiZi_IIoT/board/cortex-m7-emulator/third_party_driver/uart/connect_uart.c @@ -753,7 +753,7 @@ static void USARTTX_IRQHandler (USART_RESOURCES *usart) { } -#if (defined (RTE_USART0) && (RTE_USART0 == 1)) +#ifdef BSP_USING_LPUART1 // USART0 Driver Wrapper functions void UART0RX_Handler (void); void UART0TX_Handler (void); @@ -793,7 +793,7 @@ extern ARM_DRIVER_USART Driver_USART0; }; #endif -#if (defined (RTE_USART1) && (RTE_USART1 == 1)) +#ifdef BSP_USING_LPUART2 // USART1 Driver Wrapper functions void UART1RX_Handler (void); void UART1TX_Handler (void); @@ -833,7 +833,7 @@ extern ARM_DRIVER_USART Driver_USART1; }; #endif -#if (defined (RTE_USART2) && (RTE_USART2 == 1)) +#ifdef BSP_USING_LPUART3 // USART2 Driver Wrapper functions void UART2RX_Handler (void); void UART2TX_Handler (void); @@ -873,7 +873,7 @@ extern ARM_DRIVER_USART Driver_USART2; }; #endif -#if (defined (RTE_USART3) && (RTE_USART3 == 1)) +#ifdef BSP_USING_LPUART4 // USART3 Driver Wrapper functions void UART3RX_Handler (void); void UART3TX_Handler (void); @@ -914,15 +914,20 @@ extern ARM_DRIVER_USART Driver_USART3; #endif -extern int stdout_init (void); -extern int stdout_putchar (int ch); -extern int stdout_receivechar(); +// extern int stdout_init (void); +// extern int stdout_putchar (int ch); +// extern int stdout_receivechar(); // extern void UART0TX_Handler(); // extern void UART0RX_Handler(); +#define _USART_Driver_(n) Driver_USART##n +#define USART_Driver_(n) _USART_Driver_(n) + +extern ARM_DRIVER_USART USART_Driver_(0); +#define ptrUSART1 (&USART_Driver_(0)) - +#define USART_BAUDRATE 115200 @@ -972,20 +977,7 @@ static void UartIsr(struct SerialBus *serial, struct SerialDriver *serial_drv, s } -// static uint32 GetUartSrcFreq(void) -// { -// uint32 freq; -// /* To make it simple, we assume default PLL and divider settings, and the only variable -// from application is use PLL3 source or OSC source */ -// if (CLOCK_GetMux(kCLOCK_UartMux) == 0) /* PLL3 div6 80M */ { -// freq = (CLOCK_GetPllFreq(kCLOCK_PllUsb1) / 6U) / (CLOCK_GetDiv(kCLOCK_UartDiv) + 1U); -// } else { -// freq = CLOCK_GetOscFreq() / (CLOCK_GetDiv(kCLOCK_UartDiv) + 1U); -// } - -// return freq; -// } static uint32 SerialInit(struct SerialDriver *serial_drv, struct BusConfigureInfo *configure_info) { @@ -1005,7 +997,28 @@ static uint32 SerialInit(struct SerialDriver *serial_drv, struct BusConfigureInf // config serial receive sem timeout dev_param->serial_timeout = serial_cfg->data_cfg.serial_timeout; - stdout_init(); + int32_t status; + + status = ptrUSART1->Initialize(NULL); + if (status != ARM_DRIVER_OK) return (-1); + + status = ptrUSART1->PowerControl(ARM_POWER_FULL); + if (status != ARM_DRIVER_OK) return (-1); + + status = ptrUSART1->Control(ARM_USART_MODE_ASYNCHRONOUS | + ARM_USART_DATA_BITS_8 | + ARM_USART_PARITY_NONE | + ARM_USART_STOP_BITS_1 | + ARM_USART_FLOW_CONTROL_NONE, + USART_BAUDRATE); + if (status != ARM_DRIVER_OK) return (-1); + + status = ptrUSART1->Control(ARM_USART_CONTROL_TX, 1); + if (status != ARM_DRIVER_OK) return (-1); + + status = ptrUSART1->Control(ARM_USART_CONTROL_RX, 1); + if (status != ARM_DRIVER_OK) return (-1); + // stdout_init(); // stdout_putchar(36); if (configure_info->private_data) { @@ -1047,14 +1060,20 @@ static uint32 SerialConfigure(struct SerialDriver *serial_drv, int serial_operat return EOK; } + static int SerialPutChar(struct SerialHardwareDevice *serial_dev, char c) { struct SerialCfgParam *serial_cfg = (struct SerialCfgParam *)serial_dev->private_data; - // LPUART_Type *uart_base = (LPUART_Type *)serial_cfg->hw_cfg.private_data; + + uint8_t buf[1]; + + buf[0] = c; + if (ptrUSART1->Send(buf, 1) != ARM_DRIVER_OK) { + return (-1); + } + + UART0TX_Handler(); - stdout_putchar(c); - // LPUART_WriteByte(uart_base, c); - // while (!(LPUART_GetStatusFlags(uart_base) & kLPUART_TxDataRegEmptyFlag)); return 1; } @@ -1062,13 +1081,16 @@ static int SerialPutChar(struct SerialHardwareDevice *serial_dev, char c) static int SerialGetChar(struct SerialHardwareDevice *serial_dev) { struct SerialCfgParam *serial_cfg = (struct SerialCfgParam *)serial_dev->private_data; - // LPUART_Type *uart_base = (LPUART_Type *)serial_cfg->hw_cfg.private_data; + + int c=-1; + int buf[1]; + buf[0]=0; + do{ + buf[0]=ptrUSART1->Receive(buf, 1); + }while (buf[0]==0); + + c=buf[0]; - int c = -1; - c=stdout_receivechar(); - // if (LPUART_GetStatusFlags(uart_base) & kLPUART_RxDataRegFullFlag) { - // c = LPUART_ReadByte(uart_base); - // } return c; } diff --git a/Ubiquitous/XiZi_IIoT/board/cortex-m7-emulator/third_party_driver/uart/stdout_uart.c b/Ubiquitous/XiZi_IIoT/board/cortex-m7-emulator/third_party_driver/uart/stdout_uart.c deleted file mode 100644 index 48e877022..000000000 --- a/Ubiquitous/XiZi_IIoT/board/cortex-m7-emulator/third_party_driver/uart/stdout_uart.c +++ /dev/null @@ -1,133 +0,0 @@ -/*----------------------------------------------------------------------------- - * Name: stdout_USART.c - * Purpose: STDOUT USART Template - * Rev.: 1.0.0 - *-----------------------------------------------------------------------------*/ - -/* Copyright (c) 2013 - 2015 ARM LIMITED - - All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of ARM nor the names of its contributors may be used - to endorse or promote products derived from this software without - specific prior written permission. - * - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - ---------------------------------------------------------------------------*/ - -#include "Driver_USART.h" - #include "RTE_Components.h" -#include "CMSDK_CM7_SP.h" -//-------- <<< Use Configuration Wizard in Context Menu >>> -------------------- - -// STDOUT USART Interface - -// Connect to hardware via Driver_USART# <0-255> -// Select driver control block for USART interface -#define USART_DRV_NUM 0 - -// Baudrate -#define USART_BAUDRATE 115200 - -// - - -#define _USART_Driver_(n) Driver_USART##n -#define USART_Driver_(n) _USART_Driver_(n) - -extern ARM_DRIVER_USART USART_Driver_(USART_DRV_NUM); -#define ptrUSART (&USART_Driver_(USART_DRV_NUM)) - - -/** - Initialize stdout - - \return 0 on success, or -1 on error. -*/ -int stdout_init (void) { - int32_t status; - - status = ptrUSART->Initialize(NULL); - if (status != ARM_DRIVER_OK) return (-1); - - status = ptrUSART->PowerControl(ARM_POWER_FULL); - if (status != ARM_DRIVER_OK) return (-1); - - status = ptrUSART->Control(ARM_USART_MODE_ASYNCHRONOUS | - ARM_USART_DATA_BITS_8 | - ARM_USART_PARITY_NONE | - ARM_USART_STOP_BITS_1 | - ARM_USART_FLOW_CONTROL_NONE, - USART_BAUDRATE); - if (status != ARM_DRIVER_OK) return (-1); - - status = ptrUSART->Control(ARM_USART_CONTROL_TX, 1); - if (status != ARM_DRIVER_OK) return (-1); - - status = ptrUSART->Control(ARM_USART_CONTROL_RX, 1); - if (status != ARM_DRIVER_OK) return (-1); - - return (0); -} - - -/** - Put a character to the stdout - - \param[in] ch Character to output - \return The character written, or -1 on write error. -*/ -extern void UART0TX_Handler(); - -int stdout_putchar (int ch) { - uint8_t buf[1]; - - buf[0] = ch; - if (ptrUSART->Send(buf, 1) != ARM_DRIVER_OK) { - return (-1); - } -// while (ptrUSART->GetTxCount() != 1); - UART0TX_Handler(); - return (ch); -} - - -int stdout_receivechar() { - int ch=-1; - int buf[1]; - buf[0]=0; - do{ - buf[0]=ptrUSART->Receive(buf, 1); - }while (buf[0]==0); - - ch=buf[0]; - - return (ch); -} - -// volatile int32_t ITM_RxBuffer = ITM_RXBUFFER_EMPTY; - -// int stdin_getchar (void) { -// int32_t ch; - -// do { -// ch = ITM_ReceiveChar(); -// } while (ch == -1); -// return (ch); -// } \ No newline at end of file