Skip to content

🤖 repo + rp2040 integration with FreeRtos and SysView template.

License

Notifications You must be signed in to change notification settings

MiguelNarv/self-balancing-robot-pico-w

Repository files navigation

Description

The following is a project based on RP2040 Pico W oriented to a self-balancing robot. At this moment a demo is included with 2 tasks alternating LEDs with different periods to test the integration functionality.

LED_PIN_1 connected to pin 22 toggling at 50ms.
LED_PIN_2 connected to pin 24 toggling at 100ms.

pico pinout

Structure

main branch will contain the RP2040 project template for now.
develop branch contains the robot implementation, from there each feature has its own branch. For robot documentation go to My robot Wiki!.

Features

Located under Source/lib to achieve portability, main folder contains .cmakes for configuration of each of them.

Pico C SDK v1.5.1

Contains MCAL libraries for peripherals, CMSIS, among others. See repository for more information.

FreeRTOS v11.0.1

RTOS used for deterministic task operation, critical for target application. See repository for more information.

User configuration can be defined under Source/inc/FreeRTOSConfig.h. Modifications:

  • RP2040.h for CMSIS SytemCoreClock definition.
  • SEGGER_SYSVIEW_FreeRTOS.h required patching.
  • User configurations.

SEGGER SystemView v3.54

Used to analize events timing as well as other cpu properties. See page for more information. Single shot analysis is being used.

Segger SytemView can be decoupled setting SYSVIEW_ENABLED FALSE in CMakeLists.txt file making generated binary smaller.

Modifications:

  • Patching for M0+ according to user manual.

SystemView trace

Notes

  • FreeRtos config is set for 1 core as SystemView doesn't support multi core yet. If you are not interested in SystemView analysis you can set #define configNUMBER_OF_CORES 2 and other configurations accordingly.
  • For SystemView:
    • It is recommended to add SEGGER_SYSVIEW_TickCnt++; at the beggining of xPortSysTickHandler and include #include "SEGGER_SYSVIEW.h" under source\lib\FreeRTOS-Kernel\portable\ThirdParty\GCC\RP2040\port.c. Inaccurate timestamps may be recorded if this patch is not applied.
      Patch available under misc folder.
    • The recording buffer can be modified in SEGGER_SYSVIEW_Conf.h, its size has an impact on your system SRAM.
    • If the number of task, interruptions, timers or their occurences increase in your application, the recording buffer will fill faster. This means that tasks with high period of execution won't be recorded unless you decrease the frequency of configTICK_RATE_HZ or increase the buffer size.
      Error -140 in the application might mean that the buffer overflowed.
    • If tasks are invisible in timeline but visible in trace window go to the last event in timeline and start analysis from there.

Tools

The project is designed to be used with VScode, the following extensions might be needed:

OPENOCD-xpack v0.12.0

Used to debug and flash the target. Portable version installed under tools folder.
See repo for more information about xpack.

The configuration for integration with VScode is defined under .vscode/launch.json, upload and make tasks are defined under .vscode/tasks.json. You can modify those files accordingly.

Additionally you need to define you path to CMake in tasks.json "command", current one might be different from yours.

Any DAPLink debugger can be used, tested with LuatOS debugger.

Debug window

dump_format.py

Creates the .SVDat required to load for SystemView analysis. How to use it:

  1. With cortex-debug extension create a new watch variable called _SEGGER_RTT.
  2. Stop your debug session when you are done with recording, go to _SEGGER_RTT.aUp[1] and copy the address of pBuffer. By default that index will contain the recording, if not replace it with the one that does.
  3. Go to MEMORY tab and create a new view with the pBuffer address.
  4. Copy all the memory view.
  5. Create a .txt and paste it.
  6. Open in a terminal dump_format.py and execute with the following arguments.
    python dump_format.py [TXT PATH - String] [MEMORY OFFSET (0 to 15) - Integer] [LENGHT (pBuffer.WrOff) - Integer]
  7. The .SVDat will be created under the same .txt path.
  8. Open SystemView and load it.

ram_parse.py

Prints RAM blocks and its percentage consumed in the current build.

It is executed by Upload task or Parse RAM task, the script can also be executed from tools folder: python ram_parse.py.

Installation

FreeRTOS and PicoSDK submodules need to be cloned as well, to do that open a git console in the project folder and do:

git submodule update --init --recursive

Alternatively you can checkout other submodule version individually doing:

cd Source/lib/pico-sdk
cd checkout [VERSION]
git submodule update --init --recursive
...
cd Source/lib/FreeRTOS-Kernel
cd checkout [VERSION]
git submodule update --init --recursive

SystemView can be download from this page. Any update or patch on it needs to be done manually.

Use

To flash the code you can run the Upload task in VScode.
To debug you can select the Cortex Debug OPENOCD configuration and click start or press F5.