zef
This commit is contained in:
parent
9e3969dfc5
commit
49d8d4269d
10
part2_architecture/lab4-2_gpio_interrupt_mode/.gitignore
vendored
Normal file
10
part2_architecture/lab4-2_gpio_interrupt_mode/.gitignore
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
|
||||||
|
# Configuration files
|
||||||
|
sdkconfig
|
||||||
|
sdkconfig.old
|
||||||
|
|
||||||
|
# Production folder
|
||||||
|
build/
|
||||||
|
|
||||||
|
# HTML documentation
|
||||||
|
html_doc/
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
# The following lines of boilerplate have to be in your project's
|
||||||
|
# CMakeLists in this exact order for cmake to work correctly
|
||||||
|
cmake_minimum_required(VERSION 3.5)
|
||||||
|
|
||||||
|
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||||
|
project(main)
|
||||||
2494
part2_architecture/lab4-2_gpio_interrupt_mode/Doxyfile
Normal file
2494
part2_architecture/lab4-2_gpio_interrupt_mode/Doxyfile
Normal file
File diff suppressed because it is too large
Load Diff
3
part2_architecture/lab4-2_gpio_interrupt_mode/Makefile
Normal file
3
part2_architecture/lab4-2_gpio_interrupt_mode/Makefile
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
PROJECT_NAME := main
|
||||||
|
|
||||||
|
include $(IDF_PATH)/make/project.mk
|
||||||
@ -0,0 +1,22 @@
|
|||||||
|
interface ftdi
|
||||||
|
ftdi_vid_pid 0x0403 0x6010
|
||||||
|
ftdi_layout_init 0x0038 0x003b
|
||||||
|
|
||||||
|
# The ESP32 only supports JTAG.
|
||||||
|
transport select jtag
|
||||||
|
|
||||||
|
# This can go as high as 20MHz if CPU frequency is 80MHz, or 26MHz
|
||||||
|
# if CPU frequency is 160MHz or 240MHz.
|
||||||
|
adapter_khz 20000
|
||||||
|
|
||||||
|
# If single core debugging is required, uncomment the following line
|
||||||
|
#set ESP32_ONLYCPU 1
|
||||||
|
|
||||||
|
# To disable RTOS support, uncomment the following line
|
||||||
|
# set ESP32_RTOS none
|
||||||
|
|
||||||
|
# This option defaults to 3.3v
|
||||||
|
set ESP32_FLASH_VOLTAGE 3.3
|
||||||
|
|
||||||
|
# Source the ESP32 configuration file
|
||||||
|
source [find target/esp32.cfg]
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
idf_component_register(
|
||||||
|
SRC_DIRS "."
|
||||||
|
INCLUDE_DIRS ".")
|
||||||
@ -0,0 +1,2 @@
|
|||||||
|
COMPONENT_SRCDIRS := .
|
||||||
|
COMPONENT_ADD_INCLUDEDIRS := .
|
||||||
89
part2_architecture/lab4-2_gpio_interrupt_mode/main/main.c
Normal file
89
part2_architecture/lab4-2_gpio_interrupt_mode/main/main.c
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* Copyright (C) 2020 by Fabrice Muller *
|
||||||
|
* *
|
||||||
|
* This file is useful for ESP32 Design course. *
|
||||||
|
* *
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file lab4-2_main.c
|
||||||
|
* @author Fabrice Muller
|
||||||
|
* @date 30 Sept. 2020
|
||||||
|
* @brief File containing the lab4-2 of Part 2.
|
||||||
|
*
|
||||||
|
* @see https://github.com/fmuller-pns/esp32-vscode-project-template
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "freertos/task.h"
|
||||||
|
#include "driver/gpio.h"
|
||||||
|
|
||||||
|
// Led: RTC_GPIO12
|
||||||
|
static const gpio_num_t PIN_LED = 2;
|
||||||
|
|
||||||
|
// Push button: RTC_GPIO13
|
||||||
|
static const gpio_num_t PIN_PUSH_BUTTON = 15;
|
||||||
|
|
||||||
|
// Press Counter
|
||||||
|
static volatile uint32_t count=0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief interrupt when push switch
|
||||||
|
*
|
||||||
|
* @param args
|
||||||
|
*/
|
||||||
|
static void IRAM_ATTR gpio_switch_isr_handler(void *args) {
|
||||||
|
|
||||||
|
int pinLedNumber = (int)args;
|
||||||
|
count++;
|
||||||
|
gpio_set_level(pinLedNumber, (count % 2));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Starting point function
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
void app_main(void) {
|
||||||
|
|
||||||
|
gpio_config_t config_out = {
|
||||||
|
.intr_type = GPIO_INTR_DISABLE,
|
||||||
|
.mode = GPIO_MODE_OUTPUT,
|
||||||
|
.pin_bit_mask = (1ULL<<PIN_LED),
|
||||||
|
};
|
||||||
|
gpio_config(&config_out);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
gpio_config_t config_in = {
|
||||||
|
.intr_type = GPIO_INTR_POSEDGE,
|
||||||
|
.mode = GPIO_MODE_INPUT,
|
||||||
|
.pull_down_en= GPIO_PULLDOWN_DISABLE,
|
||||||
|
.pull_up_en = GPIO_PULLUP_ENABLE,
|
||||||
|
.pin_bit_mask = (1ULL<<PIN_PUSH_BUTTON),
|
||||||
|
};
|
||||||
|
gpio_config(&config_in);
|
||||||
|
|
||||||
|
gpio_install_isr_service(0);
|
||||||
|
gpio_isr_handler_add(PIN_PUSH_BUTTON, gpio_switch_isr_handler, (void *)PIN_LED);
|
||||||
|
|
||||||
|
uint32_t previous_count=-1;
|
||||||
|
uint32_t tmpCount;
|
||||||
|
for (;;){
|
||||||
|
tmpCount = count;
|
||||||
|
|
||||||
|
if (previous_count != tmpCount) {
|
||||||
|
uint32_t pressNumber = tmpCount-previous_count;
|
||||||
|
if (pressNumber == 1)
|
||||||
|
printf("count: %d\n", tmpCount);
|
||||||
|
else
|
||||||
|
printf("count (bounce: %d): %d\n", pressNumber, tmpCount);
|
||||||
|
|
||||||
|
previous_count = tmpCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
294
part2_architecture/lab4-2_gpio_interrupt_mode/readme.md
Normal file
294
part2_architecture/lab4-2_gpio_interrupt_mode/readme.md
Normal file
@ -0,0 +1,294 @@
|
|||||||
|
# Visual Studio Code Template for ESP32
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
We consider that the Espressif IoT Development Framework (ESP-IDF), version 4.4.1, and Visual Studio Code environment is installed on the computer.
|
||||||
|
For more details, see:
|
||||||
|
- https://docs.espressif.com/projects/esp-idf/en/v4.4.1/esp32/get-started/index.html#installation-step-by-step
|
||||||
|
- https://code.visualstudio.com/
|
||||||
|
|
||||||
|
As of VS-code v1.56.1 integrated terminals require additional configuration to work correctly. see https://code.visualstudio.com/docs/getstarted/settings#_settings-file-locations to edit the `setting.json` file and add the following entry:
|
||||||
|
```bash
|
||||||
|
"terminal.integrated.allowWorkspaceConfiguration":true
|
||||||
|
```
|
||||||
|
|
||||||
|
In Linux (from Ubuntu 20.x), on connecting an ESP32 board with a CP210x USB to serial converter, there is a problem of connection. Add the following entries below that disable both parts of the brltty service and allowed the ESP32 development boards to properly connect.
|
||||||
|
```bash
|
||||||
|
sudo systemctl stop brltty-udev.service
|
||||||
|
sudo systemctl mask brltty-udev.service
|
||||||
|
sudo systemctl stop brltty.service
|
||||||
|
sudo systemctl disable brltty.service
|
||||||
|
```
|
||||||
|
Another solution is to uninstall brltty as below:
|
||||||
|
```bash
|
||||||
|
sudo apt remove brltty
|
||||||
|
```
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
Firstly, you have to clone the `esp32-vscode-project-template` project and follow the next steps.
|
||||||
|
```bash
|
||||||
|
git clone https://github.com/fmuller-pns/esp32-vscode-project-template.git
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 1. Rename the `vscode_project_template` folder
|
||||||
|
```bash
|
||||||
|
mv esp32-vscode-project-template <my_project_name>
|
||||||
|
```
|
||||||
|
#### 2. Go to the project directory
|
||||||
|
```bash
|
||||||
|
cd <my_project_name>
|
||||||
|
```
|
||||||
|
#### 3. Remove the GIT directory
|
||||||
|
```bash
|
||||||
|
rm -fR .git
|
||||||
|
```
|
||||||
|
#### 4. Open visual studio code for the new project
|
||||||
|
```bash
|
||||||
|
code .
|
||||||
|
```
|
||||||
|
#### 5. Verify paths in the `c_cpp_properties.json` file and change them if wrong.
|
||||||
|
```json
|
||||||
|
"IDF_TOOLS": "~/.espressif/tools",
|
||||||
|
"IDF_PATH": "~/esp/esp-idf"
|
||||||
|
```
|
||||||
|
#### 6. [Not required] Change the default project name called `main` in files.
|
||||||
|
This step renames the executable file. By default, the executable file is `main.elf`.
|
||||||
|
1. Open `CMakeLists.txt` and replace `main` by <my_project_name>
|
||||||
|
2. Open `Makefile` and replace `main` by <my_project_name>
|
||||||
|
3. Open `.vscode/launch.json` and replace `main` by <my_project_name> (lines 11 and 19)
|
||||||
|
|
||||||
|
#### 7. Open a terminal from Visual Studio Code to perform commands
|
||||||
|
Choose an external or internal terminal.
|
||||||
|
|
||||||
|
##### Open integrated terminal from Visual Studio Code
|
||||||
|
|
||||||
|
* using keyboard shortcut: `Ctrl+Shift+`<sup>2</sup>
|
||||||
|
* or pressing `F1` key and typing `integrated`
|
||||||
|
|
||||||
|
##### Open external terminal from Visual Studio Code
|
||||||
|
|
||||||
|
* using keyboard shortcut: `Ctrl+Shift+C`
|
||||||
|
* or pressing `F1` key and typing `external`
|
||||||
|
|
||||||
|
#### 8. Identify the USB serial port (usually `/dev/ttyUSB0`)
|
||||||
|
```bash
|
||||||
|
ls /dev/ttyUSB*
|
||||||
|
```
|
||||||
|
<span style="color:yellow">/dev/ttyUSB0</span>
|
||||||
|
|
||||||
|
#### 9. Building, flashing and running project
|
||||||
|
The serial port is `/dev/ttyUSB0` identified above.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
idf.py -p /dev/ttyUSB0 flash monitor
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Push the button on the ESP32 board when connecting
|
||||||
|
|
||||||
|
```bash
|
||||||
|
Serial port /dev/ttyUSB0
|
||||||
|
Connecting........_____....._
|
||||||
|
Detecting chip type... ESP32
|
||||||
|
Chip is ESP32-PICO-D4 (revision 1)
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Flashing and monitoring
|
||||||
|
The message "`Hello ESP32 !`" appears.
|
||||||
|
```bash
|
||||||
|
...
|
||||||
|
W (290) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
|
||||||
|
I (300) cpu_start: Starting scheduler on PRO CPU.
|
||||||
|
I (0) cpu_start: Starting scheduler on APP CPU.
|
||||||
|
Hello ESP32 !
|
||||||
|
```
|
||||||
|
|
||||||
|
To exit monitoring, typing `Ctrl+AltGr+]`
|
||||||
|
|
||||||
|
## Useful Commands
|
||||||
|
|
||||||
|
#### Open external terminal from vscode to perform commands
|
||||||
|
|
||||||
|
* using keyboard shortcut: `Ctrl+Shift+C`
|
||||||
|
* or pressing `F1` key and typing `external`
|
||||||
|
|
||||||
|
#### Open integrated terminal from vscode to perform commands
|
||||||
|
|
||||||
|
* using keyboard shortcut: `Ctrl+Shift+`<sup>2</sup>
|
||||||
|
* or pressing `F1` key and typing `integrated`
|
||||||
|
|
||||||
|
#### Clean project
|
||||||
|
```bash
|
||||||
|
idf.py fullclean
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Configuration of the ESP32 board (only in external terminal)
|
||||||
|
```bash
|
||||||
|
idf.py menuconfig
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Compile and build the executable file (`.elf` extension)
|
||||||
|
```bash
|
||||||
|
idf.py build
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Identify the USB serial port (usually `/dev/ttyUSB0`)
|
||||||
|
```bash
|
||||||
|
ls /dev/ttyUSB*
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Compile, build, flash
|
||||||
|
```bash
|
||||||
|
idf.py -p /dev/ttyUSB0 flash
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Compile, build, flash and monitor
|
||||||
|
```bash
|
||||||
|
idf.py -p /dev/ttyUSB0 flash monitor
|
||||||
|
```
|
||||||
|
To exit monitoring, typing `Ctrl+AltGr+]`
|
||||||
|
|
||||||
|
## Using Tasks for ESP32 to run, debug Project and so on
|
||||||
|
|
||||||
|
1. In the menu, select `Run Task...`
|
||||||
|
2. Select the task you want to launch:
|
||||||
|
- `ESP32 - Build only`: just build the project
|
||||||
|
- `ESP32 - Flash and Monitor`: build (when modifications of code), flash and monitor
|
||||||
|
- `ESP32 - Clean Project`: Clean project (Full clean)
|
||||||
|
- `ESP32 - OpenOCD with FT2232`: Run in dedicated terminal the openOCD command to debug the project
|
||||||
|
- `ESP32 - Doxygen - HTML doc.`: Generate HTML documentation with Doxygen
|
||||||
|
|
||||||
|
## Configure GIT for your new project
|
||||||
|
|
||||||
|
#### Go to your new project folder
|
||||||
|
```bash
|
||||||
|
cd <project_name>
|
||||||
|
```
|
||||||
|
#### Configure name and email address
|
||||||
|
```bash
|
||||||
|
git config --global user.name "your name"
|
||||||
|
git config --global user.email "your email address"
|
||||||
|
```
|
||||||
|
#### Avoid typing your username and personal access token in vscode each time
|
||||||
|
This is useful when connecting your GIT to GitHub.
|
||||||
|
```bash
|
||||||
|
git config credential.helper store
|
||||||
|
```
|
||||||
|
|
||||||
|
## Using GITHUB with visual studio code
|
||||||
|
|
||||||
|
We consider you have followed the sections above:
|
||||||
|
* Getting Started
|
||||||
|
* Configure GIT for your new project
|
||||||
|
|
||||||
|
Now, how to communicate with GitHub ?
|
||||||
|
|
||||||
|
1. Open visual studio code.
|
||||||
|
2. Click on the `Source Control` icon on your left side or use `Ctrl+Shift+G` shortcut.
|
||||||
|
3. For the first time, click on `Initialize Repository` button
|
||||||
|
4. Enter a message for your first commit (ex: first commit) and click on Commit icon
|
||||||
|
5. Press `F1` and typing `git add remote` and entering :
|
||||||
|
* *remote name* : your github repository previously created
|
||||||
|
* *remote url* : https://github.com/xxx/your_project.git
|
||||||
|
* *username* and *password*
|
||||||
|
6. Push to the GitHub server (master branch)
|
||||||
|
|
||||||
|
See https://code.visualstudio.com/docs/editor/versioncontrol for more details.
|
||||||
|
|
||||||
|
## Debugging with JTAG FT2232
|
||||||
|
|
||||||
|
You must install FTDI FT2232 driver.
|
||||||
|
### Quick Driver installation for Linux:
|
||||||
|
|
||||||
|
1. Install USB Driver
|
||||||
|
```bash
|
||||||
|
sudo apt-get install libusb-1.0
|
||||||
|
$ lsusb
|
||||||
|
Bus 001 Device 002: ID 0403:6010 Future Technology Devices International, Ltd FT2232C Dual USB-UART/FIFO IC
|
||||||
|
```
|
||||||
|
2. Install OpenOCD rules. The path for rule copy can be different and depend on your ESP-IDF installation.
|
||||||
|
```bash
|
||||||
|
$ sudo usermod -a -G dialout $USER
|
||||||
|
$ sudo usermod -a -G plugdev $USER
|
||||||
|
$ sudo cp ~/.espressif/tools/openocd-esp32/v0.10.0-esp32-20210401/openocd-esp32/share/openocd/contrib/60-openocd.rules /etc/udev/rules.d/
|
||||||
|
$ sudo reboot
|
||||||
|
```
|
||||||
|
|
||||||
|
### Step 1: From external terminals
|
||||||
|
|
||||||
|
1. Connect the ESP32 board (USB)
|
||||||
|
2. Open an external terminal for building, flashing and running project
|
||||||
|
The serial port is `/dev/ttyUSB0` identified above.
|
||||||
|
```bash
|
||||||
|
idf.py -p /dev/ttyUSB0 flash monitor
|
||||||
|
```
|
||||||
|
3. Connect the JTAG FT2232 (USB)
|
||||||
|
4. Open another external terminal for running `openocd` with configuration file (`ftdi_ft2232.cfg`) located in the project root.
|
||||||
|
```bash
|
||||||
|
openocd -f ftdi_ft2232.cfg
|
||||||
|
```
|
||||||
|
|
||||||
|
5. Result on openocd terminal
|
||||||
|
```bash
|
||||||
|
Open On-Chip Debugger v0.10.0-esp32-20190313 (2019-03-13-09:52)
|
||||||
|
Licensed under GNU GPL v2
|
||||||
|
adapter speed: 20000 kHz
|
||||||
|
Info : Configured 2 cores
|
||||||
|
esp32 interrupt mask on
|
||||||
|
Info : Listening on port 6666 for tcl connections
|
||||||
|
Info : Listening on port 4444 for telnet connections
|
||||||
|
Info : ftdi: if you experience problems at higher adapter clocks, try the command "ftdi_tdo_sample_edge falling"
|
||||||
|
Info : clock speed 20000 kHz
|
||||||
|
Info : JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
|
||||||
|
Info : JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
|
||||||
|
Info : esp32: Debug controller 0 was reset (pwrstat=0x5F, after clear 0x0F).
|
||||||
|
Info : esp32: Core 0 was reset (pwrstat=0x5F, after clear 0x0F).
|
||||||
|
Info : esp32: Debug controller 1 was reset (pwrstat=0x5F, after clear 0x0F).
|
||||||
|
Info : esp32: Core 1 was reset (pwrstat=0x5F, after clear 0x0F).
|
||||||
|
Info : Detected debug stubs @ 3ffb2950 on core0 of target 'esp32'
|
||||||
|
Info : Listening on port 3333 for gdb connections
|
||||||
|
```
|
||||||
|
|
||||||
|
### Step 2: From Visual Studio Code
|
||||||
|
1. Click on the left on the line you want to set a breakpoint. A red bullet appears.
|
||||||
|
|
||||||
|
2. Click on debug Icon
|
||||||
|
|
||||||
|
3. Click on RUN `ESP32 OpenOCD`. If an error arises, click again.
|
||||||
|
|
||||||
|
4. The program stops at the breakpoint and you can see variables and more
|
||||||
|
|
||||||
|
### Step 3: When you modify the code
|
||||||
|
|
||||||
|
Do not touch the terminal with `openocd` command.
|
||||||
|
|
||||||
|
1. Stop the program into the terminal, typing `Ctrl+AltGr+]`
|
||||||
|
2. Build, flash and run program
|
||||||
|
The serial port is `/dev/ttyUSB0` identified above.
|
||||||
|
```bash
|
||||||
|
idf.py -p /dev/ttyUSB0 flash monitor
|
||||||
|
```
|
||||||
|
3. Click on RUN `ESP32 OpenOCD`. If an error arises, click again.
|
||||||
|
4. The program stops at the breakpoint and you can see variables and more
|
||||||
|
|
||||||
|
## Generate Doxygen documentation
|
||||||
|
|
||||||
|
You can use [Using Tasks for ESP32](#using-tasks-for-esp32-to-run-debug-project-and-so-on) or follow the steps below.
|
||||||
|
|
||||||
|
1. Open external terminal from vscode, using keyboard shortcut: `Ctrl+Shift+C`, or pressing `F1` key and typing `external`
|
||||||
|
2. Generate HTML documentation in `html_doc` folder
|
||||||
|
|
||||||
|
* From the User interface (allow you updating the `Doxyfile` configuration file)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
doxywizard
|
||||||
|
```
|
||||||
|
|
||||||
|
* Directly from `Doxyfile` configuration file
|
||||||
|
|
||||||
|
|
||||||
|
```bash
|
||||||
|
doxygen
|
||||||
|
```
|
||||||
|
3. A new `html` folder is created, the entry file is `index.html`
|
||||||
|
|
||||||
10
part3_freertos/lab1-2_2_cores_sched/.gitignore
vendored
Normal file
10
part3_freertos/lab1-2_2_cores_sched/.gitignore
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
|
||||||
|
# Configuration files
|
||||||
|
sdkconfig
|
||||||
|
sdkconfig.old
|
||||||
|
|
||||||
|
# Production folder
|
||||||
|
build/
|
||||||
|
|
||||||
|
# HTML documentation
|
||||||
|
html_doc/
|
||||||
6
part3_freertos/lab1-2_2_cores_sched/CMakeLists.txt
Normal file
6
part3_freertos/lab1-2_2_cores_sched/CMakeLists.txt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# The following lines of boilerplate have to be in your project's
|
||||||
|
# CMakeLists in this exact order for cmake to work correctly
|
||||||
|
cmake_minimum_required(VERSION 3.5)
|
||||||
|
|
||||||
|
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||||
|
project(main)
|
||||||
2494
part3_freertos/lab1-2_2_cores_sched/Doxyfile
Normal file
2494
part3_freertos/lab1-2_2_cores_sched/Doxyfile
Normal file
File diff suppressed because it is too large
Load Diff
3
part3_freertos/lab1-2_2_cores_sched/Makefile
Normal file
3
part3_freertos/lab1-2_2_cores_sched/Makefile
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
PROJECT_NAME := main
|
||||||
|
|
||||||
|
include $(IDF_PATH)/make/project.mk
|
||||||
22
part3_freertos/lab1-2_2_cores_sched/ftdi_ft2232.cfg
Normal file
22
part3_freertos/lab1-2_2_cores_sched/ftdi_ft2232.cfg
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
interface ftdi
|
||||||
|
ftdi_vid_pid 0x0403 0x6010
|
||||||
|
ftdi_layout_init 0x0038 0x003b
|
||||||
|
|
||||||
|
# The ESP32 only supports JTAG.
|
||||||
|
transport select jtag
|
||||||
|
|
||||||
|
# This can go as high as 20MHz if CPU frequency is 80MHz, or 26MHz
|
||||||
|
# if CPU frequency is 160MHz or 240MHz.
|
||||||
|
adapter_khz 20000
|
||||||
|
|
||||||
|
# If single core debugging is required, uncomment the following line
|
||||||
|
#set ESP32_ONLYCPU 1
|
||||||
|
|
||||||
|
# To disable RTOS support, uncomment the following line
|
||||||
|
# set ESP32_RTOS none
|
||||||
|
|
||||||
|
# This option defaults to 3.3v
|
||||||
|
set ESP32_FLASH_VOLTAGE 3.3
|
||||||
|
|
||||||
|
# Source the ESP32 configuration file
|
||||||
|
source [find target/esp32.cfg]
|
||||||
3
part3_freertos/lab1-2_2_cores_sched/main/CMakeLists.txt
Normal file
3
part3_freertos/lab1-2_2_cores_sched/main/CMakeLists.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
idf_component_register(
|
||||||
|
SRC_DIRS "."
|
||||||
|
INCLUDE_DIRS ".")
|
||||||
2
part3_freertos/lab1-2_2_cores_sched/main/component.mk
Normal file
2
part3_freertos/lab1-2_2_cores_sched/main/component.mk
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
COMPONENT_SRCDIRS := .
|
||||||
|
COMPONENT_ADD_INCLUDEDIRS := .
|
||||||
184
part3_freertos/lab1-2_2_cores_sched/main/main.c
Normal file
184
part3_freertos/lab1-2_2_cores_sched/main/main.c
Normal file
@ -0,0 +1,184 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* Copyright (C) 2020 by Fabrice Muller *
|
||||||
|
* *
|
||||||
|
* This file is useful for ESP32 Design course. *
|
||||||
|
* *
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file lab1-2_main.c
|
||||||
|
* @author Fabrice Muller
|
||||||
|
* @date 12 Oct. 2020
|
||||||
|
* @brief File containing the lab1-2 of Part 3.
|
||||||
|
*
|
||||||
|
* @see https://github.com/fmuller-pns/esp32-vscode-project-template
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include "soc/rtc_wdt.h"
|
||||||
|
|
||||||
|
/* FreeRTOS.org includes. */
|
||||||
|
#include "freertos/FreeRTOSConfig.h"
|
||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "freertos/task.h"
|
||||||
|
#include "freertos/semphr.h"
|
||||||
|
#include "esp_freertos_hooks.h"
|
||||||
|
|
||||||
|
#include "my_helper_fct.h"
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************/
|
||||||
|
/**************************************/
|
||||||
|
/* Scenarios */
|
||||||
|
|
||||||
|
//#define DIFF_PRIORITY
|
||||||
|
|
||||||
|
#define PINNED_TO_CORE 0x00
|
||||||
|
// 0x00: Task 1: Core 0, Task 2: Core 0
|
||||||
|
// 0x01: Task 1: Core 0, Task 2: Core 1
|
||||||
|
// 0x10: Task 1: Core 1, Task 2: Core 0
|
||||||
|
// 0x11: Task 1: Core 1, Task 2: Core 1
|
||||||
|
|
||||||
|
//#define IDLE_HOOKS
|
||||||
|
|
||||||
|
//#define TASK_DELAY
|
||||||
|
|
||||||
|
//#define PERIODIC_TASK_DELAY
|
||||||
|
|
||||||
|
/**************************************/
|
||||||
|
/**************************************/
|
||||||
|
|
||||||
|
/* Default stack size for tasks */
|
||||||
|
static const uint32_t STACK_SIZE = 4000;
|
||||||
|
|
||||||
|
#ifdef DIFF_PRIORITY
|
||||||
|
|
||||||
|
static const uint32_t T1_PRIO = 5;
|
||||||
|
static const uint32_t T2_PRIO = 6;
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
static const uint32_t T1_PRIO = 5;
|
||||||
|
static const uint32_t T2_PRIO = 5;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef IDLE_HOOKS
|
||||||
|
|
||||||
|
volatile uint32_t countIdle0 = 0;
|
||||||
|
volatile uint32_t countIdle1 = 0;
|
||||||
|
|
||||||
|
bool vApplicationIdleHook_0 ( void ){
|
||||||
|
countIdle0++;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool vApplicationIdleHook_1 ( void ){
|
||||||
|
countIdle1++;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef PERIODIC_TASK_DELAY
|
||||||
|
/* Buffer to extract trace information */
|
||||||
|
static char buffer[40*12];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Used as a loop counter to create a very crude delay. */
|
||||||
|
#define mainDELAY_LOOP_COUNT (0x1FFFFF)
|
||||||
|
|
||||||
|
/* The task function. */
|
||||||
|
void vTaskFunction(void *pvParameters);
|
||||||
|
|
||||||
|
|
||||||
|
void app_main(void) {
|
||||||
|
|
||||||
|
DISPLAY("Start of app_main task, priority = %d",uxTaskPriorityGet(NULL));
|
||||||
|
|
||||||
|
#ifdef IDLE_HOOKS
|
||||||
|
esp_register_freertos_idle_hook_for_cpu(vApplicationIdleHook_0, CORE_0);
|
||||||
|
esp_register_freertos_idle_hook_for_cpu(vApplicationIdleHook_1, CORE_1);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
vTaskSuspendAll();
|
||||||
|
|
||||||
|
/* Create tasks. */
|
||||||
|
#if PINNED_TO_CORE == 0x00
|
||||||
|
xTaskCreatePinnedToCore(vTaskFunction, "Task 1", STACK_SIZE, (void*)"Task 1", T1_PRIO, NULL,CORE_0);
|
||||||
|
xTaskCreatePinnedToCore(vTaskFunction, "Task 2", STACK_SIZE, (void*)"Task 2", T2_PRIO, NULL,CORE_0);
|
||||||
|
#elif PINNED_TO_CORE == 0x01
|
||||||
|
xTaskCreatePinnedToCore(vTaskFunction, "Task 1", STACK_SIZE, (void*)"Task 1", T1_PRIO, NULL,CORE_0);
|
||||||
|
xTaskCreatePinnedToCore(vTaskFunction, "Task 2", STACK_SIZE, (void*)"Task 2", T2_PRIO, NULL,CORE_1);
|
||||||
|
#elif PINNED_TO_CORE == 0x10
|
||||||
|
xTaskCreatePinnedToCore(vTaskFunction, "Task 1", STACK_SIZE, (void*)"Task 1", T1_PRIO, NULL,CORE_1);
|
||||||
|
xTaskCreatePinnedToCore(vTaskFunction, "Task 2", STACK_SIZE, (void*)"Task 2", T2_PRIO, NULL,CORE_0);
|
||||||
|
#elif PINNED_TO_CORE == 0x11
|
||||||
|
xTaskCreatePinnedToCore(vTaskFunction, "Task 1", STACK_SIZE, (void*)"Task 1", T1_PRIO, NULL,CORE_1);
|
||||||
|
xTaskCreatePinnedToCore(vTaskFunction, "Task 2", STACK_SIZE, (void*)"Task 2", T2_PRIO, NULL,CORE_1);
|
||||||
|
#else
|
||||||
|
xTaskCreate(vTaskFunction, "Task 1", STACK_SIZE, (void*)"Task 1", T1_PRIO, NULL);
|
||||||
|
xTaskCreate(vTaskFunction, "Task 2", STACK_SIZE, (void*)"Task 2", T2_PRIO, NULL);
|
||||||
|
#endif
|
||||||
|
xTaskResumeAll();
|
||||||
|
|
||||||
|
#ifdef IDLE_HOOKS
|
||||||
|
|
||||||
|
#ifndef PERIODIC_TASK_DELAY
|
||||||
|
/* Print task list */
|
||||||
|
vTaskList(buffer);
|
||||||
|
DISPLAY("Trace information");
|
||||||
|
printf("--------------------------------------------------------\n");
|
||||||
|
printf("task\t\tstate\tprio\tstack\ttsk id\tcore id\n");
|
||||||
|
printf("--------------------------------------------------------\n");
|
||||||
|
printf(buffer);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
vTaskDelay(100 / portTICK_PERIOD_MS); // 100 ms
|
||||||
|
DISPLAY("IDLE0: %d, IDLE1:%d", countIdle0, countIdle1);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
for (;;) {
|
||||||
|
vTaskDelay(100 / portTICK_PERIOD_MS); // 100 ms
|
||||||
|
DISPLAY("Hello app_main task!");
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* to ensure its exit is clean */
|
||||||
|
vTaskDelete(NULL);
|
||||||
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
void vTaskFunction(void *pvParameters) {
|
||||||
|
char *pcTaskName;
|
||||||
|
volatile uint32_t ul;
|
||||||
|
|
||||||
|
/* The string to print out is passed in via the parameter. Cast this to a
|
||||||
|
character pointer. */
|
||||||
|
pcTaskName = (char *)pvParameters;
|
||||||
|
|
||||||
|
DISPLAY("Start of %s task, priority = %d",pcTaskName, uxTaskPriorityGet(NULL));
|
||||||
|
|
||||||
|
/* As per most tasks, this task is implemented in an infinite loop. */
|
||||||
|
for (;; ) {
|
||||||
|
DISPLAY("Run computation of %s", pcTaskName);
|
||||||
|
|
||||||
|
/* Delay for simulating a computation */
|
||||||
|
for (ul = 0; ul < mainDELAY_LOOP_COUNT; ul++){
|
||||||
|
}
|
||||||
|
|
||||||
|
// To run APP_MAIN TASK
|
||||||
|
#ifdef TASK_DELAY
|
||||||
|
DISPLAY("Delay of %s", pcTaskName);
|
||||||
|
vTaskDelay(400 / portTICK_PERIOD_MS);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
DISPLAY("End of %s", pcTaskName);
|
||||||
|
}
|
||||||
|
}
|
||||||
47
part3_freertos/lab1-2_2_cores_sched/main/my_helper_fct.h
Normal file
47
part3_freertos/lab1-2_2_cores_sched/main/my_helper_fct.h
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
#ifndef _MY_HELPER_FCT_
|
||||||
|
#define _MY_HELPER_FCT_
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include "esp_log.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* Core constants fot xTaskCreatePinnedToCore() function */
|
||||||
|
const uint32_t CORE_0 = 0;
|
||||||
|
const uint32_t CORE_1 = 1;
|
||||||
|
const uint32_t PRO_CPU = 0;
|
||||||
|
const uint32_t APP_CPU = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Macro to display the buffer with arguments. msg is a formatted string as printf() function.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#define DISPLAY(msg, ...) printf("%d:%d>\t"msg"\r\n", xTaskGetTickCount(), xPortGetCoreID(), ##__VA_ARGS__);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Macro to display error/warning/info for the buffer with arguments. msg is a formatted string as printf() function.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#define DISPLAYE(tag, msg, ...) ESP_LOGE(tag, "%d:%d>\t"msg"", xTaskGetTickCount(), xPortGetCoreID(), ##__VA_ARGS__);
|
||||||
|
|
||||||
|
#define DISPLAYW(tag, msg, ...) ESP_LOGW(tag, "%d:%d>\t"msg"", xTaskGetTickCount(), xPortGetCoreID(), ##__VA_ARGS__);
|
||||||
|
|
||||||
|
#define DISPLAYI(tag, msg, ...) ESP_LOGI(tag, "%d:%d>\t"msg"", xTaskGetTickCount(), xPortGetCoreID(), ##__VA_ARGS__);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Macro to display the buffer without argument
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#define DISPLAYB(msg) printf("%d:%d>\t", xTaskGetTickCount(), xPortGetCoreID());\
|
||||||
|
printf(msg);\
|
||||||
|
printf("\r\n");
|
||||||
|
|
||||||
|
|
||||||
|
/* Consume CPU cycles. Time parameter is for the default frequency: 160MHz (ESP32_DEFAULT_CPU_FREQ_MHZ=160) */
|
||||||
|
#define COMPUTE_IN_TIME_US(time_us) {register uint32_t i=(uint32_t)time_us*5.02*100/22; while (i-- > 0) {asm(" nop");}}
|
||||||
|
|
||||||
|
#define COMPUTE_IN_TIME_MS(time_ms) {register uint32_t i=(uint32_t)time_ms*1000*5.02*100/22; while (i-- > 0) {asm(" nop");}}
|
||||||
|
|
||||||
|
#define COMPUTE_IN_TICK(tick) {register uint32_t i=(uint32_t)(tick*1000/configTICK_RATE_HZ)*1000*5.02*100/22; while (i-- > 0) {asm(" nop");}}
|
||||||
|
|
||||||
|
#endif
|
||||||
294
part3_freertos/lab1-2_2_cores_sched/readme.md
Normal file
294
part3_freertos/lab1-2_2_cores_sched/readme.md
Normal file
@ -0,0 +1,294 @@
|
|||||||
|
# Visual Studio Code Template for ESP32
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
We consider that the Espressif IoT Development Framework (ESP-IDF), version 4.4.1, and Visual Studio Code environment is installed on the computer.
|
||||||
|
For more details, see:
|
||||||
|
- https://docs.espressif.com/projects/esp-idf/en/v4.4.1/esp32/get-started/index.html#installation-step-by-step
|
||||||
|
- https://code.visualstudio.com/
|
||||||
|
|
||||||
|
As of VS-code v1.56.1 integrated terminals require additional configuration to work correctly. see https://code.visualstudio.com/docs/getstarted/settings#_settings-file-locations to edit the `setting.json` file and add the following entry:
|
||||||
|
```bash
|
||||||
|
"terminal.integrated.allowWorkspaceConfiguration":true
|
||||||
|
```
|
||||||
|
|
||||||
|
In Linux (from Ubuntu 20.x), on connecting an ESP32 board with a CP210x USB to serial converter, there is a problem of connection. Add the following entries below that disable both parts of the brltty service and allowed the ESP32 development boards to properly connect.
|
||||||
|
```bash
|
||||||
|
sudo systemctl stop brltty-udev.service
|
||||||
|
sudo systemctl mask brltty-udev.service
|
||||||
|
sudo systemctl stop brltty.service
|
||||||
|
sudo systemctl disable brltty.service
|
||||||
|
```
|
||||||
|
Another solution is to uninstall brltty as below:
|
||||||
|
```bash
|
||||||
|
sudo apt remove brltty
|
||||||
|
```
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
Firstly, you have to clone the `esp32-vscode-project-template` project and follow the next steps.
|
||||||
|
```bash
|
||||||
|
git clone https://github.com/fmuller-pns/esp32-vscode-project-template.git
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 1. Rename the `vscode_project_template` folder
|
||||||
|
```bash
|
||||||
|
mv esp32-vscode-project-template <my_project_name>
|
||||||
|
```
|
||||||
|
#### 2. Go to the project directory
|
||||||
|
```bash
|
||||||
|
cd <my_project_name>
|
||||||
|
```
|
||||||
|
#### 3. Remove the GIT directory
|
||||||
|
```bash
|
||||||
|
rm -fR .git
|
||||||
|
```
|
||||||
|
#### 4. Open visual studio code for the new project
|
||||||
|
```bash
|
||||||
|
code .
|
||||||
|
```
|
||||||
|
#### 5. Verify paths in the `c_cpp_properties.json` file and change them if wrong.
|
||||||
|
```json
|
||||||
|
"IDF_TOOLS": "~/.espressif/tools",
|
||||||
|
"IDF_PATH": "~/esp/esp-idf"
|
||||||
|
```
|
||||||
|
#### 6. [Not required] Change the default project name called `main` in files.
|
||||||
|
This step renames the executable file. By default, the executable file is `main.elf`.
|
||||||
|
1. Open `CMakeLists.txt` and replace `main` by <my_project_name>
|
||||||
|
2. Open `Makefile` and replace `main` by <my_project_name>
|
||||||
|
3. Open `.vscode/launch.json` and replace `main` by <my_project_name> (lines 11 and 19)
|
||||||
|
|
||||||
|
#### 7. Open a terminal from Visual Studio Code to perform commands
|
||||||
|
Choose an external or internal terminal.
|
||||||
|
|
||||||
|
##### Open integrated terminal from Visual Studio Code
|
||||||
|
|
||||||
|
* using keyboard shortcut: `Ctrl+Shift+`<sup>2</sup>
|
||||||
|
* or pressing `F1` key and typing `integrated`
|
||||||
|
|
||||||
|
##### Open external terminal from Visual Studio Code
|
||||||
|
|
||||||
|
* using keyboard shortcut: `Ctrl+Shift+C`
|
||||||
|
* or pressing `F1` key and typing `external`
|
||||||
|
|
||||||
|
#### 8. Identify the USB serial port (usually `/dev/ttyUSB0`)
|
||||||
|
```bash
|
||||||
|
ls /dev/ttyUSB*
|
||||||
|
```
|
||||||
|
<span style="color:yellow">/dev/ttyUSB0</span>
|
||||||
|
|
||||||
|
#### 9. Building, flashing and running project
|
||||||
|
The serial port is `/dev/ttyUSB0` identified above.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
idf.py -p /dev/ttyUSB0 flash monitor
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Push the button on the ESP32 board when connecting
|
||||||
|
|
||||||
|
```bash
|
||||||
|
Serial port /dev/ttyUSB0
|
||||||
|
Connecting........_____....._
|
||||||
|
Detecting chip type... ESP32
|
||||||
|
Chip is ESP32-PICO-D4 (revision 1)
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Flashing and monitoring
|
||||||
|
The message "`Hello ESP32 !`" appears.
|
||||||
|
```bash
|
||||||
|
...
|
||||||
|
W (290) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
|
||||||
|
I (300) cpu_start: Starting scheduler on PRO CPU.
|
||||||
|
I (0) cpu_start: Starting scheduler on APP CPU.
|
||||||
|
Hello ESP32 !
|
||||||
|
```
|
||||||
|
|
||||||
|
To exit monitoring, typing `Ctrl+AltGr+]`
|
||||||
|
|
||||||
|
## Useful Commands
|
||||||
|
|
||||||
|
#### Open external terminal from vscode to perform commands
|
||||||
|
|
||||||
|
* using keyboard shortcut: `Ctrl+Shift+C`
|
||||||
|
* or pressing `F1` key and typing `external`
|
||||||
|
|
||||||
|
#### Open integrated terminal from vscode to perform commands
|
||||||
|
|
||||||
|
* using keyboard shortcut: `Ctrl+Shift+`<sup>2</sup>
|
||||||
|
* or pressing `F1` key and typing `integrated`
|
||||||
|
|
||||||
|
#### Clean project
|
||||||
|
```bash
|
||||||
|
idf.py fullclean
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Configuration of the ESP32 board (only in external terminal)
|
||||||
|
```bash
|
||||||
|
idf.py menuconfig
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Compile and build the executable file (`.elf` extension)
|
||||||
|
```bash
|
||||||
|
idf.py build
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Identify the USB serial port (usually `/dev/ttyUSB0`)
|
||||||
|
```bash
|
||||||
|
ls /dev/ttyUSB*
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Compile, build, flash
|
||||||
|
```bash
|
||||||
|
idf.py -p /dev/ttyUSB0 flash
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Compile, build, flash and monitor
|
||||||
|
```bash
|
||||||
|
idf.py -p /dev/ttyUSB0 flash monitor
|
||||||
|
```
|
||||||
|
To exit monitoring, typing `Ctrl+AltGr+]`
|
||||||
|
|
||||||
|
## Using Tasks for ESP32 to run, debug Project and so on
|
||||||
|
|
||||||
|
1. In the menu, select `Run Task...`
|
||||||
|
2. Select the task you want to launch:
|
||||||
|
- `ESP32 - Build only`: just build the project
|
||||||
|
- `ESP32 - Flash and Monitor`: build (when modifications of code), flash and monitor
|
||||||
|
- `ESP32 - Clean Project`: Clean project (Full clean)
|
||||||
|
- `ESP32 - OpenOCD with FT2232`: Run in dedicated terminal the openOCD command to debug the project
|
||||||
|
- `ESP32 - Doxygen - HTML doc.`: Generate HTML documentation with Doxygen
|
||||||
|
|
||||||
|
## Configure GIT for your new project
|
||||||
|
|
||||||
|
#### Go to your new project folder
|
||||||
|
```bash
|
||||||
|
cd <project_name>
|
||||||
|
```
|
||||||
|
#### Configure name and email address
|
||||||
|
```bash
|
||||||
|
git config --global user.name "your name"
|
||||||
|
git config --global user.email "your email address"
|
||||||
|
```
|
||||||
|
#### Avoid typing your username and personal access token in vscode each time
|
||||||
|
This is useful when connecting your GIT to GitHub.
|
||||||
|
```bash
|
||||||
|
git config credential.helper store
|
||||||
|
```
|
||||||
|
|
||||||
|
## Using GITHUB with visual studio code
|
||||||
|
|
||||||
|
We consider you have followed the sections above:
|
||||||
|
* Getting Started
|
||||||
|
* Configure GIT for your new project
|
||||||
|
|
||||||
|
Now, how to communicate with GitHub ?
|
||||||
|
|
||||||
|
1. Open visual studio code.
|
||||||
|
2. Click on the `Source Control` icon on your left side or use `Ctrl+Shift+G` shortcut.
|
||||||
|
3. For the first time, click on `Initialize Repository` button
|
||||||
|
4. Enter a message for your first commit (ex: first commit) and click on Commit icon
|
||||||
|
5. Press `F1` and typing `git add remote` and entering :
|
||||||
|
* *remote name* : your github repository previously created
|
||||||
|
* *remote url* : https://github.com/xxx/your_project.git
|
||||||
|
* *username* and *password*
|
||||||
|
6. Push to the GitHub server (master branch)
|
||||||
|
|
||||||
|
See https://code.visualstudio.com/docs/editor/versioncontrol for more details.
|
||||||
|
|
||||||
|
## Debugging with JTAG FT2232
|
||||||
|
|
||||||
|
You must install FTDI FT2232 driver.
|
||||||
|
### Quick Driver installation for Linux:
|
||||||
|
|
||||||
|
1. Install USB Driver
|
||||||
|
```bash
|
||||||
|
sudo apt-get install libusb-1.0
|
||||||
|
$ lsusb
|
||||||
|
Bus 001 Device 002: ID 0403:6010 Future Technology Devices International, Ltd FT2232C Dual USB-UART/FIFO IC
|
||||||
|
```
|
||||||
|
2. Install OpenOCD rules. The path for rule copy can be different and depend on your ESP-IDF installation.
|
||||||
|
```bash
|
||||||
|
$ sudo usermod -a -G dialout $USER
|
||||||
|
$ sudo usermod -a -G plugdev $USER
|
||||||
|
$ sudo cp ~/.espressif/tools/openocd-esp32/v0.10.0-esp32-20210401/openocd-esp32/share/openocd/contrib/60-openocd.rules /etc/udev/rules.d/
|
||||||
|
$ sudo reboot
|
||||||
|
```
|
||||||
|
|
||||||
|
### Step 1: From external terminals
|
||||||
|
|
||||||
|
1. Connect the ESP32 board (USB)
|
||||||
|
2. Open an external terminal for building, flashing and running project
|
||||||
|
The serial port is `/dev/ttyUSB0` identified above.
|
||||||
|
```bash
|
||||||
|
idf.py -p /dev/ttyUSB0 flash monitor
|
||||||
|
```
|
||||||
|
3. Connect the JTAG FT2232 (USB)
|
||||||
|
4. Open another external terminal for running `openocd` with configuration file (`ftdi_ft2232.cfg`) located in the project root.
|
||||||
|
```bash
|
||||||
|
openocd -f ftdi_ft2232.cfg
|
||||||
|
```
|
||||||
|
|
||||||
|
5. Result on openocd terminal
|
||||||
|
```bash
|
||||||
|
Open On-Chip Debugger v0.10.0-esp32-20190313 (2019-03-13-09:52)
|
||||||
|
Licensed under GNU GPL v2
|
||||||
|
adapter speed: 20000 kHz
|
||||||
|
Info : Configured 2 cores
|
||||||
|
esp32 interrupt mask on
|
||||||
|
Info : Listening on port 6666 for tcl connections
|
||||||
|
Info : Listening on port 4444 for telnet connections
|
||||||
|
Info : ftdi: if you experience problems at higher adapter clocks, try the command "ftdi_tdo_sample_edge falling"
|
||||||
|
Info : clock speed 20000 kHz
|
||||||
|
Info : JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
|
||||||
|
Info : JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
|
||||||
|
Info : esp32: Debug controller 0 was reset (pwrstat=0x5F, after clear 0x0F).
|
||||||
|
Info : esp32: Core 0 was reset (pwrstat=0x5F, after clear 0x0F).
|
||||||
|
Info : esp32: Debug controller 1 was reset (pwrstat=0x5F, after clear 0x0F).
|
||||||
|
Info : esp32: Core 1 was reset (pwrstat=0x5F, after clear 0x0F).
|
||||||
|
Info : Detected debug stubs @ 3ffb2950 on core0 of target 'esp32'
|
||||||
|
Info : Listening on port 3333 for gdb connections
|
||||||
|
```
|
||||||
|
|
||||||
|
### Step 2: From Visual Studio Code
|
||||||
|
1. Click on the left on the line you want to set a breakpoint. A red bullet appears.
|
||||||
|
|
||||||
|
2. Click on debug Icon
|
||||||
|
|
||||||
|
3. Click on RUN `ESP32 OpenOCD`. If an error arises, click again.
|
||||||
|
|
||||||
|
4. The program stops at the breakpoint and you can see variables and more
|
||||||
|
|
||||||
|
### Step 3: When you modify the code
|
||||||
|
|
||||||
|
Do not touch the terminal with `openocd` command.
|
||||||
|
|
||||||
|
1. Stop the program into the terminal, typing `Ctrl+AltGr+]`
|
||||||
|
2. Build, flash and run program
|
||||||
|
The serial port is `/dev/ttyUSB0` identified above.
|
||||||
|
```bash
|
||||||
|
idf.py -p /dev/ttyUSB0 flash monitor
|
||||||
|
```
|
||||||
|
3. Click on RUN `ESP32 OpenOCD`. If an error arises, click again.
|
||||||
|
4. The program stops at the breakpoint and you can see variables and more
|
||||||
|
|
||||||
|
## Generate Doxygen documentation
|
||||||
|
|
||||||
|
You can use [Using Tasks for ESP32](#using-tasks-for-esp32-to-run-debug-project-and-so-on) or follow the steps below.
|
||||||
|
|
||||||
|
1. Open external terminal from vscode, using keyboard shortcut: `Ctrl+Shift+C`, or pressing `F1` key and typing `external`
|
||||||
|
2. Generate HTML documentation in `html_doc` folder
|
||||||
|
|
||||||
|
* From the User interface (allow you updating the `Doxyfile` configuration file)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
doxywizard
|
||||||
|
```
|
||||||
|
|
||||||
|
* Directly from `Doxyfile` configuration file
|
||||||
|
|
||||||
|
|
||||||
|
```bash
|
||||||
|
doxygen
|
||||||
|
```
|
||||||
|
3. A new `html` folder is created, the entry file is `index.html`
|
||||||
|
|
||||||
16
part3_freertos/lab1-2_2_cores_sched/sdkconfig.defaults
Normal file
16
part3_freertos/lab1-2_2_cores_sched/sdkconfig.defaults
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
|
||||||
|
CONFIG_ESPTOOLPY_FLASHSIZE="4MB"
|
||||||
|
|
||||||
|
# disable watchdog for task
|
||||||
|
CONFIG_ESP_TASK_WDT=n
|
||||||
|
|
||||||
|
# 2 cores to perform freertos
|
||||||
|
CONFIG_FREERTOS_UNICORE=n
|
||||||
|
|
||||||
|
# stack size for hook functions
|
||||||
|
CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=4096
|
||||||
|
|
||||||
|
# Trace facility to extract trace information
|
||||||
|
CONFIG_FREERTOS_USE_TRACE_FACILITY=y
|
||||||
|
CONFIG_FREERTOS_USE_STATS_FORMATTING_FUNCTIONS=y
|
||||||
|
CONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID=y
|
||||||
10
part3_freertos/lab1-3_periodic_task/.gitignore
vendored
Normal file
10
part3_freertos/lab1-3_periodic_task/.gitignore
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
|
||||||
|
# Configuration files
|
||||||
|
sdkconfig
|
||||||
|
sdkconfig.old
|
||||||
|
|
||||||
|
# Production folder
|
||||||
|
build/
|
||||||
|
|
||||||
|
# HTML documentation
|
||||||
|
html_doc/
|
||||||
6
part3_freertos/lab1-3_periodic_task/CMakeLists.txt
Normal file
6
part3_freertos/lab1-3_periodic_task/CMakeLists.txt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# The following lines of boilerplate have to be in your project's
|
||||||
|
# CMakeLists in this exact order for cmake to work correctly
|
||||||
|
cmake_minimum_required(VERSION 3.5)
|
||||||
|
|
||||||
|
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||||
|
project(main)
|
||||||
2494
part3_freertos/lab1-3_periodic_task/Doxyfile
Normal file
2494
part3_freertos/lab1-3_periodic_task/Doxyfile
Normal file
File diff suppressed because it is too large
Load Diff
3
part3_freertos/lab1-3_periodic_task/Makefile
Normal file
3
part3_freertos/lab1-3_periodic_task/Makefile
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
PROJECT_NAME := main
|
||||||
|
|
||||||
|
include $(IDF_PATH)/make/project.mk
|
||||||
22
part3_freertos/lab1-3_periodic_task/ftdi_ft2232.cfg
Normal file
22
part3_freertos/lab1-3_periodic_task/ftdi_ft2232.cfg
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
interface ftdi
|
||||||
|
ftdi_vid_pid 0x0403 0x6010
|
||||||
|
ftdi_layout_init 0x0038 0x003b
|
||||||
|
|
||||||
|
# The ESP32 only supports JTAG.
|
||||||
|
transport select jtag
|
||||||
|
|
||||||
|
# This can go as high as 20MHz if CPU frequency is 80MHz, or 26MHz
|
||||||
|
# if CPU frequency is 160MHz or 240MHz.
|
||||||
|
adapter_khz 20000
|
||||||
|
|
||||||
|
# If single core debugging is required, uncomment the following line
|
||||||
|
#set ESP32_ONLYCPU 1
|
||||||
|
|
||||||
|
# To disable RTOS support, uncomment the following line
|
||||||
|
# set ESP32_RTOS none
|
||||||
|
|
||||||
|
# This option defaults to 3.3v
|
||||||
|
set ESP32_FLASH_VOLTAGE 3.3
|
||||||
|
|
||||||
|
# Source the ESP32 configuration file
|
||||||
|
source [find target/esp32.cfg]
|
||||||
3
part3_freertos/lab1-3_periodic_task/main/CMakeLists.txt
Normal file
3
part3_freertos/lab1-3_periodic_task/main/CMakeLists.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
idf_component_register(
|
||||||
|
SRC_DIRS "."
|
||||||
|
INCLUDE_DIRS ".")
|
||||||
2
part3_freertos/lab1-3_periodic_task/main/component.mk
Normal file
2
part3_freertos/lab1-3_periodic_task/main/component.mk
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
COMPONENT_SRCDIRS := .
|
||||||
|
COMPONENT_ADD_INCLUDEDIRS := .
|
||||||
197
part3_freertos/lab1-3_periodic_task/main/main.c
Normal file
197
part3_freertos/lab1-3_periodic_task/main/main.c
Normal file
@ -0,0 +1,197 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* Copyright (C) 2020 by Fabrice Muller *
|
||||||
|
* *
|
||||||
|
* This file is useful for ESP32 Design course. *
|
||||||
|
* *
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file lab1-2_main.c
|
||||||
|
* @author Fabrice Muller
|
||||||
|
* @date 12 Oct. 2020
|
||||||
|
* @brief File containing the lab1-2 of Part 3.
|
||||||
|
*
|
||||||
|
* @see https://github.com/fmuller-pns/esp32-vscode-project-template
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include "soc/rtc_wdt.h"
|
||||||
|
|
||||||
|
/* FreeRTOS.org includes. */
|
||||||
|
#include "freertos/FreeRTOSConfig.h"
|
||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "freertos/task.h"
|
||||||
|
#include "freertos/semphr.h"
|
||||||
|
#include "esp_freertos_hooks.h"
|
||||||
|
|
||||||
|
#include "my_helper_fct.h"
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************/
|
||||||
|
/**************************************/
|
||||||
|
/* Scenarios */
|
||||||
|
|
||||||
|
#define DIFF_PRIORITY
|
||||||
|
|
||||||
|
#define PINNED_TO_CORE 0x00
|
||||||
|
// 0x00: Task 1: Core 0, Task 2: Core 0
|
||||||
|
// 0x01: Task 1: Core 0, Task 2: Core 1
|
||||||
|
// 0x10: Task 1: Core 1, Task 2: Core 0
|
||||||
|
// 0x11: Task 1: Core 1, Task 2: Core 1
|
||||||
|
|
||||||
|
#define IDLE_HOOKS
|
||||||
|
|
||||||
|
#define TASK_DELAY
|
||||||
|
|
||||||
|
#define PERIODIC_TASK_DELAY
|
||||||
|
|
||||||
|
/**************************************/
|
||||||
|
/**************************************/
|
||||||
|
|
||||||
|
/* Default stack size for tasks */
|
||||||
|
static const uint32_t STACK_SIZE = 4000;
|
||||||
|
|
||||||
|
#ifdef DIFF_PRIORITY
|
||||||
|
|
||||||
|
static const uint32_t T3_PRIO = 1;
|
||||||
|
static const uint32_t T1_PRIO = 5;
|
||||||
|
static const uint32_t T2_PRIO = 6;
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
static const uint32_t T3_PRIO = 1;
|
||||||
|
static const uint32_t T1_PRIO = 5;
|
||||||
|
static const uint32_t T2_PRIO = 5;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef IDLE_HOOKS
|
||||||
|
|
||||||
|
volatile uint32_t countIdle0 = 0;
|
||||||
|
volatile uint32_t countIdle1 = 0;
|
||||||
|
|
||||||
|
bool vApplicationIdleHook_0 ( void ){
|
||||||
|
countIdle0++;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool vApplicationIdleHook_1 ( void ){
|
||||||
|
countIdle1++;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef PERIODIC_TASK_DELAY
|
||||||
|
/* Buffer to extract trace information */
|
||||||
|
static char buffer[40*12];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Used as a loop counter to create a very crude delay. */
|
||||||
|
#define mainDELAY_LOOP_COUNT (0xFFFFF)
|
||||||
|
|
||||||
|
/* The task function. */
|
||||||
|
void vTaskFunction(void *pvParameters);
|
||||||
|
|
||||||
|
|
||||||
|
void app_main(void) {
|
||||||
|
|
||||||
|
DISPLAY("Start of app_main task, priority = %d",uxTaskPriorityGet(NULL));
|
||||||
|
|
||||||
|
#ifdef IDLE_HOOKS
|
||||||
|
esp_register_freertos_idle_hook_for_cpu(vApplicationIdleHook_0, CORE_0);
|
||||||
|
esp_register_freertos_idle_hook_for_cpu(vApplicationIdleHook_1, CORE_1);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
vTaskSuspendAll();
|
||||||
|
|
||||||
|
/* Create tasks. */
|
||||||
|
#if PINNED_TO_CORE == 0x00
|
||||||
|
xTaskCreatePinnedToCore(vTaskFunction, "Task 1", STACK_SIZE, (void*)"Task 1", T1_PRIO, NULL,CORE_0);
|
||||||
|
xTaskCreatePinnedToCore(vTaskFunction, "Task 2", STACK_SIZE, (void*)"Task 2", T2_PRIO, NULL,CORE_0);
|
||||||
|
#elif PINNED_TO_CORE == 0x01
|
||||||
|
xTaskCreatePinnedToCore(vTaskFunction, "Task 1", STACK_SIZE, (void*)"Task 1", T1_PRIO, NULL,CORE_0);
|
||||||
|
xTaskCreatePinnedToCore(vTaskFunction, "Task 2", STACK_SIZE, (void*)"Task 2", T2_PRIO, NULL,CORE_1);
|
||||||
|
#elif PINNED_TO_CORE == 0x10
|
||||||
|
xTaskCreatePinnedToCore(vTaskFunction, "Task 1", STACK_SIZE, (void*)"Task 1", T1_PRIO, NULL,CORE_1);
|
||||||
|
xTaskCreatePinnedToCore(vTaskFunction, "Task 2", STACK_SIZE, (void*)"Task 2", T2_PRIO, NULL,CORE_0);
|
||||||
|
#elif PINNED_TO_CORE == 0x11
|
||||||
|
xTaskCreatePinnedToCore(vTaskFunction, "Task 1", STACK_SIZE, (void*)"Task 1", T1_PRIO, NULL,CORE_1);
|
||||||
|
xTaskCreatePinnedToCore(vTaskFunction, "Task 2", STACK_SIZE, (void*)"Task 2", T2_PRIO, NULL,CORE_1);
|
||||||
|
#else
|
||||||
|
xTaskCreate(vTaskFunction, "Task 1", STACK_SIZE, (void*)"Task 1", T1_PRIO, NULL);
|
||||||
|
xTaskCreate(vTaskFunction, "Task 2", STACK_SIZE, (void*)"Task 2", T2_PRIO, NULL);
|
||||||
|
#endif
|
||||||
|
xTaskResumeAll();
|
||||||
|
|
||||||
|
xTaskCreatePinnedToCore(vTaskFunction, "Task 3", STACK_SIZE, (void*)"Task 3", T3_PRIO, NULL,CORE_0);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef IDLE_HOOKS
|
||||||
|
|
||||||
|
#ifndef PERIODIC_TASK_DELAY
|
||||||
|
/* Print task list */
|
||||||
|
vTaskList(buffer);
|
||||||
|
DISPLAY("Trace information");
|
||||||
|
printf("--------------------------------------------------------\n");
|
||||||
|
printf("task\t\tstate\tprio\tstack\ttsk id\tcore id\n");
|
||||||
|
printf("--------------------------------------------------------\n");
|
||||||
|
printf(buffer);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
vTaskDelay(100 / portTICK_PERIOD_MS); // 100 ms
|
||||||
|
DISPLAY("IDLE0: %d, IDLE1:%d", countIdle0, countIdle1);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
for (;;) {
|
||||||
|
vTaskDelay(100 / portTICK_PERIOD_MS); // 100 ms
|
||||||
|
DISPLAY("Hello app_main task!");
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* to ensure its exit is clean */
|
||||||
|
vTaskDelete(NULL);
|
||||||
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
void vTaskFunction(void *pvParameters) {
|
||||||
|
char *pcTaskName;
|
||||||
|
TickType_t xLastWakeTime;
|
||||||
|
const TickType_t xDelay250ms = pdMS_TO_TICKS(250UL);
|
||||||
|
volatile uint32_t ul;
|
||||||
|
|
||||||
|
/* The string to print out is passed in via the parameter. Cast this to a
|
||||||
|
character pointer. */
|
||||||
|
pcTaskName = (char *)pvParameters;
|
||||||
|
xLastWakeTime= xTaskGetTickCount();
|
||||||
|
DISPLAY("Start of %s task, priority = %d",pcTaskName, uxTaskPriorityGet(NULL));
|
||||||
|
|
||||||
|
/* As per most tasks, this task is implemented in an infinite loop. */
|
||||||
|
for (;; ) {
|
||||||
|
DISPLAY("Run computation of %s", pcTaskName);
|
||||||
|
|
||||||
|
/* Delay for simulating a computation */
|
||||||
|
for (ul = 0; ul < mainDELAY_LOOP_COUNT; ul++){
|
||||||
|
}
|
||||||
|
|
||||||
|
// To run APP_MAIN TASK
|
||||||
|
#ifdef TASK_DELAY
|
||||||
|
/* Approximated/Periodic Delay */
|
||||||
|
#ifdef PERIODIC_TASK_DELAY
|
||||||
|
DISPLAY("Periodic Delay of %s", pcTaskName);
|
||||||
|
vTaskDelayUntil (& xLastWakeTime , pdMS_TO_TICKS (300));
|
||||||
|
#else
|
||||||
|
DISPLAY("Approximated Delay of %s", pcTaskName);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS (300));
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
DISPLAY("End of %s", pcTaskName);
|
||||||
|
}
|
||||||
|
}
|
||||||
47
part3_freertos/lab1-3_periodic_task/main/my_helper_fct.h
Normal file
47
part3_freertos/lab1-3_periodic_task/main/my_helper_fct.h
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
#ifndef _MY_HELPER_FCT_
|
||||||
|
#define _MY_HELPER_FCT_
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include "esp_log.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* Core constants fot xTaskCreatePinnedToCore() function */
|
||||||
|
const uint32_t CORE_0 = 0;
|
||||||
|
const uint32_t CORE_1 = 1;
|
||||||
|
const uint32_t PRO_CPU = 0;
|
||||||
|
const uint32_t APP_CPU = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Macro to display the buffer with arguments. msg is a formatted string as printf() function.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#define DISPLAY(msg, ...) printf("%d:%d>\t"msg"\r\n", xTaskGetTickCount(), xPortGetCoreID(), ##__VA_ARGS__);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Macro to display error/warning/info for the buffer with arguments. msg is a formatted string as printf() function.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#define DISPLAYE(tag, msg, ...) ESP_LOGE(tag, "%d:%d>\t"msg"", xTaskGetTickCount(), xPortGetCoreID(), ##__VA_ARGS__);
|
||||||
|
|
||||||
|
#define DISPLAYW(tag, msg, ...) ESP_LOGW(tag, "%d:%d>\t"msg"", xTaskGetTickCount(), xPortGetCoreID(), ##__VA_ARGS__);
|
||||||
|
|
||||||
|
#define DISPLAYI(tag, msg, ...) ESP_LOGI(tag, "%d:%d>\t"msg"", xTaskGetTickCount(), xPortGetCoreID(), ##__VA_ARGS__);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Macro to display the buffer without argument
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#define DISPLAYB(msg) printf("%d:%d>\t", xTaskGetTickCount(), xPortGetCoreID());\
|
||||||
|
printf(msg);\
|
||||||
|
printf("\r\n");
|
||||||
|
|
||||||
|
|
||||||
|
/* Consume CPU cycles. Time parameter is for the default frequency: 160MHz (ESP32_DEFAULT_CPU_FREQ_MHZ=160) */
|
||||||
|
#define COMPUTE_IN_TIME_US(time_us) {register uint32_t i=(uint32_t)time_us*5.02*100/22; while (i-- > 0) {asm(" nop");}}
|
||||||
|
|
||||||
|
#define COMPUTE_IN_TIME_MS(time_ms) {register uint32_t i=(uint32_t)time_ms*1000*5.02*100/22; while (i-- > 0) {asm(" nop");}}
|
||||||
|
|
||||||
|
#define COMPUTE_IN_TICK(tick) {register uint32_t i=(uint32_t)(tick*1000/configTICK_RATE_HZ)*1000*5.02*100/22; while (i-- > 0) {asm(" nop");}}
|
||||||
|
|
||||||
|
#endif
|
||||||
294
part3_freertos/lab1-3_periodic_task/readme.md
Normal file
294
part3_freertos/lab1-3_periodic_task/readme.md
Normal file
@ -0,0 +1,294 @@
|
|||||||
|
# Visual Studio Code Template for ESP32
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
We consider that the Espressif IoT Development Framework (ESP-IDF), version 4.4.1, and Visual Studio Code environment is installed on the computer.
|
||||||
|
For more details, see:
|
||||||
|
- https://docs.espressif.com/projects/esp-idf/en/v4.4.1/esp32/get-started/index.html#installation-step-by-step
|
||||||
|
- https://code.visualstudio.com/
|
||||||
|
|
||||||
|
As of VS-code v1.56.1 integrated terminals require additional configuration to work correctly. see https://code.visualstudio.com/docs/getstarted/settings#_settings-file-locations to edit the `setting.json` file and add the following entry:
|
||||||
|
```bash
|
||||||
|
"terminal.integrated.allowWorkspaceConfiguration":true
|
||||||
|
```
|
||||||
|
|
||||||
|
In Linux (from Ubuntu 20.x), on connecting an ESP32 board with a CP210x USB to serial converter, there is a problem of connection. Add the following entries below that disable both parts of the brltty service and allowed the ESP32 development boards to properly connect.
|
||||||
|
```bash
|
||||||
|
sudo systemctl stop brltty-udev.service
|
||||||
|
sudo systemctl mask brltty-udev.service
|
||||||
|
sudo systemctl stop brltty.service
|
||||||
|
sudo systemctl disable brltty.service
|
||||||
|
```
|
||||||
|
Another solution is to uninstall brltty as below:
|
||||||
|
```bash
|
||||||
|
sudo apt remove brltty
|
||||||
|
```
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
Firstly, you have to clone the `esp32-vscode-project-template` project and follow the next steps.
|
||||||
|
```bash
|
||||||
|
git clone https://github.com/fmuller-pns/esp32-vscode-project-template.git
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 1. Rename the `vscode_project_template` folder
|
||||||
|
```bash
|
||||||
|
mv esp32-vscode-project-template <my_project_name>
|
||||||
|
```
|
||||||
|
#### 2. Go to the project directory
|
||||||
|
```bash
|
||||||
|
cd <my_project_name>
|
||||||
|
```
|
||||||
|
#### 3. Remove the GIT directory
|
||||||
|
```bash
|
||||||
|
rm -fR .git
|
||||||
|
```
|
||||||
|
#### 4. Open visual studio code for the new project
|
||||||
|
```bash
|
||||||
|
code .
|
||||||
|
```
|
||||||
|
#### 5. Verify paths in the `c_cpp_properties.json` file and change them if wrong.
|
||||||
|
```json
|
||||||
|
"IDF_TOOLS": "~/.espressif/tools",
|
||||||
|
"IDF_PATH": "~/esp/esp-idf"
|
||||||
|
```
|
||||||
|
#### 6. [Not required] Change the default project name called `main` in files.
|
||||||
|
This step renames the executable file. By default, the executable file is `main.elf`.
|
||||||
|
1. Open `CMakeLists.txt` and replace `main` by <my_project_name>
|
||||||
|
2. Open `Makefile` and replace `main` by <my_project_name>
|
||||||
|
3. Open `.vscode/launch.json` and replace `main` by <my_project_name> (lines 11 and 19)
|
||||||
|
|
||||||
|
#### 7. Open a terminal from Visual Studio Code to perform commands
|
||||||
|
Choose an external or internal terminal.
|
||||||
|
|
||||||
|
##### Open integrated terminal from Visual Studio Code
|
||||||
|
|
||||||
|
* using keyboard shortcut: `Ctrl+Shift+`<sup>2</sup>
|
||||||
|
* or pressing `F1` key and typing `integrated`
|
||||||
|
|
||||||
|
##### Open external terminal from Visual Studio Code
|
||||||
|
|
||||||
|
* using keyboard shortcut: `Ctrl+Shift+C`
|
||||||
|
* or pressing `F1` key and typing `external`
|
||||||
|
|
||||||
|
#### 8. Identify the USB serial port (usually `/dev/ttyUSB0`)
|
||||||
|
```bash
|
||||||
|
ls /dev/ttyUSB*
|
||||||
|
```
|
||||||
|
<span style="color:yellow">/dev/ttyUSB0</span>
|
||||||
|
|
||||||
|
#### 9. Building, flashing and running project
|
||||||
|
The serial port is `/dev/ttyUSB0` identified above.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
idf.py -p /dev/ttyUSB0 flash monitor
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Push the button on the ESP32 board when connecting
|
||||||
|
|
||||||
|
```bash
|
||||||
|
Serial port /dev/ttyUSB0
|
||||||
|
Connecting........_____....._
|
||||||
|
Detecting chip type... ESP32
|
||||||
|
Chip is ESP32-PICO-D4 (revision 1)
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Flashing and monitoring
|
||||||
|
The message "`Hello ESP32 !`" appears.
|
||||||
|
```bash
|
||||||
|
...
|
||||||
|
W (290) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
|
||||||
|
I (300) cpu_start: Starting scheduler on PRO CPU.
|
||||||
|
I (0) cpu_start: Starting scheduler on APP CPU.
|
||||||
|
Hello ESP32 !
|
||||||
|
```
|
||||||
|
|
||||||
|
To exit monitoring, typing `Ctrl+AltGr+]`
|
||||||
|
|
||||||
|
## Useful Commands
|
||||||
|
|
||||||
|
#### Open external terminal from vscode to perform commands
|
||||||
|
|
||||||
|
* using keyboard shortcut: `Ctrl+Shift+C`
|
||||||
|
* or pressing `F1` key and typing `external`
|
||||||
|
|
||||||
|
#### Open integrated terminal from vscode to perform commands
|
||||||
|
|
||||||
|
* using keyboard shortcut: `Ctrl+Shift+`<sup>2</sup>
|
||||||
|
* or pressing `F1` key and typing `integrated`
|
||||||
|
|
||||||
|
#### Clean project
|
||||||
|
```bash
|
||||||
|
idf.py fullclean
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Configuration of the ESP32 board (only in external terminal)
|
||||||
|
```bash
|
||||||
|
idf.py menuconfig
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Compile and build the executable file (`.elf` extension)
|
||||||
|
```bash
|
||||||
|
idf.py build
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Identify the USB serial port (usually `/dev/ttyUSB0`)
|
||||||
|
```bash
|
||||||
|
ls /dev/ttyUSB*
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Compile, build, flash
|
||||||
|
```bash
|
||||||
|
idf.py -p /dev/ttyUSB0 flash
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Compile, build, flash and monitor
|
||||||
|
```bash
|
||||||
|
idf.py -p /dev/ttyUSB0 flash monitor
|
||||||
|
```
|
||||||
|
To exit monitoring, typing `Ctrl+AltGr+]`
|
||||||
|
|
||||||
|
## Using Tasks for ESP32 to run, debug Project and so on
|
||||||
|
|
||||||
|
1. In the menu, select `Run Task...`
|
||||||
|
2. Select the task you want to launch:
|
||||||
|
- `ESP32 - Build only`: just build the project
|
||||||
|
- `ESP32 - Flash and Monitor`: build (when modifications of code), flash and monitor
|
||||||
|
- `ESP32 - Clean Project`: Clean project (Full clean)
|
||||||
|
- `ESP32 - OpenOCD with FT2232`: Run in dedicated terminal the openOCD command to debug the project
|
||||||
|
- `ESP32 - Doxygen - HTML doc.`: Generate HTML documentation with Doxygen
|
||||||
|
|
||||||
|
## Configure GIT for your new project
|
||||||
|
|
||||||
|
#### Go to your new project folder
|
||||||
|
```bash
|
||||||
|
cd <project_name>
|
||||||
|
```
|
||||||
|
#### Configure name and email address
|
||||||
|
```bash
|
||||||
|
git config --global user.name "your name"
|
||||||
|
git config --global user.email "your email address"
|
||||||
|
```
|
||||||
|
#### Avoid typing your username and personal access token in vscode each time
|
||||||
|
This is useful when connecting your GIT to GitHub.
|
||||||
|
```bash
|
||||||
|
git config credential.helper store
|
||||||
|
```
|
||||||
|
|
||||||
|
## Using GITHUB with visual studio code
|
||||||
|
|
||||||
|
We consider you have followed the sections above:
|
||||||
|
* Getting Started
|
||||||
|
* Configure GIT for your new project
|
||||||
|
|
||||||
|
Now, how to communicate with GitHub ?
|
||||||
|
|
||||||
|
1. Open visual studio code.
|
||||||
|
2. Click on the `Source Control` icon on your left side or use `Ctrl+Shift+G` shortcut.
|
||||||
|
3. For the first time, click on `Initialize Repository` button
|
||||||
|
4. Enter a message for your first commit (ex: first commit) and click on Commit icon
|
||||||
|
5. Press `F1` and typing `git add remote` and entering :
|
||||||
|
* *remote name* : your github repository previously created
|
||||||
|
* *remote url* : https://github.com/xxx/your_project.git
|
||||||
|
* *username* and *password*
|
||||||
|
6. Push to the GitHub server (master branch)
|
||||||
|
|
||||||
|
See https://code.visualstudio.com/docs/editor/versioncontrol for more details.
|
||||||
|
|
||||||
|
## Debugging with JTAG FT2232
|
||||||
|
|
||||||
|
You must install FTDI FT2232 driver.
|
||||||
|
### Quick Driver installation for Linux:
|
||||||
|
|
||||||
|
1. Install USB Driver
|
||||||
|
```bash
|
||||||
|
sudo apt-get install libusb-1.0
|
||||||
|
$ lsusb
|
||||||
|
Bus 001 Device 002: ID 0403:6010 Future Technology Devices International, Ltd FT2232C Dual USB-UART/FIFO IC
|
||||||
|
```
|
||||||
|
2. Install OpenOCD rules. The path for rule copy can be different and depend on your ESP-IDF installation.
|
||||||
|
```bash
|
||||||
|
$ sudo usermod -a -G dialout $USER
|
||||||
|
$ sudo usermod -a -G plugdev $USER
|
||||||
|
$ sudo cp ~/.espressif/tools/openocd-esp32/v0.10.0-esp32-20210401/openocd-esp32/share/openocd/contrib/60-openocd.rules /etc/udev/rules.d/
|
||||||
|
$ sudo reboot
|
||||||
|
```
|
||||||
|
|
||||||
|
### Step 1: From external terminals
|
||||||
|
|
||||||
|
1. Connect the ESP32 board (USB)
|
||||||
|
2. Open an external terminal for building, flashing and running project
|
||||||
|
The serial port is `/dev/ttyUSB0` identified above.
|
||||||
|
```bash
|
||||||
|
idf.py -p /dev/ttyUSB0 flash monitor
|
||||||
|
```
|
||||||
|
3. Connect the JTAG FT2232 (USB)
|
||||||
|
4. Open another external terminal for running `openocd` with configuration file (`ftdi_ft2232.cfg`) located in the project root.
|
||||||
|
```bash
|
||||||
|
openocd -f ftdi_ft2232.cfg
|
||||||
|
```
|
||||||
|
|
||||||
|
5. Result on openocd terminal
|
||||||
|
```bash
|
||||||
|
Open On-Chip Debugger v0.10.0-esp32-20190313 (2019-03-13-09:52)
|
||||||
|
Licensed under GNU GPL v2
|
||||||
|
adapter speed: 20000 kHz
|
||||||
|
Info : Configured 2 cores
|
||||||
|
esp32 interrupt mask on
|
||||||
|
Info : Listening on port 6666 for tcl connections
|
||||||
|
Info : Listening on port 4444 for telnet connections
|
||||||
|
Info : ftdi: if you experience problems at higher adapter clocks, try the command "ftdi_tdo_sample_edge falling"
|
||||||
|
Info : clock speed 20000 kHz
|
||||||
|
Info : JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
|
||||||
|
Info : JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
|
||||||
|
Info : esp32: Debug controller 0 was reset (pwrstat=0x5F, after clear 0x0F).
|
||||||
|
Info : esp32: Core 0 was reset (pwrstat=0x5F, after clear 0x0F).
|
||||||
|
Info : esp32: Debug controller 1 was reset (pwrstat=0x5F, after clear 0x0F).
|
||||||
|
Info : esp32: Core 1 was reset (pwrstat=0x5F, after clear 0x0F).
|
||||||
|
Info : Detected debug stubs @ 3ffb2950 on core0 of target 'esp32'
|
||||||
|
Info : Listening on port 3333 for gdb connections
|
||||||
|
```
|
||||||
|
|
||||||
|
### Step 2: From Visual Studio Code
|
||||||
|
1. Click on the left on the line you want to set a breakpoint. A red bullet appears.
|
||||||
|
|
||||||
|
2. Click on debug Icon
|
||||||
|
|
||||||
|
3. Click on RUN `ESP32 OpenOCD`. If an error arises, click again.
|
||||||
|
|
||||||
|
4. The program stops at the breakpoint and you can see variables and more
|
||||||
|
|
||||||
|
### Step 3: When you modify the code
|
||||||
|
|
||||||
|
Do not touch the terminal with `openocd` command.
|
||||||
|
|
||||||
|
1. Stop the program into the terminal, typing `Ctrl+AltGr+]`
|
||||||
|
2. Build, flash and run program
|
||||||
|
The serial port is `/dev/ttyUSB0` identified above.
|
||||||
|
```bash
|
||||||
|
idf.py -p /dev/ttyUSB0 flash monitor
|
||||||
|
```
|
||||||
|
3. Click on RUN `ESP32 OpenOCD`. If an error arises, click again.
|
||||||
|
4. The program stops at the breakpoint and you can see variables and more
|
||||||
|
|
||||||
|
## Generate Doxygen documentation
|
||||||
|
|
||||||
|
You can use [Using Tasks for ESP32](#using-tasks-for-esp32-to-run-debug-project-and-so-on) or follow the steps below.
|
||||||
|
|
||||||
|
1. Open external terminal from vscode, using keyboard shortcut: `Ctrl+Shift+C`, or pressing `F1` key and typing `external`
|
||||||
|
2. Generate HTML documentation in `html_doc` folder
|
||||||
|
|
||||||
|
* From the User interface (allow you updating the `Doxyfile` configuration file)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
doxywizard
|
||||||
|
```
|
||||||
|
|
||||||
|
* Directly from `Doxyfile` configuration file
|
||||||
|
|
||||||
|
|
||||||
|
```bash
|
||||||
|
doxygen
|
||||||
|
```
|
||||||
|
3. A new `html` folder is created, the entry file is `index.html`
|
||||||
|
|
||||||
16
part3_freertos/lab1-3_periodic_task/sdkconfig.defaults
Normal file
16
part3_freertos/lab1-3_periodic_task/sdkconfig.defaults
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
|
||||||
|
CONFIG_ESPTOOLPY_FLASHSIZE="4MB"
|
||||||
|
|
||||||
|
# disable watchdog for task
|
||||||
|
CONFIG_ESP_TASK_WDT=n
|
||||||
|
|
||||||
|
# 2 cores to perform freertos
|
||||||
|
CONFIG_FREERTOS_UNICORE=n
|
||||||
|
|
||||||
|
# stack size for hook functions
|
||||||
|
CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=4096
|
||||||
|
|
||||||
|
# Trace facility to extract trace information
|
||||||
|
CONFIG_FREERTOS_USE_TRACE_FACILITY=y
|
||||||
|
CONFIG_FREERTOS_USE_STATS_FORMATTING_FUNCTIONS=y
|
||||||
|
CONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID=y
|
||||||
Loading…
x
Reference in New Issue
Block a user