6. Embedded programing¶
Assignments in this week¶
Group Assignment:
- [x] browse through the data sheet for your microcontroller
- [x] compare the performance and development workflows for other architectures
Individual assignment:
- [x] write a program for a microcontroller development board that you made
- [x] to interact (with local input &/or output devices)
- [x] and communicate (with remote wired or wireless devices)
- [x] extra credit: use different languages &/or development
- [x] extra credit: connect external components to the board
Datasheet of different microcontrollers¶
Comparison with diffrent microcontrollers.¶
RP2040 vs STM32 vs SAMD21 vs ESP32-S3
Raspberry Pi RP2040 | STM32F103C8T6 | ATSAMD21G18 | ESP32-S3 | Product Image |
---|---|---|---|---|
Dev Board | Raspberry Pi Pico | Blue Pill | MKRZero, Seeed XIAO | ESP-S3, Seeed XIAO |
Cores | Dual-Core | Single Core | Single Core | Dual-Core |
Core Architechture | 32-bit ARM Coretex-M0+ | 32-bit ARM Coretex-M3 | 32-bit ARM Coretex-M0+ | Xtensa® 32-bit LX7 |
|
Flexible Clock up to 133MHZ | 72MHz | 48MHz | Up to 240 MHz |
RAM Size | 264 KByte SRAM | 20 KByte | 32 KByte | 512 KByte SRAM |
Flash Size | Up to 16 MByte external Flash | 64 KByte | 256 KByte | Up to 1 GByte external Flash |
DIrect Memory Access | 12 x DMA | 7 x DMA | 12 x DMA | 3 x DMA |
Wireless | None | None | None | IEEE 802.11b/g/n |
Programming Lanuage | MicroPython, CircuitPython, C/C++, Arduino | C alike, Arduino IDE | C alike, Arduino IDE | Espressif IDF, Arduino IDE, CircuitPython |
MCU Power Voltage | 3.3VDC | 3.3VDC | 3.3VDC | 3.3VDC |
USB Interface | USB 1.1 Device and Host | USB 2.0 Full Speed | USB OTG | USB OTG |
Program Laoding | USB Mass Storage, UF2 | External device, Serial | USB, UF2 | USB, UF2 |
GPIO | 30 x Digital Input/Output | 37 x GPIO | 38 x GPIO | 45 x GPIO |
High-Speed PIO | 2 blocks, 8 x State Machine, 8 × 10 | No | No | No |
ADC | 4 x 12-bit | 10 x 12-bit | 12 x 12-bit | 2 × 12-bit SAR ADCs, up to 20 channels |
DAC | No | No | 1 x 10-bit | 2 x 8-bit |
UART | 2 | 3 | 6 x Sercom (UART, I2C, SPI) | 3 |
I2C | 2 | 2 | 6 x Sercom (UART, I2C, SPI) | 2 |
SPI | 2 | 3 | 6 x Sercom (UART, I2C, SPI) | 4 |
PWM | 16 | 15 | 20 | 2 × MCPWM |
On Chip Sensor | Temperature | No | No | Temperature |
IC Package | QEN-56 | LQFP-48 | 48-pin TQFP, QFN, WLCSP | VFQFN-56 |
Retail Price | USD 1.00 | USD 3.50 | USD 3.15 | USD 1.20 |
Reference¶
In this week’s course, I learned various knowledge about embedded programming. As a former embedded engineer, we will all retain the habit of studying datasheets. Based on the classification of microcontrollers that are currently on the market, I selected several important specifications to study and read, such as RP2040,STM32,ATSAMD12,ESP32-S3.
In terms of length, RP2040 is currently the most detailed datasheet.According to the latest information, 640 pages of information detail the origin, parameters and usage specifications of the chip. As a former embedded engineer, we often pay more attention to the performance processing parameters of the chip and some interface design references, so that developers and engineers can design chip reference development boards according to their own needs.
Programing on XIAO ESPS3¶
1. Install Arduino IDE and board manager¶
Installing the Arduino Ide is a relatively painless task. But when I installed the board manager according to Seeed XIAO’s WIKI, an error occurred. The main reason for the error was due to the timeout of loading the github library resources. After continuous inquiries, I found the reason. Due to VPN problems, I was unable to obtain the library files in real time, which resulted in the loading failure.
2. Sample code for LED Blink¶
After successfully installing the library files, you can finally select the board model in the Arduino IDE. I used the Blink program in the sample program. By compiling and uploading the program, I can finally see that the right LED of XIAO ESP32 flashes.
3. Microphone Testing for XIAO ESP32 Sense¶
According to XIAO’s product introduction, the board integrates peripherals such as a microphone, so I will follow the tutorial to test the microphone peripherals and train through edge pulse.
- A. Initialize the Micro SD card: Since XIAO ESP32 requires a memory card in FAT32 format, I first found a memory card to initialize it to facilitate subsequent storage of sound files collected by the microphone.
- B. Test the microphone function and monitor the sound through the serial port: After compiling and uploading the program, we can set the corresponding baud rate through the serial port for signal observation. After shouting to XIAO loudly, we can clearly see the signal displayed on the serial port. The value increases and changes occur.
Sample Code for XIAO ESP32S3 Microphone Testing
#include <I2S.h>
void setup() {
// Open serial communications and wait for port to open:
// A baud rate of 115200 is used instead of 9600 for a faster data rate
// on non-native USB ports
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// start I2S at 16 kHz with 16-bits per sample
I2S.setAllPins(-1, 42, 41, -1, -1);
if (!I2S.begin(PDM_MONO_MODE, 16000, 16)) {
Serial.println(“Failed to initialize I2S!”);
while (1); // do nothing
}
}
void loop() {
// read a sample
int sample = I2S.read();
if (sample && sample != -1 && sample != 1) {
Serial.println(sample);
}
} `
4. XIAO ESP32S3 Sense Keywords Spotting via TinyML EdgeImpules¶
- A.Capturing the offline audio data:
As we all know, if you need to train an AI model, the first step you need to do is to obtain the original data set to facilitate subsequent model training. According to the tutorial, we collected 2 sets of data respectively with the keywords “hello” and “crail” through XIAO ESP32S3. Each set of data is about 10 seconds in length, and finally saved in the microSD card. Since I am currently just testing, there are not many data samples collected. If you want to conduct more accurate AI model training, more data sets will be more helpful for model generation.
- B.Uploading collected sound data to Edgeimpluse then make pre-processing and model defining: