STM32F407Disc : Not able to use UART1

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
Post Reply
nikhiledutech
Posts: 118
Joined: Wed Dec 27, 2017 8:52 am

STM32F407Disc : Not able to use UART1

Post by nikhiledutech » Wed Jan 03, 2018 10:48 am

Hey,
So i am using STM32Fdisc board. I wanted to use UART1 on my board.
I run the test script for checking UART
for bus in (-1, 0, 1, 2, 3, 4, 5, 6, 7, "XA", "XB", "YA", "YB", "Z"):
try:
UART(bus, 9600)
print("UART", bus)
except ValueError:
print("ValueError", bus)
And here is what i get:
Error -1
Error 0
Error 1
UART(2, baudrate=9600, bits=8, parity=None, stop=1, timeout=1000, timeout_char=3, read_buf_len=64)
UART 2
UART(3, baudrate=9600, bits=8, parity=None, stop=1, timeout=1000, timeout_char=3, read_buf_len=64)
UART 3
Error 4
Error 5
UART(6, baudrate=9600, bits=8, parity=None, stop=1, timeout=1000, timeout_char=3, read_buf_len=64)
UART 6
It gives me Error for UART1 too, which i don't think should happen. USART1 Tx & Rx pins are on PB7 & PB8. And also the example given in the test file are using UART1.

Here is some of the method available in example file.
uart = UART(1)
uart = UART(1, 9600)
uart = UART(1, 9600, bits=8, parity=None, stop=1)
print(uart)
So if they are able to use UART1, why I am not able to use UART1 ? Or is their any other way to use UART1 ?

SpotlightKid
Posts: 380
Joined: Wed Apr 08, 2015 5:19 am

Re: STM32F407Disc : Not able to use UART1

Post by SpotlightKid » Wed Jan 03, 2018 1:44 pm

The examples in the docs are for the pyboard, which has a different layout than the STM32F4DISCOVERY. For the latter UART 1 is disabled. The board configuration header has a comment as to why that is:

Code: Select all

// UART config
#if 0
// A9 is used for USB VBUS detect, and A10 is used for USB_FS_ID.
// UART1 is also on PB6/7 but PB6 is tied to the Audio SCL line.
// Without board modifications, this makes UART1 unusable on this board.
#define MICROPY_HW_UART1_TX     (pin_A9)
#define MICROPY_HW_UART1_RX     (pin_A10)
#endif

nikhiledutech
Posts: 118
Joined: Wed Dec 27, 2017 8:52 am

Re: STM32F407Disc : Not able to use UART1

Post by nikhiledutech » Thu Jan 04, 2018 10:56 am

Okay. So can't i modify and use different pins for USB_Vbus_detect and USB_FS_ID ? Or is their any way of using UART1 ?

SpotlightKid
Posts: 380
Joined: Wed Apr 08, 2015 5:19 am

Re: STM32F407Disc : Not able to use UART1

Post by SpotlightKid » Thu Jan 04, 2018 1:03 pm

If you don't use USB and/or the audio DAC, I think you should be able to use UART1 safely. Uncomment the MICROPY_HW_UART1_* defines and re-compile the firmware. I haven't tested this myself, though, do so at your own risk.

nikhiledutech
Posts: 118
Joined: Wed Dec 27, 2017 8:52 am

Re: STM32F407Disc : Not able to use UART1

Post by nikhiledutech » Fri Jan 05, 2018 4:54 am

Thanks. But i wanted to know is their any functions available by which, I can redefine pins ?

User avatar
dhylands
Posts: 3202
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: STM32F407Disc : Not able to use UART1

Post by dhylands » Fri Jan 05, 2018 2:42 pm

The default pins associated with a particular UART are controlled by the #defined in the mpconfigboard.h for the board.

If UART 1 was defined to use pins A9/A10, then you could make the UART show up on PB6/PB7 by initializing the PB6/7 pins using the appropriate alternate function.

Which pins UART1_TX or UART1_RX can show up on is limited by the hardware. See the datasheet:
http://www.st.com/content/ccc/resource/ ... 037051.pdf
The alternate function map is on pages 62-70. If you search for USART1_TX or USART1_RX

For pin PA9 in column AF7 you'll see USART1_TX
For pin PA10 in column AF7 you'll see USART1_RX
For pin PB6 in column AF7 you'll see USART1_TX
For pin PB7 in column AF7 you'll see USART1_RX

Those are the only pins that USART1 TX/RX can appear on.

This thread: viewtopic.php?f=3&t=3173&p=23604 discusses how you can control the alternate function that appears on a pin, and how to examine how the pin is currently configured.

nikhiledutech
Posts: 118
Joined: Wed Dec 27, 2017 8:52 am

Re: STM32F407Disc : Not able to use UART1

Post by nikhiledutech » Sat Jan 06, 2018 5:10 am

Okay, so i need to define UART1 Tx and Rx on alternate pins PB6 & PB7 in mpconfigboard.h file of the board and recompile it.
Because at present UART1 is commented in the file.

Or
I can just un-comment the UART1, and define its pins in my programs .

User avatar
dhylands
Posts: 3202
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: STM32F407Disc : Not able to use UART1

Post by dhylands » Sat Jan 06, 2018 6:05 am

Correct to both

nikhiledutech
Posts: 118
Joined: Wed Dec 27, 2017 8:52 am

Re: STM32F407Disc : Not able to use UART1

Post by nikhiledutech » Sat Jan 06, 2018 10:47 am

Okay thanks :)

Post Reply