Skip to content
GCtronic edited this page Sep 25, 2023 · 23 revisions

Firmware

Firmware development

For the firmware development Visual Studio Code is used. Compilation and flashing is done via terminal though.

Frameworks versions

  • esp-adf 2.4
  • esp-idf 4.4.1
  • Micropython 1.20.0

Build (Ubuntu)

  1. Clone the esp-adf repository (that includes esp-idf): git clone --recursive -b release/v2.4 https://github.com/Mobsya/esp-adf.git esp-adf-2.4
  2. Install espressif toolchain:
  • sudo apt-get install git wget flex bison gperf python3 python3-pip python3-setuptools cmake ninja-build ccache libffi-dev libssl-dev dfu-util libusb-1.0-0
  • cd esp-adf-2.4/esp-idf/
  • ./install.sh
  1. Clone the Thymio ESP32 firmware: git clone -b micropython https://github.com/Mobsya/thymio3-firmware-esp32.git thymio3-firmware-esp32_micropython
  2. source /PATH-TO/esp-adf-2.4/esp-idf/export.sh
  3. cd thymio3-firmware-esp32_micropython/
  4. git submodule init
  5. git submodule update
  6. cd components/mp_component/micropython/
  7. make -C mpy-cross
  8. cd ports/esp32
  9. make submodules
  10. change adf_path in CmakeLists.txt in the project root directory
  11. idf.py build (from project root directory)
  12. Flash the firmware: idf.py -p /dev/ttyACM0 flash -b 115200

Last release

STM32

Since it will be rarely upgraded, the default USB DFU mode will be used. The STM32 Cube Programmer application is used to flash the chip. To program the STM32 follows these steps:

  1. download the last firmware STM32 firmware (13.09.23)
  2. enter DFU mode: while robot is on, press on/off button and then quickly the reset button once. The robot seems to be turned off but instead it entered DFU mode.
  3. open STM32 programmer, on the left side select "Erasing and Programming" and browse the "elf" file
  4. on the right side select USB interface, click on refresh icon and a device should be recognized
  5. click on "start programming"
  6. reset the robot

ESP32

The first time the robot must be programmed via USB cable by following these steps:

  1. download the last firmware: bootloader (22.09.23), partition table (22.09.23), ESP32 firmware (22.09.23)
  2. erase the flash: esptool.py -p /dev/ttyACM0 erase_flash
  3. source /PATH-TO/esp-adf-2.4/esp-idf/export.sh
  4. flash the firmware: esptool.py -p /dev/ttyACM0 -b 115200 --before=default_reset --after=hard_reset write_flash --flash_mode dio --flash_freq 80m --flash_size 8MB 0x1000 bootloader.bin 0x10000 thymio3-esp32-firmware.bin 0x8000 partition-table.bin

Also the built-in sound must be programmed once:

  1. download the audio binary data: audio_tone.bin
  2. flash the audio data: esptool.py -p /dev/ttyACM0 -b 115200 --before=default_reset --after=hard_reset write_flash --flash_mode dio --flash_freq 80m --flash_size 8MB 0x780000 audio_tone.bin

The following updates (after the first programming via USB cable) can be done using OTA by following these steps:

  1. download the following files and transfer them to the robot (if not already present): open_url.py, ota32.py, test_ota_dfu.py
  2. configure WiFi with internet access on the robot
  3. run the script test_ota_dfu.py
  4. restart robot

Micropython

Micropython is integrated in the Thymio firmware as esp-idf component.

Micropython library for Thymio

At the moment the library gives complete access to all sensors and actuators, but there is no event implementation yet.

The documentation of the library is available in the following link https://mobsya.github.io/thymio-platform/?path=/docs/thymio-iii-python-library--page.

The library is implemented by extending the ESP32 port (micropython\ports\esp32): two files are added for each sensor/actuator (e.g. thymio_buttons.c and thymio_buttons.h, thymio_imu.c and thymio_imu.h, ...). All these modules are then exported from the main file modthymio.c.

The events will be probably implemented using asnycio.

REPL

REPL is not enabled by default, it must be enabled from the menu:

  1. Turn on the robot and navigate to the REPL menu identified by: RGB LEDs off + front lego LEDs off + first LED on the left turned on for the back lego LEDs. Refer to the modes T3 (state machines) for more information on the menu modes.
  2. Press enter to enter REPL
  3. Open a terminal (e.g. TeraTerm for Windows or Minicom for Linux) and connect to the USB serial port of the robot. You can now interact with REPL, for instance you can run a script by issuing the command from REPL: exec(open("test.py").read())

pyboard.py tool

The following examples make use of the Python script pyboard.py, refer to https://docs.micropython.org/en/latest/reference/pyboard.py.html#pyboard-py.

Transfer files between pc and robot:

  • transfer from pc to robot: pyboard.py --device /dev/ttyACM0 -f cp /PC-path-to-file/test.py :test.py
  • transfer from robot to pc: pyboard.py --device /dev/ttyACM0 -f cp :test.py /PC-path-to-file/test2.py

Others useful commands:

  • list files on robot: pyboard.py --device /dev/ttyACM0 -f ls
  • print content of file on robot: pyboard.py --device /dev/ttyACM0 -f cat boot.py
  • run script on robot from the pc: pyboard.py --device /dev/ttyACM0 /PC-path-to-file/test.py

WiFi configuration

The boot.py script can be used to configure the WiFi connection at boot. Simply put this script on the robot.

You can call directly connect() at the end of the script to automatically connect on boot. Otherwise you can connect manually by issuing: import boot boot.connect()

Aseba

No more supported

Onboard behaviors

Not all behaviors are implemented: attentive, obedient and NN are missing.

Some behaviors need fine tuning.

Refer to the following document for detailed informations https://docs.google.com/presentation/d/11YURm4wyTFIW-WM7v4zo3Jsm14PWats5pz4ayr20tw8/edit?usp=sharing