2018-04-04 03:50 AM
Hello. I'm doing CubeMX generation, but earlier I also copied bits of firmware UART printf example. Tried with USART1, USART3, USART2. HAL_UART_Transmit(&huart2, ''Hello\n'', 6, 0xFFFF); doesn't yield output (i.e. zero reaction on serial console app; running simultaneously openned project derived from firmware-example works, without touching the serial application; UART parameters like parity etc. is the same).
Screenshots of pinout and CLOCK & USART2 configuration:
USART initialization code is:
void HAL_UART_MspInit(UART_HandleTypeDef* huart)
{GPIO_InitTypeDef GPIO_InitStruct;
if(huart->Instance==USART2) { /* USER CODE BEGIN USART2_MspInit 0 *//* USER CODE END USART2_MspInit 0 */
/* Peripheral clock enable */ __HAL_RCC_USART2_CLK_ENABLE(); /**USART2 GPIO Configuration PA3 ------> USART2_RX PD5 ------> USART2_TX */ GPIO_InitStruct.Pin = GPIO_PIN_3; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF7_USART2; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);GPIO_InitStruct.Pin = GPIO_PIN_5;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF7_USART2; HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);/* USER CODE BEGIN USART2_MspInit 1 */
/* USER CODE END USART2_MspInit 1 */
}}
void SystemClock_Config(void)
{RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct; RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;/**Configure the main internal regulator output voltage
*/ __HAL_RCC_PWR_CLK_ENABLE();__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
/**Initializes the CPU, AHB and APB busses clocks
*/ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.HSEState = RCC_HSE_ON; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLM = 25; RCC_OscInitStruct.PLL.PLLN = 432; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; RCC_OscInitStruct.PLL.PLLQ = 2; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); }/**Activate the Over-Drive mode
*/ if (HAL_PWREx_EnableOverDrive() != HAL_OK) { _Error_Handler(__FILE__, __LINE__); }/**Initializes the CPU, AHB and APB busses clocks
*/ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_7) != HAL_OK)
{ _Error_Handler(__FILE__, __LINE__); }PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART2;
PeriphClkInitStruct.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1; if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); }/**Configure the Systick interrupt time
*/ HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);/**Configure the Systick
*/ HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);/* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SysTick_IRQn, 15, 0);}/* USART2 init function */
static void MX_USART2_UART_Init(void){huart2.Instance = USART2;
huart2.Init.BaudRate = 9600; huart2.Init.WordLength = UART_WORDLENGTH_9B; huart2.Init.StopBits = UART_STOPBITS_1; huart2.Init.Parity = UART_PARITY_ODD; huart2.Init.Mode = UART_MODE_TX_RX; huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; huart2.Init.OverSampling = UART_OVERSAMPLING_16; huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; if (HAL_UART_Init(&huart2) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); }}
/** Configure pins as
* Analog * Input * Output * EVENT_OUT * EXTI*/static void MX_GPIO_Init(void){/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOH_CLK_ENABLE(); __HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); __HAL_RCC_GPIOG_CLK_ENABLE(); __HAL_RCC_GPIOD_CLK_ENABLE();}
My board is Nucleo-144 F767ZIT6. I can run the firmware UART printf example and it works. Can anyone help?
#lwip-stm32f7-nucleo-144 #printf #nucleo-144 #hal-uart #hal_uart_transmit #hal-usart2018-04-04 10:32 AM
I was specific in replies, also updated the question and added screenshots.
2018-04-04 10:55 AM
>>
No change in UART (lack of) communication, though.
What exactly are you talking too to make this determination? STM32 outputting CMOS levels, would need MAX3232 to get RS232 compatible levels.
Other method might be to loop RX and TX externally and confirm you can receive what is sent.
Used PD5/PD6 for USART2 here
2018-04-04 12:28 PM
Your advice to confirm on pin seems to match my impression that something is more than wrong. I do not feel the board, I would say, how come 3 different USARTs don't react to transmit function, I should see at least junk on terminal. It's like FreeRTOS is changing something, or LWIP. The screenshots show that I have ETH configured.
EDIT: Tried your pinout, PD5 & PD6, no effect. I regenerate project without problems having customs in user-code sections, so I can test things.
2018-04-04 12:40 PM
Not using CubeMX here.
Your options here are to use the debugger and walk the Peripheral View for RCC, USART, GPIO, etc and confirm settings. If using interrupts for the USART check the vector table linkage, and calls into HAL/RTOS
void SystemClock_Config(void) // I'd explicitly clear the auto/local variables here
{RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};...