UM2721 Introduction User manual · 7. Stop data acquisition when enough data is collected with the...

25
Introduction The FP-AI-NANOEDG1 function pack helps users to jump-start easily the development and implementation of their condition monitoring applications designed with the NanoEdge AI Studio solution from Cartesiam. This user manual describes the content of the FP-AI-NANOEDG1 function pack and details the different steps to build such applications on the STM32L562E-DK Discovery kit. Artificial Intelligence (AI) condition monitoring function pack for STM32Cube UM2721 User manual UM2721 - Rev 1 - July 2020 For further information contact your local STMicroelectronics sales office. www.st.com

Transcript of UM2721 Introduction User manual · 7. Stop data acquisition when enough data is collected with the...

Page 1: UM2721 Introduction User manual · 7. Stop data acquisition when enough data is collected with the stop command ( or even more conveniently with hitting the ESC key ) $ stop 8. Configure

IntroductionThe FP-AI-NANOEDG1 function pack helps users to jump-start easily the development and implementation of their conditionmonitoring applications designed with the NanoEdge™ AI Studio solution from Cartesiam.

This user manual describes the content of the FP-AI-NANOEDG1 function pack and details the different steps to build suchapplications on the STM32L562E-DK Discovery kit.

Artificial Intelligence (AI) condition monitoring function pack for STM32Cube

UM2721

User manual

UM2721 - Rev 1 - July 2020For further information contact your local STMicroelectronics sales office.

www.st.com

Page 2: UM2721 Introduction User manual · 7. Stop data acquisition when enough data is collected with the stop command ( or even more conveniently with hitting the ESC key ) $ stop 8. Configure

1 General information

The FP-AI-NANOEDG1 function pack runs on STM32 microcontrollers based on Arm® cores.

Note: Arm is a registered trademark of Arm Limited (or its subsidiaries) in the US and/or elsewhere.

1.1 Feature overview

• Complete firmware to program an STM32L5 sensor node for condition monitoring and predictivemaintenance applications

• Stub for replacement with a Cartesiam Machine Learning library generated using the NanoEdge™ AI Studiofor the desired AI application

• Configuration and acquisition of STMicroelectronics iNEMO LSM6DSO 3D digital accelerometer andgyroscope

• Data logging on a microSD™ card• Simple LCD user interface• Autonomous mode controlled by user button• Interactive command-line interface (CLI) for

– Node and sensor configuration– Data logging– Learning and detection phase management of the NanoEdge™ library

• Easy portability across STM32 microcontrollers by means of the STM32Cube ecosystem• Free and user-friendly license terms

1.2 Software architecture

The STM32Cube function packs leverage the modularity and interoperability of STM32 Nucleo boards andexpansion boards running STM32Cube MCU Packages and Expansion Packages to create functional examplesrepresenting some of the most common use cases in certain applications. The function packs are designed tofully exploit the underlying STM32 ODE hardware and software components to best satisfy the final userapplication requirements.Function packs may include additional libraries and frameworks, not present in the original STM32CubeExpansion Packages, which enable new functions and create more targeted and usable systems for developers.

UM2721General information

UM2721 - Rev 1 page 2/25

Page 3: UM2721 Introduction User manual · 7. Stop data acquisition when enough data is collected with the stop command ( or even more conveniently with hitting the ESC key ) $ stop 8. Configure

STM32Cube includes:• A set of user-friendly software development tools to cover project development from the conception to the

realization, among which are:– STM32CubeMX, a graphical software configuration tool that allows the automatic generation of C

initialization code using graphical wizards– STM32CubeIDE, an all-in-one development tool with peripheral configuration, code generation, code

compilation, and debug features– STM32CubeProgrammer (STM32CubeProg), a programming tool available in graphical and command-

line versions– STM32CubeMonitor (STM32CubeMonitor, STM32CubeMonPwr, STM32CubeMonRF,

STM32CubeMonUCPD) powerful monitoring tools to fine-tune the behavior and performance of STM32applications in real-time

• STM32Cube MCU & MPU Packages, comprehensive embedded-software platforms specific to eachmicrocontroller and microprocessor series (such as STM32CubeL5 for the STM32L5 Series), which include:– STM32Cube hardware abstraction layer (HAL), ensuring maximized portability across the STM32

portfolio– STM32Cube low-layer APIs, ensuring the best performance and footprints with a high degree of user

control over the HW– A consistent set of middleware components such as RTOS, USB Device, USB PD, FAT file system,

Touch library, Trusted Firmware (TF-M), mbedTLS, and mbed-crypto– All embedded software utilities with full sets of peripheral and applicative examples

• STM32Cube Expansion Packages, which contain embedded software components that complement thefunctionalities of the STM32Cube MCU & MPU Packages with:– Middleware extensions and applicative layers– Examples running on some specific STMicroelectronics development boards

To access and use the sensor expansion board, the application software uses:• STM32Cube hardware abstraction layer (HAL): provides a simple, generic and multi-instance set of generic

and extension APIs (application programming interfaces) to interact with the upper layer applications,libraries and stacks. It is directly based on a generic architecture and allows the layers that are built on it,such as the middleware layer, to implement their functions without requiring the specific hardwareconfiguration for a given microcontroller unit (MCU). This structure improves library code reusability andguarantees easy portability across other devices.

• Board support package (BSP) layer: supports the peripherals on the STM32 Nucleo boards(1) (except theMCU) with a limited set of APIs providing a programming interface for certain board-specific peripherals likethe LED, user button, and others. It helps to determine the specific board version.

1. There is no support for Nucleo boards in the FP-AI-NANOEDG1 function pack.

UM2721Software architecture

UM2721 - Rev 1 page 3/25

Page 4: UM2721 Introduction User manual · 7. Stop data acquisition when enough data is collected with the stop command ( or even more conveniently with hitting the ESC key ) $ stop 8. Configure

The top-level architecture of the FP-AI-NANOEDG1 function pack is shown in Figure 1.

Figure 1. FP-AI-NANOEDG1 architecture

Middleware level

Drivers

Condition monitoring and predictive maintenance application

FatFS

Hardware abstraction layer(HAL)

Board support package(BSP)

Hardware components

STM32L562QESensors

FreeRTOS™

Development boards

STM32L562E-DK

NanoEdge™ AI library stub

USB Device Parson

LCD SD card reader

UM2721Software architecture

UM2721 - Rev 1 page 4/25

Page 5: UM2721 Introduction User manual · 7. Stop data acquisition when enough data is collected with the stop command ( or even more conveniently with hitting the ESC key ) $ stop 8. Configure

1.3 Development flow

FP-AI-NANOEDG1 does not embed any Machine Learning technology. Instead, it provides all the means to helpthe generation of the Machine Learning algorithm by NanoEdge™ AI Studio and embed it easily in theSTM32L562E-DK Discovery kit in a practical way. The steps of the suggested flow are presented in Figure 2 andin the document referenced chapters.

Figure 2. Development flow

Initial setup

· Download FP-AI-NANOEDG1from www.st.com

Data acquisition

· Acquire data onto the microSD™ card

Machine Learning library generation

· Generate a Machine Learning library with NanoEdge™ AI Studio based on the data acquisition

Chapter 2 Chapter 4

Library installation

· Replace the stub provided with the function pack by the newly generated library

Learn

· Learn the nominal modes on the edge

Detect

· Monitor anomalies in detection mode

Chapter 4 Chapter 5

STMicroelectronics CartesiamLegend:

· Program the STM32 board · Export logs using the Python™ scripts provided · Download the library from the

Cartesiam website

· Rebuild firmware· Program the new firmware

· Go back to learn mode to acquire new modes

UM2721Development flow

UM2721 - Rev 1 page 5/25

Page 6: UM2721 Introduction User manual · 7. Stop data acquisition when enough data is collected with the stop command ( or even more conveniently with hitting the ESC key ) $ stop 8. Configure

1.4 Folder structure

Figure 3. FP-AI-NANOEDG1 folder structure

The following folders are included in the function pack:• Documentation: contains a compiled html file generated from the source code, which details the software

components and APIs.• Drivers: contains the HAL drivers, the board-specific drivers for each supported board or hardware

platform (including the on-board components), and the CMSIS vendor-independent hardware abstractionlayer for the Cortex®-M processors.

• Middlewares: contains libraries and protocols for USB Device library, generic FAT file system module(FatFS), FreeRTOS™ real-time OS, Parson a json browser and the NanoEdge™ AI library stub.

• Projects: contains a sample application used for collecting data from motion sensors onto the microSD™

card and manage the learning and detection phases of Cartesiam Machine Learning solution provided forthe STM32L562E-DK platforms through the STM32CubeIDE development environment.

• Utilities: contains scripts and samples for exporting the datalogs generated by the function packdatalogger to NanoEdge™ AI Studio compliant .csv files, which are required to generate the MachineLearning libraries from NanoEdge™ AI Studio. It also contains an STM32CubeMX companion project thatcan help to port or configure the function pack. Ressources for the LCD GUI can also be found in this folder.

1.5 Terms and definitions

Table 1 presents the definitions of the acronyms that are relevant for a better contextual understanding of thisdocument.

Table 1. Acronyms

Acronym Definition

API Application programming interface

BSP Board support package

CLI Command-line interface

FP Function pack

GUI Graphical user interface

HAL Hardware abstraction layer

LCD Liquid-crystal display

MCU Microcontroller unit

ML Machine Learning

ODE Open development environment

UM2721Folder structure

UM2721 - Rev 1 page 6/25

Page 7: UM2721 Introduction User manual · 7. Stop data acquisition when enough data is collected with the stop command ( or even more conveniently with hitting the ESC key ) $ stop 8. Configure

1.6 References

Table 2. References

Reference Description Source

[1] Cartesiam web site cartesiam.ai

[2] STM32L562E-DK Discovery kit www.st.com/en/product/stm32l562e-dk

1.7 Prerequisites

The following IDE for STM32 must be installed:• STMicroelectronics - STM32CubeIDE version 1.0.1 or later

FP-AI-NANOEDG1 can be deployed on the following operating systems:• Windows® 10• Ubuntu® 18.4 and Ubuntu® 16.4 (or derived)• macOS® (x64)

Note: Ubuntu® is a registered trademark of Canonical Ltd.macOS® is a trademark of Apple Inc. registered in the U.S. and other countries.

1.8 License

FP-AI-NANOEDG1 is delivered under the Mix Ultimate Liberty+OSS+3rd-party V1 software license agreement(SLA0048).The software components provided in this package come with different license schemes as shown in Table 3.

Table 3. Software component license agreements

Software component Owner License

Cortex®-M CMSIS Arm Limited Apache License 2.0

FreeRTOS™ Amazon.com, Inc. or its affiliates MIT

STM32L5xx_HAL_Driver STMicroelectronics BSD-3-Clause

Board support package (BSP) STMicroelectronics BSD-3-Clause

STM32L5xx CMSIS Arm Limited - STMicroelectronics Apache License 2.0

FatFS ChaN BSD-3-Clause

Parson Krzysztof Gabis MIT

Applications STMicroelectronics Ultimate Liberty (source release)

UM2721References

UM2721 - Rev 1 page 7/25

Page 8: UM2721 Introduction User manual · 7. Stop data acquisition when enough data is collected with the stop command ( or even more conveniently with hitting the ESC key ) $ stop 8. Configure

2 Hardware and firmware setup

2.1 Presentation of the STM32L562E-DK Discovery kit

The FP-AI-NANOEDG1 Discovery kit is a complete demonstration and development platform for Arm® Cortex®-M33 with Arm® TrustZone® and ARMv8-M mainline security extension core-based STM32L562QEI6Qmicrocontroller, with 512 Kbytes of Flash memory and 256 Kbytes of SRAM. The STM32L562E-DK Discovery kitmakes use of the STM32L562QEI6Q innovative ultra-low-power oriented features to enable prototyping for manywearable or sensor (iNEMO 3D accelerometer and 3D gyroscope) applications, with state-of-the-art energyefficiency, Secure Boot, and TrustZone®-based software isolation. For even more user-friendliness, the on-boardSTLINK-V3E debugger provides out of-the-box loading and debugging capabilities, as well as a USB Virtual COMport bridge.

2.2 Connect hardware

To start using FP-AI-NANOEDG1, the user needs:• A personal computer with one of the supported operating systems• One USB cable to connect the PC to the Micro-B USB connector on the board

Figure 4. USB Micro-B and Type-A cable connectors

• An STM32L562E-DK Discovery kit

Figure 5. STM32L562E-DK Discovery kit

• One microSD™ card

UM2721Hardware and firmware setup

UM2721 - Rev 1 page 8/25

Page 9: UM2721 Introduction User manual · 7. Stop data acquisition when enough data is collected with the stop command ( or even more conveniently with hitting the ESC key ) $ stop 8. Configure

Follow the next two steps to connect hardware:1. Connect the USB cable between the PC and STM32L562E-DK board (CN17) to program and debug the on-

board STM32 MCU. This connection is also used to display STM32 firmware traces and results onto a serialterminal.

2. Insert the microSD™ card into the dedicated slot to store the data from the datalogger.

Note: Before connecting the STM32L562E-DK board to a Windows® PC via the USB, the user must install a driver forthe STLINK-V3E (not required for Windows 10®). It is available on the www.st.com website.The power source is by default the USB cable (CN17). Refer to the UM2617 user manual for details.

2.3 Program firmware into the STM32 microcontroller

This section explains how to select binary firmware and program it into the STM32 microcontroller.Binary firmware is delivered as part of the FP-AI-NANOEDG1 function pack. It is located in the Projects\STM32L562E-DK\Applications\NanoEdgeConsole\Binary folder.When the STM32 board and PC are connected through the USB cable on the STLINK-V3E connector, the relateddrive is available on the PC. Drag and drop the chosen firmware into that drive. Wait a few seconds for thefirmware file to disappear from the file manager: this indicates that firmware is programmed into the STM32microcontroller.

2.4 Autonomous mode operations

When powered up, for instance by the insertion of the USB cable, the on-board LCD displays the following splashscreen.

Figure 6. Splash screen at power up

Blueuser button STLINK-V3E USB connector (CN17)Black

reset button

A long press (three seconds) on the blue user button starts the learning phase. A short press starts the detectionphase. Since only the stub version is provided, results are not based on real sensor. The board only pretends tolearn and detection always returns a 100% similarity index. For meaningful results, the user must generate aMachine Learning library as described in Section 4 Generating a Machine Learning library with NanoEdge AIStudio.

UM2721Program firmware into the STM32 microcontroller

UM2721 - Rev 1 page 9/25

Page 10: UM2721 Introduction User manual · 7. Stop data acquisition when enough data is collected with the stop command ( or even more conveniently with hitting the ESC key ) $ stop 8. Configure

2.5 Using the serial console

2.5.1 Set the serial terminal configurationA serial console is used to interact with the host board (Virtual COM port over USB). With the Windows®

operating system, the use of the Tera Term software is recommended.Start Tera Term, select the proper connection (featuring the STMicroelectronics name), and set the parameters:• Terminal

– [New line]– [Receive]: CR– [Transmit]: CR– [Local echo] selected

• Serial– [Baud rate]: 115200– [Data]: 8 bit– [Parity]: none– [Stop]: 1 bit– [Flow control]: none– [Transmit delay]: 10 ms

2.5.2 Start FP-AI-NANOEDG1 firmwareRestart the board by pressing the black reset button. The following welcome screen is displayed on the terminal.

Figure 7. Welcome screen

From this point, start entering the commands directly or type help to get the list of available commands alongwith their usage guidelines.

Note: The provided firmware is generated with a stub in place of the actual library. The user must generate the librarywith the help of the NanoEdge™ AI Studio, replace the stub with it, and rebuild firmware. These steps aredetailed in the following sections.

UM2721Using the serial console

UM2721 - Rev 1 page 10/25

Page 11: UM2721 Introduction User manual · 7. Stop data acquisition when enough data is collected with the stop command ( or even more conveniently with hitting the ESC key ) $ stop 8. Configure

3 Command line interface

The command-line interface (CLI) is a simple method for the user to control the application by sending command-line inputs to be processed on the device.

3.1 Command execution model

The commands are grouped into three main sets:• (CS1) Generic commands

Generic commands to get help or information from the device like the firmware version, and to start and stopan execution phase.

• (CS2) Predictive maintenance (PdM) commandsPdM commands specific to the Cartesiam NanoEdge™ AI library.

• (CS3) Sensor configuration commandsSelection and configuration of one or more sensors for any execution phase.

3.2 Execution phases and execution context

The three system execution phases are:• Datalogging: data coming from the sensor are logged onto the microSD™ card.• NanoEdge™ AI learning: data coming from the sensor are passed to the NanoEdge™ AI library to train the

model.• NanoEdge™ AI detection: data coming from the sensor are passed to the NanoEdge™ AI library to detect

anomalies.

Each execution phase can be started and stopped with a user command issued through the CLI.An execution context, which is a set of parameters controlling execution, is associated to each execution phase.One single parameter can belong to more than one execution context.The CLI provides commands to set and get execution context parameters. The execution context cannot bechanged while an execution phase is active. If the user attempts to set a parameter belonging to any activeexecution context, the BUSY status is returned, and the requested parameter is not modified.

3.3 Command summary

Table 4. CLI command summary

Command name Command string Note

CS1 - Generic commands

help helpLists all registered commands with briefusage guidelines, including the list ofapplicable parameters.

info info Shows firmware details and version.

uid uid Shows STM32 microcontroller UID.

reset reset Resets the microcontroller system.

start start [ datalog |neai_learn | neai_detect]

Starts an execution phase according toits execution context, such asdatalog, neai_learn orneai_detect.

stop stop (or ESC key)Stops the currently active executionphases.

Use ESC as shortcut for this command.

UM2721Command line interface

UM2721 - Rev 1 page 11/25

Page 12: UM2721 Introduction User manual · 7. Stop data acquisition when enough data is collected with the stop command ( or even more conveniently with hitting the ESC key ) $ stop 8. Configure

Command name Command string Note

CS2 - PdM specific commands

neai_init neai_initInitializes the AI model by forgetting anylearning. Used in the beginning and / orto create a new NanoEdge™ AI model

neai_set neai_set <param> <value> Sets a PdM specific parameters in anexecution context.

neai_get neai_get <param> Displays the value of the parameters inthe execution context.

CS3 - Sensor configuration commands

sensor_set sensor_set <id><parameter> <value>

Sets the value of a parameter for asensor with sensor ID provided in id.

<id> ::=<sensor_id>.<subsensor_id>is a combination of the sensor ID andsub-sensor ID as reported by thesensor_info command.

sensor_get sensor_get <id><parameter>

Gets the value of a parameter for asensor with sensor ID provided in id.

<id> ::=<sensor_id>.<subsensor_id>is a combination of the sensor ID andsub-sensor ID as reported by thesensor_info command.

sensor_info sensor_info Lists the type and ID of all supportedsensors.

UM2721Command summary

UM2721 - Rev 1 page 12/25

Page 13: UM2721 Introduction User manual · 7. Stop data acquisition when enough data is collected with the stop command ( or even more conveniently with hitting the ESC key ) $ stop 8. Configure

4 Generating a Machine Learning library with NanoEdge™ AI Studio

Using NanoEdge™ AI Studio, the library generation is done in five steps:1. Hardware description

– Microcontroller type: Arm® Cortex®-M33– Maximum amount of RAM: usually a few Kbytes is enough (depends on the frame size)– Sensor type: accelerometer

2. Contextual data are needed to test the performance of several machine learning models against theprovided data, along with a multitude of different (hyper) parameters and signal processing algorithms. Thisstep requires:– Regular dataset– Abnormal dataset

3. Optimize and benchmark: NanoEdge™ AI Studio uses the provided contextual datasets to create a modelthat best separates the regular signals from the abnormal signals with the smallest RAM footprint possible.

4. Validate the model: emulate the behavior of your custom NanoEdge™ AI library directly on the PC, as if thelibrary was running on the microcontroller. The generated library can be tested with previously unseen data.The performance must be validated before deploying on the board.

5. Compile and download the library after choosing compilation flags from the Cartesiam website: mfloat-abi and fno-short-wchar.

Refer to [1] for the full NanoEdge™ AI Studio documentation.

4.1 Generating contextual data

As mentioned previously, the user must provide contextual data for NanoEdge™ AI Studio to work on selectingthe best algorithm and optimizing its hyper parameters. NanoEdge™ AI Studio documentation at cartesiam-neai-docs.readthedocs-hosted.com/studio/studio.html gives the following guidelines:• The Regular signals file corresponds to nominal machine behavior that includes all the different regimes, or

behaviors, that the user wishes to consider as nominal.• The Abnormal signals file corresponds to abnormal machine behavior, including some anomalies already

encountered by the user, or that the user suspects could happen.

The behavior of the generated library heavily depends on this initial signal selection step but will not contain any apriori knowledge that needs to be acquired during the learning phases the user will carry out on the field.FP-AI-NANOEDG1 provides data logging capabilities for embedded sensors on the STM32L562E-DK board. Inthis version, digital microphones are not supported.To proceed with data acquisition:1. Make sure that a microSD™ card is inserted, and USB cable is plugged in.2. List the supported sensors with the sensor_info command and collect their IDs:

$ sensor_infoLSM6DSO ID=0, sub sensors=2 sub sensor ID=0, type=ACC sub sensor ID=1, type=GYRO1 sensors supported

3. Select the desired sub-sensor, the accelerometer for instance, with the sensor_set command:

$ sensor_set 0.0 enable 1sensor 0.0: enable.enable

4. You can further configure other parameters (Output Data Rate and full-scale settings) using sensor_setand sensor_get commands.

5. Configure and run the device you want to monitor in normal operating condition and start the datalogging.

UM2721Generating a Machine Learning library with NanoEdge™ AI Studio

UM2721 - Rev 1 page 13/25

Page 14: UM2721 Introduction User manual · 7. Stop data acquisition when enough data is collected with the stop command ( or even more conveniently with hitting the ESC key ) $ stop 8. Configure

6. Start data acquisition with the start datalogcommand

$ start datalog7. Stop data acquisition when enough data is collected with the stop command ( or even more conveniently

with hitting the ESC key )

$ stop8. Configure the monitored device for abnormal operation, start it .and repeat steps 6. and 7.

During each data acquisition cycle a new folder is created with name STM32_DL_nnn. The suffix nnnincrements by one each time a new folder is created, starting from 001. This means that if noSTM32_DL_nnn directory pre-exists, directories STM32_DL_001 and STM32_DL_002 are created fornormal and abnormal data respectively. Each created directory contains two files:a. DeviceConfig.json: the configurations used for the sensors to acquire data.b. LSM6DSO.dat: the sensor acquisition data.

4.2 Exporting the data collection to NanoEdge™

FP-AI-NANOEDG1 comes with utility Python™ scripts located in Utilities\AI_ressources\DataLog toexport data from the STWIN datalog application to the NanoEdge™ AI Studio format.The script DataParser.py parses the .dat files in the folder provided and create .csv files. It requires thepath to a data directory that contains all the .dat files named as sensor names, as well as DeviceConfig.json.In FP-AI-NANOEDG1, the script is invoked as follows:

python STM_DataParser.py Sample-DataLogs/STM32_DL_001python STM_DataParser.py Sample-DataLogs/STM32_DL_002

As a result, a .csv file is added to each directory.These .csv files contain data for the user, in human readable format, so they can be interpreted, cleaned, orplotted. Another step is needed to export them to NanoEdge™ AI Studio required format as explained incartesiam-neai-docs.readthedocs-hosted.com/studio/studio.html#expected-file-format. This is done using script, PrepareNEAIData.py. The script converts the data stream into frames of equal length. The length, whichdepends on the use case and features to be extracted, must be given as a parameter along with the good and thebad data folders (respectively STM32_DL_001 and STM32_DL_002 in the example) as follows:python PrepareNEAIData.py Sample-DataLogs/STM32_DL_001 Sample-DataLogs/STM32_DL_002-seqLength 1024As a result, two .csv files are created:1. normalDataFull.csv2. abnormalDataFull.csv

Note: When multiple acquisitions are made for normal and abnormal behaviors of the machine, the user is expected tocollect all the normal data files in a single folder and all the abnormal files in another folder. The script PrepareNEAIData.py can handle the multiple files and create a single .csv file for both normal and abnormal cases,irrespective of the number of .csv present in normal and abnormal data folders.

Detailed script usage is provided in a Jupyter™ notebook located in the datalog directory (Parser_for_HS_Logged_Data.ipynb). Samples of accelerometer data are provided in Utilities\AI_ressources\DataLog\Sample-DataLogs.

UM2721Exporting the data collection to NanoEdge™

UM2721 - Rev 1 page 14/25

Page 15: UM2721 Introduction User manual · 7. Stop data acquisition when enough data is collected with the stop command ( or even more conveniently with hitting the ESC key ) $ stop 8. Configure

4.3 Installing the NanoEdge™ library

Once the libraries are generated and downloaded from Cartesiam NanoEdge™ AI Studio, the next step is toincorporate these libraries into FP-AI-NANOEDG1. The FP-AI-NANOEDG1 function pack comes with the librarystubs replacing the actual libraries generated by NanoEdge™ AI Studio. This makes it easy for users to link thegenerated libraries and have a place holder for the libraries that are generated as described inSection 4.2 Exporting the data collection to NanoEdge. To link the actual libraries, the user must copy thegenerated libraries and replace the existing stub/dummy libraries and header files NanoEdgeAI.h, and libneai.a present in folders lib and bin respectively. The relative path of these folders is /FP_AI_NANOEDG1/Middlewares/Third_Party/Cartesiam_NanoEdge_AI_Library/ as shown in Figure 8.

Figure 8. Copy and replace the NanoEdge™ library and its header file

UM2721Installing the NanoEdge™ library

UM2721 - Rev 1 page 15/25

Page 16: UM2721 Introduction User manual · 7. Stop data acquisition when enough data is collected with the stop command ( or even more conveniently with hitting the ESC key ) $ stop 8. Configure

Once these files are copied, the project must be reconstructed and programmed on the sensor board to link thelibraries. To perform these operations, the user must open the .project file from the FP-AI-NANOEDG1 folderlocated at FP_AI_NANOEDG1/Projects/STM32L562E-DK/Applications/NanoEdgeConcole/STM32CubeIDE/ as shown in Figure 9.

Figure 9. Open the STM32CubeIDE project file

To install new firmware after linking the library, connect the sensor board and rebuild the project using the playbutton highlighted in Figure 10. Build and download the project in STM32CubeIDE.

Figure 10. Build and download the project in STM32CubeIDE

UM2721Installing the NanoEdge™ library

UM2721 - Rev 1 page 16/25

Page 17: UM2721 Introduction User manual · 7. Stop data acquisition when enough data is collected with the stop command ( or even more conveniently with hitting the ESC key ) $ stop 8. Configure

See the console for the outputs and wait for the build and download success message as shown in Figure 11.

Figure 11. Build and download console message

UM2721Installing the NanoEdge™ library

UM2721 - Rev 1 page 17/25

Page 18: UM2721 Introduction User manual · 7. Stop data acquisition when enough data is collected with the stop command ( or even more conveniently with hitting the ESC key ) $ stop 8. Configure

5 Building and programming

Once a new binary is generated through the build process with an own Machine Learning library usingNanoEdge™ AI Studio, the user must upload it onto the target and test it:1. Connect the discovery board to the personal computer through a USB cable.2. Drag and drop the newly generated FP-AI-NANOEDGE-L562E-DK.bin file onto drive DIS_L562QE.3. When the programming process is complete, observe the same splash screen as presented in Figure 6.4. After reset, no knowledge base exists yet. The user must provide real signals corresponding to the actual

device nominal mode. Place the device in nominal conditions, start the learning phase by a long press onthe blue button, and observe the screen as in Figure 12.

Figure 12. Learning screen

The signals used for learning are counted. During the benchmark phase, a graph shows the number oflearning iterations needed to obtain optimal performance from the library. It is suggested to learn between 3to 10 times more signals than this number. These learned signals must cover all the device nominal modes.

5. Once the desired number of signals are learned, press the blue button again to stop the process. The splashscreen is displayed again.

6. Applying a short press on the blue button to start the detection phase.– When operating in normal conditions, a very high similarity score is obtained and the screen in

Figure 13 is displayed.

Figure 13. Nominal detection screen

UM2721Building and programming

UM2721 - Rev 1 page 18/25

Page 19: UM2721 Introduction User manual · 7. Stop data acquisition when enough data is collected with the stop command ( or even more conveniently with hitting the ESC key ) $ stop 8. Configure

7. Force or simulate defaults that impair nominal operating conditions . The green light goes orange or reddepending on the amplitude of the defect as shown in Figure 14 and Figure 15.

Figure 14. Anomaly detection screen

Figure 15. Failure detection screen

Some practical use cases (such as ukulele, coffee machine and others) and tutorials are available from theCartesiam website:• cartesiam-neai-docs.readthedocs-hosted.com/tutorials/ukulele/ukulele.html• cartesiam-neai-docs.readthedocs-hosted.com/tutorials/coffee/coffee.html

UM2721Building and programming

UM2721 - Rev 1 page 19/25

Page 20: UM2721 Introduction User manual · 7. Stop data acquisition when enough data is collected with the stop command ( or even more conveniently with hitting the ESC key ) $ stop 8. Configure

Revision history

Table 5. Document revision history

Date Version Changes

27-Jul-2020 1 Initial release.

UM2721

UM2721 - Rev 1 page 20/25

Page 21: UM2721 Introduction User manual · 7. Stop data acquisition when enough data is collected with the stop command ( or even more conveniently with hitting the ESC key ) $ stop 8. Configure

Contents

1 General information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2

1.1 Feature overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

1.2 Software architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

1.3 Development flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

1.4 Folder structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

1.5 Terms and definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

1.6 References. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

1.7 Prerequisites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

1.8 License . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

2 Hardware and firmware setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8

2.1 Presentation of the STM32L562E-DK Discovery kit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

2.2 Connect hardware. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

2.3 Program firmware into the STM32 microcontroller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

2.4 Autonomous mode operations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

2.5 Using the serial console . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

2.5.1 Set the serial terminal configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

2.5.2 Start FP-AI-NANOEDG1 firmware. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

3 Command line interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11

3.1 Command execution model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

3.2 Execution phases and execution context . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

3.3 Command summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

4 Generating a Machine Learning library with NanoEdge™ AI Studio . . . . . . . . . . . . . . . .13

4.1 Generating contextual data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

4.2 Exporting the data collection to NanoEdge™ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

4.3 Installing the NanoEdge™ library. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

5 Building and programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .18

Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .20

Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .21

List of tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .23

UM2721Contents

UM2721 - Rev 1 page 21/25

Page 22: UM2721 Introduction User manual · 7. Stop data acquisition when enough data is collected with the stop command ( or even more conveniently with hitting the ESC key ) $ stop 8. Configure

List of figures. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .24

UM2721Contents

UM2721 - Rev 1 page 22/25

Page 23: UM2721 Introduction User manual · 7. Stop data acquisition when enough data is collected with the stop command ( or even more conveniently with hitting the ESC key ) $ stop 8. Configure

List of tablesTable 1. Acronyms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6Table 2. References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7Table 3. Software component license agreements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7Table 4. CLI command summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11Table 5. Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

UM2721List of tables

UM2721 - Rev 1 page 23/25

Page 24: UM2721 Introduction User manual · 7. Stop data acquisition when enough data is collected with the stop command ( or even more conveniently with hitting the ESC key ) $ stop 8. Configure

List of figuresFigure 1. FP-AI-NANOEDG1 architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4Figure 2. Development flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5Figure 3. FP-AI-NANOEDG1 folder structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6Figure 4. USB Micro-B and Type-A cable connectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8Figure 5. STM32L562E-DK Discovery kit. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8Figure 6. Splash screen at power up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9Figure 7. Welcome screen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10Figure 8. Copy and replace the NanoEdge™ library and its header file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15Figure 9. Open the STM32CubeIDE project file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16Figure 10. Build and download the project in STM32CubeIDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16Figure 11. Build and download console message . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17Figure 12. Learning screen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18Figure 13. Nominal detection screen. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18Figure 14. Anomaly detection screen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19Figure 15. Failure detection screen. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

UM2721List of figures

UM2721 - Rev 1 page 24/25

Page 25: UM2721 Introduction User manual · 7. Stop data acquisition when enough data is collected with the stop command ( or even more conveniently with hitting the ESC key ) $ stop 8. Configure

IMPORTANT NOTICE – PLEASE READ CAREFULLY

STMicroelectronics NV and its subsidiaries (“ST”) reserve the right to make changes, corrections, enhancements, modifications, and improvements to STproducts and/or to this document at any time without notice. Purchasers should obtain the latest relevant information on ST products before placing orders. STproducts are sold pursuant to ST’s terms and conditions of sale in place at the time of order acknowledgement.

Purchasers are solely responsible for the choice, selection, and use of ST products and ST assumes no liability for application assistance or the design ofPurchasers’ products.

No license, express or implied, to any intellectual property right is granted by ST herein.

Resale of ST products with provisions different from the information set forth herein shall void any warranty granted by ST for such product.

ST and the ST logo are trademarks of ST. For additional information about ST trademarks, please refer to www.st.com/trademarks. All other product or servicenames are the property of their respective owners.

Information in this document supersedes and replaces information previously supplied in any prior versions of this document.

© 2020 STMicroelectronics – All rights reserved

UM2721

UM2721 - Rev 1 page 25/25