[STM32F4-discovery] setting UART2 in PD5 and PD6

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
neoclassic
Posts: 8
Joined: Wed Aug 30, 2017 8:58 am

[STM32F4-discovery] setting UART2 in PD5 and PD6

Post by neoclassic » Tue Oct 03, 2017 2:07 pm

Hello all, I'm trying to use REPL in uart2 pin PD5 (TX) and PD6(RX) in the STM32F4-discovery board, with the code below I got the console output (PD5 is transmitting successfully) but I can not enter any command, it looks like PD6 (RX) is not propertly configured.
Cables and boards (I tested two boards) are ok.
I tryed with the two available ports (stm32f4disc-20170526-v1.9 and stm32f4disc-20170108-v1.8.7).
Do you have any idea what it is happening?
when I get the current pin configuration it looks ok:
PD4 Pin(Pin.cpu.D4, mode=Pin.IN)
PD5 Pin(Pin.cpu.D5, mode=Pin.ALT, pull=Pin.PULL_UP, af=Pin.AF7_USART2)
PD6 Pin(Pin.cpu.D6, mode=Pin.ALT, pull=Pin.PULL_UP, af=Pin.AF7_USART2)
PD7 Pin(Pin.cpu.D7, mode=Pin.IN)


Thank you very much.

import pyb
import micropython
import sys

pinD5 = pyb.Pin(pyb.Pin.board.PD5, mode=pyb.Pin.ALT, pull=pyb.Pin.PULL_UP, af=pyb.Pin.AF7_USART2)
pinD6 = pyb.Pin(pyb.Pin.board.PD6, mode=pyb.Pin.ALT, pull=pyb.Pin.PULL_UP, af=pyb.Pin.AF7_USART2)
uart2 = pyb.UART(2,115200)
pyb.repl_uart(uart2)

ajie_dirgantara
Posts: 81
Joined: Fri Sep 02, 2016 9:26 am

Re: [STM32F4-discovery] setting UART2 in PD5 and PD6

Post by ajie_dirgantara » Mon Oct 09, 2017 8:43 am

Most likely the pin PD6 is used as other functtion. maybe you could try to set the REPL in boards\mpconfigboard.h by add the code :

#define MICROPY_HW_UART2_TX (pin_D5)
#define MICROPY_HW_UART2_RX (pin_D6)
#define MICROPY_HW_UART_REPL PYB_UART_2
#define MICROPY_HW_UART_REPL_BAUD 115200

neoclassic
Posts: 8
Joined: Wed Aug 30, 2017 8:58 am

Re: [STM32F4-discovery] setting UART2 in PD5 and PD6

Post by neoclassic » Sun Nov 12, 2017 10:11 pm

Excellent it works!!, right to the point, thank you very much.

Post Reply