Page 1 of 1

UART (Pin Alternate Functions)

Posted: Sat Nov 14, 2020 7:48 pm
by mpython
I am trying to reconfigure UART to new pins on Nucleo F429ZI board.

And followings code doesn't work.
pd0=Pin('D0')
>>> pd1=Pin('D1')
>>> pd0.init(mode=machine.Pin.ALT, alt=machine.Pin.AF7_USART2)
>>> pd1.init(mode=machine.Pin.ALT, alt=machine.Pin.AF7_USART2)
>>> pd1.af()
7
>>> pd0.af()
7
>>> from machine import UART
>>> uart=UART(2,9600)
>>> uart.write ('Ahoj')
4

Where can I found Pin alternate functions for all pins?

Thanks for your response.

Re: UART (Pin Alternate Functions)

Posted: Sun Nov 15, 2020 4:28 am
by jimmo
mpython wrote:
Sat Nov 14, 2020 7:48 pm
I am trying to reconfigure UART to new pins on Nucleo F429ZI board.
This code looks right (although might be worth trying setting the pin AFs after initialising the UART, but I don't think that's it).

One thing to check... these ST Nucleo boards are very confusing because the pins are simultaneously laid out for Arduino, Morpho and ST pin naming.

So when you say "D0", do you mean the "D0" Arduino pin, or PD0 (i.e. port D, pin 0). Looking at pins.csv for this board, it doesn't appear that MicroPython knows about the Arduino names, so I suspect you're getting the latter. However, looking at the datasheet, PD0/PD1 don't have USART2 as alternate functions:
USART2_TX: PA2, PD5
USART2_RX: PA3, PD6

PD6 and PD5 are available on the header, they're shown in the schematic at USART_B_RX/USART_B_TX. PA2 and PA3 are on the morpho connector.

Re: UART (Pin Alternate Functions)

Posted: Wed Nov 18, 2020 8:18 pm
by mpython
OK, I have to really call the stm32 pins.
So, when some pins don't have the alternate function, which is in the: Pin.af_list().
I can't add a new function to the pins?

Re: UART (Pin Alternate Functions)

Posted: Wed Nov 18, 2020 9:03 pm
by dhylands
mpython wrote:
Wed Nov 18, 2020 8:18 pm
OK, I have to really call the stm32 pins.
So, when some pins don't have the alternate function, which is in the: Pin.af_list().
I can't add a new function to the pins?
No. The AF functions are hard-coded in the hardware. You can find the detailed mapping in the datasheet for the particular processor you're using.

For example, with the STM32F405 used in the pyboard: https://www.st.com/resource/en/datasheet/dm00037051.pdf If you look at Tabele 9 (Alternate function mapping) (on page 62) it gives the full alternate functions for each pin.

The Pin.af_list shows a subset of those, as it only shows the af's which are supported. For example you won't see the DCMI pins shown in the af_list for Pin A4 since micropython doesn't currently have any DCMI support.

This file: https://github.com/micropython/micropyt ... 405_af.csv is the actual file that MicroPython uses, and it was extracted from the datasheet. There are occasionally some transcription errors.

This is the list of "supported" peripherals: https://github.com/micropython/micropyt ... ins.py#L11

The make-pins.py parses the _af.csv file aloing with the pins.csv file for a particular board to produce the set of pins and af which can be seen from within micropython.

Re: UART (Pin Alternate Functions)

Posted: Sat Dec 05, 2020 10:59 pm
by mpython
Thank you for your response.
Now I can write to UART, but not read. Where could be the problem?

Code: Select all

>>> from machine import UART
>>> uart=UART(2,9600)
>>> uart.write ('444')
3
>>> response=uart.read(5)
>>> print (response)
None