EPuck2 Communicating with the EPuck2 - EPFL-MICRO-315/TPs-Wiki GitHub Wiki
⚠ wiki page used in TP Intro and TP3
🖧 Communication related components
- The EPuck2's Block diagram with communication-related components highlighted
- Structure of connections and protocols involving these communication-related components
- What is connected to the USB Hub (say a computer) will see at most 3 different communication ports:
- By Bluetooth it is also possible to have access up to 3 COM ports, in this course we will only be interested by UART one in
TP4
🔌 USB Port Communication 1 - GDB Server
- Through this port, it is possible to program/debug the main mcu STM32F407 using the SWD (Serial Wire Debug) protocol
- The programmer's MCU STM32F413 runs among others the GDB server (the program used to program/debug)
- It is this GDB server that manage the SWD protocol
- The EPuck2's embedded programmer/debugger is actually derived from BMP (Black Magic Probe), a debugging hardware platform that can be used over a variety of MCU
🔌 USB Port Communication 2 - Serial Monitor
- Through this port, it is possible to communicate via UART with either:
- the main MCU STM32F407: the target used in the context of this course via its SD3 (3rd serial data) port
- the ESP32
- the CAN bus
- By default, the serial is linked to the main MCU
STM32F407. A special gdb command is required to choose another target - 💡 More precisely, the UART is tunneled into the USB, the programmer's MCU STM32F413 then de-encapsulates the packets and sends them to one of the three targets
- A
tunneling protocolis a communication protocol making use of encapsulation. Put in other words, a tunnel puts the data inside packets and, once arrived at the end of the tunnel, the original message is de-encapsulated from the packets.
🔌 USB Port Communication 3 - STM32F407 [Optional]
- Through this port, it is possible to communicate directly with the main MCU STM32F407 using the USB protocol via its SDU1 (1st Serial USB Driver) port
- ⚠ This port will not show up if the STM32F407 is not programmed to do so. That requires the use of a software driver on the microcontroller for the USB port, hence being optional
STM32F407 UART communication - Serial Monitor
- Looking at the electrical documentation of the e-puck2 shows that the UART3 is connected to the programmer and ESP32 (Bluetooth)
- In order to see what the e-puck2 is writing to the serial port, you need to connect a terminal to the good USB / Bluetooth COM port of the programmer (Serial Monitor but NOT GDB server)
- You can then use Hterm, RealTerm, CoolTerm, SerialTools (on Apple Store) or any capable software to read the data from the e-puck2
- You must specify
- com port
- enable the DTR signal (otherwise you won't be receiving anything)
- other parameters such as the baudrate, parity, ... are not relevant
Conclusion on communication with the e-puck2
- The e-puck2 has quite complex interconnections between its components. What interests us here is to understand the 2 different ways you can communicate with the microcontroller such that you are able to use them in your code to transmit data to the computer
- One way is directly using the USB of the microcontroller (SDU1) and the other way uses the UART (SD3) which then goes through the programmer and/or the ESP32. The programmer converts it to a USB com port and the ESP32 converts it to a Bluetooth com port
- Thus you have two distinct ways to communicate with a computer that you can use simultaneously and independently, namely the USB (SDU1) and the UART (SD3)
Behavior of the different com ports -- ChibiOS specific - TP3
- The USB protocol (SDU1) is much more complex than the Serial one (UART or SD3), it implements a complete flow control
- The Serial could also have a flow control but it would have taken more than two pins for the communication
- Thus when trying to communicate with the USB, if the USB cannot send the data (for example when the cable is not connected) the ChibiOS thread in which the function is called is put into sleep until the sending is possible
- This behavior doesn't apply to the UART because it simply sends the data, without taking care if someone on the other side is listening or not
- ⚠ Be sure the USB cable is connected and you are reading the com port when using a communication function with the USB of the microcontroller
- 💡 If you need to use only one communication protocol, we advise you to use the UART3, as it gives you the possibility to use the Bluetooth or the USB without changing the code and without blocking the code if the cable is not connected
- 💡 But if you need to use two independent communication channels, then you can add the use of the USB of the MCU
Table1
Behavior of the different com ports
Communication protocol Behavior when not connected Must disconnect from the com port before reprogramming ? USB (microcontroller) blocking yes because if we are programming the microcontroller, then it cannot control its USB UART3 Bluetooth and USB Programmer) non blocking, no matter if connected or not no because the Bluetooth and the USB connected to the UART3 are controlled by other components
Identify the ports
❖ Windows
- Open the Device Manager (
Windows+X, then selectDevices Manager(orMkey) (Pour Windows en françaisGestionnaire des périphériquesou toucheG)) - Go in the Ports section
- Identify the USB Serial Devices related to the e-puck2
- 💡 unplug then plug again the USB cable to find by discriminating the serial ports of the e-puck2
- Identify the ID of the port attributed to the e-puck2 devices: GDB Server, Serial Monitor or e-puck2 STM32F407
- 💡 open the properties and look for the property Bus reported device description (Description du bus signalée en français) under Details
🍎 MacOS
- Open a terminal window and enter the following command:
ls /dev/cu.usbmodem* - Look for cu.usbmodemEPUCKX, where X is the number attributed by your computer
- You should find two names, with a numbering near to each other, which are respectively e-puck2 GDB Server (lower number) and e-puck2 Serial Monitor (higher number)
- 💡 A third device cu.usbmodemXXXX may be also available, that is related to e-puck2 STM32F407 port
🐧 Linux
- Run the task
List Epuck2 ports
Select the port
- In VSCode EPuck2, open the file .vscode/settings.json
- Modify the com_port settings accordingly
- Windows:
"com_port": "\\\\.\\COMx", - Linux:
"com_port": "/dev/ttyACMx", - MacOS:
"com_port": "/dev/cu.usbmodemEPUCKx",
- Windows:
💡 Further readings
-
In the courtesy of GCTronic
-
Video in construction about USB Serial Ports