cancel
Showing results for 
Search instead for 
Did you mean: 

Upgrading to CubeMX v6.14.1 failing RS485 communication

npatil15
Associate III

Hello,

Previously I had CubeMX 6.13.0 and here is the code which was autogenerated and working as expected for RS485 communication, where I have manually handled the Direction pin in my code.

static void MX_LPUART1_UART_Init(void)
{
  hlpuart1.Instance = LPUART1;
  hlpuart1.Init.BaudRate = 115200;
  hlpuart1.Init.WordLength = UART_WORDLENGTH_8B;
  hlpuart1.Init.StopBits = UART_STOPBITS_1;
  hlpuart1.Init.Parity = UART_PARITY_NONE;
  hlpuart1.Init.Mode = UART_MODE_TX_RX;
  hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
  hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
  if (HAL_RS485Ex_Init(&hlpuart1, UART_DE_POLARITY_HIGH, 0, 0) != HAL_OK)
  {
    Error_Handler();
  }
  if (HAL_UARTEx_SetTxFifoThreshold(&hlpuart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
  {
    Error_Handler();
  }
  if (HAL_UARTEx_SetRxFifoThreshold(&hlpuart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
  {
    Error_Handler();
  }
  if (HAL_UARTEx_DisableFifoMode(&hlpuart1) != HAL_OK)
  {
    Error_Handler();
  }
}

 

Now I have updated the CubeMX version to 6.14.1, which fails the RS485 communication.

static void MX_LPUART1_UART_Init(void)
{
  hlpuart1.Instance = LPUART1;
  hlpuart1.Init.BaudRate = 115200;
  hlpuart1.Init.WordLength = UART_WORDLENGTH_8B;
  hlpuart1.Init.StopBits = UART_STOPBITS_1;
  hlpuart1.Init.Parity = UART_PARITY_NONE;
  hlpuart1.Init.Mode = UART_MODE_TX_RX;
  hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
  hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
  hlpuart1.FifoMode = UART_FIFOMODE_ENABLE;
  if (HAL_UART_Init(&hlpuart1) != HAL_OK)
  {
    Error_Handler();
  }
  if (HAL_UARTEx_SetTxFifoThreshold(&hlpuart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
  {
    Error_Handler();
  }
  if (HAL_UARTEx_SetRxFifoThreshold(&hlpuart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
  {
    Error_Handler();
  }
  if (HAL_UARTEx_EnableFifoMode(&hlpuart1) != HAL_OK)
  {
    Error_Handler();
  }
  if (HAL_RS485Ex_Init(&hlpuart1, UART_DE_POLARITY_HIGH, 0, 0) != HAL_OK)
  {
    Error_Handler();
  }
}


Then I did these changes (re-arrange HAL_RS485Ex_Init() function position), and it works, but as this code is autogenerated multiple times which increase my re-work to arrange the code again and again.

static void MX_LPUART1_UART_Init(void)
{
  hlpuart1.Instance = LPUART1;
  hlpuart1.Init.BaudRate = 115200;
  hlpuart1.Init.WordLength = UART_WORDLENGTH_8B;
  hlpuart1.Init.StopBits = UART_STOPBITS_1;
  hlpuart1.Init.Parity = UART_PARITY_NONE;
  hlpuart1.Init.Mode = UART_MODE_TX_RX;
  hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
  hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
  hlpuart1.FifoMode = UART_FIFOMODE_ENABLE;
  if (HAL_UART_Init(&hlpuart1) != HAL_OK)
  {
    Error_Handler();
  }
  if (HAL_RS485Ex_Init(&hlpuart1, UART_DE_POLARITY_HIGH, 0, 0) != HAL_OK)
  {
    Error_Handler();
  }
  if (HAL_UARTEx_SetTxFifoThreshold(&hlpuart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
  {
    Error_Handler();
  }
  if (HAL_UARTEx_SetRxFifoThreshold(&hlpuart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
  {
    Error_Handler();
  }
  if (HAL_UARTEx_EnableFifoMode(&hlpuart1) != HAL_OK)
  {
    Error_Handler();
  }
}

 

Please guide me how I can resolve this permanently?

Thanks,

Nitin

3 REPLIES 3
Imen.D
ST Employee

Hello @npatil15 

Check the option "Keep user code when regenerating".

Make sure to use the latest release of STM32CubeMX v6.15.

You can share your ioc file, if your issue is not resolved.

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen

Hi Imen,

I am also facing the same and tried to use with latest v6.15 and cube latest library but still the same behaviour.

So can you please how we can fix it. As if we initialize uart or rs485 before fifo threshold setting or fifo enable then code works or else it receives the data but not transmit it or give response on TX.

Also using low level driver library in another project instead of HAL so there also the same issue:

void MX_LPUART1_UART_Init(void)

{

 

/* USER CODE BEGIN LPUART1_Init 0 */

 

/* USER CODE END LPUART1_Init 0 */

 

LL_LPUART_InitTypeDef LPUART_InitStruct = {0};

 

LL_GPIO_InitTypeDef GPIO_InitStruct = {0};

 

LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_PCLK1);

 

/* Peripheral clock enable */

LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_LPUART1);

 

LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB);

/**LPUART1 GPIO Configuration

PB10 ------> LPUART1_RX

PB11 ------> LPUART1_TX

PB12 ------> LPUART1_DE

*/

GPIO_InitStruct.Pin = LL_GPIO_PIN_10|LL_GPIO_PIN_11;

GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;

GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;

GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;

GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;

GPIO_InitStruct.Alternate = LL_GPIO_AF_8;

LL_GPIO_Init(GPIOB, &GPIO_InitStruct);

 

GPIO_InitStruct.Pin = LL_GPIO_PIN_12;

GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;

GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;

GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;

GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;

GPIO_InitStruct.Alternate = LL_GPIO_AF_8;

LL_GPIO_Init(GPIOB, &GPIO_InitStruct);

 

/* LPUART1 interrupt Init */

NVIC_SetPriority(USART3_LPUART1_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),0, 0));

NVIC_EnableIRQ(USART3_LPUART1_IRQn);

 

/* USER CODE BEGIN LPUART1_Init 1 */

 

/* USER CODE END LPUART1_Init 1 */

LPUART_InitStruct.PrescalerValue = LL_LPUART_PRESCALER_DIV1;

LPUART_InitStruct.BaudRate = 115200;

LPUART_InitStruct.DataWidth = LL_LPUART_DATAWIDTH_8B;

LPUART_InitStruct.StopBits = LL_LPUART_STOPBITS_1;

LPUART_InitStruct.Parity = LL_LPUART_PARITY_NONE;

LPUART_InitStruct.TransferDirection = LL_LPUART_DIRECTION_TX_RX;

LPUART_InitStruct.HardwareFlowControl = LL_LPUART_HWCONTROL_NONE;

LL_LPUART_Init(LPUART1, &LPUART_InitStruct);

LL_LPUART_SetTXFIFOThreshold(LPUART1, LL_LPUART_FIFOTHRESHOLD_1_8);

LL_LPUART_SetRXFIFOThreshold(LPUART1, LL_LPUART_FIFOTHRESHOLD_1_8);

LL_LPUART_EnableFIFO(LPUART1);

 

/* USER CODE BEGIN WKUPType LPUART1 */

 

/* USER CODE END WKUPType LPUART1 */

 

LL_LPUART_Enable(LPUART1);

LL_LPUART_Init(LPUART1, &LPUART_InitStruct);

LL_LPUART_SetTXFIFOThreshold(LPUART1, LL_LPUART_FIFOTHRESHOLD_1_8);

LL_LPUART_SetRXFIFOThreshold(LPUART1, LL_LPUART_FIFOTHRESHOLD_1_8);

LL_LPUART_EnableDEMode(LPUART1);

LL_LPUART_SetDESignalPolarity(LPUART1, LL_LPUART_DE_POLARITY_LOW);

LL_LPUART_SetDEAssertionTime(LPUART1, 0);

LL_LPUART_SetDEDeassertionTime(LPUART1, 0);

LL_LPUART_EnableFIFO(LPUART1);

LL_LPUART_Enable(LPUART1);

/* USER CODE BEGIN LPUART1_Init 2 */

 

/* USER CODE END LPUART1_Init 2 */

 

}

 

Surprising after cubemx update why function calling sequence updated in new version and code suddenly stopped working after upgrade

Waiting for the solution...

Thanks & Regards,

Mahendra Rana

 

Please find attached my ioc file.

And in another project the same ioc file but using HAL instead of LL and some other gpio output used in place of gpio analog pins. Rest is same.