|
reactor-uc 0.1
|
![]()
This is a project template for developing applications targeting the Raspberry Pi Pico using the micro-C target of Lingua Franca.
You must use one of the following operating systems:
Linux Officially supported are Debian & UbuntumacOSYour system must have the following software packages (you likely have at least some of these already):
git — a distributed version control systemjava — Java 17REACTOR_UC_PATH environment variable pointing to it.This template uses reactor-uc, the "micro C" target for Lingua Franca. Clone this repo with one of the following commands:
And make sure that the REACTOR_UC_PATH environment variable is pointing to it.
Create a new repository based on this template, clone it recursively to your local machine and enter the directory from your favourite shell.
Install a toolchain by following this instruction: https://www.lf-lang.org/embedded-lab/Non-Nix.html#install-cmake-standard-c-library-arm-cross-compiler
Install the picotool as describer here: https://www.lf-lang.org/embedded-lab/Non-Nix.html#install-picotool
Make sure that the pico-sdk submodule is initialized:
These instructions can also support the Pico 2 and Pico 2 W, which use the RP2350. Ensure that the environment variables are set correctly (e.g., export PICO_BOARD=pico2_w; export PICO_PLATFORM=rp2350 to accomodate the Pico 2 W).
In this template we have integrated the Lingua Franca compiler lfc into the CMake. To build an application, first configure the project using
This step will invoke lfc on the main LF application (src/Blink.lf by default) and create the build directory populated with build files.
Next, compile the application with
which will create build/Blink.elf.
To rebuild the application simply repeat the last command
If CMake detects any changes to any files found in src/*.lf the configure step will be rerun.
Before flashing the binary to your rp2040 based board, the board must be placed into BOOTSEL mode. On a Raspberry Pi Pico this can be entered by holding the RESET button while connecting the board to the host device. Run picotool help for more information on its capabilities.
Run the following to flash an application binary on to your board.
To change build parameters, such as which LF application to build or the log level, we recommend that you modify the corresponding variable at the top of the CMakeLists.txt. Alternatively, you can override the variables from the command line.
To delete all build artifacts both from CMake and LFC do:
When using the Windows Subsystem for Linux on a windows machine for development, there are a few extra steps to attach the device to your wsl instance. The official instructions are reflected here. Install the required software and execute the following.
Open a powershell prompt as an administrator.
Note the busid of either the RP2040 board or pico-probe that is trying to be mounted to the instance. These boards will likely show as either USB Mass Storage Device, RP2 Boot when connected in bootsel mode or as a USB Serial Device of some type when connected and hosting a USB stdio application. Attach the device using the following command.
This wil mount the device to the wsl instance while removing access to the device from the windows instance. In a wsl shell check the device has been attached. After this is confirmed, copy the rp2040 udev rules and hotplug restart udev.
To debug applications for RP2040 based boards, there exists a nice tool called picoprobe. This applications allows a Raspberry Pi Pico or RP2040 board to act as a cmsis-dap device which interacts with the target device cortex cores through a serial wire debug(swd) pin interface connection.
To get started, you'll need a secondary RP2040 based board and will need to flash the picoprobe binarieslinked here. The page contains pre-built firmware packages that can be flashed using picotool or copied to a bootsel mounted board.
Once the probe device is prepared, wire it up to the target device as follows. The following is an example of a pico to pico connection and the pin numbers will differ from board to board.
UART0 is the default uart peripheral used for stdio when uart is enabled for stdio in cmake. The target board uart is passed through the probe and can be accessed as usual using a serial port communication program on the host device connected to the probe.
Open On-Chip Debugger is a program that runs on host machines called a debug translator It understands the swd protocol and is able to communicate with the probe device while exposing a local debug server for GDB to attach to.
After wiring, run the following command to flash a test binary of your choice
The above will specify the
cmsis-daprp2040-c flag will directly run open ocd commands used to configure the flash operation.adapter speed 5000 makes the transaction fasterprogram <binary>.elf specifies the elf binary to load into flash memory. These binaries specify the areas of where different parts of the program are loaded and the sizes.verify reads the flash and checks against the binaryreset places the mcu in a clean initial stateexit disconnects openocd and the program will start to run on the boardThe gnu debugger is an open source program for stepping through application code. Here we use the remote target feature to connect to the exposed debug server provided by openocd.
Make sure the intended program to be debugged on the target device has an accessible .elf binary that was built using the Debug option. To specify this property in an LF program, add the following to the program header:
First start openocd using the following command
In a separate terminal window, run the following GDB session providing the elf binary. Since this binary was built using the Debug directive, it will include a symbol table that will be used for setting up breakpoints in gdb.
Once the GDB environment is opened, connect to the debug server using the following. Each core exposes its own port but core0 which runs the main thread exposes 3333.
From this point onwards normal gdb functionality such as breakpoints, stack traces and register analysis can be accessed through various gdb commands.