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

UART1 on pin PA10, PA9 does not work on Nucleo-G071RB #1180

Closed
Khelicon opened this issue Sep 21, 2020 · 5 comments · Fixed by #1091
Closed

UART1 on pin PA10, PA9 does not work on Nucleo-G071RB #1180

Khelicon opened this issue Sep 21, 2020 · 5 comments · Fixed by #1091
Assignees
Labels
Milestone

Comments

@Khelicon
Copy link
Contributor

Khelicon commented Sep 21, 2020

I found issue where UART1 is not working on pin PA10 & PA9 on Nucleo-G071RB but UART1 works fine on pin PB7 & PB6.

I verified with following code in Arduino IDE and PlatformIO

 

HardwareSerial rfUart(PA10, PA9);  // do not work
//HardwareSerial rfUart(PB7, PB6); // work successfully
 
void setup()
{
 Serial.begin(115200);
 delay(100);

 rfUart.begin(115200);

 pinMode(LED_BUILTIN, OUTPUT);

 Serial.println("\nSG0 Begin....");
 rfUart.println("\nSG0 RF Begin....");
}

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

 Serial.printf("\nSG0 Count: %02d", count);
 rfUart.print("\nRF Count:"); rfUart.println(count++);

 digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}

Note: I tried using Stm32Cube Framework, UART1 on pin PA10 & PA9 works fine.

@fpistm fpistm added this to To do in STM32 core based on ST HAL via automation Sep 21, 2020
@fpistm fpistm added this to the 2.0.0 milestone Sep 21, 2020
@fpistm
Copy link
Member

fpistm commented Sep 22, 2020

Hi @harji2130

Thanks for reporting this issue. Error comes from the REMAP of those pins. When adding the Disco G031 we introduced the remap by default but this is not correct.

/* Handle pin remap if any */
#if defined(LL_SYSCFG_PIN_RMP_PA11) && defined(LL_SYSCFG_PIN_RMP_PA12)
if ((pin >= PA_9) && (pin <= PA_12)) {
__HAL_RCC_SYSCFG_CLK_ENABLE();
switch ((int)pin) {
case PA_9:
LL_SYSCFG_EnablePinRemap(LL_SYSCFG_PIN_RMP_PA11);
break;
case PA_11:
LL_SYSCFG_DisablePinRemap(LL_SYSCFG_PIN_RMP_PA11);
break;
case PA_10:
LL_SYSCFG_EnablePinRemap(LL_SYSCFG_PIN_RMP_PA12);
break;
case PA_12:
LL_SYSCFG_DisablePinRemap(LL_SYSCFG_PIN_RMP_PA12);
break;
default:
break;
}
}
#endif

So in your case PA9 is remap to PA11. If you wire the Tx pin on PA11 you will see the output.

I will fix that soon.

@fpistm fpistm self-assigned this Sep 22, 2020
@Khelicon
Copy link
Contributor Author

Khelicon commented Sep 22, 2020

Thank you @fpistm, now as a workaround, I comment the defines in "stm32g0xx_ll_system.h" at line 87 & 88

//#define LL_SYSCFG_PIN_RMP_PA11              SYSCFG_CFGR1_PA11_RMP                           /*!< PA11 pad behaves as PA9 pin */
//#define LL_SYSCFG_PIN_RMP_PA12              SYSCFG_CFGR1_PA12_RMP                           /*!< PA12 pad behaves as PA10 pin */

#define LL_SYSCFG_PIN_RMP_PA11 SYSCFG_CFGR1_PA11_RMP /*!< PA11 pad behaves as PA9 pin */
#define LL_SYSCFG_PIN_RMP_PA12 SYSCFG_CFGR1_PA12_RMP /*!< PA12 pad behaves as PA10 pin */

@Khelicon
Copy link
Contributor Author

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");
  } 
}

@fpistm
Copy link
Member

fpistm commented Sep 24, 2020

Hi @harji2130
I found the issue.
After fixing this issue #1141

I forgot to update the IRQ handler function then for USART4 the HAL_UART_IRQHandler is not called.
I will fix it too...

fpistm added a commit to fpistm/Arduino_Core_STM32 that referenced this issue Jan 23, 2021
Fix stm32duino#1180

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
fpistm added a commit to fpistm/Arduino_Core_STM32 that referenced this issue Jan 23, 2021
Fix stm32duino#1180

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
fpistm added a commit to fpistm/Arduino_Core_STM32 that referenced this issue Jan 25, 2021
Fix stm32duino#1180

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
fpistm added a commit to fpistm/Arduino_Core_STM32 that referenced this issue Jan 29, 2021
Fix stm32duino#1180

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
fpistm added a commit to fpistm/Arduino_Core_STM32 that referenced this issue Jan 29, 2021
Fix stm32duino#1180

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
fpistm added a commit to fpistm/Arduino_Core_STM32 that referenced this issue Feb 1, 2021
Fix stm32duino#1180

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
fpistm added a commit to fpistm/Arduino_Core_STM32 that referenced this issue Feb 1, 2021
Fix stm32duino#1180

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
fpistm added a commit to fpistm/Arduino_Core_STM32 that referenced this issue Feb 5, 2021
Fix stm32duino#1180

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
fpistm added a commit to fpistm/Arduino_Core_STM32 that referenced this issue Feb 10, 2021
Fix stm32duino#1180

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
fpistm added a commit to fpistm/Arduino_Core_STM32 that referenced this issue Feb 17, 2021
Fix stm32duino#1180

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
fpistm added a commit to fpistm/Arduino_Core_STM32 that referenced this issue Feb 25, 2021
Fix stm32duino#1180

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
fpistm added a commit to fpistm/Arduino_Core_STM32 that referenced this issue Mar 9, 2021
Fix stm32duino#1180

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
fpistm added a commit to fpistm/Arduino_Core_STM32 that referenced this issue Mar 10, 2021
Fix stm32duino#1180

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
valeros pushed a commit to valeros/Arduino_Core_STM32 that referenced this issue Mar 16, 2021
Fix stm32duino#1180

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
fpistm added a commit to fpistm/Arduino_Core_STM32 that referenced this issue Mar 30, 2021
Fix stm32duino#1180

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
fpistm added a commit to fpistm/Arduino_Core_STM32 that referenced this issue Mar 30, 2021
Fix stm32duino#1180

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
@matthijskooijman
Copy link
Contributor

matthijskooijman commented Apr 1, 2021

As a workaround, you can now explicitly disable remapping again by using PA11 and PA12 explicitly. e.g.:

HardwareSerial rfUart(PA10, PA9);

void setup() {
  rfUart.begin(9600);
  pinMode(PA11, INPUT);
  pinMode(PA12, INPUT);
}

Note that this does briefly initialize the UART with remap (so on PA11/PA12), making PA12 output high for a little while.

matthijskooijman added a commit to 3devo/Gp20HopperboardFirmware that referenced this issue Apr 1, 2021
This sets an explicit mode for PA11/PA12 (aux and RTS/DE) to disable the
remapping again. See stm32duino/Arduino_Core_STM32#1180
fpistm added a commit to fpistm/Arduino_Core_STM32 that referenced this issue Apr 2, 2021
Fix stm32duino#1180

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

Successfully merging a pull request may close this issue.

3 participants