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

bricks/ev3: New arm none port. #241

Merged
merged 1 commit into from
Mar 22, 2024
Merged

bricks/ev3: New arm none port. #241

merged 1 commit into from
Mar 22, 2024

Conversation

laurensvalk
Copy link
Member

@laurensvalk laurensvalk commented Mar 5, 2024

This adds a new bare arm Pybricks port for EV3 using the same arm-none-eabi makefile used for the other ports.

The goal is to get to a standalone firmware that works just like the Powered Up hubs with Pybricks. This means they can share almost all code except for low-level drivers. So without Linux underneath. And with drivers to make it compatible with WebUSB for compatibility with Pybricks Code for easy use.

If we get that far, it should be easier to maintain this brick just like the other hubs long term, and solve most of the Linux-related issues we currently have such as motor control loop time problems. It also wouldn't require low-capacity microSD cards which are increasingly hard to get.


It boots all the way to MicroPython with standard output over UART on sensor port 1. It has a dummy static program preloaded. The expected output is:

ImportError: no module named 'pybricks.tools'
Traceback (most recent call last):

Which shows that MicroPython is running. Hardware peripherals are not implemented.

Unlike previous nxt and ev3rt ports, this properly starts and runs via pbsys, which means that we could build gradually from here, adding one hardware driver at a time.

To build:

make -C bricks/ev3 -j  uImage

Prepare a microSD card (16 GB or less) and format it as a single FAT32 partition. Then copy the uImage to it.

This should be modified to add a build target for a firmware that can be installed via the EV3 update mode so it can run without a microSD card and installed with a web USB driver via Pybricks Code.


The minimalist linker file and startup.s was inspired by @pepijndevos ' devos.


Inspiration for future hardware implementation:

  • ev3dev: Well documented resources for EV3 on debian Linux.
  • EV3RT: RTOS (not Linux). Closer to the metal, but drivers mixed in with RTOS.
  • am18xlib: Good inspiration for minimal peripheral drivers, including PRU and so on.

This boots all the way up to MicroPython and outputs stdout over UART on sensor port 1.
@coveralls
Copy link

Coverage Status

coverage: 56.126%. remained the same
when pulling af4d6b2 on ev3
into b93a1b6 on master.

@pepijndevos
Copy link
Contributor

Super exciting developments!

@laurensvalk
Copy link
Member Author

For context, we basically "just" need implementations for functions like the following. Likewise for I2C, PWM, and so on.

void pbdrv_uart_set_baud_rate(pbdrv_uart_dev_t *uart, uint32_t baud);
pbio_error_t pbdrv_uart_read_begin(pbdrv_uart_dev_t *uart, uint8_t *msg, uint8_t length, uint32_t timeout);
pbio_error_t pbdrv_uart_read_end(pbdrv_uart_dev_t *uart);

Most higher level protocols like LEGO LPF2, or motor control drivers are already done, because they are almost the same as on the platforms we already have.

Of course, getting these peripherals to work is a bit more involved compared to your average STM32 (some UARTs even require the PRU), but things such as pin configs should be available from the projects linked above. Existing PRU code can probably be used as well.

So hopefully it's quite not as bad as creating an entire new firmware 😄

@winklerp
Copy link

winklerp commented Mar 5, 2024

super exciting! Thank you very much!

@jaguilar
Copy link
Sponsor

This is very exciting. To the extent you need anyone to help beta test, or even if you have small-scoped programming tasks that could be done by someone with limited knowledge of the system, please feel welcome to reach out to me.

@BertLindeman
Copy link
Contributor

I see the assets listed above.
I looked at the LEGO NXT software and the nxt-firmware generated here has no *.rfw file that the nxt software wants to update the firmware.
EV3 wants a *.bin file.

It's probably too soon to try.
That's fine.
If it's time to do some preliminary testing. let me know.

J is so right: exiting!

@jaguilar
Copy link
Sponsor

@BertLindeman I believe the bin files for the PRU are here: https://github.com/mindboards/ev3sources/tree/master/extra/linux-03.20.00.13/pru-firmware-05-31-2011-1423-v3.0/pru/firmware/bin

I'm trying to read and understand what the deal is with these things. As far as I can tell they are similar to the RP2040's programmable IO subsystem -- they're little coprocessors that can run a small instruction set and control IO pins. It looks like one of the purposes of this coprocessor is to implement UART functionality, which requires realtime scheduling, without involving the main CPU.

@BertLindeman
Copy link
Contributor

@BertLindeman I believe the bin files for the PRU are here: https://github.com/mindboards/ev3sources/tree/master/extra/linux-03.20.00.13/pru-firmware-05-31-2011-1423-v3.0/pru/firmware/bin

I'm trying to read and understand what the deal is with these things. As far as I can tell they are similar to the RP2040's programmable IO subsystem -- they're little coprocessors that can run a small instruction set and control IO pins. It looks like one of the purposes of this coprocessor is to implement UART functionality, which requires realtime scheduling, without involving the main CPU.

Thanks, J.
This is (just a bit) beyond my hardware knowledge, Will look into it.
Bert

@laurensvalk laurensvalk merged commit 911cdab into master Mar 22, 2024
38 checks passed
@dlech dlech deleted the ev3 branch March 22, 2024 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants