diff --git a/Core/Src/main.c b/Core/Src/main.c index 854e4f1..8169a02 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -22,6 +22,7 @@ /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ #include "printf.h" +#include #include #include #include "usart1_it.h" @@ -135,24 +136,67 @@ int main(void) { /* USER CODE BEGIN WHILE */ while (1) { static uint32_t Tick10msRef = 0; + /* per-second and total byte counters */ + static uint32_t bytes_2to6 = 0; + static uint32_t bytes_6to2 = 0; + static uint32_t total_2to6 = 0; + static uint32_t total_6to2 = 0; if (TickChk(&Tick10msRef, 10)) { } static uint32_t Tick1secRef = 0; if (TickChk(&Tick1secRef, 1000)) { LED2_Toggle(); + /* print per-second data rates and cumulative totals */ + printf("OUT:%5u IN:%5u B/s (Total:%u/%u)\n", (unsigned) bytes_2to6, (unsigned) bytes_6to2, (unsigned) total_2to6, (unsigned) total_6to2); + /* reset per-second counters */ + bytes_2to6 = 0; + bytes_6to2 = 0; } int c; + c = Usart1_GetByte(); + if (c != -1) { // new incoming data +/* + switch (c) { + case '1': + printf("Send 800 bytes to UART1\n"); + for (int i = 0; i < 800; i++) { + Usart1_PutByte((i % 10) + '0'); + } + break; + case '2': + printf("Send 800 bytes to UART2\n"); + for (int i = 0; i < 800; i++) { + Usart2_PutByte((i % 20) + 'A'); + } + break; + case '6': + printf("Send 800 bytes to UART6\n"); + for (int i = 0; i < 800; i++) { + Usart6_PutByte((i % 20) + 'a'); + } + break; + default: // echo back + Usart1_PutByte(c); + break; + } +*/ + } + c = Usart2_GetByte(); - if (c != -1) {// new incoming data - Usart6_PutByte(c);// UART2rx --> UART6tx + if (c != -1) { // new incoming data + Usart6_PutByte(c); // UART2rx --> UART6tx + bytes_2to6++; + total_2to6++; } c = Usart6_GetByte(); - if (c != -1) {// new incoming data - Usart2_PutByte(c);// UART6rx --> UART2tx + if (c != -1) { // new incoming data + Usart2_PutByte(c); // UART6rx --> UART2tx + bytes_6to2++; + total_6to2++; } /* USER CODE END WHILE */