No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Thomas Buck 53fe41b308 test for can bus hardware 8 months ago
..
can2040 @ 9e761ae353 test for can bus hardware 8 months ago
include test for can bus hardware 8 months ago
pico-sdk @ 6a7db34ff6 start work on firmware 8 months ago
pico-ssd1306 @ 607fe1cc3c detect if OLED is plugged in 8 months ago
src test for can bus hardware 8 months ago
.clangd clean up firmware skeleton 8 months ago
.gitignore start work on firmware 8 months ago
CMakeLists.txt test for can bus hardware 8 months ago
README.md test for can bus hardware 8 months ago
debug.sh start work on firmware 8 months ago
debug_swd.sh start work on firmware 8 months ago
flash.sh start work on firmware 8 months ago
flash_swd.sh start work on firmware 8 months ago

README.md

Dispensy Firmware

TODO

Quick Start

When compiling for the first time, check out the required git submodules.

git submodule update --init
cd pico-sdk
git submodule update --init

Then do this to build.

mkdir build
cmake -B build
make -C build -j4

And flash the resulting dispensy.uf2 file to your Pico as usual.

For convenience you can use the included flash.sh, as long as you flashed the binary manually once before.

make -C build -j4
./flash.sh build/dispensy.uf2

This will use the mass storage bootloader to upload a new uf2 image.

For old-school debugging a serial port will be presented by the firmware. Open it using eg. picocom, or with the included debug.sh script.

For dependencies to compile, on Arch install these.

sudo pacman -S arm-none-eabi-gcc arm-none-eabi-newlib picocom cmake cxxtest

Sniffing the CAN Bus

Using a USB CAN adapter that is supported in Linux, like the UCAN, you can easily interact with the CAN bus.

You need to install the can-utils in your Linux distro.

After plugging the adapter in, bring up the CAN network interface and dump all received packets:

sudo ip link set can0 type can bitrate 1000000
sudo ip link set up can0
candump can0

Proper Debugging

You can also use the SWD interface for proper hardware debugging.

This follows the instructions from the RP2040 Getting Started document from chapter 5 and 6.

For ease of reading the disassembly, create a debug build.

mkdir build_debug
cmake -B build_debug -DCMAKE_BUILD_TYPE=Debug
make -C build -j4

You need a hardware SWD probe. This can be made from another Pico, see Appendix A in the document linked above. For this you need to compile the picoprobe firmware, like this.

git clone https://github.com/raspberrypi/picoprobe.git
cd picoprobe

git submodule update --init
mkdir build
cd build

PICO_SDK_PATH=../../../pico-sdk cmake ..
make -j4

cd ../.. # back to build_debug directory from before

And flash the resulting picoprobe.uf2 to your probe. Connect GP2 of the probe to SWCLK of the target and GP3 of the probe to SWDIO of the target. Of course you also need to connect GND between both.

You need some dependencies, mainly gdb-multiarch and the RP2040 fork of OpenOCD.

sudo apt install gdb-multiarch   # Debian / Ubuntu
sudo pacman -S arm-none-eabi-gdb # Arch Linux

git clone https://github.com/raspberrypi/openocd.git --branch rp2040 --recursive --depth=1
cd openocd

# install udev rules
sudo cp contrib/60-openocd.rules /etc/udev/rules.d
sudo udevadm control --reload-rules && sudo udevadm trigger

./bootstrap
./configure --enable-ftdi --enable-sysfsgpio --enable-bcm2835gpio
make -j4

cd .. # back to build_debug directory from before

Now we can flash a firmware image via OpenOCD.

./openocd/src/openocd -s openocd/tcl -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000" -c "cmsis_dap_vid_pid 0x2e8a 0x000c" -c "program gadget.elf verify reset exit"

And also start a GDB debugging session.

./openocd/src/openocd -s openocd/tcl -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000" -c "cmsis_dap_vid_pid 0x2e8a 0x000c"
arm-none-eabi-gdb gadget.elf
target extended-remote localhost:3333

load # program elf into flash
monitor reset init # put into clean initial state
continue # start program

These commands have also been put in the flash_swd.sh and debug_swd.sh scripts, respectively. They require the build_debug folder where you checked out and built OpenOCD. Here are some general GDB tips.