Serial Communication

Limited support for STM32F4 Discovery, Nucleo and custom F4 boards
cimd
Posts: 9
Joined: Fri Jul 01, 2016 9:35 pm
Location: Rio de Janeiro

Serial Communication

Postby cimd » Sun Jul 03, 2016 6:52 pm

Serial1 and Serial2 are working ok here, but I'm not getting anything through Serial. I'm using pins PA9 and PA10 for Serial. Isn't that right?
___________________________________________________
Christian D'Aquino

User avatar
martinayotte
Posts: 1145
Joined: Mon Apr 27, 2015 1:45 pm

Re: Serial Communication

Postby martinayotte » Sun Jul 03, 2016 8:07 pm

Yes, in STM32F4/variants/discovery_f407/discovery_f4.h, those are defined as :

Code: Select all

#define BOARD_USART1_TX_PIN     Port2Pin('A', 9)
#define BOARD_USART1_RX_PIN     Port2Pin('A',10)
#define BOARD_USART2_TX_PIN     Port2Pin('A', 2)
#define BOARD_USART2_RX_PIN     Port2Pin('A', 3)
#define BOARD_USART3_TX_PIN     Port2Pin('D', 8)
#define BOARD_USART3_RX_PIN     Port2Pin('D', 9)
#define BOARD_UART4_TX_PIN      Port2Pin('C',10)
#define BOARD_UART4_RX_PIN      Port2Pin('C',11)
#define BOARD_UART5_TX_PIN      Port2Pin('C',12)
#define BOARD_UART5_RX_PIN      Port2Pin('D', 2)


And in the STM32F4/cores/maple/libmaple/HardwareSerial.cpp file, there ports are :

Code: Select all

HardwareSerial Serial(USART1, TX1, RX1);

#ifdef TX2
HardwareSerial Serial1(USART2, TX2, RX2);
#endif

#ifdef TX3
HardwareSerial Serial2(USART3, TX3, RX3);
#endif

#if defined(STM32_HIGH_DENSITY) && !defined(BOARD_maple_RET6)
HardwareSerial Serial3(UART4,  TX4, RX4);
HardwareSerial Serial4(UART5,  TX5, RX5);
#endif


So, I don't know why it is not working for you, in my sketches, they are all working fine.

User avatar
RogerClark
Posts: 5461
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Serial Communication

Postby RogerClark » Sun Jul 03, 2016 10:45 pm

I thought PA9 and PA10 were connected to USB OTG on the 407 discovery

User avatar
martinayotte
Posts: 1145
Joined: Mon Apr 27, 2015 1:45 pm

Re: Serial Communication

Postby martinayotte » Mon Jul 04, 2016 12:35 pm

You are right, Roger, they are connected to VBUS and ID on F407-DISCO.
But on F429-DISCO, they are left free on header, OTG is using PB12-15 instead.

cimd
Posts: 9
Joined: Fri Jul 01, 2016 9:35 pm
Location: Rio de Janeiro

Re: Serial Communication

Postby cimd » Mon Jul 04, 2016 6:14 pm

@Roger, @martinayotte,

Yes, PA9 and PA10 are connected to the USB OTG. But they are also USART1 PINs on the F4-DISCO. Shouldn't they work for serial communication, as long as I'm not using the USB OTG?
___________________________________________________
Christian D'Aquino

User avatar
martinayotte
Posts: 1145
Joined: Mon Apr 27, 2015 1:45 pm

Re: Serial Communication

Postby martinayotte » Mon Jul 04, 2016 6:32 pm

cimd wrote:Shouldn't they work for serial communication, as long as I'm not using the USB OTG?


Of course, as long as you never call USBSerial.begin(), otherwise pins will be switched into USB alternate function.
It is hard to figure out what's happening to you on F407-Disco, since I don't have one.
But on my F429-Disco, if I don't call USBSerial.begin(), the Serial is working nicely.


Return to “STM32F4 Boards”

Who is online

Users browsing this forum: No registered users and 1 guest