Giter Site home page Giter Site logo

cogip / mcu-firmware Goto Github PK

View Code? Open in Web Editor NEW
6.0 5.0 1.0 39.76 MB

Robotics firmware based on RIOT-OS

Home Page: https://cogip.github.io/mcu-firmware

License: GNU Lesser General Public License v2.1

Makefile 0.95% C 18.69% Shell 0.61% C++ 79.65% PHP 0.02% Dockerfile 0.08%
riot-os

mcu-firmware's Introduction

 ██████╗ ██████╗  ██████╗ ██╗██████╗
██╔════╝██╔═══██╗██╔════╝ ██║██╔══██╗
██║     ██║   ██║██║  ███╗██║██████╔╝
██║     ██║   ██║██║   ██║██║██╔═══╝
╚██████╗╚██████╔╝╚██████╔╝██║██║
 ╚═════╝ ╚═════╝  ╚═════╝ ╚═╝╚═╝

MCU firmware

This repository contains firmware source code of Cogip robot for Eurobot, French robotic contest. Its firmware intends to run on stm32f4xx MCU family and rely on RIOT-OS.

As this firmware and RIOT-OS are both evolving, two git repositories lives next to each other, and both are required to generate the firwmare binaries.

Build status

Build Status

Environment setup

Cloning repositories

$ git clone https://github.com/cogip/RIOT.git -b cogip_master
$ git clone https://github.com/cogip/mcu-firmware.git

Requirements

Toolchain

To install toolchain and development on ubuntu 20.04:

$ sudo apt install build-essential gcc-multilib g++-multilib openocd

Minimal gcc version: 8.1

To manually install arm-none-eabi toolchain:

$ mkdir ~/toolchain/
$ cd ~/toolchain/
$ wget https://developer.arm.com/-/media/Files/downloads/gnu-rm/8-2018q4/gcc-arm-none-eabi-8-2018-q4-major-linux.tar.bz2
$ tar xf gcc-arm-none-eabi-8-2018-q4-major-linux.tar.bz2

Edit ~/.bashrc file and add $HOME/toolchain/gcc-arm-none-eabi-8-2018-q4-major/bin/ to $PATH variable:

PATH=${PATH}:$HOME/toolchain/gcc-arm-none-eabi-8-2018-q4-major/bin/

Quilt

Quilt is a tool to manage large sets of patches by keeping track of the changes each patch makes. It is used to apply patches on RIOT-OS

$ sudo apt install quilt

cqfd (for native architecture only)

Cqfd wraps commands to run them inside the Docker container using your host current user. It can be configured with some pre defined commands called flavors and it can produce release artifacts.

To install cqfd:

git clone [email protected]:savoirfairelinux/cqfd.git
cd cqfd/
sudo make install

For more information: cqfd repository

Python Virtual Environment

$ sudo apt install  python3-pip python3-venv
$ python3 -m venv venv
$ source venv/bin/activate
$ pip install -r mcu-firmware/requirements.txt

Apply RIOT-OS patches

Prior to any build, apply RIOT-OS patches

make riot-patches

Simulation target (x86_64 architecture)

Assuming the platform is pf_test and the application is app_test

Build

Build one application with default board

$ make -j$(nproc) -C applications/<application_name>

Build one application with an other board

$ make -j$(nproc) BOARD=<board_name> -C applications/<application_name>

Using cqfd

Init cqfd docker image

This command has to be done once per project:

$ cqfd init

Launch the build using a flavor

$ cqfd -b app_test-native

Build and launch in debugger (only for native cpu architecture)

$ make -j$(nproc) BOARD=<board_name> -C applications/<application_name> all-debug
$ ddd applications/<application_name>/bin/<board_name>/<binary>.elf

Build and flash (only for real board, not native based)

Make sure JTAG programmer is plugged on target board.

$ make -j$(nproc) BOARD=<board_name> -C applications/<application_name> flash

Start ddd on a gdbserver's target

$ make DBG=ddd DBG_FLAGS='--debugger "${GDB} ${DBG_DEFAULT_FLAGS}"' debug

Then, inside DDD application, in gdb prompt, type

target remote localhost:3333

To debug specific function, type

list <functionname>

General build targets

Build all applications on all boards

$ make

Clean all platforms

$ make clean

Distclean all platforms

$ make distclean

Generate doc in various formats

$ make doc docman doclatex

Clean doc

$ make docclean

Run uncrustify to check coding rules

$ make check-codingrules

mcu-firmware's People

Contributors

dependabot[bot] avatar ecourtois avatar gdoffe avatar kheprys avatar yanok35 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

jhaand

mcu-firmware's Issues

Add support for actuators and remote control using PB messages

Add C++ classes to represent servomotors and vacuum pumps.
Initialize all actuators.
Define PB messages to send actuators state to Copilot.
Define PB messages to receive actuator commands from Copilot.
Create a thread to send actuators state.
Add uartpb handlers for actuator commands.

speed_order variable is not contained in the controller object

pose_t pose_order; /**< Position order */
pose_t pose_current; /**< Current position */
polar_t* speed_order; /**< Speed order to reach the position */
polar_t speed_current; /**< Current speed reaching the position */

The "speed_order" member variable has been designed to be private one. It's content should not be modified outside the object, asynchronously, without passing by relevant accessor.

sys: uartpb: use a unique ID to identify each Protobuf message

Using a unique ID for each Protobuf message allows libraries/applications defining these messages to register a callback function associated with each ID. This way, uartpb is not dependent of applications anymore, which had to declare a Protobuf message gathering all known Protobuf messages.

This unique ID will be sent first, followed by encoded Protobuf message. The unique id can also be sent alone if the message does not required any content (like a reset or trigger message).

Add RIOT patching mechanism

Sometimes RIOT needs to be patched, mainly to temporary fix a bug.
To avoids maintaining our own RIOT-OS fork, we prefer to add few patches to mcu-firmware and stay aligned on RIOT mainline repository.

2023 post cup cleanup

Add following improvments:

  • rework motor_driver
  • make pegasus and cup2023 applications working with native architecture
  • bump RIOT version to 2023.07
  • improve RIOT patches
  • various small fixes

Bad array for PCA9548_NUMOF

In platform.h:

#define PCA9548_NUMOF (sizeof(motor_driver_config) / sizeof(motor_driver_config[0]))

uses motor_driver_config array instead of pca9845_config

Rework controller changes

Changes of controller implies duplicating all the quadpid controller chains which is overkill regarding the changes.
Simplify code to be able to only change a part of the controllers chain.

Create global Makefile.dep

Several USEMODULE and FEATURES_REQUIRED are set inside the Makefile.include.
They should be moved inside a Makefile.dep dedicated file.

Makefile race condition on embedded proto

When make -j is used to build all applications and examples, each embedded-application uses the same build directory to build packages leading to race conditions.

Add module providing logging features

A log module is required to properly handle:

  • debug messages, that can be disabled at compile time,
  • warning/error messages,
  • log messages, that could also be sent to the Copilot.

This will also replace COGIP_DEBUG_COUT macro.

Update EmbeddedProto to version 3.0

From EmbeddedProto README:

What is new in version 3.0.0

The most notable improvements in this version are:

  • The length of repeated, string and bytes fields can now be set from the .proto file. You can find information on how to this in the online documentation.
  • The ram size of messages has been reduced. This was done by using less polymorphism in the low level field classes. This required upgrading to C++17 and up.
  • In a .proto file it is now possible to use a message or enum before it is defined. The plugin will make a dependency tree of the messages and enums defined and sort them before generating the source code. Recursive inclusion are not supported.
  • Some of the message functions changed. The functions where already marked as deprecated in the latest 2.X.X release.

boards: cogip-native: mallinfo2 is not supported on Ubuntu 20.04

With the introduction of sys/sysmon in a previous release (c1ed38b), applications/examples does not compile anymore with cogip-native board.
It is due to the use of mallinfo2 which was introduced in glibc 2.33, but Ubuntu 20.04 uses glibc 2.31.

In file included from <command-line>:
mcu-firmware/boards/cogip-native/board_init.c: In function 'board_init':
mcu-firmware/examples/sys_sysmon/bin/cogip-native/riotbuild/riotbuild.h:14:25: error: variable 'minfo' has initializer but incomplete type
   14 | #define MALLINFO struct mallinfo2
      |                         ^~~~~~~~~
mcu-firmware/boards/cogip-native/board_init.c:44:5: note: in expansion of macro 'MALLINFO'
   44 |     MALLINFO minfo = MALLINFO_FUNC();
      |     ^~~~~~~~
mcu-firmware/examples/sys_sysmon/bin/cogip-native/riotbuild/riotbuild.h:15:25: error: implicit declaration of function 'mallinfo2'; did you mean 'mallinfo'? [-Werror=implicit-function-declaration]
   15 | #define MALLINFO_FUNC() mallinfo2()
      |                         ^~~~~~~~~
mcu-firmware/boards/cogip-native/board_init.c:44:22: note: in expansion of macro 'MALLINFO_FUNC'
   44 |     MALLINFO minfo = MALLINFO_FUNC();
      |                      ^~~~~~~~~~~~~
mcu-firmware/boards/cogip-native/board_init.c:44:14: error: storage size of 'minfo' isn't known
   44 |     MALLINFO minfo = MALLINFO_FUNC();
      |              ^~~~~
mcu-firmware/boards/cogip-native/board_init.c:44:14: error: unused variable 'minfo' [-Werror=unused-variable]
cc1: all warnings being treated as errors

Functions printing JSON are broken

With introduction of COGIP_DEBUG_COUT macro that automatically adds a new line at the end, the functions printing JSON are broken since there are new lines added in the middle of the messages.

Possible fixes:

  • remove those functions that are not used anymore (but could be useful for debug)
  • implement a log module to handle info/log/error/debug messages
  • remove the new line from the macro

Use ztimer instead of xtimer

The ztimer implementation is the new timer implementation in RIOT-OS.
Thus migrates to ztimer before xtimer becomes deprecated 1.
Moreover this commit is removing all cpp11-compat timer API calls,
replacing them by ztimer low level API.
Also a global clean of timer use is done.

Remove tracefd module

tracefd was used to save logs on SD card or to print datas in json format on serial link for RPi communication.
However uartpb is now used for communication and we do not use SD Card any more, thus remove this module and clean all modules/code using it.

Migrate Lidar from STM32 to Raspberry Pi

Connect the Lidar to Raspberry Pi instead of STM32.
Obstacles list is received from Copilot through Protobuf messages.

This is a very first step of migration path planning and actions from STM32 to Raspberry Pi.

Add new module canpb

This module is used for communication inside the robot, like for uartpb, but on CAN bus.

applications: compilation fails after cleaning of board-native

Since cleaning of board cogip-native in commit 6d48a4a, applications does not compile anymore:

mcu-firmware/platforms/pf_test/platform.cpp: In function ‘void pf_init()’:
mcu-firmware/platforms/pf_test/platform.cpp:310:19: error: ‘GPIO_DEBUG_LED’ was not declared in this scope
  310 |     if (gpio_init(GPIO_DEBUG_LED, GPIO_OUT)) {
      |                   ^~~~~~~~~~~~~~
/mcu-firmware/platforms/pf_test/platform.cpp:313:16: error: ‘GPIO_DEBUG_LED’ was not declared in this scope
  313 |     gpio_clear(GPIO_DEBUG_LED);
      |                ^~~~~~~~~~~~~~

After commenting out this code, there is a link error:

/usr/bin/ld: mcu-firmware/applications/app_test/bin/cogip-native/native_drivers/native-qdec.o: in function `native_motor_driver_qdec_simulation':
RIOT/boards/native/drivers/native-qdec.c:30: multiple definition of `native_motor_driver_qdec_simulation'; mcu-firmware/applications/app_test/bin/cogip-native/board/board.o:/home/eric/cogip/simulation/submodules/mcu-firmware/boards/cogip-native/board.c:32: first defined here
collect2: error: ld returned 1 exit status
make: *** [mcu-firmware/../RIOT//Makefile.include:728: mcu-firmware/applications/app_test/bin/cogip-native/app_test.elf] Error 1

CI: add compilation with native boards

CI compiles applications and examples only for the default board defined in the Makefile.
But almost all applications/examples can be compile with native or cogip-native boards, and this is not part of the CI.

Add static analysis for C++ files

Actual tools/check-codingrules.sh script does not check *.cpp and *.hpp files.
Use cppcheck to analye both C and C++ files, and fix related warnings.

riot patches distclean fails

$ make riot-patches 
Application de  drivers/motor_driver: rework driver
Application de  boards/native: clean motor_driver old configuration
Application de  boards/nucleo64: clean motor_driver old configuration
Application de  tests/drivers/motor_driver: rework test
Application de  cpu/native/periph/qdec: remove useless loop
Application de  drivers: pca9685: fix missing (void *) cast
Application de  cpu/native: return 0 for all gpio_init*() calls
Application de  cpu/native: make GPIO_PIN available to gpio_mock
Application de  drivers/pcf857x: fix returns on void functions
$ make distclean-riot-patches 
fatal: argument '~10' ambigu : révision inconnue ou chemin inexistant.
Utilisez '--' pour séparer les chemins des révisions, comme ceci :
'git <commande> [<révision>...] -- [<chemin>...]'
make: *** [/simulation/submodules/mcu-firmware/makefiles/riot-patches.mk.inc:17 : distclean-riot-patches] Erreur 128

Use fixed size strings and containers, remove dynamic allocation

Remove dynamic memory allocation to have a better control of memory usage.

This task will be split in sub-tasks for each modules:

Dynamic allocation

  • sys/shell_menu: #89
  • sys/uartpb
  • sys/wizard
  • applications (obstacles, samples, ...)
  • std::function => etl::delegate
  • platforms (dynamic obstacles)

Fixed-size containers

  • lib/cogip_defs/Polygon
  • lib/obstacles
  • lib/path
  • lib/avoidance
  • applications (obstacles, samples, ...)
  • strings

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.