Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UART does not return to REPL #70

Closed
microbit-mark opened this issue Mar 24, 2021 · 7 comments
Closed

UART does not return to REPL #70

microbit-mark opened this issue Mar 24, 2021 · 7 comments
Labels
Milestone

Comments

@microbit-mark
Copy link

microbit-mark commented Mar 24, 2021

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
Copy link
Contributor

microbit-carlos commented Mar 24, 2021

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:

microbit_hal_uart_init(tx, rx, args[ARG_baudrate].u_int,
args[ARG_bits].u_int, parity, args[ARG_stop].u_int);

int microbit_hal_uart_init(int tx, int rx, int baudrate, int bits, int parity, int stop) {
// TODO set bits, parity stop
int ret = uBit.serial.redirect(*pin_obj[tx], *pin_obj[rx]);
if (ret != DEVICE_OK) {
return ret;
}
ret = uBit.serial.setBaud(baudrate);
if (ret != DEVICE_OK) {
return ret;
}
return 0;
}

@martinwork
Copy link
Collaborator

Created lancaster-university/codal-microbit-v2#92

@microbit-carlos
Copy link
Contributor

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

@martinwork
Copy link
Collaborator

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

@dpgeorge
Copy link
Collaborator

dpgeorge commented May 3, 2021

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

@microbit-mark
Copy link
Author

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
Copy link
Collaborator

Fixed by 291e05c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants