Using USART1 on the STM32F4Discovery

While it was very good of ST to make the fantastically inexpensive and versatile STM32F4Discovery board, they have made things a little difficult in the choice of peripherals in places.

I use the board as a test bed for my micromouse code. All the micromouse peripherals are wired up to some perfboard that also holds the STM32F4Discovery. The drivers for everything on the mouse can easily be tested and I can experiment with different user interfaces, motor PWM schemes and sensor combinations. All without putting my mouse board at risk.

Generally, this works fine but, for compatibility with my STM32F103 code, I chose to use USART1 as the main serial terminal on the mouse. The STM32f4Discovery schematic shows that the default pin for serial TX on this USART is PA9. That is connected to an LED and a 4.7uF capacitor (C49). The pin is used for the VBUS line on the USB OTG port. The capacitor means that the pin is essentially incapable fo doing any useful serial speed at all.

STM32F4 USB OTG Schematic

Since I have no interest in using the USB OTG functions, I simply desoldered the capacitor. Actually, I stood it up on one end so that I could put it back if ever I had a change of heart.

A further look at the schematic shows that pin PC0 is used to enable the STMPS2141 power switch. This will place 5V on the PA9 serial line whenever PC0 is set low. A zero Ohm resistor connects PC0 to the enable line of this switch so I stood that on end as well.

Finally, the LED (LD7) is lit when PA9 is high. However, the base of the driver transistor is not held low so the LED does not turn off reliably. There are pads available on the board to fit a suitable resistor as R57. I chose a 22k resistor so that 3V on PA9 would be enough to turn on the LED but anything less than about 2V would not.

Now I get good serial data out of USART1 and I don’t have to worry about 5V appearing on the line when PC0 is changed. As a bonus, I get the LED (LD7 at the bottom of the board) telling me when there is activity on the PA9 line. The TX line will idle high so the LED is on most of the time.

 

Incoming search terms:

  • stm32f4discovery usart (13)
  • stm32f4 project (10)
  • yhs-fh_lsonsw (7)
  • STM32F4 USB OTG schematic (3)
  • stm32f4 usart example (3)
  • freertos stm32f4 uart (3)
  • usart1 stm32f4 (2)
  • STM32F4 USART1 (2)
  • STM32F4 Discovery USART dma (1)
  • uart example with stm32f4 discovery (1)
This entry was posted in Hardware, STM32 and tagged , , , . Bookmark the permalink.

3 Responses to Using USART1 on the STM32F4Discovery

  1. Green says:

    I agree with you that STM32F4 eval uses PA9 for some other purpose. Alternatively we can still use PB6 and PB7 to remap USART1_TX and USART1_RX if we only want to redirect printf() to USART1. Beisdes, other USART ports are available as well except the max baud rate will be lower than USART1. I guess the setting are all similar.
    PB6 is connected to Audio.shDoc however the pin is still available to use for remap.

  2. Peter Harrison says:

    All true. There are plenty of other ports. However, I want to be able to run the same code on both the mouse and the STM32F4Discovery without worrying that I have the correct configuration.

    I have a great fear of putting the wrong code in a mouse at competition. I hope the last time it happened will really be the last time.

  3. Green says:

    oh yeah, ST should really free the PA9 and PA10 on their next possible version of eval board. PB6 PB7 are time will likely occupied by encoder or motor on the mouse.

Leave a Reply