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.
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!.
Located under Source/lib to achieve portability, main folder contains .cmakes for configuration of each of them.
Contains MCAL libraries for peripherals, CMSIS, among others. See repository for more information.
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.
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.
- 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.
- It is recommended to add
The project is designed to be used with VScode, the following extensions might be needed:
-
C/C++
Id: ms-vscode.cpptools Description: C/C++ IntelliSense, debugging, and code browsing. Version: 1.19.9 Publisher: Microsoft VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools
-
CMake
Name: CMake Tools Id: ms-vscode.cmake-tools Description: Extended CMake support in Visual Studio Code Version: 1.17.17 Publisher: Microsoft VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ms-vscode.cmake-tools
-
Cortex-Debug
Name: Cortex-Debug Id: marus25.cortex-debug Description: ARM Cortex-M GDB Debugger support for VSCode Version: 1.12.1 Publisher: marus25 VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=marus25.cortex-debug
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.
Creates the .SVDat required to load for SystemView analysis. How to use it:
- With cortex-debug extension create a new watch variable called _SEGGER_RTT.
- 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.
- Go to MEMORY tab and create a new view with the pBuffer address.
- Copy all the memory view.
- Create a .txt and paste it.
- 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]
- The .SVDat will be created under the same .txt path.
- Open SystemView and load it.
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
.
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.
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.