Skip to content

Add new port to Alif Ensemble MCUs #17050

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

Merged
merged 77 commits into from
Apr 8, 2025
Merged

Conversation

dpgeorge
Copy link
Member

Summary

This PR adds a new alif port with support for Alif Ensemble MCUs; https://alifsemi.com/

Supported features of this port:

  • UART REPL
  • TinyUSB support, for REPL and MSC
  • octal SPI flash support, for filesystem and XIP mode, including ROMFS
  • Pin, ADC, I2C, UART, SPI peripheral support
  • openamp module support for the second HE core
  • networking, cyw43 WiFi and BLE integration

Supported boards:

General notes about the port:

  • it uses make, similar to other bare-metal ports here
  • the toolchain is the standard arm-none-eabi- toolchain
  • flashing a board can be done using either the built-in serial bootloader, or JLink (both supported here)
  • there are two required submodules (one for drivers/SDK, one for security tools), both of which are open source and on GitHub
  • no special hardware or software is needed for development, just a board connected over USB

There are 175 commits in this PR, showing the development history. Some of those should probably be squashed down (a few already have been).

OpenMV have generously sponsored the development of this port.

Testing

Extensive testing has been done during development over the past 15 months. Most of the existing MicroPython test suite passes, including hardware and networking tests. (There are a few anomalies which still need fixing, such as an implementation of RTC.datetime.)

Copy link

codecov bot commented Mar 31, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.54%. Comparing base (91cff8e) to head (037f2da).
Report is 77 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #17050   +/-   ##
=======================================
  Coverage   98.54%   98.54%           
=======================================
  Files         169      169           
  Lines       21890    21890           
=======================================
  Hits        21571    21571           
  Misses        319      319           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

github-actions bot commented Mar 31, 2025

Code size report:

   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

@iabdalkader
Copy link
Contributor

iabdalkader commented Mar 31, 2025

Commits that can be squashed:

  • All changes to board config should be squashed into 2 commits and moved last (I see at least 28 commits).
  • Gradual changes to mpconfigport.h that enable small features and fix for object representation, stack entry size etc.. could just be squashed into the initial port support.
  • USB DCD updates, make USB IRQ handler weak etc.. can be squashed into the initial port.
  • Add IRQ priorities, Lower CSI priority, add pendSV, softtimer etc.. can be squashed into the initial port.
  • Minor Makefile flags fixes (like single precision, arch fix, add deploy-jlink target, fix jlink command. etc..)
  • I see 3-4 machine_spi commits, should probably squash them all with the initial machine_spi support, or at least in one commit. This might be tricky though if the af unit changes were introduced in between.
  • Many commits add new SE service wrappers, I'd squash them, along with small changes to se_services, ex: "Synchronize with SE after initialisation".
  • Open-AMP support, and followup fixes, could be squashed and moved after MPU support.

This should be enough for a first pass, will take another look after these are squashed.

@dpgeorge dpgeorge added the ports Relates to multiple ports, or a new/proposed port label Apr 1, 2025
@kwagyeman
Copy link
Contributor

@dpgeorge - YAY! It's almost merged!

@kwagyeman
Copy link
Contributor

kwagyeman commented Apr 7, 2025

@dpgeorge - Any update on getting this merged?

@iabdalkader
Copy link
Contributor

iabdalkader commented Apr 8, 2025

@dpgeorge I see we're down to 127 commits. Note you could drop some of the commits here if you merge #16848 and rebase.

Also, some more commits could be easily squashed if you like:

Initial port:

pick alif: Add initial port to Alif Ensemble MCUs.
squash alif/tinyusb_port: Add Alif TinyUSB DCD driver.
squash alif/tinyusb_port: Disable USB IRQ on deinit.
squash alif/tinyusb_port: Implement SOF event.
squash alif/mpconfigport: Enable machine.SoftI2C. 
squash alif/mpconfigport: Enable os.sep, os.sync, os.uname.
squash alif/mpconfigport: Enable os.urandom(). 
squash alif/mpconfigport: Enable MICROPY_PY_RANDOM_SEED_INIT_FUNC. 
squash  alif/modalif: Add alif.info() function.
squash  alif/modmachine: Implement machine.unique_id(), fix machine.reset(). 
squash  alif: Update to work with latest DFP 1.2.0. 
squash alif: Enable dupterm. 
squash alif: Define more IRQ priorities.
squash alif/irq.h: Lower CSI priority.
squash alif: Update to work with latest DFP 1.3.0.

Systick:

pick alif/system_tick: Implement system_tick_wfe_with_timeout_us(). 
squash alif/system_tick: Use a UTIMER for system ticks and timing. 

Makefile:

pick alif: Misc Makefile updates and fixes.
squash alif/Makefile: Fix location of output build of alif-dfp files. 
squash alif/Makefile: Rename firmware.toc to firmware_toc.bin.

SE services:

pick alif/se_services: Add SE services interface, with rand64 func.
squash alif/se_services: Add services to reset SoC, get unique-id, dump info.
squash alif: Add more SE service calls, including CPU control services.
squash alif/se_services: SE services initialization race condition.
squash alif/se_services: Add SE select PLL source service call.
squash alif/services: Add off_profile.
squash alif/se_services: Fix UID.

ADC:

pick alif/machine_adc: Add basic ADC support.
squash alif/mcu: Add ADC12 information to pin struct.

@dpgeorge dpgeorge force-pushed the alif-port-add branch 2 times, most recently from b67b57b to 1ed5e01 Compare April 8, 2025 07:21
@dpgeorge
Copy link
Member Author

dpgeorge commented Apr 8, 2025

Thanks @iabdalkader for looking at the commits. It's now down to 88 and I think I've applied almost all your suggestions.

Do you think we can squash down Support building the port for HE or HP or both into the main initial commit Add initial port to Alif Ensemble MCUs.?

@iabdalkader
Copy link
Contributor

iabdalkader commented Apr 8, 2025

I think you should squash these too on initial port or in a single "Add DCD driver" commit.

pick alif/tinyusb_port: Add Alif TinyUSB DCD driver.
squash alif/tinyusb_port: Disable USB IRQ on deinit.
squash alif/tinyusb_port: Implement SOF event.

Note that the second commit just disables USB IRQ in deinit and that all three precede the initial port, which doesn't make sense. Or maybe you want to see changes to the original DCD driver? In this case, should probably move them after initial port?

Could possibly also squash the following on initial port:

alif/mpconfigport: Enable os.urandom(). 
alif/modalif: Add alif.info() function. 
alif/modmachine: Implement machine.unique_id(), fix machine.reset(). 
alif/usbd: Implement proper USB serial number. 

Do you think we can squash down Support building the port for HE or HP or both into the main initial commit Add initial port to Alif Ensemble MCUs.?

Might be tricky, but we could probably squash the following commits:

squash alif: Add ToC config for dual images.
pick alif: Support building the port for HE or HP or both.
squash alif: Support running the port on the HE core.

@iabdalkader
Copy link
Contributor

In any case, I think it's good enough as it is.

@dpgeorge
Copy link
Member Author

dpgeorge commented Apr 8, 2025

Or maybe you want to see changes to the original DCD driver?

Yes, that's the intention. That driver is copied from upstream Alif GitHub and then modified by those two small commits.

I put this before the actual alif port commit because it's like adding the SDK and security toolkit submodules, only they are files rather than submodules. (They could go in lib/alif-tinuysb/* but I think it's simpler to have them live in the alif port directory.)

@dpgeorge
Copy link
Member Author

dpgeorge commented Apr 8, 2025

Could possibly also squash the following on initial port:

alif/mpconfigport: Enable os.urandom(). 
alif/modalif: Add alif.info() function. 
alif/modmachine: Implement machine.unique_id(), fix machine.reset(). 
alif/usbd: Implement proper USB serial number. 

They all rely on adding SE services, which is currently done as a separate commit.

@iabdalkader
Copy link
Contributor

Okay, then this should be good to go.

@dpgeorge
Copy link
Member Author

dpgeorge commented Apr 8, 2025

I now have this down to 76 commits after squashing a few smaller ones that were fixing things.

I also fixed cyw43 BLE on stm32 and mimxrt ports (they will continue to use the old drivers/cyw43/cywbt.c driver until after v1.25.0 is released).

@dpgeorge
Copy link
Member Author

dpgeorge commented Apr 8, 2025

Testing this on OPENMV_AE3, the WiFi cannot connect... not sure exactly what is wrong. It can associated with the AP but sending out a DHCP discover packet the board gets no response.

@dpgeorge
Copy link
Member Author

dpgeorge commented Apr 8, 2025

Testing this on OPENMV_AE3, the WiFi cannot connect... not sure exactly what is wrong. It can associated with the AP but sending out a DHCP discover packet the board gets no response.

I rebooted all the routers here and now it works...! I also tested the OPENMV_AE3 in STA mode connecting to a PYBD in AP mode, and that worked.

So, the WLAN support seems fine.

@iabdalkader
Copy link
Contributor

I tested it, seems to be working fine. However, I noticed this was dropped at some point:

 mp_obj_t machine_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
@@ -279,8 +284,6 @@
     machine_spi_obj_t *self = (machine_spi_obj_t *)self_in;
     // Disable all interrupts.
     spi_mask_interrupts(self->inst);
-    // Disable SCLK clock
-    spi_set_bus_speed(self->inst, 0, self->is_lp ? GetSystemCoreClock() : GetSystemAHBClock());

Not sure if it's important.

@dpgeorge
Copy link
Member Author

dpgeorge commented Apr 8, 2025

However, I noticed this was dropped at some point:

I had to remove that, it was causing a crash when deiniting the SPI due to a divide by zero.

dpgeorge added 4 commits April 8, 2025 23:52
This file is part of the updated cyw43-driver.  It will only be used if
`CYW43_USE_SPI` is enabled.

Signed-off-by: Damien George <damien@micropython.org>
The cyw43-driver now provides the Bluetooth initialisation code, making
`drivers/cyw43/cywbt.c` obsolete.  To use the new code a port must enable
the `CYW43_ENABLE_BLUETOOTH_OVER_UART` option.

Some ports have yet to migrate to the new code, so in the meantime they can
explicitly add the old source to their source list and continue to use it
without change.

Signed-off-by: Damien George <damien@micropython.org>
This word appears in the upcoming alif port.

Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
dpgeorge and others added 21 commits April 9, 2025 00:22
Signed-off-by: Damien George <damien@micropython.org>
This allows HE to execute code from the ROMFS in MRAM.

Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
They will be generated as part of the build.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
Now raises an exception if the pin doesn't support the alternate function
unit number and line type, eg UART0_TX (previously it only checked the
peripheral).

Signed-off-by: Damien George <damien@micropython.org>
It's not needed, the MPU configures the XIP as non-cacheable.

Signed-off-by: Damien George <damien@micropython.org>
To match the instruction length, so the DFS is restored to the XIP value
after an erase or write (due to the final wait WIP).

Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
Signed-off-by: Damien George <damien@micropython.org>
Supports Murata 1YN for WiFi and BLE.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
This test is not intended to be run automatically and does not have a
corresponding .exp file.

Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
@dpgeorge dpgeorge merged commit 037f2da into micropython:master Apr 8, 2025
67 checks passed
@dpgeorge dpgeorge deleted the alif-port-add branch April 8, 2025 14:53
@dpgeorge
Copy link
Member Author

dpgeorge commented Apr 8, 2025

Merged!!

@kwagyeman
Copy link
Contributor

Yay!

@TheKitty
Copy link

TheKitty commented Apr 9, 2025

Congratulations, a wonderful effort & development. We posted about it
https://blog.adafruit.com/2025/04/09/micropythons-new-port-for-the-super-interesting-alif-ensemble-microcontroller/ to celebrate.

@kwagyeman
Copy link
Contributor

kwagyeman commented Apr 9, 2025

Note! This MCU blows others away. You have 11MB of RAM onboard at 3.2GB/s peak speed.

It's truly the first MCU where you can just abuse the heap using MicroPython.

Meaning, you can write code like how you would on the PC.

@mattytrentini
Copy link
Contributor

mattytrentini commented Apr 9, 2025

Note! This MCU blows others away. You have 11MB of RAM onboard at 3.2GB/s peak speed.

I'm really looking forward to experimenting with it! @kwagyeman do you know of any affordable development boards for the micro? I'm only aware of the official E7-based board which is ~$400, a little above the buy-to-experiment cost... (and I'm waiting in anticipation for an AE3!)

[Sorry, this is off-topic but a few folks have asked me the same question.]

@kwagyeman
Copy link
Contributor

We're kinda the first. So, the OpenMV N6 and AE3 Kickstarter is your best bet. We will probably ship the AE3 before December.

https://www.kickstarter.com/projects/openmv/openmv-n6-and-ae3-low-power-python-programmable-ai-cameras

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ports Relates to multiple ports, or a new/proposed port
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants