Zephyr support for Ambiq Apollo4 Plus

Published: October 17th, 2023

The Zephyr Project counts most of the major MCU manufacturers among its members, and its vendor-neutral nature is one of its many strengths, requiring systematic solutions to common problems and preventing overfitting to a single use case. As a Platinum member of the project, Antmicro works with customers including product makers, hyperscalers and silicon vendors to get the best of the structuredness and configurability of Zephyr to support their device families and configurations.

One of our latest Zephyr porting projects involved adding Zephyr support for the Ambiq Apollo4 Plus, an ARM® Cortex®-M4 based SoC with a built-in GPU targeted for wearables and smart devices from the Austin-based SoC vendor. This note will discuss the work done to port the RTOS to this new target including using Renode to make the process smoother, as well as show how structured data for the SoC and Evaluation Kit added in the Zephyr porting process can be represented visually in Antmicro’s Visual System Desiger.

Zephyr support for Ambiq Apollo4 Plus

Initial support, licensing, and drivers

While in some sense this was a clean slate project as no prior support for the Apollo platforms existed in Zephyr, Ambiq did want to use parts of their existing SDK as a Hardware Abstraction Layer (HAL) to align with their other software offerings. To address this requirement while keeping things simple, we based the Ambiq HAL in Zephyr on a stripped down version of the Ambiq SDK which only includes the elements needed for low-level hardware access.

As part of the usual due diligence, Antmicro also worked with Ambiq to make sure all their HAL code is licensed on the OSI-approved 3-Clause BSD License, as required by Zephyr.

With the HAL prepared and properly licensed, we were able to add initial support for the Apollo4 Plus SoC and its Apollo4P EVB evaluation board by submitting a PR adding:

  • The new Ambiq HAL module
  • Ambiq Apollo4 Plus SoC support
  • Ambiq Apollo4P EVB board support
  • Ambiq System Timer (STIMER) driver
  • Changes to PL011 UART driver to support the Apollo4 Plus variant

A multi-step, incremental approach is always recommended when upstreaming new code to Zephyr to ease the burden on the maintainers and minimize the amount of back-and-forth (which can still be considerable for new ports, given that multiple aspects like the ones listed above need to be addressed at once).

After some rounds of feedback and the required TSC vote around adding a new HAL, this initial support allowed us to start upstreaming drivers specific to the Apollo4 Plus platform. There are several useful I/O peripherals and features that were added:

  • Counter driver
  • Watchdog driver
  • I2C driver
  • SPI driver
  • GPIO driver
  • MSPI - Multibit SPI
  • Shield support, e.g. Ambiq’s dedicated AMAP4PDISP Display Shield

Apollo4 Plus Evaluation Kit and Display Shield Visualization

As is fairly common in various silicon implementations, SPI and I2C controllers on the Apollo4 Plus SoC are handled by generic Input/Output Master Modules (IOMs), where the user chooses the interface they want to enable by using a respective compatible string in the device tree.

From other interesting implementation details, since the Ambiq Apollo4 Plus GPIO has a single, 128-pin port, while the Zephyr GPIO API limits the number of pins per port to 32, we needed to introduce a workaround where we virtually group the physical pins in sets of 32. This limitation results in slightly larger overhead when controlling the pins (using a 4 x 32-bit value instead of a single 128-bit one) but should not impact the GPIO functionality in any way.

With sensible support for the Apollo4 now in Zephyr and given the chip’s extensive I/O list, it will be interesting to see (based on real-world usage) what Ambiq’s customers will request next, and whether new chip families from the vendor can be enabled soon.

Early SW development and automated testing in Renode

Porting to new hardware can be a cumbersome process - before the initial version starts working, you don’t have much introspection into what is happening, and logging may not be possible yet. Despite best intentions, it’s hard to avoid a waterfall-like methodology since you must properly solve system initialization before you can proceed to write drivers. Limited access to hardware, especially for new platforms, can also make it difficult to collaborate between multiple developers and set up a CI-based flow.

Using Renode to simulate your early port addresses these limitations as it lets you automatically test new implementations in CI, look up the state of the entire system, and easily share development environments across teams. Support Ambiq Apollo 4 SoCs in Renode has been available for some time now, as we have added it as part of another customer project, even before the release of the SoC itself.

Zephyr’s integrations with Renode Robot Framework tests and Renode let you create complex, real-world test cases and avoid regressions while you’re building up your port.

To get started with the port without having to source Ambiq’s hardware, you can run the commands below to install Renode and simulate Apollo4 Plus with the Zephyr shell submodule, letting you access the RTOS’s console:

pip3 install --user --upgrade git+https://github.com/antmicro/renode-run.git
renode-run demo -b apollo4p_evb shell_module

To find more demos, you can head to the Apollo4 Plus Evaluation Board’s Renodepedia page. Renodepedia lets you run boards supported in Renode in simulation and launch several demos for each of them. You can run the available demos locally in Renode or in Google Colab, see real UART output, view build artifacts, execution traces and cross-reference Zephyr drivers and Renode models for specific I/O and sensors.

To explore the landscape of devices supported in Zephyr RTOS, you can head on to the Renode Zephyr Dashboard and see over 290 boards working in simulation.

Apollo4 Plus Evaluation Kit and Display Shield in Visual System Designer

Drawing upon the data structures created as part of the Zephyr port, and building on Antmicro’s open source component database, a natural consequence was including the board in Antmicro’s Visual System Designer .

The Designer is a tool allowing you to develop block diagrams of embedded systems, including both completely new hardware concepts and remixes of existing boards. To start from the Ambiq devkit, open its representation in the Designer and see for yourself.

A photorealistic 3D render of the Evaluation Kit and Display Shield (seen above) as well as an interactive block diagram of the board, provides you with links to components’ pages in Renodepedia and Antmicro’s Open Hardware Portal and even lets you play around and experiment with altering connections and peripherals.

Apollo4 Plus Evaluation Kit and Display Shield in VSD

Antmicro for your porting needs

Bringing OS support to new hardware is one of the core services in Antmicro’s offering. The knowledge and experience of working with Zephyr RTOS and the capabilities unlocked by using Renode for deterministic simulation make Antmicro the go-to address for porting the RTOS to your silicon and for development of Zephyr code for real-life products. Our broad open hardware and components database together with the methodology based on Visual System Designer and other tools lets us rapidly develop complete new products for our customers.

If you’d like to learn about the possibilities Zephyr and Renode can open for your projects based on platforms such as Ambiq Apollo 4 Plus, reach out at contact@antmicro.com.

Go back