From 9f10725bee9ae6fcd3a3b122bca8ad71445b26d6 Mon Sep 17 00:00:00 2001 From: RichardBarry <3073890+RichardBarry@users.noreply.github.com> Date: Tue, 20 Apr 2021 21:04:29 -0700 Subject: [PATCH] Minor update to the UART write function in the IAR/QEMU/MPS2 demo (#535) * Minor update to the UART write function in the IAR/QEMU/MPS2 demo project. Now the function checks to ensure there is space in the Tx buffer before writing to the buffer - although this does not appear to be necessary in QEMU it is more correct. * Update main.c Co-authored-by: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> --- FreeRTOS/Demo/CORTEX_MPS2_QEMU_IAR/main.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/FreeRTOS/Demo/CORTEX_MPS2_QEMU_IAR/main.c b/FreeRTOS/Demo/CORTEX_MPS2_QEMU_IAR/main.c index 0f1fd6e0c..a251c4182 100644 --- a/FreeRTOS/Demo/CORTEX_MPS2_QEMU_IAR/main.c +++ b/FreeRTOS/Demo/CORTEX_MPS2_QEMU_IAR/main.c @@ -66,8 +66,10 @@ implemented and described in main_full.c. */ required UART registers. */ #define UART0_ADDRESS ( 0x40004000UL ) #define UART0_DATA ( * ( ( ( volatile uint32_t * )( UART0_ADDRESS + 0UL ) ) ) ) +#define UART0_STATE ( * ( ( ( volatile uint32_t * )( UART0_ADDRESS + 4UL ) ) ) ) #define UART0_CTRL ( * ( ( ( volatile uint32_t * )( UART0_ADDRESS + 8UL ) ) ) ) #define UART0_BAUDDIV ( * ( ( ( volatile uint32_t * )( UART0_ADDRESS + 16UL ) ) ) ) +#define TX_BUFFER_MASK ( 1UL ) /* * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1. @@ -257,25 +259,26 @@ static StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ]; static void prvUARTInit( void ) { - UART0_BAUDDIV = 16; - UART0_CTRL = 1; + UART0_BAUDDIV = 16; + UART0_CTRL = 1; } /*-----------------------------------------------------------*/ int __write( int iFile, char *pcString, int iStringLength ) { - uint32_t ulNextChar; + uint32_t ulNextChar; /* Avoid compiler warnings about unused parameters. */ ( void ) iFile; /* Output the formatted string to the UART. */ - for( ulNextChar = 0; ulNextChar < iStringLength; ulNextChar++ ) + for( ulNextChar = 0; ulNextChar < iStringLength; ulNextChar++ ) { - UART0_DATA = *pcString; + while( ( UART0_STATE & TX_BUFFER_MASK ) != 0 ); + UART0_DATA = *pcString; pcString++; - } + } - return iStringLength; + return iStringLength; }