Skip to content

Commit

Permalink
Docs: update Zephyr SDK app note
Browse files Browse the repository at this point in the history
  • Loading branch information
josuah committed Dec 9, 2024
1 parent 809e2fe commit 939e415
Showing 1 changed file with 70 additions and 63 deletions.
133 changes: 70 additions & 63 deletions Docs/appnote_zephyr_sdk.md
Original file line number Diff line number Diff line change
@@ -1,103 +1,110 @@
# Zephyr SDK {#appnote_zephyr_sdk}

> The following document describe the current organization with forks
> of Zephyr used by tinyCLUNX33 users.
> This approach has flaws, and is being replaced by the `tinyclunx33_sdk`
> as introduced on @ref appnote_firmware..
[Source](https://github.com/tinyvision-ai-inc/zephyr_private/) |
[Example](https://github.com/tinyvision-ai-inc/tinyclunx33_zephyr_example/) |
[Release](https://github.com/tinyvision-ai-inc/tinyclunx33_zephyr_example/releases/)

On the [RTL Reference Design](rtl_reference_design.md) of the FPGA, there is the a RISC-V soft-CPU integrated.
This allows to run a firmware, and an RTOS such as [Zephyr](https://docs.zephyrproject.org/) with an USB stack and USB drivers.
The firmware is loaded into the flash after the FPGA image, and the RISC-V soft CPU starts it.
<div class="grid">
[Source](https://github.com/tinyvision-ai-inc/tinyvision_zephyr_sdk/)
[Example project](https://github.com/tinyvision-ai-inc/tinyclunx33_zephyr_example/)
[Example binaries](https://github.com/tinyvision-ai-inc/tinyclunx33_zephyr_example/releases/)
</div>

![](images/tinyclunx33_zephyr_architecture.drawio.png)


## Features

- A Driver for Lattice USB23
- The Zephyr USB stack
- An UVC device class
- UART for debug logs over the FTDI (on the devkit)
- I2C control for sensors
- Any other driver alrelady present on Zephyr
- etc. (about anything Zephyr can do)


## Getting started

Follow the Zephyr guide up to the point to build the "blinky" example:
## Repositories

<https://docs.zephyrproject.org/latest/develop/getting_started/index.html>

Follow the extra steps for any tinyCLUNX33 example:
A public **fork of Zephyr** is maintained for contributing patches to the Zephyr Project: the
`usb3` branch contains modifications that are required for the tinyCLUNX33 to work with USB3,
and are in the process of being upstreamed.
For everything else, the upstream Zephyr repository is used unchanged.

<https://github.com/tinyvision-ai-inc/tinyclunx33_zephyr_example/>
- [`zephyr`](https://github.com/tinyvision-ai-inc/zephyr)

Or follow this longer step-by-step guide including both the install of Zephyr tools and the build process.
The **tinyVision Zephyr SDK** contains additional drivers implemented by tinyVision.ai
that are compatible with upstream Zephyr, which will also be upstreamed in the long term.
This allows shipping features long before, without forking the entire Zephyr project.

<https://github.com/tinyvision-ai-inc/tinyclunx33_zephyr_example/blob/main/README.ubuntu.md>
- [`tinyvision_zephyr_sdk`](https://github.com/tinyvision-ai-inc/tinyvision_zephyr_sdk)

The **tinyCLUNX33 Zephyr Example** repository is a starting point for new applications,
and makes use of the tinyVision Zephyr SDK.

## Repositories organization
- [`tinyclunx33_zephyr_example`](https://github.com/tinyvision-ai-inc/tinyclunx33_zephyr_example):

Fork of Zephyr: how our development is organized
The dependencies are managed the
[`west.yml`](https://github.com/tinyvision-ai-inc/tinyclunx33_zephyr_example/blob/main/west.yml)
file.
The example repository contains a `west.yml` that has all the dependencies correctly setup already,
and more can be added for integrating 3rd-party code, or splitting a larger codebase in modules.

- [`zephyr_internal`](https://github.com/tinyvision-ai-inc/zephyr_internal):

where the development happens, the `zephyr_internal` branch acts as a `dev` branch
## Building the firmware

- [`zephyr_private`](https://github.com/tinyvision-ai-inc/zephyr_private):
This guide uses the
[`tinyclunx33_zephyr_example`](https://github.com/tinyvision-ai-inc/tinyclunx33_zephyr_example)
sample application named ``app_imx219``.

releases of the `zephyr_internal` repo, the `zephyr_private` branch acts as a `main` branch.
You can ask the access to it to tinyVision.ai Inc.
First, follow the general Zephyr to setup the build environment for your platform:
<https://docs.zephyrproject.org/latest/develop/getting_started/index.html>

- [`zephyr_public`](https://github.com/tinyvision-ai-inc/zephyr):
Then, download the tinyCLUNX33 Zephyr example repository. This will download the tinyVision Zephyr SDK:

only used for public contributions to Zephyr, and not relevant for using the tinyCLUNX33 at this time.
```console
# Reset the workspace directory you created from Zephyr's Getting Started Guide
cd ~/zephyrproject
rm -rf .west

Example repository: all you need to get started.
# Clone the example repository recursively
west init -m https://github.com/tinyvision-ai-inc/tinyclunx33_zephyr_example
west update
```

- [`tinyclunx33_zephyr_example`](https://github.com/tinyvision-ai-inc/tinyclunx33_zephyr_example):
Then, build a sample application from this example repository, for instance `app_imx219`.
You would have to choose the build target that matches the hardware you have:

the top-level repository that contains the example, and points at the `zephyr_private` repo, downloaded in chain by the
[`west`](https://docs.zephyrproject.org/latest/develop/west/index.html) build tool.
* `tinyclunx33_devkit_rev1` or `tinyclunx33_devkit_rev2` or `custom` *Shield*
* `tinyclunx33@rev1` or `tinyclunx33@rev2` *Board*
* `rtl008` or `rtl009` or `rtl010` or `custom` *SoC* (FPGA image)

For example, this will build a firmware image for the tinyCLUNX33 SoM Rev2 on which the RTL010 was loaded,
assuming that the SoM is attached to the Devkit Rev2:

## Release process
```console
cd ~/zephyrproject/tinyclunx33_zephyr_example/app_imx219//
west build --board tinyclunx33@rev2/rtl010 --shield tinyclunx33_devkit_rev2
```

For transparency, here is how tinyVision.ai performs a new [release](https://github.com/tinyvision-ai-inc/tinyclunx33_zephyr_example/releases/) internally:
Then, program the firmware into the devkit, with the DEBUG interface connected.
The `ecpprog` utility is integrated with `west` and can be called this way:

1. Build and test every example using the `zephyr_internal` repo and `zephyr_internal` branch,
and commit as needed to fix the exapmles.
```console
west flash
```

2. Once all the examples work, run [`blobify.sh`](https://github.com/tinyvision-ai-inc/zephyr_private/blob/zephyr_private/drivers/usb/udc/blobify.sh)
to obfuscate the function names from [`udc_usb23blob.c`](https://github.com/tinyvision-ai-inc/zephyr_internal/blob/zephyr_internal/drivers/usb/udc/udc_usb23blob.c).
See also [SoM Flash](som_flash.md) for other flash programming options.

3. Build any example another time to generate [`udc_usb23blob.c.obj`](https://github.com/tinyvision-ai-inc/zephyr_private/blob/zephyr_private/drivers/usb/udc/udc_usb23blob.c.obj)
and commit it on the `zephyr_internal_blob` branch.

4. Import the content of the `zephyr_internal_blob` branch onto `zephyr_private` with `git checkout zephyr_private` then `git checkout --no-overlay zephyr_internal_blob`.
## Including the SDK into your existing project

5. Remove the `udc_usb23blob.c` file and commit the result into the `zephyr_private` branch,
with a message indicating which commit of `zephyr_internal` this came from.
In case your application was started without using the SDK, you may be interested in adding it as a dependency in
[`west.yml`](https://github.com/tinyvision-ai-inc/tinyclunx33_zephyr_example/blob/main/west.yml),
by adding the following snippet at the bottom of the file:

6. Re-test and re-build each example using the `zephyr_private` branch, and publish the generated files.
```yaml
- name: tinyclunx33_sdk
url: [email protected]:tinyvision-ai-inc/zephyr_internal
revision: tinyclunx33_sdk
```
## Troubleshooting
The first sign of life from the Zephyr RTOS coming from the board will happen over the FTDI UART interface, available by plugging the DEBUG USB cable.

Once a serial console viewer is connected to the second interface (often numbered #1, such as `/dev/ttyUSB1`), logs will be available to review what is going on.
The first sign of life from the Zephyr RTOS comes the UART interface, available by plugging the DEBUG USB cable.
In order to get early boot logs, you can hit the SW2 button which will reset the board but keep the serial console attached.
On the logging interface directly, the Zephyr shell is available with debug commands, except for the Shell example for which it goes over a separate `/dev/ttyACM0`.
Depending on firmware configuration (see `chosen { zephyr,shell-uart = ...; }` property of `build/zephyr/zephyr.dts`),
the Zephyr shell will be available over that same UART interface.
For the Shell example, this goes through the DATA USB port, `/dev/ttyACM0`.

These debug commands permit to review the internal state of the driver using subcommands of `usb23`.
These debug commands permit to review the internal state of the USB peripheral, using subcommands of `dwc3`.

Their usage is described with tab completion.
Interactive help is given by entering the `help dwc3` comand.

0 comments on commit 939e415

Please sign in to comment.