2015-05-21 08:56 PM
//--------------------------------------------------------------------------------------------------------------
/* USER CODE BEGIN USART2_MspInit 0 */ /* USER CODE END USART2_MspInit 0 */ /* Peripheral clock enable */ __USART2_CLK_ENABLE(); /**USART2 GPIO Configuration PD5 ------> USART2_TX PD6 ------> USART2_RX */ GPIO_InitStruct.Pin = GPIO_PIN_5; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Speed = GPIO_SPEED_LOW; HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); GPIO_InitStruct.Pin = GPIO_PIN_6; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); __HAL_AFIO_REMAP_USART2_ENABLE(); // here STM32F103ZE run error! /* System interrupt init*/ HAL_NVIC_SetPriority(USART2_IRQn, 0, 0); HAL_NVIC_EnableIRQ(USART2_IRQn); /* USER CODE BEGIN USART2_MspInit 1 */ /* USER CODE END USART2_MspInit 1 *///--------------------------------------------------------------------------------------------------------------USART2 code run error! but old code is normal! use USE_STDPERIPH_DRIVER lib//-------------------------------------------------------------------------------------------------------------- GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure;&sharpifdef USART2_Remap_PD5_PD6 /* Configure USART2 GPIO PD5 PD6 */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_AFIO,ENABLE);&sharpelse /* Configure USART2 GPIO PA2 PA3 */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO,ENABLE);&sharpendif /* Configure and enable the USART2 */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);&sharpifdef USART2_Remap_PD5_PD6 /* USART2 TX PD.05 */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOD, &GPIO_InitStructure); /* USART2 RX PD.06 */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOD, &GPIO_InitStructure); /*Configure peripheral I/O remapping */ GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);&sharpelse /* USART2 TX PA.02 */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); /* USART2 RX PA.03 */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA, &GPIO_InitStructure);&sharpendif USART_InitStructure.USART_BaudRate = linecoding2.bitrate; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_Init(USART2, &USART_InitStructure); USART_Cmd(USART2, ENABLE); USART_ITConfig(USART2,USART_IT_RXNE,ENABLE); #stm32cubemx-4.7.1-remap_usart22015-05-21 10:34 PM
2015-05-21 11:20 PM
but baud ratechange to 19200 bps, all receive data and number is
correct
! when baud rate up to 1000000 bps , into this code and not exit! Of course, baud rate is 230400bps,hardware have noproblem 。 if(huart->ErrorCode != HAL_UART_ERROR_NONE) { /* Set the UART state ready to be able to start again the process */ huart->State = HAL_UART_STATE_READY; HAL_UART_ErrorCallback(huart); } USE_STDPERIPH_DRIVER, USB_Dual_CDC, two MAX3232, hardware test is ok:2015-05-22 04:40 AM
/* Initialize all configured peripherals */
MX_USART1_UART_Init(); MX_USART2_UART_Init(); /* USART2 init, but not send */ /* USER CODE BEGIN 2 */ HAL_UART_Receive_IT(&huart1, &USART1_RXD_Buffer[0],USART1_RX_LEN); //HAL_UART_Transmit_IT(&huart2,&USART2_TXD_Buffer[0],USART2_TX_LEN); /* not run ,but still usart1 receive a 0xF8 */ /* USER CODE END 2 */ /* Initialize all configured peripherals */ MX_USART1_UART_Init(); //MX_USART2_UART_Init(); /* off this code, normal */ /* USER CODE BEGIN 2 */ HAL_UART_Receive_IT(&huart1, &USART1_RXD_Buffer[0],USART1_RX_LEN); //HAL_UART_Transmit_IT(&huart2,&USART2_TXD_Buffer[0],USART2_TX_LEN); /* not run */ /* USER CODE END 2 */