Error in user YAML: (<unknown>): mapping values are not allowed in this context at line 2 column 16
---
author: Ethan HUANG @ STMicroelectronics
title: Hands-on: UART_Receiving_DMA
---
主要流程:
- 開啟UART DMA
- 修改程式碼
- 編譯專案
- 執行專案
- 延續「05_UART_Receiving_IT」的實作,在IOC Editor左側的「Connectivity」展開項目中點選「USART1」,接著在中間下方的「Configuration」設定畫面點選「DMA Settings」分頁,並點選「Add」鈕開啟DMA設定,並在「DMA Request」下拉選單中選取「USART_RX」:
- 接著在中間下方的「Configuration」設定畫面點選「NVIC Settings」分頁,將「USART1 global interrupt」的「Enabled」取消勾選:
- 在CubeIDE上方的選單當中點選「Project -> Generate Code」以產生程式碼和專案檔:
- 開啟「Core\Src\main.c」檔:
- 將在main.c的USER CODE Block 2當中的程式碼修改如下:
/* USER CODE BEGIN 2 */ HAL_UART_Receive_DMA(&huart1, uart1_rx_buffer, 10); /* USER CODE END 2 */
- 在main.c的USER CODE Block 4當中新增HAL_UART_RxHalfCpltCallback()程式碼如下:
/* USER CODE BEGIN 4 */ #ifdef __GNUC__ #define PUTCHAR_PROTOTYPE int __io_putchar(int ch) #else #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f) #endif /* __GNUC__ */ PUTCHAR_PROTOTYPE { HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF); return ch; } void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) { printf("Receiving Completed!\n\r"); } void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart) { printf("Received 5 characters...\n\r"); } /* USER CODE END 4 */
- 修改新增程式碼完成之後存檔。