我在尝试通过
STM32H7B3I-DK 上的 USART1 输出数据时遇到问题。根据文档 (UM2569),USART1 是连接到 USB STLINK (CN14) 的虚拟 com 端口。所以理论上我应该能够使用 USART1 通过连接到笔记本电脑的 Mirco-USB 输出到我的串行控制台?但出于某种原因,我的串行控制台根本没有输出任何内容。我已经检查过 STM32CubeMX 和串行控制台中 USART1 的设置是否匹配,所以我假设它与我的串行控制台设置无关。
这是我的主循环和 USART1 的代码片段。代码基本上是由 STM32CubeMX 在我在“板选择器”中选择了正确的发现板后生成的。
- int main(void)
- {
- /* USER CODE BEGIN 1 */
- /* USER CODE END 1 */
- /* MCU Configuration--------------------------------------------------------*/
- /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
- HAL_Init();
- /* USER CODE BEGIN Init */
- /* USER CODE END Init */
- /* Configure the system clock */
- SystemClock_Config();
- /* Configure the peripherals common clocks */
- PeriphCommonClock_Config();
- /* USER CODE BEGIN SysInit */
- /* USER CODE END SysInit */
- /* Initialize all configured peripherals */
- MX_GPIO_Init();
- MX_FMC_Init();
- MX_I2C1_Init();
- MX_I2C4_Init();
- MX_I2S6_Init();
- MX_LTDC_Init();
- MX_OCTOSPI1_Init();
- MX_RTC_Init();
- MX_SDMMC1_SD_Init();
- MX_SPI1_Init();
- MX_SPI2_Init();
- MX_USART1_UART_Init();
- MX_USART2_UART_Init();
- /* USER CODE BEGIN 2 */
- /* USER CODE END 2 */
- /* Infinite loop */
- /* USER CODE BEGIN WHILE */
- while (1)
- {
- /* USER CODE END WHILE */
- /* USER CODE BEGIN 3 */
- uint8_t Test[] = "Hello World !!!rn"; //Data to send
- HAL_UART_Transmit(&huart1,Test,sizeof(Test),10);// Sending in normal mode
- HAL_Delay(1000);
- }
- /* USER CODE END 3 */
- }
- static void MX_USART1_UART_Init(void)
- {
- /* USER CODE BEGIN USART1_Init 0 */
- /* USER CODE END USART1_Init 0 */
- /* USER CODE BEGIN USART1_Init 1 */
- /* USER CODE END USART1_Init 1 */
- huart1.Instance = USART1;
- huart1.Init.BaudRate = 115200;
- huart1.Init.WordLength = UART_WORDLENGTH_8B;
- huart1.Init.StopBits = UART_STOPBITS_1;
- huart1.Init.Parity = UART_PARITY_NONE;
- huart1.Init.Mode = UART_MODE_TX_RX;
- huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
- huart1.Init.OverSampling = UART_OVERSAMPLING_16;
- huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
- huart1.Init.ClockPrescaler = UART_PRESCALER_DIV1;
- huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
- if (HAL_UART_Init(&huart1) != HAL_OK)
- {
- Error_Handler();
- }
- if (HAL_UARTEx_SetTxFifoThreshold(&huart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
- {
- Error_Handler();
- }
- if (HAL_UARTEx_SetRxFifoThreshold(&huart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
- {
- Error_Handler();
- }
- if (HAL_UARTEx_DisableFifoMode(&huart1) != HAL_OK)
- {
- Error_Handler();
- }
- /* USER CODE BEGIN USART1_Init 2 */
- /* USER CODE END USART1_Init 2 */
- }
谢谢您的帮助!