Page 1 of 2

STM32G070KB support

Posted: Sat Jan 30, 2021 5:06 pm
by msadeghz
Hi there,
I have created new variant for stm32g070kb chip and I have checked the blink test and it's working find.
I wanted to test the communications like uart, as a default interface called Serial.
but I don't see anything on Uart1 tx pin, and software serial is not working at all.
which parts should I check to debug the problem?

Re: STM32G070KB support

Posted: Sat Jan 30, 2021 6:25 pm
by fpiSTM
How did you define the serial in your variant.h?

Re: STM32G070KB support

Posted: Sat Jan 30, 2021 7:43 pm
by msadeghz
you can find the attached image,
I put uart1 pins for tx and rx, as I set them in peripheralPins.h file.

Re: STM32G070KB support

Posted: Sat Jan 30, 2021 7:45 pm
by msadeghz
I don't what is SERIAL_UART_INSTANCE meaning?
how can I use other uarts?

Re: STM32G070KB support

Posted: Sat Jan 30, 2021 7:54 pm
by fpiSTM
See the wiki😉

Re: STM32G070KB support

Posted: Sun Jan 31, 2021 11:11 am
by msadeghz
I have seen and do anything said in wiki, I can program blink and it works.

Re: STM32G070KB support

Posted: Sun Jan 31, 2021 1:06 pm
by msadeghz
fpiSTM wrote: ↑Sat Jan 30, 2021 7:54 pmSee the wiki😉
I have enabled uarts by HAL_UART_MODULE_ENABLED macro and use Serial.begin(115200) to use uart1, but I haven't anything on uart1_tx
for test I have commented usart1 pins in variant.h and periphaeralpins.h files, but arduino IDE doesn't get error and compile successfully!

part of variant.h:

Code: Select all

// Default pin used for 'Serial' instance (ex: ST-Link)
// Mandatory for Firmata
//#define PIN_SERIAL_RX           PA10
//#define PIN_SERIAL_TX           PA9
part of peripheralpins.h:

Code: Select all

#ifdef HAL_UART_MODULE_ENABLED
WEAK const PinMap PinMap_UART_TX[] = {
  {PA_0,  USART4,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF4_USART4)},
  {PA_2,  USART2,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_USART2)},
  {PA_5,  USART3,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF4_USART3)},
//  {PA_9,  USART1,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_USART1)},
  {PA_14, USART2,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_USART2)},
  {PB_2,  USART3,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF4_USART3)},
 // {PB_6,  USART1,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF0_USART1)},
  {PB_8,  USART3,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF4_USART3)},
  {NC,    NP,    0}
};
#endif

#ifdef HAL_UART_MODULE_ENABLED
WEAK const PinMap PinMap_UART_RX[] = {
  {PA_1,  USART4,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF4_USART4)},
  {PA_3,  USART2,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_USART2)},
 // {PA_10, USART1,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_USART1)},
  {PA_15, USART2,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_USART2)},
  {PB_0,  USART3,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF4_USART3)},
 // {PB_7,  USART1,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF0_USART1)},
  {PB_9,  USART3,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF4_USART3)},
  {NC,    NP,    0}
};
#endif
I have checked that

Code: Select all

HAVE_HWSERIAL1
is defined.

Code: Select all

#include "HardwareSerial.h"

void setup()
{

  Serial1.begin(115200);
  pinMode(LED_RED,OUTPUT);
  pinMode(LED_GREEN,OUTPUT);
}


void loop()
{
  Serial1.println("Reading");
  
  #if defined(HAVE_HWSERIAL1)
  digitalWrite(LED_RED,1);
  #else
  digitalWrite(LED_GREEN,0);
  #endif
  delay(500);
  #if defined(HAVE_HWSERIAL1)
  digitalWrite(LED_RED,0);
  #else
  digitalWrite(LED_GREEN,1);
  #endif
  delay(500);
}
I did all steps based on wiki.

Re: STM32G070KB support

Posted: Sun Jan 31, 2021 1:38 pm
by fpiSTM

Code: Select all

SERIAL_UART_INSTANCE  
is the number of the USART instance. In that case USART1.
The Serial naming is explained in the Wiki:
https://github.com/stm32duino/wiki/wiki ... wareserial
The STM32 MCU's have several U(S)ART peripherals. By convenience, the U(S)ARTx number is used to define the Serialxinstance:

Serial1 for USART1
Serial2 for USART2
Serial3 for USART3
Serial4 for UART4
... For LPUART1 this is SerialLP1

By default, only one Serialx instance is available mapped to the generic Serial name.
Serial is only a define to the Serial1 instance.

Then you can define the default pins to use for the default generic Serial instance.

Code: Select all

#define PIN_SERIAL_RX           PA10
#define PIN_SERIAL_TX           PA9
If you do not define those pins then the first pin found in the PinMap_UART_RX/TX arrays for USART1 will be used.
In your PeripheralPins.c (and not .h) you have commented those pins so it could not be initialized....
msadeghz wrote: ↑Sat Jan 30, 2021 7:45 pm how can I use other uarts?
As said it is in the Wiki:
https://github.com/stm32duino/wiki/wiki ... wareserial

Honestly, I know it works as I've already tested the Nucleo G070 when user raises an issue with the LPTIM2 IRQ handler error.
So, you probably made a mistake in your variant.
Note that in the next core release the way to create a variant will be different and easier as a default generic variant is generated (only linker script and system core clock config will have to be added).

Re: STM32G070KB support

Posted: Sun Jan 31, 2021 1:48 pm
by msadeghz
fpiSTM wrote: ↑Sun Jan 31, 2021 1:38 pm

Code: Select all

SERIAL_UART_INSTANCE  
is the number of the USART instance. In that case USART1.
The Serial naming is explained in the Wiki:
https://github.com/stm32duino/wiki/wiki ... wareserial
The STM32 MCU's have several U(S)ART peripherals. By convenience, the U(S)ARTx number is used to define the Serialxinstance:

Serial1 for USART1
Serial2 for USART2
Serial3 for USART3
Serial4 for UART4
... For LPUART1 this is SerialLP1

By default, only one Serialx instance is available mapped to the generic Serial name.
Serial is only a define to the Serial1 instance.

Then you can define the default pins to use for the default generic Serial instance.

Code: Select all

#define PIN_SERIAL_RX           PA10
#define PIN_SERIAL_TX           PA9
If you do not define those pins then the first pin found in the PinMap_UART_RX/TX arrays for USART1 will be used.
In your PeripheralPins.c (and not .h) you have commented those pins so it could not be initialized....
msadeghz wrote: ↑Sat Jan 30, 2021 7:45 pm how can I use other uarts?
As said it is in the Wiki:
https://github.com/stm32duino/wiki/wiki ... wareserial

Honestly, I know it works as I've already tested the Nucleo G070 when user raises an issue with the LPTIM2 IRQ handler error.
So, you probably made a mistake in your variant.
Note that in the next core release the way to create a variant will be different and easier as a default generic variant is generated (only linker script and system core clock config will have to be added).
thank you for response,
can you say how can I define stm32 pins to arduino pins in variant.h file?
I think the mistake is related to define PA9 and PA10 in variant.h.

Re: STM32G070KB support

Posted: Sun Jan 31, 2021 1:51 pm
by fpiSTM
Ahah! I've just remember why it does not work with USART1. ;)
This is linked to the pin used: PA9/PA10.
On G0 those pins could be remapped on PA11/PA12.

https://github.com/stm32duino/Arduino_C ... ssues/1180

This will be fixed in the next core release. As a workaround, simply comments the code described here:
https://github.com/stm32duino/Arduino_C ... -696617262