Using UART4 in PC10 and PC11 pins

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
joseaugusto07
Posts: 4
Joined: Fri Jul 17, 2020 6:40 pm

Using UART4 in PC10 and PC11 pins

Post by joseaugusto07 » Wed Nov 25, 2020 6:24 pm

Hi, the PCB that was made in my project (PCB with a STM32F405 with some complements to use in other purposes), i have two UART's connected:

-UART3 in pins PB10 and PB11 (Y9, Y10)
-UART4 in pins PC10 and PC11 (SDIO_D2, SDIO_D3)

But after the PCB was made we notice the USART3 in PC10 and PC11 besides the dedicated pins to uSD. And now I'm stucked with that problem. Can I use the pins PC10 and PC11 in UART mode?

User avatar
jimmo
Posts: 2244
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Using UART4 in PC10 and PC11 pins

Post by jimmo » Thu Nov 26, 2020 11:08 am

joseaugusto07 wrote:
Wed Nov 25, 2020 6:24 pm
But after the PCB was made we notice the USART3 in PC10 and PC11 besides the dedicated pins to uSD. And now I'm stucked with that problem. Can I use the pins PC10 and PC11 in UART mode?
Sorry I'm not quite sure what you're asking.

Yes, PC10 and PC11 can be set to alternate function for USART3 TX/RX, or for UART4 TX/RX.

joseaugusto07
Posts: 4
Joined: Fri Jul 17, 2020 6:40 pm

Re: Using UART4 in PC10 and PC11 pins

Post by joseaugusto07 » Thu Nov 26, 2020 2:13 pm

Ok, sorry if I don't explicited what I'm need. How can I set these pins to work with uart4 (in my script), I tried to initialize in "normal way" with pyb.UART(4,115200), but din't worked.

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

Re: Using UART4 in PC10 and PC11 pins

Post by dhylands » Thu Nov 26, 2020 2:23 pm

When you use

Code: Select all

pyb.UART(4,115200)
then it will use the pins configured in the mpconfigboard.h file for your board.

For example, the pyboard is configured to use A0 and A1 for UART4: https://github.com/micropython/micropyt ... .h#L41-L42

If you want to use pins PC10/PC11 then you can either update mpconfigboard.h for your board and rebuild the firmware, or you can modify your script to fiddle with the AF stuff.

joseaugusto07
Posts: 4
Joined: Fri Jul 17, 2020 6:40 pm

Re: Using UART4 in PC10 and PC11 pins

Post by joseaugusto07 » Thu Nov 26, 2020 4:22 pm

Sorry, I'm not experienced with rebuild firmwares in pyboard, can you help me with this? How can I start?

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

Re: Using UART4 in PC10 and PC11 pins

Post by dhylands » Thu Nov 26, 2020 5:29 pm

The README.md here: https://github.com/micropython/micropyt ... orts/stm32 (you need to scroll down past the file list to see it) has build instructions.

To change things in python, you'd do something like this:

Code: Select all

uart = pyb.UART(4,115200)
# Switch A0/A1 back to GPIO inputs (after opening UART)
a0 = pyb.Pin('A0', mode = pyb.Pin.IN)
a1 = pyb.Pin('A0', mode = pyb.Pin.IN)
# Switch C10/C11 to be UART4
txPin = pyb.Pin('C10', mode=pyb.Pin.AF_PP, pull=pyb.Pin.PULL_NONE, af=pyb.Pin.AF8_UART4)
rxPin = pyb.Pin('C11', mode=pyb.Pin.AF_PP, pull=pyb.Pin.PULL_NONE, af=pyb.Pin.AF8_UART4)

joseaugusto07
Posts: 4
Joined: Fri Jul 17, 2020 6:40 pm

Re: Using UART4 in PC10 and PC11 pins

Post by joseaugusto07 » Thu Nov 26, 2020 6:31 pm

dhylands wrote:
Thu Nov 26, 2020 5:29 pm
The README.md here: https://github.com/micropython/micropyt ... orts/stm32 (you need to scroll down past the file list to see it) has build instructions.

To change things in python, you'd do something like this:

Code: Select all

uart = pyb.UART(4,115200)
# Switch A0/A1 back to GPIO inputs (after opening UART)
a0 = pyb.Pin('A0', mode = pyb.Pin.IN)
a1 = pyb.Pin('A0', mode = pyb.Pin.IN)
# Switch C10/C11 to be UART4
txPin = pyb.Pin('C10', mode=pyb.Pin.AF_PP, pull=pyb.Pin.PULL_NONE, af=pyb.Pin.AF8_UART4)
rxPin = pyb.Pin('C11', mode=pyb.Pin.AF_PP, pull=pyb.Pin.PULL_NONE, af=pyb.Pin.AF8_UART4)
Thanks! I will use the python method for now (to continue the project) but I will try to rebuild firmware in in parallel.

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

Re: Using UART4 in PC10 and PC11 pins

Post by dhylands » Thu Nov 26, 2020 8:35 pm

I see a typo in my respone. I entered A0 twice when it should have been one for A0 and one for A1

Post Reply