microbit-foundation / micropython-microbit-v2

Temporary home for MicroPython for micro:bit v2 as we stablise it before pushing upstream
MIT License
42 stars 23 forks source link

UART does not return to REPL #70

Closed microbit-mark closed 3 years ago

microbit-mark commented 3 years ago

micro:bit support: 44148

from microbit import *
def uart_test():
    uart.init(baudrate=115200,tx=pin0,rx=pin1)
    display.scroll("UART")
    uart.init(baudrate=115200)
    return ('done son')

On v1 program displays 'UART' and returns the string 'done son' in the REPL

on V2 program displays 'UART' but does not return the string 'done son' in the REPL

Tested in https://python.microbit.org/v/beta

Flash the script then open a serial connection. Call the uart_test() function

>>>print(uart_test())

Notice the program works as expected on V1 but hangs V2.

Clicking on on send CTRC-C or CTRL-D does not reset the REPL

microbit-carlos commented 3 years ago

Removing the display.scroll() and the function shows the same issue:

from microbit import *

print("this prints normally")
sleep(1000)
uart.init(baudrate=115200,tx=pin0,rx=pin1)
print("this goes to the edge connector pins")
sleep(1000)
uart.init(baudrate=115200)
print("this doesn't print on serial")
sleep(1000)

I can replicate this as well in MakeCode (the stable deployment with CODAL 0.2.25):

serial.writeLine("this prints normally")
basic.pause(1000)
serial.redirect(SerialPin.P0, SerialPin.P1, BaudRate.BaudRate115200)
serial.writeLine("this goes to the edge connector pins")
basic.pause(1000)
serial.redirect(SerialPin.USB_TX, SerialPin.USB_RX, BaudRate.BaudRate115200)
serial.writeLine("this doesn't print on serial")
basic.pause(1000)

@martinwork could you try to create a test in C++ to see if this is reproducible in the CODAL side?

If a normal call to uBit.serial.redirect() with the edge connector pins, and then with the internal pins doesn't work we can try to replicate the MicroPython uart.init call:

https://github.com/microbit-foundation/micropython-microbit-v2/blob/e0f3e60c5e7755eb71c789b3a765d271320b2e17/src/codal_port/microbit_uart.c#L86-L87 https://github.com/microbit-foundation/micropython-microbit-v2/blob/b7a76e449cf1b437972c21efaf468fbe5891c6a2/src/codal_app/microbithal.cpp#L210-L221

martinwork commented 3 years ago

Created https://github.com/lancaster-university/codal-microbit-v2/issues/92

microbit-carlos commented 3 years ago

@martinwork thanks for looking into this! Is PR https://github.com/lancaster-university/codal-nrf52/pull/31 the only thing pending for this being fixed in CODAL, or are there more?

martinwork commented 3 years ago

@microbit-carlos I believe that PR on its own should fix this issue, but I haven't tested it in a micropython build.

dpgeorge commented 3 years ago

This is now waiting on a tag in codal-microbit-v2

microbit-mark commented 3 years ago

Latest tagged release is in https://github.com/lancaster-university/codal-microbit-v2/releases/tag/v0.2.26 which I think should resolve this issue.

dpgeorge commented 3 years ago

Fixed by 291e05c8440de4e90dcf1f443136d2b7005272a1