|
|
|
|
@ -22,10 +22,8 @@
|
|
|
|
|
/* Private includes ----------------------------------------------------------*/
|
|
|
|
|
/* USER CODE BEGIN Includes */
|
|
|
|
|
#include "printf.h"
|
|
|
|
|
#include <stm32f4xx_it.h>
|
|
|
|
|
#include <usart2_it.h>
|
|
|
|
|
#include <usart6_it.h>
|
|
|
|
|
#include "usart1_it.h"
|
|
|
|
|
/* USER CODE END Includes */
|
|
|
|
|
|
|
|
|
|
/* Private typedef -----------------------------------------------------------*/
|
|
|
|
|
@ -71,22 +69,8 @@ static void MX_USART1_UART_Init(void);
|
|
|
|
|
/***************************************************************************//**
|
|
|
|
|
* @brief Character send interface for printf function
|
|
|
|
|
*//****************************************************************************/
|
|
|
|
|
void printf_putc(void *p, char c) {
|
|
|
|
|
Usart1_PutByte(c);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***************************************************************************//**
|
|
|
|
|
* @brief Check if specified time interval has elapsed
|
|
|
|
|
* @param tref Pointer to time reference variable
|
|
|
|
|
* @param tcycle Time interval in milliseconds
|
|
|
|
|
*//****************************************************************************/
|
|
|
|
|
static inline uint32_t TickChk(uint32_t *tref, int_fast16_t tcycle) {
|
|
|
|
|
int32_t tdif = SysTickCnt - *tref;
|
|
|
|
|
if (tdif >= tcycle) {
|
|
|
|
|
*tref += tcycle;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
void uart_putc(void *p, char c) {
|
|
|
|
|
Usart6_PutByte(c);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* USER CODE END 0 */
|
|
|
|
|
@ -127,76 +111,23 @@ int main(void) {
|
|
|
|
|
|
|
|
|
|
Usart2_Init();
|
|
|
|
|
Usart6_Init();
|
|
|
|
|
Usart1_Init();
|
|
|
|
|
init_printf(NULL, &printf_putc);
|
|
|
|
|
printf("Nucleo UART with IRQ and ring buffer\n");
|
|
|
|
|
init_printf(NULL, &uart_putc);// connect printf to UART
|
|
|
|
|
printf("Hello world. This is a Nucleo UART and printf sample with IRQ and ring buffer.\n");
|
|
|
|
|
/* USER CODE END 2 */
|
|
|
|
|
|
|
|
|
|
/* Infinite loop */
|
|
|
|
|
/* 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
|
|
|
|
|
bytes_2to6++;
|
|
|
|
|
total_2to6++;
|
|
|
|
|
if (c != -1) {// new incoming data
|
|
|
|
|
Usart6_PutByte(c);// UART2rx --> UART6tx
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c = Usart6_GetByte();
|
|
|
|
|
if (c != -1) { // new incoming data
|
|
|
|
|
Usart2_PutByte(c); // UART6rx --> UART2tx
|
|
|
|
|
bytes_6to2++;
|
|
|
|
|
total_6to2++;
|
|
|
|
|
if (c != -1) {// new incoming data
|
|
|
|
|
Usart2_PutByte(c);// UART6rx --> UART2tx
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* USER CODE END WHILE */
|
|
|
|
|
@ -222,13 +153,14 @@ void SystemClock_Config(void) {
|
|
|
|
|
/** Initializes the RCC Oscillators according to the specified parameters
|
|
|
|
|
* in the RCC_OscInitTypeDef structure.
|
|
|
|
|
*/
|
|
|
|
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
|
|
|
|
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
|
|
|
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
|
|
|
|
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
|
|
|
|
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
|
|
|
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
|
|
|
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
|
|
|
|
RCC_OscInitStruct.PLL.PLLM = 8;
|
|
|
|
|
RCC_OscInitStruct.PLL.PLLN = 256;
|
|
|
|
|
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV8;
|
|
|
|
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
|
|
|
|
RCC_OscInitStruct.PLL.PLLM = 16;
|
|
|
|
|
RCC_OscInitStruct.PLL.PLLN = 336;
|
|
|
|
|
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
|
|
|
|
|
RCC_OscInitStruct.PLL.PLLQ = 7;
|
|
|
|
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
|
|
|
|
|
Error_Handler();
|
|
|
|
|
@ -240,10 +172,10 @@ void SystemClock_Config(void) {
|
|
|
|
|
| RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
|
|
|
|
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
|
|
|
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
|
|
|
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
|
|
|
|
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
|
|
|
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
|
|
|
|
|
|
|
|
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) {
|
|
|
|
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) {
|
|
|
|
|
Error_Handler();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|