Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USART4 issue on Nucleo-G071RB #1188

Closed
fpistm opened this issue Sep 24, 2020 · 0 comments · Fixed by #1189
Closed

USART4 issue on Nucleo-G071RB #1188

fpistm opened this issue Sep 24, 2020 · 0 comments · Fixed by #1189
Labels
bug 🐛 Something isn't working
Milestone

Comments

@fpistm
Copy link
Member

fpistm commented Sep 24, 2020

Hello @fpistm , I was further exploring more uart for my project and found that UART4 on pin PA1 & PA0 also do not work under Arduino framework.

I have tested the UART1, UART2 & UART4 using STM32Cube Framework and everything works fine.

#include <Arduino.h> 

#define pin  LED_BUILTIN

HardwareSerial UART1(PA10, PA9);          // works fine after workaround provided by @fpistm in above comments
HardwareSerial Uart4(PA1, PA0);             // UART 4 on Pin PA1 & PA0 does not work and MCU stop working.
UART_HandleTypeDef huart4;                 // HACK using STM32 HAL Library  for UART4 on Pin PA1 & PA0

void Uart4_Init();
void UART4_Send(); 
 
void setup()
{
  Serial.begin(115200);               // on Pin rx_PA3 tx_PA2
  delay(100);

  UART1.begin(115200);             // on Pin rx_PA10 tx_PA9 
  delay(100);

  Uart4.begin(115200);               // Error working using Arduino library // on Pin rx_PA1 tx_PA0
  //Uart4_Init();                           // using STM32 HAL Library as workaround to send data but cannot receive due to lib conflict
  delay(100);

  pinMode(LED_BUILTIN, OUTPUT);
  
}

int count = 0;
void loop()
{
  delay(1000); 

  Serial.print("\nSG0  UART2(Serial): "); Serial.print(++count);
  
  UART1.print("\nSG0 UART1: "); UART1.print(count);
  
  Uart4.print("\nSG0 Uart4: "); Uart4.print(count); // **SOC stop working at this point...**
  
  //UART4_Send(); //using STM32 HAL Library (Sending is fine, receiving data is problem)
 
  digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}

/* Sending data on UART 4 using STM32 HAL Library*/
void UART4_Send()
{
   char str[20];
   String thisString = "\nSG0  UART4: " + String(count) + "\n";
   thisString.toCharArray(str, thisString.length());
   HAL_UART_Transmit(&huart4, (uint8_t*)str, thisString.length()-1, 1000);
}

/* Initializing UART 4 using STM32 HAL Library*/ 
void Uart4_Init()
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};
  /* Peripheral clock enable */
  __HAL_RCC_USART4_CLK_ENABLE();

  __HAL_RCC_GPIOA_CLK_ENABLE();
  /**USART4 GPIO Configuration
  PA0     ------> USART4_TX
  PA1     ------> USART4_RX
  */
  GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;
  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  GPIO_InitStruct.Alternate = GPIO_AF4_USART4;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

     /* USER CODE END USART4_Init 1 */
  huart4.Instance = USART4;
  huart4.Init.BaudRate = 115200;
  huart4.Init.WordLength = UART_WORDLENGTH_8B;
  huart4.Init.StopBits = UART_STOPBITS_1;
  huart4.Init.Parity = UART_PARITY_NONE;
  huart4.Init.Mode = UART_MODE_TX_RX;
  huart4.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart4.Init.OverSampling = UART_OVERSAMPLING_16;
  huart4.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
  huart4.Init.ClockPrescaler = UART_PRESCALER_DIV1;
  huart4.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;

  if (HAL_UART_Init(&huart4) != HAL_OK)
  { 
    Serial.println("\nUart4 Error");
  }
  /* USER CODE BEGIN USART4_Init 2 */
  
  if (HAL_UARTEx_SetTxFifoThreshold(&huart4, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
  {
    Serial.println("\nUart4 Error");
  }

  if (HAL_UARTEx_SetRxFifoThreshold(&huart4, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
  {
    Serial.println("\nUart4 Error");
  }

  if (HAL_UARTEx_DisableFifoMode(&huart4) != HAL_OK)
  {
    Serial.println("\nUart4 Error");
  } 
}

Originally posted by @harji2130 in #1180 (comment)

@fpistm fpistm added the bug 🐛 Something isn't working label Sep 24, 2020
@fpistm fpistm added this to the 2.0.0 milestone Sep 24, 2020
fpistm added a commit to fpistm/Arduino_Core_STM32 that referenced this issue Sep 24, 2020
Fix stm32duino#1188

Signed-off-by: Frederic Pillon <[email protected]>
fpistm added a commit that referenced this issue Sep 24, 2020
Fix #1188

Signed-off-by: Frederic Pillon <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant