Page 1 of 1

Using UART4 in PC10 and PC11 pins

Posted: Wed Nov 25, 2020 6:24 pm
by joseaugusto07
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?

Re: Using UART4 in PC10 and PC11 pins

Posted: Thu Nov 26, 2020 11:08 am
by jimmo
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.

Re: Using UART4 in PC10 and PC11 pins

Posted: Thu Nov 26, 2020 2:13 pm
by joseaugusto07
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.

Re: Using UART4 in PC10 and PC11 pins

Posted: Thu Nov 26, 2020 2:23 pm
by dhylands
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.

Re: Using UART4 in PC10 and PC11 pins

Posted: Thu Nov 26, 2020 4:22 pm
by joseaugusto07
Sorry, I'm not experienced with rebuild firmwares in pyboard, can you help me with this? How can I start?

Re: Using UART4 in PC10 and PC11 pins

Posted: Thu Nov 26, 2020 5:29 pm
by dhylands
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)

Re: Using UART4 in PC10 and PC11 pins

Posted: Thu Nov 26, 2020 6:31 pm
by joseaugusto07
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.

Re: Using UART4 in PC10 and PC11 pins

Posted: Thu Nov 26, 2020 8:35 pm
by dhylands
I see a typo in my respone. I entered A0 twice when it should have been one for A0 and one for A1