Voir : PlatformIO
Une fois PlatformIO installé, on obtient l’arborescence suivante :
$ ls -l $HOME/.platformio/
total 24
-rw-r--r-- 1 tv tv 217 avril 1 06:13 appstate.json
-rw-r--r-- 1 tv tv 2744 avril 1 06:39 homestate.json
drwxr-xr-x 5 tv tv 4096 mars 26 10:54 lib
drwxr-xr-x 26 tv tv 4096 avril 1 06:51 packages
drwxr-xr-x 6 tv tv 4096 nov. 19 2018 penv
drwxr-xr-x 6 tv tv 4096 avril 1 06:38 platforms
L’utilitaire platformio
se trouve dans le dossier $HOME/.platformio/penv/bin/
.
Le dossier lib
contiendra l’ensemble des bibliothèques de développement installées. Elles peuvent aussi être installées directement dans le dossier du projet à développer. Et on retrouvera l’ensemble des outils dans le dossier packages
.
$ ls -l /home/tv/.platformio/packages/
total 96
drwx------ 4 tv tv 4096 mars 10 08:30 contrib-piohome
drwx------ 53 tv tv 4096 oct. 24 10:44 contrib-pysite
drwx------ 5 tv tv 4096 mars 13 2019 framework-arduinoavr
drwx------ 6 tv tv 4096 févr. 5 04:25 framework-arduino-avr
drwx------ 6 tv tv 4096 mars 26 10:54 framework-arduinoespressif32
drwx------ 8 tv tv 4096 mars 27 18:05 framework-arduinoespressif8266
drwx------ 18 tv tv 4096 avril 1 06:39 framework-mbed
drwx------ 2 tv tv 4096 janv. 11 11:50 tool-avrdude
drwx------ 13 tv tv 4096 janv. 11 11:50 toolchain-atmelavr
drwx------ 6 tv tv 4096 avril 1 06:38 toolchain-gccarmnoneeabi
drwx------ 8 tv tv 4096 mars 27 18:05 toolchain-xtensa
drwx------ 8 tv tv 4096 nov. 19 2018 toolchain-xtensa32
drwx------ 5 tv tv 4096 janv. 18 08:18 tool-cppcheck
drwx------ 5 tv tv 4096 avril 1 06:51 tool-dfuutil
drwx------ 2 tv tv 4096 févr. 26 2019 tool-espotapy
drwx------ 2 tv tv 4096 mars 27 18:05 tool-esptool
drwx------ 6 tv tv 4096 mars 27 18:05 tool-esptoolpy
drwx------ 5 tv tv 4096 févr. 26 2019 tool-esptoolpy@1.20600.0
drwx------ 2 tv tv 4096 nov. 19 2018 tool-mkspiffs
drwx------ 8 tv tv 4096 avril 1 07:57 tool-openocd
drwx------ 2 tv tv 4096 avril 1 06:13 tool-pioplus
drwx------ 4 tv tv 4096 janv. 11 10:26 tool-scons
drwx------ 6 tv tv 4096 avril 1 06:51 tool-stm32duino
drwx------ 2 tv tv 4096 mars 23 11:18 tool-unity
Ici, on retrouve notamment :
les outils pour flasher des cartes Atmel SAM et ST (STM32) avec OpenOCD, des cartes à base d’ESP avec esptool ou encore des cartes Arduino avec avrdude.
les chaînes développement pour processeur ARM avec gccarmnoneeabi, Atmel avec atmelavr, ESP32 xtensa32 et ESP8266 avec xtensa.
les frameworks Arduino, mbed, espressif, …
$ ls -l /home/tv/.platformio/platforms/
total 16
drwx------ 6 tv tv 4096 janv. 11 11:50 atmelavr
drwx------ 7 tv tv 4096 mars 26 10:54 espressif32
drwx------ 7 tv tv 4096 mars 27 18:05 espressif8266
drwx------ 9 tv tv 4096 avril 1 06:38 ststm32
Dans VSCode, ouvrir un Terminal
:
$ platformio --version
PlatformIO, version 4.3.2a1
$ pio --version
PlatformIO, version 4.3.2a1
Remarque : pio
est un alias de la commande platformio
.
$ platformio --help
$ pio --help
Usage: platformio [OPTIONS] COMMAND [ARGS]...
Options:
--version Show the version and exit.
-f, --force DEPRECATE
-c, --caller TEXT Caller ID (service)
--no-ansi Do not print ANSI control characters
-h, --help Show this message and exit.
Commands:
account Manage PIO Account
boards Embedded Board Explorer
check Run a static analysis tool on code
ci Continuous Integration
debug PIO Unified Debugger
device Monitor device or list existing
home PIO Home
lib Library Manager
platform Platform Manager
project Project Manager
remote PIO Remote
run Process project environments
settings Manage PlatformIO settings
test Unit Testing
update Update installed platforms, packages and libraries
upgrade Upgrade PlatformIO to the latest version
STMicroelectronics commercialise un kit de découverte B-L475E-IOT01A (nœud IoT) exploitant les fonctionnalités de la série STM32L4 à base de noyau ARM® Cortex® M4. Elle est commercialisée pour un prix d’environ 53 dollars (45 euros) ! Le kit est pris en charge par la plateforme de développement mbed.
Quelques caractéristiques :
Les connecteurs compatibles Arduino :
L’autre connecteur :
Site officiel : www.st.com
Documentation : b-l475e-iot01a.pdf, User Manual UM2153 et User Manual UM2052
Distributeurs :
Détection sous Linux (USB ST-LINK) :
$ dmesg
...
[1205723.946447] usb 3-9.2: new full-speed USB device number 45 using xhci_hcd
[1205723.963928] usb 3-9.2: New USB device found, idVendor=0483, idProduct=374b
[1205723.963938] usb 3-9.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[1205723.963943] usb 3-9.2: Product: STM32 STLink
[1205723.963948] usb 3-9.2: Manufacturer: STMicroelectronics
[1205723.963952] usb 3-9.2: SerialNumber: 0665FF555051897267243257
[1205723.964177] usb 3-9.2: ep 0x84 - rounding interval to 1024 microframes, ep desc says 2040 microframes
[1205724.022783] scsi28 : usb-storage 3-9.2:1.1
[1205724.650379] cdc_acm 3-9.2:1.2: This device cannot do calls on its own. It is not a modem.
[1205724.650388] cdc_acm 3-9.2:1.2: ttyACM0: USB ACM device
[1205724.650597] usbcore: registered new interface driver cdc_acm
[1205724.650598] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
[1205725.019733] scsi 28:0:0:0: Direct-Access MBED microcontroller 1.0 PQ: 0 ANSI: 2
[1205725.021613] sd 28:0:0:0: Attached scsi generic sg10 type 0
[1205725.022042] sd 28:0:0:0: [sdj] 2120 512-byte logical blocks: (1.08 MB/1.03 MiB)
...
$ lsusb
...
Bus 003 Device 045: ID 0483:374b SGS Thomson Microelectronics
$ ls -l /dev/ttyACM0
crw-rw---- 1 root dialout 166, 0 janv. 23 09:50 /dev/ttyACM0
$ sudo chmod 666 /dev/ttyACM0
$ sudo vim /etc/udev/rules.d/51-usb.rules
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="374b", MODE:="0666"
$ cat /media/DIS_L4IOT/DETAILS.TXT
Version: 0221
Build: Nov 17 2016 13:37:06
Rechercher une carte stm32 :
$ pio boards stm32
...
Platform: ststm32
=================================================================================================
ID MCU Frequency Flash RAM Name
------------------------- -------------- ----------- -------- -------- ----------------------
...
disco_l475vg_iot01a STM32L475VGT6 80MHz 1MB 128KB ST DISCO-L475VG-IOT01A
...
nucleo_f401re STM32F401RET6 84MHz 512KB 96KB ST Nucleo F401RE
...
$ pio boards disco_l475vg_iot01a
Platform: ststm32
======================================================================================
ID MCU Frequency Flash RAM Name
------------------- ------------- ----------- ------- ----- ----------------------
disco_l475vg_iot01a STM32L475VGT6 80MHz 1MB 128KB ST DISCO-L475VG-IOT01A
Les frameworks disponibles pour cette carte sont : Arduino, mbed, STM32Cube et Zephyr.
Remarque : Mbed est une plate-forme et un système d’exploitation pour des cartes basées sur des microcontrôleurs ARM Cortex-M 32 bits. Le langage de programmation est le C++. Mbed fournit notamment un environnement de Développement en ligne.
$ mkdir -p $HOME/PlatformIO/Projects/st
$ cd $HOME/PlatformIO/Projects/st
$ mkdir disco_l475vg_iot01a
$ cd disco_l475vg_iot01a
$ pio project init --board disco_l475vg_iot01a --project-option="framework=mbed"
The current working directory $HOME/PlatformIO/Projects/st/disco_l475vg_iot01a will be used for the project.
The next files/directories have been created in $HOME/PlatformIO/Projects/st/disco_l475vg_iot01a
include - Put project header files here
lib - Put here project specific (private) libraries
src - Put project source files here
platformio.ini - Project Configuration File
Project has been successfully initialized! Useful commands:
`pio run` - process/build project from the current directory
`pio run --target upload` or `pio run -t upload` - upload firmware to a target
`pio run --target clean` - clean project (remove compiled files)
`pio run --help` - additional information
$ ls -l
total 20
drwxrwxr-x 2 tv tv 4096 avril 1 10:43 include
drwxrwxr-x 2 tv tv 4096 avril 1 10:43 lib
-rw-rw-r-- 1 tv tv 455 avril 1 10:43 platformio.ini
drwxrwxr-x 2 tv tv 4096 avril 1 10:43 src
drwxrwxr-x 2 tv tv 4096 avril 1 10:43 test
platform.ini
généré :$ cat platformio.ini
[env:disco_l475vg_iot01a]
platform = ststm32
board = disco_l475vg_iot01a
$ vim src/main.cpp
#include <mbed.h>
int main()
{
// put your setup code here, to run once: -> setup()
printf("Start STM32L475\n");
while(1)
{
// put your main code here, to run repeatedly: -> loop()
}
}
$ pio run -v
Processing disco_l475vg_iot01a (platform: ststm32; board: disco_l475vg_iot01a; framework: mbed)
----------------------------------------------------------------------------------------
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/disco_l475vg_iot01a.html
PLATFORM: ST STM32 6.0.0 > ST DISCO-L475VG-IOT01A
HARDWARE: STM32L475VGT6 80MHz, 128KB RAM, 1MB Flash
DEBUG: Current (stlink) On-board (stlink) External (blackmagic, jlink)
PACKAGES:
- framework-mbed 5.51401.200110 (5.14.1)
- toolchain-gccarmnoneeabi 1.70201.0 (7.2.1)
Collecting mbed sources...
...
arm-none-eabi-objcopy -O binary .pio/build/disco_l475vg_iot01a/firmware.elf .pio/build/disco_l475vg_iot01a/firmware.bin
MethodWrapper(["checkprogsize"], [".pio/build/disco_l475vg_iot01a/firmware.elf"])
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM: [ ] 3.1% (used 4008 bytes from 131072 bytes)
Flash: [ ] 4.5% (used 47124 bytes from 1048576 bytes)
.pio/build/disco_l475vg_iot01a/firmware.elf :
section size addr
.text 44348 134217728
.ARM.exidx 8 134262076
.crash_data_ram 256 268435848
.stack 4096 268436104
.heap_0 28024 268440200
.data 2768 536870912
.bss 1240 536873680
.heap 94296 536874920
.ARM.attributes 46 0
.comment 126 0
.debug_info 275822 0
.debug_abbrev 36319 0
.debug_loc 65250 0
.debug_aranges 6320 0
.debug_ranges 7864 0
.debug_line 66047 0
.debug_str 60372 0
.debug_frame 21556 0
Total 714758
============== [SUCCESS] Took 6.57 seconds ==============
La fabrication a créé deux fichiers dans .pio/build/
:
firmware.elf
:$ ls -hl .pio/build/disco_l475vg_iot01a/firmware.elf .pio/build/disco_l475vg_iot01a/firmware.elf
-rwxrwxr-x 1 tv tv 722K avril 1 11:03 .pio/build/disco_l475vg_iot01a/firmware.elf
$ file .pio/build/disco_l475vg_iot01a/firmware.elf .pio/build/disco_l475vg_iot01a/firmware.elf
.pio/build/disco_l475vg_iot01a/firmware.elf: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, ...
$ ~/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-size -B -d .pio/build/disco_l475vg_iot01a/firmware.elf
text data bss dec hex filename
44356 2768 5592 52716 cdec .pio/build/disco_l475vg_iot01a/firmware.elf
$ ~/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-objdump -f .pio/build/disco_l475vg_iot01a/firmware.elf
.pio/build/disco_l475vg_iot01a/firmware.elf: file format elf32-littlearm
architecture: arm, flags 0x00000012:
EXEC_P, HAS_SYMS
start address 0x080013d1
firmware.bin
: ce fichier a été généré par arm-none-eabi-objcopy
$ ls -hl .pio/build/disco_l475vg_iot01a/firmware.elf .pio/build/disco_l475vg_iot01a/firmware.bin
-rwxrwxr-x 1 tv tv 47K avril 1 11:03 .pio/build/disco_l475vg_iot01a/firmware.bin
Au total, on a : 44356+2768 = 47124÷1024 soit 47K, pour un simple printf ;)
Au besoin, on peut réduire la taille du firmware avec :
$ ~/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-strip .pio/build/disco_l475vg_iot01a/firmware.elf
On peut “nettoyer” les fichiers générés :
$ pio run -t clean
Le fichier firmware.bin
peut être directement copié dans le dossier DIS_L4IOT
(l’espace flash est monté comme une clef USB) :
$ dmesg
...
[201025.006218] scsi 6:0:0:0: Direct-Access MBED microcontroller 1.0 PQ: 0 ANSI: 2
[201025.006605] sd 6:0:0:0: Attached scsi generic sg5 type 0
[201025.006845] sd 6:0:0:0: [sde] 2120 512-byte logical blocks: (1.09 MB/1.04 MiB)
[201025.007128] sd 6:0:0:0: [sde] Write Protect is off
[201025.007128] sd 6:0:0:0: [sde] Mode Sense: 03 00 00 00
[201025.007373] sd 6:0:0:0: [sde] No Caching mode page found
[201025.007375] sd 6:0:0:0: [sde] Assuming drive cache: write through
[201025.025663] sd 6:0:0:0: [sde] Attached SCSI removable disk
$ ls -l /media/$USERNAME/DIS_L4IOT/
total 16K
drwxr-xr-x 2 tv tv 1,0K janv. 1 1970 ./
drwxr-x---+ 5 root root 4,0K avril 1 18:32 ../
-r--r--r-- 1 tv tv 46 mai 27 2004 DETAILS.TXT
-r--r--r-- 1 tv tv 512 mai 27 2006 MBED.HTM
$ cat /media/$USERNAME/DIS_L4IOT/DETAILS.TXT
Version: 0221
Build: Nov 17 2016 13:37:06
$ cp .pio/build/disco_l475vg_iot01a/firmware.elf .pio/build/disco_l475vg_iot01a/firmware.bin /media/$USERNAME/DIS_L4IOT/
On peut effectuer cette opération à partir de PlatformIO en téléversant le firmware.elf
:
$ pio run -t upload -v
Processing disco_l475vg_iot01a (platform: ststm32; board: disco_l475vg_iot01a; framework: mbed)
----------------------------------------------------------------------------------------
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/disco_l475vg_iot01a.html
PLATFORM: ST STM32 6.0.0 > ST DISCO-L475VG-IOT01A
HARDWARE: STM32L475VGT6 80MHz, 128KB RAM, 1MB Flash
DEBUG: Current (stlink) On-board (stlink) External (blackmagic, jlink)
PACKAGES:
- framework-mbed 5.51401.200110 (5.14.1)
- tool-dfuutil 1.9.200310
- tool-openocd 2.1000.190707 (10.0)
- tool-stm32duino 1.0.1
- toolchain-gccarmnoneeabi 1.70201.0 (7.2.1)
Collecting mbed sources...
...
RAM: [ ] 3.1% (used 4008 bytes from 131072 bytes)
Flash: [ ] 4.5% (used 47124 bytes from 1048576 bytes)
.pio/build/disco_l475vg_iot01a/firmware.elf :
section size addr
.text 44348 134217728
.ARM.exidx 8 134262076
.crash_data_ram 256 268435848
.stack 4096 268436104
.heap_0 28024 268440200
.data 2768 536870912
.bss 1240 536873680
.heap 94296 536874920
.ARM.attributes 46 0
.comment 126 0
.debug_info 275822 0
.debug_abbrev 36319 0
.debug_loc 65250 0
.debug_aranges 6320 0
.debug_ranges 7864 0
.debug_line 66047 0
.debug_str 60372 0
.debug_frame 21556 0
Total 714758
<lambda>(["upload"], [".pio/build/disco_l475vg_iot01a/firmware.elf"])
AVAILABLE: blackmagic, jlink, mbed, stlink
CURRENT: upload_protocol = stlink
openocd -d2 -s /home/tv/.platformio/packages/tool-openocd/scripts -f board/stm32l4discovery.cfg -c "program {.pio/build/disco_l475vg_iot01a/firmware.elf} verify reset; shutdown;"
xPack OpenOCD, 64-bit Open On-Chip Debugger 0.10.0+dev (2019-07-17-11:25)
Licensed under GNU GPL v2
...
Info : clock speed 500 kHz
Info : STLINK V2J28M18 (API v2) VID:PID 0483:374B
Info : Target voltage: 3.235743
Info : stm32l4x.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 3333 for gdb connections
...
** Programming Started **
Info : device id = 0x10076415
Info : flash size = 1024kbytes
Warn : block write succeeded
** Programming Finished **
** Verify Started **
** Verified OK **
** Resetting Target **
...
shutdown command invoked
======================= [SUCCESS] Took 7.95 seconds =======================
Remarque : attention aux droits d’accès au périphérique USB. Le plus simple étant de copier le fichier de règles udev fourni par OpenOCD.
$ sudo cp $HOME/.platformio/packages/tool-openocd/contrib/60-openocd.rules /etc/udev/rules.d/
La carte étant branchée sur le port USB ST-LINK, PlatformIO a utilisé OpenOCD :
$ ~/.platformio/packages/tool-openocd/bin/openocd --version
xPack OpenOCD, 64-bit Open On-Chip Debugger 0.10.0+dev (2019-07-17-11:25)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Les options disponibles sont :
$ platformio device monitor --help
Usage: platformio device monitor [OPTIONS]
Options:
-p, --port TEXT Port, a number or a device name
-b, --baud INTEGER Set baud rate, default=9600
--parity [N|E|O|S|M] Set parity, default=N
--rtscts Enable RTS/CTS flow control, default=Off
--xonxoff Enable software flow control, default=Off
--rts [0|1] Set initial RTS line state, default=0
--dtr [0|1] Set initial DTR line state, default=0
--echo Enable local echo, default=Off
--encoding TEXT Set the encoding for the serial port (e.g. hexlify,
Latin1, UTF-8), default: UTF-8
-f, --filter TEXT Add filters / text transformation
--eol [CR|LF|CRLF] End of line mode, default=CRLF
--raw Do not apply any encodings/transformations
--exit-char INTEGER ASCII code of special character that is used to exit
the application, default=29 (DEC)
--menu-char INTEGER ASCII code of special character that is used to
control miniterm (menu), default=20 (DEC)
--quiet Diagnostics: suppress non-error messages, default=Off
-h, --help Show this message and exit.
Liens :
Les options peuvent être placées directement dans le fichier plaftform.ini
, par exemple :
...
upload_port = /dev/ttyUSB0
upload_speed = 115200
monitor_speed = 115200
monitor_filters = colorize, debug
monitor_flags =
--encoding
hexlify
Liste des ports disponibles :
$ platformio device list
...
/dev/ttyACM0
------------
Hardware ID: USB VID:PID=0483:374B SER=0672FF555051897267243807 LOCATION=1-4.4.2:1.2
Description: STM32 STLink - ST-Link VCP Ctrl
Un joli printf : )
$ platformio device monitor -p /dev/ttyACM0
--- Available filters and text transformations: colorize, debug, default, direct, hexlify, log2file, nocontrol, printable, send_on_enter, time
--- More details at http://bit.ly/pio-monitor-filters
--- Miniterm on /dev/ttyACM0 9600,8,N,1 ---
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
Start STM32L475
$ platformio device monitor -p /dev/ttyACM0 --encoding hexlify
...
--- Miniterm on /dev/ttyACM0 9600,8,N,1 ---
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
53 74 61 72 74 20 53 54 4D 33 32 4C 34 37 35 0A
Un petit programme pour jouer avec les 4 leds et le bouton :
#include <mbed.h>
DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalInOut led34(LED3); // LED3 = LED4
InterruptIn bouton(USER_BUTTON);
int choixLed = 0;
double tempo = 0.1; // 100 ms
void appuiBouton()
{
choixLed = !choixLed;
}
void commanderLed3(bool etat)
{
if(etat)
{
led34.output();
led34 = 1;
}
else
{
led34.input();
}
}
void commanderLed4(bool etat)
{
if(etat)
{
led34.output();
led34 = 0;
}
else
{
led34.input();
}
}
int main()
{
printf("Tests des leds et bouton\n");
bouton.fall(&appuiBouton);
while(1)
{
if(choixLed)
{
led1 = 1;
wait(tempo);
led1 = 0;
wait(tempo*10);
commanderLed3(1); // orange
}
else
{
led2 = 1;
wait(tempo);
led2 = 0;
wait(tempo*10);
commanderLed4(1); // bleue
}
}
}
La gestion des bibliothèques sous PlatormIO est contrôlée par la commande :
$ pio lib
Usage: pio lib [OPTIONS] COMMAND [ARGS]...
Options:
-g, --global Manager global PlatformIO library storage
-d, --storage-dir DIRECTORY Manage custom library storage
-h, --help Show this message and exit.
Commands:
install Install library
list List installed libraries
register Register new library
search Search for library
show Show details about installed library
uninstall Uninstall libraries
update Update installed libraries
Les bibliothèques peuvent être installées :
.platformio/lib
de votre installation)$ pio lib -g list
Library Storage: $HOME/.platformio/lib
AsyncTCP
========
#ID: 1826
Asynchronous TCP Library for ESP32
Version: 1.1.1
License: LGPL-3.0
Keywords: async, tcp
Compatible frameworks: arduino
Compatible platforms: espressif32
Authors: Hristo Gochkov
...
.pio/libdeps/
du projet)$ pio lib list
Library Storage: $HOME/Documents/PlatformIO/Projects/st/disco_l475vg_iot01a/.pio/libdeps/disco_l475vg_iot01a
No items found
On va rechercher et installer la bibliothèque es_wifi
:
$ pio lib search es_wifi
Found 1 libraries:
DISCO_L475VG_IOT01A_wifi
========================
#ID: 3438
Wifi driver for DISCO_L475VG_IOT1A es_wifi (Inventek Systems ISM43362-M3G-L44 )
Keywords: disco, iot, wifi
Compatible frameworks: mbed
Compatible platforms: Atmel SAM, Freescale Kinetis, Maxim Integrated MAX32, Nordic nRF51, Nordic nRF52, NXP LPC, Silicon Labs EFM32, ST STM32, Teensy, WIZNet W7500
Authors: ST
$ pio lib install 3438
Library Storage: $HOME/Documents/PlatformIO/Projects/st/disco_l475vg_iot01a/.pio/libdeps/disco_l475vg_iot01a
LibraryManager: Installing id=3438
Downloading [####################################] 100%
Unpacking [####################################] 100%
DISCO_L475VG_IOT01A_wifi @ c61a936354 has been successfully installed!
$ pio lib list
Library Storage: /home/tv/Documents/PlatformIO/Projects/st/disco_l475vg_iot01a/.pio/libdeps/disco_l475vg_iot01a
DISCO_L475VG_IOT01A_wifi
========================
#ID: 3438
Wifi driver for DISCO_L475VG_IOT1A es_wifi (Inventek Systems ISM43362-M3G-L44 )
Version: c61a936354
Keywords: disco, iot, wifi
Compatible frameworks: mbed
Compatible platforms: atmelsam, freescalekinetis, maxim32, nordicnrf51, nordicnrf52, nxplpc, siliconlabsefm32, ststm32, teensy, wiznet7500
Authors: ST
On aurait pu tout simplement ajouter au fichier plafortio.ini
du projet la dépendance sur cette bibliothèque :
$ vim plafortio.ini
[env:disco_l475vg_iot01a]
platform = ststm32
board = disco_l475vg_iot01a
framework = mbed
lib_deps =
# Bibliothèque es_wifi
3438
Un programme de test :
#include <mbed.h>
#include "wifi.h"
uint8_t MAC_Addr[6];
int main()
{
printf("Start STM32L475 : client WiFi\n");
if(WIFI_Init() == WIFI_STATUS_OK)
{
printf("> WIFI Module Initialized.\n");
if(WIFI_GetMAC_Address(MAC_Addr) == WIFI_STATUS_OK)
{
printf("> es-wifi module MAC Address : %X:%X:%X:%X:%X:%X\n",
MAC_Addr[0],
MAC_Addr[1],
MAC_Addr[2],
MAC_Addr[3],
MAC_Addr[4],
MAC_Addr[5]);
}
else
{
printf("> ERROR : CANNOT get MAC address\n");
}
...
}
while(1)
{
printf(".");
wait(0.5);
}
}
$ pio run -v
$ pio run -t upload -v
$ pio device monitor -p /dev/ttyACM0
Start STM32L475 : client WiFi
> WIFI Module Initialized.
> es-wifi module MAC Address : C4:7F:51:4:38:6A
...
Il est possible de créer ses propres bibliothèques à l’intérieur de son projet dans le dossier lib
. Le principe est de créer un sous répertoire qui porte le même nom que le nom des fichiers du code source :
|--lib
| |--ClientWiFi
| | |- ClientWiFi.cpp
| | |- ClientWiFi.h
ClientWiFi.h
:#ifndef CLIENTWIFI_H
#define CLIENTWIFI_H
#include "mbed.h"
#include "wifi.h"
#define MAX_TENTATIVES 3
class ClientWiFi
{
public:
ClientWiFi();
bool initialiser(const char *ssid, const char *password, WIFI_Ecn_t type=WIFI_ECN_WPA2_PSK);
bool connecter(uint8_t *adresseServeur, uint16_t portServeur, WIFI_Protocol_t type=WIFI_TCP_PROTOCOL);
bool envoyer(uint8_t *donnees, uint16_t longueur, uint16_t *nb, uint32_t timeout=10000);
bool recevoir(uint8_t *donnees, uint16_t longueur, uint16_t *nb, uint32_t timeout=10000);
bool estConnecte();
private:
int32_t socket;
};
#endif
ClientWiFi.cpp
:#include "ClientWiFi.h"
ClientWiFi::ClientWiFi() : socket(-1)
{
}
bool ClientWiFi::initialiser(const char *ssid, const char *password, WIFI_Ecn_t type)
{
uint8_t MAC_Addr[6];
uint8_t IP_Addr[4];
if(WIFI_Init() == WIFI_STATUS_OK)
{
printf("> WIFI Module Initialized.\n");
if(WIFI_GetMAC_Address(MAC_Addr) == WIFI_STATUS_OK)
{
printf("> es-wifi module MAC Address : %02X:%02X:%X02:%02X:%02X:%02X\n",
MAC_Addr[0],MAC_Addr[1], MAC_Addr[2], MAC_Addr[3], MAC_Addr[4], MAC_Addr[5]);
}
else
{
printf("> ERROR : CANNOT get MAC address\n");
}
if(WIFI_Connect(ssid, password, type) == WIFI_STATUS_OK)
{
printf("> es-wifi module connected \n");
if(WIFI_GetIP_Address(IP_Addr) == WIFI_STATUS_OK)
{
printf("> es-wifi module got IP Address : %d.%d.%d.%d\n",
IP_Addr[0], IP_Addr[1], IP_Addr[2], IP_Addr[3]);
}
else
{
printf("> ERROR : es-wifi module CANNOT get IP address\n");
}
}
else
{
printf("> ERROR : es-wifi module NOT connected\n");
return false;
}
}
else
{
printf("> ERROR : WIFI Module cannot be initialized.\n");
return false;
}
return true;
}
bool ClientWiFi::connecter(uint8_t *adresseServeur, uint16_t portServeur, WIFI_Protocol_t type)
{
uint16_t nbTentatives = MAX_TENTATIVES;
printf("> Trying to connect to Server: %d.%d.%d.%d:%d ...\n",
adresseServeur[0], adresseServeur[1], adresseServeur[2], adresseServeur[3], portServeur);
while (nbTentatives--)
{
if(type == WIFI_TCP_PROTOCOL)
{
if(WIFI_OpenClientConnection(0, WIFI_TCP_PROTOCOL, "TCP_CLIENT", adresseServeur, portServeur, 0) == WIFI_STATUS_OK)
{
printf("> TCP Connection opened successfully.\n");
socket = 0;
return true;
}
}
else if(type == WIFI_UDP_PROTOCOL)
{
if(WIFI_OpenClientConnection(0, WIFI_UDP_PROTOCOL, "UDP_CLIENT", adresseServeur, portServeur, 0) == WIFI_STATUS_OK)
{
printf("> UDP Connection opened successfully.\n");
socket = 0;
return true;
}
}
else
{
printf("> ERROR : unknown type Connection\n");
return false;
}
}
printf("> ERROR : Cannot open Connection\n");
return false;
}
bool ClientWiFi::recevoir(uint8_t *donnees, uint16_t longueur, uint16_t *nb, uint32_t timeout)
{
if(socket != -1)
{
if(WIFI_ReceiveData(socket, donnees, longueur, nb, timeout) == WIFI_STATUS_OK)
{
if(*nb > 0)
{
return true;
}
}
else
{
printf("> ERROR : Failed to Receive Data.\n");
return false;
}
}
return false;
}
bool ClientWiFi::envoyer(uint8_t *donnees, uint16_t longueur, uint16_t *nb, uint32_t timeout)
{
if(socket != -1)
{
if(WIFI_SendData(socket, donnees, longueur, nb, timeout) == WIFI_STATUS_OK)
{
return true;
}
else
{
printf("> ERROR : Failed to send Data.\n");
return false;
}
}
return false;
}
bool ClientWiFi::estConnecte()
{
if(socket != -1)
{
return true;
}
return false;
}
main.cpp
:#include <mbed.h>
#include"ClientWiFi.h"
const char *ssid = "XXXXXXXX";
const char *password = "xxxxxxxxxxxxxxxx";
uint8_t adresseServeur[] = {192, 168, 52, 12};
uint16_t portServeur = 5000;
uint8_t message[] = "HELLO\n";
uint8_t donnees[256];
ClientWiFi clientWiFi;
int main()
{
uint16_t nb;
printf("Start STM32L475 : client WiFi\n");
if(clientWiFi.initialiser(ssid, password))
{
//clientWiFi.connecter(adresseServeur, portServeur); // par défaut WIFI_TCP_PROTOCOL
clientWiFi.connecter(adresseServeur, portServeur, WIFI_UDP_PROTOCOL);
}
while(1)
{
if(clientWiFi.estConnecte())
{
if(clientWiFi.envoyer(message, sizeof(message), &nb))
{
if(clientWiFi.recevoir(donnees, sizeof(donnees), &nb))
{
printf("%s", donnees);
}
}
wait(0.5);
}
}
}
Start STM32L475 : client WiFi
> WIFI Module Initialized.
> es-wifi module MAC Address : C4:7F:5102:04:38:6A
> es-wifi module connected
> es-wifi module got IP Address : 192.168.52.30
> Trying to connect to Server: 192.168.52.12:5000 ...
> UDP Connection opened successfully.
> bonjour
Il est possible de placer des fichiers d’entête dans le dossier include
:
$ cd include
$ touch config.h
$ code config.h
#ifndef CONFIG_H
#define CONFIG_H
#define MAX_TENTATIVES 3
#endif
Dans le fichier ClientWiFi.h
:
#ifndef CLIENTWIFI_H
#define CLIENTWIFI_H
#include "mbed.h"
#include "wifi.h"
#define MAX_TENTATIVES 3
class ClientWiFi
{
...
};
#endif
Il ne faut pas oublier d’indiquer le répertoire qui contient des fichiers d’entêtes dans le fichier plaformio.ini
:
...
build_flags =
-I./include
Il faut deux conditions pour enregistrer sa bibliothèque dans PlatformIO :
library.json
(ou library.properties
ou module.json
)$ platformio lib register https://os.mbed.com/users/tvaira/code/DISCO_L475VG_IOT01_HTS221//raw-file/576400702b64/library.json
The library has been successfully registered and is waiting for moderation
La carte est équipée d’un certain nombre de capteurs :
On va tester le capteur d’humidité et de température avec la bibliothèque HTS221 :
#include <mbed.h>
#include "HTS221Sensor.h"
DevI2C devI2c(PB_11,PB_10);
HTS221Sensor capteur(&devI2c);
int main()
{
uint8_t id;
float humidite;
float temperature;
printf("Start STM32L475 : Humidité & Température\n");
/* initialise le capteur */
capteur.init(NULL);
/* active le capteur */
capteur.enable();
capteur.read_id(&id);
printf("Capteur HTS221 = 0x%X\r\n", id);
while(1)
{
capteur.get_temperature(&temperature);
capteur.get_humidity(&humidite);
printf("[capteur HTS221] temperature] = %.2f C - humidite = %.2f%%\r\n", temperature, humidite);
wait(0.5);
}
}