Page 1 of 1

b-g431b-esc1 and Serial2 RX

Posted: Thu Dec 03, 2020 1:37 pm
by owennewo
I'm in the process of adding the b-g431b-esc1 disco done kit to stm32duino, PR here:
https://github.com/stm32duino/Arduino_C ... 1236/files

The new variant mostly works but I'm having trouble with Serial2 RX. I'm not sure if it is a hardware fault / soldering fault / or pin setup fault.

I have an ftdi / usb dongle connectd to PB4 (RX) and PB3 (TX) (which matches pins in disco https://www.st.com/resource/en/user_man ... ronics.pdf)

Serial2.print() works. Serial.read() does not. I'm not suprised read does not work because when I attach an oscilloscope to PB4 I can see this feeble attempt at going LOW when I press a character on my computer serial monitor:
usart_rx.png
usart_rx.png (78.89 KiB) Viewed 5776 times
When I detach PB4 from ftdi it has no problems going low. It feels like PB4 has a massive pullup that the FTDI can't defeat.
Code is embarasingly simple:

Code: Select all

#include <Arduino.h>

void setup() {
  Serial.begin(9600);
  delay(1000);
  Serial.println("starting");
}

void loop() {
  delay(20);
  Serial.print(".");
  if (Serial.available()) {
    Serial.print("+");
    Serial.println(Serial.read());
  }
}
Which prints

Code: Select all

Starting
.......
TLDR: Why is RX not going low when attached to b-g431b-esc1 disco board

Re: b-g431b-esc1 and Serial2 RX

Posted: Thu Dec 03, 2020 2:44 pm
by fpiSTM
You can try to change the PU mode.
By default, in the PeripheralPins.c U(S)ART pin are set to PULL UP:

Code: Select all

   {PB_4,  USART2,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)}, 
For testeing you can change to GPIO_NOPULL.

Re: b-g431b-esc1 and Serial2 RX

Posted: Thu Dec 03, 2020 3:03 pm
by mlundin
On this board the USART2_TX and USART2_RX are connected to the ST_LINK as long as the daughterboard is connected. Take a look at Fig 18 in the documentation. This means that your FTDI board is battling the ST_LINK when trying to pull the RX signal low.

Serial should work through STLink if your project set U(S)ART support enabled (generic Serial).

Re: b-g431b-esc1 and Serial2 RX

Posted: Thu Dec 03, 2020 3:37 pm
by owennewo
@mlundin - thankyou, thankyou, thankyou!

So that daughterboard TX is connected to mainboard RX and was holding high. Makes sense.

For some reason I'd given up on using the USB for printf - but it seems to work! I'll be putting my ftdi back in the draw and using USB.

For completeness here are the platformio flags

Code: Select all

[env:disco_b_g431b_esc1]
platform = ststm32
board = disco_b_g431b_esc1
framework = arduino
monitor_speed = 9600
; monitor_port = /dev/ttyUSB0
debug_init_break =
lib_archive = no
build_flags =
    -D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
    -D PIO_FRAMEWORK_ARDUINO_NANOLIB_FLOAT_PRINTF
    -D PIO_FRAMEWORK_ARDUINO_USB_HIGHSPEED_FULLMODE

Re: b-g431b-esc1 and Serial2 RX

Posted: Thu Dec 03, 2020 4:42 pm
by fpiSTM
Arf! Nice catch it is a well known mistake :)