Robot Information

https://github.com/RoboTeamTwente/roboteam_microcontroller6.0

This section contains all the information with regards to the embedded systems implementation on the robot. As can be read in the Electronics section, our robots make use of STM32 chips. These we program with the help of STMCubeMX, which helps us to do all the pin-initialization. Additionally this program allows us to use the HAL Library, provided by STM. This library allows us to easily interact with the micro controller itself. All of our code is written in Embedded C.

Currently there are 4 different PCBs

Besides these PCBs there is also a general folder which contains function that are used by all of the micro controllers or all of the micro controllers of the same model. Some things that can be found in this folder are

  • Utils, like functions to set a GPIO pin and more
  • REM, used as part of the protocol for sending messages over UART to a pc or laptop.
  • logging.c/.h contains functions to send messages over UART. Used for debugging
  • Microcontroller Communication Protocol, used for communication between the PCBs on the robot

File Structure roboteam_microcontroller6.0

  • CompilerFlags.py Python script which is called at the start of compilation. It adds flags and environmental variables.
  • platformio.ini PlatformIO file, describing the project files, target platform, compiler flags, and more.
  • *.ioc STM32CubeMX files which holds all CPU configurations for every board (GPIO pins, timers, SPI/I2C/UART, etc)
  • Core
    • Inc Contains all the header files and thus the documentation strings that are present in the code.
    • Src Contains the implementations of all of the header files

In the code we use the HAL_getTick(); function to get the current time in ms. Since this value is updated by an interrupt itself, it is not completely accurate. During the testing we observed that this value is updated every 1.04 ms.

All boards have a watchdog timer. On the boards with the STM32F303K8 microcontroller it works as follows.

In STM32CubeMx activate IWDG. To have a watchdog of roughly 250ms the prescaler needs to be 64 and the down-counter reload value 156. The prescaler of 64 is chosen because it has a range from 1.6ms to 6553.6ms (see datasheet table 56). The reload value can be calculated with the formula found in IWDG and WWDG in STM32. A small adjustment needs to be made because the IWDG on the F303 is 40kHz (datasheet page 25) instead of 32kHz, so replace 32000 by 40000. After generating the code HAL_IWDG_Refresh(&hiwdg); can be called in the loop the make sure the timer doesn't reach 0.

Platformio is the extention used for uploading code on the robot. In the bottom of Visual Studio Code the environment can be selected. In our case the environment is which board you want to upload to. Due to the way it is setup platformio finds the right files that need to be uploaded. When adding new folders the build_src_filter and build_flags might need to be adjusted.

Platformio makes use of openOCD. With our code the most recent version gave some trouble, namely that the code seemed to be too big for the flash size, whilst it didn't take up more than 50% of the flash size. To still be able to upload our code version 11 of openOCD needs to be used. It automatically downloads this version. If you already had openOCD you either need to adjust the platformio.ini file or delete all versions of openOCD from your device.