STMicroelectronics / stm32wlxx_hal_driver

Provides the STM32Cube MCU Component "hal_driver" for the STM32WL series.
BSD 3-Clause "New" or "Revised" License
7 stars 1 forks source link

UART advance feature config procedure is somewaht tedious and mistake prone #2

Closed flespark closed 8 months ago

flespark commented 8 months ago

When I want config stm32wl usart tx logic level in reversion, I have to init UART such as:

  huart2.Instance = USART1;
  huart2.Init.BaudRate = 115200;
  huart2.Init.WordLength = UART_WORDLENGTH_8B;
  huart2.Init.StopBits = UART_STOPBITS_1;
  huart2.Init.Parity = UART_PARITY_NONE;
  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.Init.ClockPrescaler = UART_PRESCALER_DIV1;
// config UART advance feature
  huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_DATAINVERT_INIT | UART_ADVFEATURE_TXINVERT_INIT;
  huart2.AdvancedInit.TxPinLevelInvert = USART_CR2_TXINV;
  huart2.AdvancedInit.DataInvert = USART_CR2_DATAINV;

  if (HAL_UART_Init(&huart2) != HAL_OK)
  {
    Error_Handler();
  }

The config code of advanced feature look tedious and mistake-prone without help of cubemx,maybe the define AdvancedInit as uint32_t instead of UART_AdvFeatureInitTypeDef, only assign value to huart2.AdvancedInit.AdvFeatureInit , then UART_AdvFeatureConfig do well the remaining work. that looks more resonable

RJMSTM commented 8 months ago

Hello @flespark,

Thank you for your contribution, in fact, it's a designer's choice, you can choose which way you want to configure advanced feature.

You may reopen it at any time if you have any details to share with us, Thank you for your comprehension.

With regards