par5
This commit is contained in:
parent
56c5b81810
commit
9958803382
8
part5_i2c_com/lab1_i2c_tools/CMakeLists.txt
Normal file
8
part5_i2c_com/lab1_i2c_tools/CMakeLists.txt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# 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)
|
||||||
|
|
||||||
|
set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/system/console/advanced/components)
|
||||||
|
|
||||||
|
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||||
|
project(i2c_tools)
|
||||||
10
part5_i2c_com/lab1_i2c_tools/Makefile
Normal file
10
part5_i2c_com/lab1_i2c_tools/Makefile
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#
|
||||||
|
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
|
||||||
|
# project subdirectory.
|
||||||
|
#
|
||||||
|
|
||||||
|
PROJECT_NAME := i2c_tools
|
||||||
|
|
||||||
|
EXTRA_COMPONENT_DIRS = $(IDF_PATH)/examples/system/console/advanced/components
|
||||||
|
|
||||||
|
include $(IDF_PATH)/make/project.mk
|
||||||
204
part5_i2c_com/lab1_i2c_tools/README.md
Normal file
204
part5_i2c_com/lab1_i2c_tools/README.md
Normal file
@ -0,0 +1,204 @@
|
|||||||
|
# I2C Tools Example
|
||||||
|
|
||||||
|
(See the README.md file in the upper level 'examples' directory for more information about examples.)
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
[I2C Tools](https://i2c.wiki.kernel.org/index.php/I2C_Tools) is a simple but very useful tool for developing I2C related applications, which is also famous in Linux platform. This example just implements some of basic features of [I2C Tools](https://i2c.wiki.kernel.org/index.php/I2C_Tools) based on [esp32 console component](https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/console.html). As follows, this example supports five command-line tools:
|
||||||
|
|
||||||
|
1. `i2cconfig`: It will configure the I2C bus with specific GPIO number, port number and frequency.
|
||||||
|
2. `i2cdetect`: It will scan an I2C bus for devices and output a table with the list of detected devices on the bus.
|
||||||
|
3. `i2cget`: It will read registers visible through the I2C bus.
|
||||||
|
4. `i2cset`: It will set registers visible through the I2C bus.
|
||||||
|
5. `i2cdump`: It will examine registers visible through the I2C bus.
|
||||||
|
|
||||||
|
If you have some trouble in developing I2C related applications, or just want to test some functions of one I2C device, you can play with this example first.
|
||||||
|
|
||||||
|
## How to use example
|
||||||
|
|
||||||
|
### Hardware Required
|
||||||
|
|
||||||
|
To run this example, you should have any ESP32, ESP32-S and ESP32-C based development board. For test purpose, you should have a kind of device with I2C interface as well. Here we will take the CCS811 sensor as an example to show how to test the function of this sensor without writing any code (just use the command-line tools supported by this example). For more information about CCS811, you can consult the [online datasheet](http://ams.com/ccs811).
|
||||||
|
|
||||||
|
#### Pin Assignment:
|
||||||
|
|
||||||
|
**Note:** The following pin assignments are used by default, you can change them with `i2cconfig` command at any time.
|
||||||
|
|
||||||
|
| | SDA | SCL | GND | Other | VCC |
|
||||||
|
| ------------------- | ------ | ------ | ---- | ----- | ---- |
|
||||||
|
| ESP32 I2C Master | GPIO18 | GPIO19 | GND | GND | 3.3V |
|
||||||
|
| ESP32-S2 I2C Master | GPIO18 | GPIO19 | GND | GND | 3.3V |
|
||||||
|
| ESP32-S3 I2C Master | GPIO1 | GPIO2 | GND | GND | 3.3V |
|
||||||
|
| ESP32-C3 I2C Master | GPIO5 | GPIO6 | GND | GND | 3.3V |
|
||||||
|
| Sensor | SDA | SCL | GND | WAK | VCC |
|
||||||
|
|
||||||
|
**Note: ** There’s no need to add an external pull-up resistors for SDA/SCL pin, because the driver will enable the internal pull-up resistors itself.
|
||||||
|
|
||||||
|
### Configure the project
|
||||||
|
|
||||||
|
Open the project configuration menu (`idf.py menuconfig`). Then go into `Example Configuration` menu.
|
||||||
|
|
||||||
|
- You can choose whether or not to save command history into flash in `Store command history in flash` option.
|
||||||
|
|
||||||
|
### Build and Flash
|
||||||
|
|
||||||
|
Run `idf.py -p PORT flash monitor` to build and flash the project..
|
||||||
|
|
||||||
|
(To exit the serial monitor, type ``Ctrl-]``.)
|
||||||
|
|
||||||
|
See the [Getting Started Guide](https://docs.espressif.com/projects/esp-idf/en/latest/get-started/index.html) for full steps to configure and use ESP-IDF to build projects.
|
||||||
|
|
||||||
|
## Example Output
|
||||||
|
|
||||||
|
### Check all supported commands and their usages
|
||||||
|
|
||||||
|
```bash
|
||||||
|
==============================================================
|
||||||
|
| Steps to Use i2c-tools on ESP32 |
|
||||||
|
| |
|
||||||
|
| 1. Try 'help', check all supported commands |
|
||||||
|
| 2. Try 'i2cconfig' to configure your I2C bus |
|
||||||
|
| 3. Try 'i2cdetect' to scan devices on the bus |
|
||||||
|
| 4. Try 'i2cget' to get the content of specific register |
|
||||||
|
| 5. Try 'i2cset' to set the value of specific register |
|
||||||
|
| 6. Try 'i2cdump' to dump all the register (Experiment) |
|
||||||
|
| |
|
||||||
|
==============================================================
|
||||||
|
|
||||||
|
i2c-tools> help
|
||||||
|
help
|
||||||
|
Print the list of registered commands
|
||||||
|
|
||||||
|
i2cconfig [--port=<0|1>] [--freq=<Hz>] --sda=<gpio> --scl=<gpio>
|
||||||
|
Config I2C bus
|
||||||
|
--port=<0|1> Set the I2C bus port number
|
||||||
|
--freq=<Hz> Set the frequency(Hz) of I2C bus
|
||||||
|
--sda=<gpio> Set the gpio for I2C SDA
|
||||||
|
--scl=<gpio> Set the gpio for I2C SCL
|
||||||
|
|
||||||
|
i2cdetect
|
||||||
|
Scan I2C bus for devices
|
||||||
|
|
||||||
|
i2cget -c <chip_addr> [-r <register_addr>] [-l <length>]
|
||||||
|
Read registers visible through the I2C bus
|
||||||
|
-c, --chip=<chip_addr> Specify the address of the chip on that bus
|
||||||
|
-r, --register=<register_addr> Specify the address on that chip to read from
|
||||||
|
-l, --length=<length> Specify the length to read from that data address
|
||||||
|
|
||||||
|
i2cset -c <chip_addr> [-r <register_addr>] [<data>]...
|
||||||
|
Set registers visible through the I2C bus
|
||||||
|
-c, --chip=<chip_addr> Specify the address of the chip on that bus
|
||||||
|
-r, --register=<register_addr> Specify the address on that chip to read from
|
||||||
|
<data> Specify the data to write to that data address
|
||||||
|
|
||||||
|
i2cdump -c <chip_addr> [-s <size>]
|
||||||
|
Examine registers visible through the I2C bus
|
||||||
|
-c, --chip=<chip_addr> Specify the address of the chip on that bus
|
||||||
|
-s, --size=<size> Specify the size of each read
|
||||||
|
|
||||||
|
free
|
||||||
|
Get the current size of free heap memory
|
||||||
|
|
||||||
|
heap
|
||||||
|
Get minimum size of free heap memory that was available during program execu
|
||||||
|
tion
|
||||||
|
|
||||||
|
version
|
||||||
|
Get version of chip and SDK
|
||||||
|
|
||||||
|
restart
|
||||||
|
Software reset of the chip
|
||||||
|
|
||||||
|
deep_sleep [-t <t>] [--io=<n>] [--io_level=<0|1>]
|
||||||
|
Enter deep sleep mode. Two wakeup modes are supported: timer and GPIO. If no
|
||||||
|
wakeup option is specified, will sleep indefinitely.
|
||||||
|
-t, --time=<t> Wake up time, ms
|
||||||
|
--io=<n> If specified, wakeup using GPIO with given number
|
||||||
|
--io_level=<0|1> GPIO level to trigger wakeup
|
||||||
|
|
||||||
|
light_sleep [-t <t>] [--io=<n>]... [--io_level=<0|1>]...
|
||||||
|
Enter light sleep mode. Two wakeup modes are supported: timer and GPIO. Mult
|
||||||
|
iple GPIO pins can be specified using pairs of 'io' and 'io_level' arguments
|
||||||
|
. Will also wake up on UART input.
|
||||||
|
-t, --time=<t> Wake up time, ms
|
||||||
|
--io=<n> If specified, wakeup using GPIO with given number
|
||||||
|
--io_level=<0|1> GPIO level to trigger wakeup
|
||||||
|
|
||||||
|
tasks
|
||||||
|
Get information about running tasks
|
||||||
|
```
|
||||||
|
|
||||||
|
### Configure the I2C bus
|
||||||
|
|
||||||
|
```bash
|
||||||
|
esp32> i2cconfig --port=0 --sda=18 --scl=19 --freq=100000
|
||||||
|
```
|
||||||
|
|
||||||
|
* `--port` option to specify the port of I2C, here we choose port 0 for test.
|
||||||
|
* `--sda` and `--scl` options to specify the gpio number used by I2C bus, here we choose GPIO18 as the SDA and GPIO19 as the SCL.
|
||||||
|
* `--freq` option to specify the frequency of I2C bus, here we set to 100KHz.
|
||||||
|
|
||||||
|
### Check the I2C address (7 bits) on the I2C bus
|
||||||
|
|
||||||
|
```bash
|
||||||
|
esp32> i2cdetect
|
||||||
|
0 1 2 3 4 5 6 7 8 9 a b c d e f
|
||||||
|
00: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
||||||
|
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
||||||
|
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
||||||
|
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
||||||
|
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
||||||
|
50: -- -- -- -- -- -- -- -- -- -- -- 5b -- -- -- --
|
||||||
|
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
||||||
|
70: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
||||||
|
```
|
||||||
|
|
||||||
|
* Here we found the address of CCS811 is 0x5b.
|
||||||
|
|
||||||
|
### Get the value of status register
|
||||||
|
|
||||||
|
```bash
|
||||||
|
esp32> i2cget -c 0x5b -r 0x00 -l 1
|
||||||
|
0x10
|
||||||
|
```
|
||||||
|
|
||||||
|
* `-c` option to specify the address of I2C device (acquired from `i2cdetect` command).
|
||||||
|
* `-r` option to specify the register address you want to inspect.
|
||||||
|
* `-l` option to specify the length of the content.
|
||||||
|
* Here the returned value 0x10 means that the sensor is just in the boot mode and is ready to go into application mode. For more information about CCS811 you should consult the [official website](http://ams.com/ccs811).
|
||||||
|
|
||||||
|
### Change the working mode
|
||||||
|
|
||||||
|
```bash
|
||||||
|
esp32> i2cset -c 0x5b -r 0xF4
|
||||||
|
I (734717) cmd_i2ctools: Write OK
|
||||||
|
esp32> i2cset -c 0x5b -r 0x01 0x10
|
||||||
|
I (1072047) cmd_i2ctools: Write OK
|
||||||
|
esp32> i2cget -c 0x5b -r 0x00 -l 1
|
||||||
|
0x98
|
||||||
|
```
|
||||||
|
|
||||||
|
* Here we change the mode from boot to application and set a proper measure mode (by writing 0x10 to register 0x01)
|
||||||
|
* Now the status value of the sensor is 0x98, which means a valid data is ready to read
|
||||||
|
|
||||||
|
### Read the sensor data
|
||||||
|
|
||||||
|
```bash
|
||||||
|
esp32> i2cget -c 0x5b -r 0x02 -l 8
|
||||||
|
0x01 0xb0 0x00 0x04 0x98 0x00 0x19 0x8f
|
||||||
|
```
|
||||||
|
|
||||||
|
* The register 0x02 will output 8 bytes result, mainly including value of eCO~2~、TVOC and there raw value. So the value of eCO~2~ is 0x01b0 ppm and value of TVOC is 0x04 ppb.
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
* I don’t find any available address when running `i2cdetect` command.
|
||||||
|
* Make sure your wiring connection is right.
|
||||||
|
* Some sensor will have a “wake up” pin, via which user can put the sensor into a sleep mode. So make sure your sensor in **not** in the sleep state.
|
||||||
|
* Reset you I2C device, and then run `i2cdetect` again.
|
||||||
|
* I can’t get the right content when running `i2cdump` command.
|
||||||
|
* Currently the `i2cdump` only support those who have the same content length of registers inside the I2C device. For example, if a device have three register addresses, and the content length at these address are 1 byte, 2 bytes and 4 bytes. In this case you should not expect this command to dump the register correctly.
|
||||||
|
|
||||||
|
|
||||||
|
(For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you as soon as possible.)
|
||||||
|
|
||||||
37
part5_i2c_com/lab1_i2c_tools/example_test.py
Normal file
37
part5_i2c_com/lab1_i2c_tools/example_test.py
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
|
import ttfw_idf
|
||||||
|
|
||||||
|
EXPECT_TIMEOUT = 20
|
||||||
|
|
||||||
|
|
||||||
|
@ttfw_idf.idf_example_test(env_tag='Example_I2C_CCS811_SENSOR')
|
||||||
|
def test_i2ctools_example(env, extra_data):
|
||||||
|
# Get device under test, flash and start example. "i2ctool" must be defined in EnvConfig
|
||||||
|
dut = env.get_dut('i2ctools', 'examples/peripherals/i2c/i2c_tools', dut_class=ttfw_idf.ESP32DUT)
|
||||||
|
dut.start_app()
|
||||||
|
dut.expect('i2c-tools>', timeout=EXPECT_TIMEOUT)
|
||||||
|
# Get i2c address
|
||||||
|
dut.write('i2cdetect')
|
||||||
|
dut.expect('5b', timeout=EXPECT_TIMEOUT)
|
||||||
|
# Get chip ID
|
||||||
|
dut.write('i2cget -c 0x5b -r 0x20 -l 1')
|
||||||
|
dut.expect('0x81', timeout=EXPECT_TIMEOUT)
|
||||||
|
# Reset sensor
|
||||||
|
dut.write('i2cset -c 0x5b -r 0xFF 0x11 0xE5 0x72 0x8A')
|
||||||
|
dut.expect('OK', timeout=EXPECT_TIMEOUT)
|
||||||
|
# Get status
|
||||||
|
dut.write('i2cget -c 0x5b -r 0x00 -l 1')
|
||||||
|
dut.expect_any('0x10', timeout=EXPECT_TIMEOUT)
|
||||||
|
# Change work mode
|
||||||
|
dut.write('i2cset -c 0x5b -r 0xF4')
|
||||||
|
dut.expect('OK', timeout=EXPECT_TIMEOUT)
|
||||||
|
dut.write('i2cset -c 0x5b -r 0x01 0x10')
|
||||||
|
dut.expect('OK', timeout=EXPECT_TIMEOUT)
|
||||||
|
# Get new status
|
||||||
|
dut.write('i2cget -c 0x5b -r 0x00 -l 1')
|
||||||
|
dut.expect_any('0x98', '0x90', timeout=EXPECT_TIMEOUT)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
test_i2ctools_example()
|
||||||
3
part5_i2c_com/lab1_i2c_tools/main/CMakeLists.txt
Normal file
3
part5_i2c_com/lab1_i2c_tools/main/CMakeLists.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
idf_component_register(SRCS "i2ctools_example_main.c"
|
||||||
|
"cmd_i2ctools.c"
|
||||||
|
INCLUDE_DIRS ".")
|
||||||
10
part5_i2c_com/lab1_i2c_tools/main/Kconfig.projbuild
Normal file
10
part5_i2c_com/lab1_i2c_tools/main/Kconfig.projbuild
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
menu "Example Configuration"
|
||||||
|
|
||||||
|
config EXAMPLE_STORE_HISTORY
|
||||||
|
bool "Store command history in flash"
|
||||||
|
default y
|
||||||
|
help
|
||||||
|
Linenoise line editing library provides functions to save and load
|
||||||
|
command history. If this option is enabled, initalizes a FAT filesystem
|
||||||
|
and uses it to store command history.
|
||||||
|
endmenu
|
||||||
409
part5_i2c_com/lab1_i2c_tools/main/cmd_i2ctools.c
Normal file
409
part5_i2c_com/lab1_i2c_tools/main/cmd_i2ctools.c
Normal file
@ -0,0 +1,409 @@
|
|||||||
|
/* cmd_i2ctools.c
|
||||||
|
|
||||||
|
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, this
|
||||||
|
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||||
|
CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "argtable3/argtable3.h"
|
||||||
|
#include "driver/i2c.h"
|
||||||
|
#include "esp_console.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
|
||||||
|
#define I2C_MASTER_TX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
|
||||||
|
#define I2C_MASTER_RX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
|
||||||
|
#define WRITE_BIT I2C_MASTER_WRITE /*!< I2C master write */
|
||||||
|
#define READ_BIT I2C_MASTER_READ /*!< I2C master read */
|
||||||
|
#define ACK_CHECK_EN 0x1 /*!< I2C master will check ack from slave*/
|
||||||
|
#define ACK_CHECK_DIS 0x0 /*!< I2C master will not check ack from slave */
|
||||||
|
#define ACK_VAL 0x0 /*!< I2C ack value */
|
||||||
|
#define NACK_VAL 0x1 /*!< I2C nack value */
|
||||||
|
|
||||||
|
static const char *TAG = "cmd_i2ctools";
|
||||||
|
|
||||||
|
#if CONFIG_IDF_TARGET_ESP32S3
|
||||||
|
static gpio_num_t i2c_gpio_sda = 1;
|
||||||
|
static gpio_num_t i2c_gpio_scl = 2;
|
||||||
|
#elif CONFIG_IDF_TARGET_ESP32C3
|
||||||
|
static gpio_num_t i2c_gpio_sda = 5;
|
||||||
|
static gpio_num_t i2c_gpio_scl = 6;
|
||||||
|
#else
|
||||||
|
static gpio_num_t i2c_gpio_sda = 18;
|
||||||
|
static gpio_num_t i2c_gpio_scl = 19;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static uint32_t i2c_frequency = 100000;
|
||||||
|
static i2c_port_t i2c_port = I2C_NUM_0;
|
||||||
|
|
||||||
|
static esp_err_t i2c_get_port(int port, i2c_port_t *i2c_port)
|
||||||
|
{
|
||||||
|
if (port >= I2C_NUM_MAX) {
|
||||||
|
ESP_LOGE(TAG, "Wrong port number: %d", port);
|
||||||
|
return ESP_FAIL;
|
||||||
|
}
|
||||||
|
*i2c_port = port;
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static esp_err_t i2c_master_driver_initialize(void)
|
||||||
|
{
|
||||||
|
i2c_config_t conf = {
|
||||||
|
.mode = I2C_MODE_MASTER,
|
||||||
|
.sda_io_num = i2c_gpio_sda,
|
||||||
|
.sda_pullup_en = GPIO_PULLUP_ENABLE,
|
||||||
|
.scl_io_num = i2c_gpio_scl,
|
||||||
|
.scl_pullup_en = GPIO_PULLUP_ENABLE,
|
||||||
|
.master.clk_speed = i2c_frequency,
|
||||||
|
// .clk_flags = 0, /*!< Optional, you can use I2C_SCLK_SRC_FLAG_* flags to choose i2c source clock here. */
|
||||||
|
};
|
||||||
|
return i2c_param_config(i2c_port, &conf);
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct {
|
||||||
|
struct arg_int *port;
|
||||||
|
struct arg_int *freq;
|
||||||
|
struct arg_int *sda;
|
||||||
|
struct arg_int *scl;
|
||||||
|
struct arg_end *end;
|
||||||
|
} i2cconfig_args;
|
||||||
|
|
||||||
|
static int do_i2cconfig_cmd(int argc, char **argv)
|
||||||
|
{
|
||||||
|
int nerrors = arg_parse(argc, argv, (void **)&i2cconfig_args);
|
||||||
|
if (nerrors != 0) {
|
||||||
|
arg_print_errors(stderr, i2cconfig_args.end, argv[0]);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check "--port" option */
|
||||||
|
if (i2cconfig_args.port->count) {
|
||||||
|
if (i2c_get_port(i2cconfig_args.port->ival[0], &i2c_port) != ESP_OK) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Check "--freq" option */
|
||||||
|
if (i2cconfig_args.freq->count) {
|
||||||
|
i2c_frequency = i2cconfig_args.freq->ival[0];
|
||||||
|
}
|
||||||
|
/* Check "--sda" option */
|
||||||
|
i2c_gpio_sda = i2cconfig_args.sda->ival[0];
|
||||||
|
/* Check "--scl" option */
|
||||||
|
i2c_gpio_scl = i2cconfig_args.scl->ival[0];
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void register_i2cconfig(void)
|
||||||
|
{
|
||||||
|
i2cconfig_args.port = arg_int0(NULL, "port", "<0|1>", "Set the I2C bus port number");
|
||||||
|
i2cconfig_args.freq = arg_int0(NULL, "freq", "<Hz>", "Set the frequency(Hz) of I2C bus");
|
||||||
|
i2cconfig_args.sda = arg_int1(NULL, "sda", "<gpio>", "Set the gpio for I2C SDA");
|
||||||
|
i2cconfig_args.scl = arg_int1(NULL, "scl", "<gpio>", "Set the gpio for I2C SCL");
|
||||||
|
i2cconfig_args.end = arg_end(2);
|
||||||
|
const esp_console_cmd_t i2cconfig_cmd = {
|
||||||
|
.command = "i2cconfig",
|
||||||
|
.help = "Config I2C bus",
|
||||||
|
.hint = NULL,
|
||||||
|
.func = &do_i2cconfig_cmd,
|
||||||
|
.argtable = &i2cconfig_args
|
||||||
|
};
|
||||||
|
ESP_ERROR_CHECK(esp_console_cmd_register(&i2cconfig_cmd));
|
||||||
|
}
|
||||||
|
|
||||||
|
static int do_i2cdetect_cmd(int argc, char **argv)
|
||||||
|
{
|
||||||
|
i2c_driver_install(i2c_port, I2C_MODE_MASTER, I2C_MASTER_RX_BUF_DISABLE, I2C_MASTER_TX_BUF_DISABLE, 0);
|
||||||
|
i2c_master_driver_initialize();
|
||||||
|
uint8_t address;
|
||||||
|
printf(" 0 1 2 3 4 5 6 7 8 9 a b c d e f\r\n");
|
||||||
|
for (int i = 0; i < 128; i += 16) {
|
||||||
|
printf("%02x: ", i);
|
||||||
|
for (int j = 0; j < 16; j++) {
|
||||||
|
fflush(stdout);
|
||||||
|
address = i + j;
|
||||||
|
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
||||||
|
i2c_master_start(cmd);
|
||||||
|
i2c_master_write_byte(cmd, (address << 1) | WRITE_BIT, ACK_CHECK_EN);
|
||||||
|
i2c_master_stop(cmd);
|
||||||
|
esp_err_t ret = i2c_master_cmd_begin(i2c_port, cmd, 50 / portTICK_RATE_MS);
|
||||||
|
i2c_cmd_link_delete(cmd);
|
||||||
|
if (ret == ESP_OK) {
|
||||||
|
printf("%02x ", address);
|
||||||
|
} else if (ret == ESP_ERR_TIMEOUT) {
|
||||||
|
printf("UU ");
|
||||||
|
} else {
|
||||||
|
printf("-- ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
i2c_driver_delete(i2c_port);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void register_i2cdectect(void)
|
||||||
|
{
|
||||||
|
const esp_console_cmd_t i2cdetect_cmd = {
|
||||||
|
.command = "i2cdetect",
|
||||||
|
.help = "Scan I2C bus for devices",
|
||||||
|
.hint = NULL,
|
||||||
|
.func = &do_i2cdetect_cmd,
|
||||||
|
.argtable = NULL
|
||||||
|
};
|
||||||
|
ESP_ERROR_CHECK(esp_console_cmd_register(&i2cdetect_cmd));
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct {
|
||||||
|
struct arg_int *chip_address;
|
||||||
|
struct arg_int *register_address;
|
||||||
|
struct arg_int *data_length;
|
||||||
|
struct arg_end *end;
|
||||||
|
} i2cget_args;
|
||||||
|
|
||||||
|
static int do_i2cget_cmd(int argc, char **argv)
|
||||||
|
{
|
||||||
|
int nerrors = arg_parse(argc, argv, (void **)&i2cget_args);
|
||||||
|
if (nerrors != 0) {
|
||||||
|
arg_print_errors(stderr, i2cget_args.end, argv[0]);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check chip address: "-c" option */
|
||||||
|
int chip_addr = i2cget_args.chip_address->ival[0];
|
||||||
|
/* Check register address: "-r" option */
|
||||||
|
int data_addr = -1;
|
||||||
|
if (i2cget_args.register_address->count) {
|
||||||
|
data_addr = i2cget_args.register_address->ival[0];
|
||||||
|
}
|
||||||
|
/* Check data length: "-l" option */
|
||||||
|
int len = 1;
|
||||||
|
if (i2cget_args.data_length->count) {
|
||||||
|
len = i2cget_args.data_length->ival[0];
|
||||||
|
}
|
||||||
|
uint8_t *data = malloc(len);
|
||||||
|
|
||||||
|
i2c_driver_install(i2c_port, I2C_MODE_MASTER, I2C_MASTER_RX_BUF_DISABLE, I2C_MASTER_TX_BUF_DISABLE, 0);
|
||||||
|
i2c_master_driver_initialize();
|
||||||
|
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
||||||
|
i2c_master_start(cmd);
|
||||||
|
if (data_addr != -1) {
|
||||||
|
i2c_master_write_byte(cmd, chip_addr << 1 | WRITE_BIT, ACK_CHECK_EN);
|
||||||
|
i2c_master_write_byte(cmd, data_addr, ACK_CHECK_EN);
|
||||||
|
i2c_master_start(cmd);
|
||||||
|
}
|
||||||
|
i2c_master_write_byte(cmd, chip_addr << 1 | READ_BIT, ACK_CHECK_EN);
|
||||||
|
if (len > 1) {
|
||||||
|
i2c_master_read(cmd, data, len - 1, ACK_VAL);
|
||||||
|
}
|
||||||
|
i2c_master_read_byte(cmd, data + len - 1, NACK_VAL);
|
||||||
|
i2c_master_stop(cmd);
|
||||||
|
esp_err_t ret = i2c_master_cmd_begin(i2c_port, cmd, 1000 / portTICK_RATE_MS);
|
||||||
|
i2c_cmd_link_delete(cmd);
|
||||||
|
if (ret == ESP_OK) {
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
printf("0x%02x ", data[i]);
|
||||||
|
if ((i + 1) % 16 == 0) {
|
||||||
|
printf("\r\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (len % 16) {
|
||||||
|
printf("\r\n");
|
||||||
|
}
|
||||||
|
} else if (ret == ESP_ERR_TIMEOUT) {
|
||||||
|
ESP_LOGW(TAG, "Bus is busy");
|
||||||
|
} else {
|
||||||
|
ESP_LOGW(TAG, "Read failed");
|
||||||
|
}
|
||||||
|
free(data);
|
||||||
|
i2c_driver_delete(i2c_port);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void register_i2cget(void)
|
||||||
|
{
|
||||||
|
i2cget_args.chip_address = arg_int1("c", "chip", "<chip_addr>", "Specify the address of the chip on that bus");
|
||||||
|
i2cget_args.register_address = arg_int0("r", "register", "<register_addr>", "Specify the address on that chip to read from");
|
||||||
|
i2cget_args.data_length = arg_int0("l", "length", "<length>", "Specify the length to read from that data address");
|
||||||
|
i2cget_args.end = arg_end(1);
|
||||||
|
const esp_console_cmd_t i2cget_cmd = {
|
||||||
|
.command = "i2cget",
|
||||||
|
.help = "Read registers visible through the I2C bus",
|
||||||
|
.hint = NULL,
|
||||||
|
.func = &do_i2cget_cmd,
|
||||||
|
.argtable = &i2cget_args
|
||||||
|
};
|
||||||
|
ESP_ERROR_CHECK(esp_console_cmd_register(&i2cget_cmd));
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct {
|
||||||
|
struct arg_int *chip_address;
|
||||||
|
struct arg_int *register_address;
|
||||||
|
struct arg_int *data;
|
||||||
|
struct arg_end *end;
|
||||||
|
} i2cset_args;
|
||||||
|
|
||||||
|
static int do_i2cset_cmd(int argc, char **argv)
|
||||||
|
{
|
||||||
|
int nerrors = arg_parse(argc, argv, (void **)&i2cset_args);
|
||||||
|
if (nerrors != 0) {
|
||||||
|
arg_print_errors(stderr, i2cset_args.end, argv[0]);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check chip address: "-c" option */
|
||||||
|
int chip_addr = i2cset_args.chip_address->ival[0];
|
||||||
|
/* Check register address: "-r" option */
|
||||||
|
int data_addr = 0;
|
||||||
|
if (i2cset_args.register_address->count) {
|
||||||
|
data_addr = i2cset_args.register_address->ival[0];
|
||||||
|
}
|
||||||
|
/* Check data: "-d" option */
|
||||||
|
int len = i2cset_args.data->count;
|
||||||
|
|
||||||
|
i2c_driver_install(i2c_port, I2C_MODE_MASTER, I2C_MASTER_RX_BUF_DISABLE, I2C_MASTER_TX_BUF_DISABLE, 0);
|
||||||
|
i2c_master_driver_initialize();
|
||||||
|
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
||||||
|
i2c_master_start(cmd);
|
||||||
|
i2c_master_write_byte(cmd, chip_addr << 1 | WRITE_BIT, ACK_CHECK_EN);
|
||||||
|
if (i2cset_args.register_address->count) {
|
||||||
|
i2c_master_write_byte(cmd, data_addr, ACK_CHECK_EN);
|
||||||
|
}
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
i2c_master_write_byte(cmd, i2cset_args.data->ival[i], ACK_CHECK_EN);
|
||||||
|
}
|
||||||
|
i2c_master_stop(cmd);
|
||||||
|
esp_err_t ret = i2c_master_cmd_begin(i2c_port, cmd, 1000 / portTICK_RATE_MS);
|
||||||
|
i2c_cmd_link_delete(cmd);
|
||||||
|
if (ret == ESP_OK) {
|
||||||
|
ESP_LOGI(TAG, "Write OK");
|
||||||
|
} else if (ret == ESP_ERR_TIMEOUT) {
|
||||||
|
ESP_LOGW(TAG, "Bus is busy");
|
||||||
|
} else {
|
||||||
|
ESP_LOGW(TAG, "Write Failed");
|
||||||
|
}
|
||||||
|
i2c_driver_delete(i2c_port);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void register_i2cset(void)
|
||||||
|
{
|
||||||
|
i2cset_args.chip_address = arg_int1("c", "chip", "<chip_addr>", "Specify the address of the chip on that bus");
|
||||||
|
i2cset_args.register_address = arg_int0("r", "register", "<register_addr>", "Specify the address on that chip to read from");
|
||||||
|
i2cset_args.data = arg_intn(NULL, NULL, "<data>", 0, 256, "Specify the data to write to that data address");
|
||||||
|
i2cset_args.end = arg_end(2);
|
||||||
|
const esp_console_cmd_t i2cset_cmd = {
|
||||||
|
.command = "i2cset",
|
||||||
|
.help = "Set registers visible through the I2C bus",
|
||||||
|
.hint = NULL,
|
||||||
|
.func = &do_i2cset_cmd,
|
||||||
|
.argtable = &i2cset_args
|
||||||
|
};
|
||||||
|
ESP_ERROR_CHECK(esp_console_cmd_register(&i2cset_cmd));
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct {
|
||||||
|
struct arg_int *chip_address;
|
||||||
|
struct arg_int *size;
|
||||||
|
struct arg_end *end;
|
||||||
|
} i2cdump_args;
|
||||||
|
|
||||||
|
static int do_i2cdump_cmd(int argc, char **argv)
|
||||||
|
{
|
||||||
|
int nerrors = arg_parse(argc, argv, (void **)&i2cdump_args);
|
||||||
|
if (nerrors != 0) {
|
||||||
|
arg_print_errors(stderr, i2cdump_args.end, argv[0]);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check chip address: "-c" option */
|
||||||
|
int chip_addr = i2cdump_args.chip_address->ival[0];
|
||||||
|
/* Check read size: "-s" option */
|
||||||
|
int size = 1;
|
||||||
|
if (i2cdump_args.size->count) {
|
||||||
|
size = i2cdump_args.size->ival[0];
|
||||||
|
}
|
||||||
|
if (size != 1 && size != 2 && size != 4) {
|
||||||
|
ESP_LOGE(TAG, "Wrong read size. Only support 1,2,4");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
i2c_driver_install(i2c_port, I2C_MODE_MASTER, I2C_MASTER_RX_BUF_DISABLE, I2C_MASTER_TX_BUF_DISABLE, 0);
|
||||||
|
i2c_master_driver_initialize();
|
||||||
|
uint8_t data_addr;
|
||||||
|
uint8_t data[4];
|
||||||
|
int32_t block[16];
|
||||||
|
printf(" 0 1 2 3 4 5 6 7 8 9 a b c d e f"
|
||||||
|
" 0123456789abcdef\r\n");
|
||||||
|
for (int i = 0; i < 128; i += 16) {
|
||||||
|
printf("%02x: ", i);
|
||||||
|
for (int j = 0; j < 16; j += size) {
|
||||||
|
fflush(stdout);
|
||||||
|
data_addr = i + j;
|
||||||
|
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
||||||
|
i2c_master_start(cmd);
|
||||||
|
i2c_master_write_byte(cmd, chip_addr << 1 | WRITE_BIT, ACK_CHECK_EN);
|
||||||
|
i2c_master_write_byte(cmd, data_addr, ACK_CHECK_EN);
|
||||||
|
i2c_master_start(cmd);
|
||||||
|
i2c_master_write_byte(cmd, chip_addr << 1 | READ_BIT, ACK_CHECK_EN);
|
||||||
|
if (size > 1) {
|
||||||
|
i2c_master_read(cmd, data, size - 1, ACK_VAL);
|
||||||
|
}
|
||||||
|
i2c_master_read_byte(cmd, data + size - 1, NACK_VAL);
|
||||||
|
i2c_master_stop(cmd);
|
||||||
|
esp_err_t ret = i2c_master_cmd_begin(i2c_port, cmd, 50 / portTICK_RATE_MS);
|
||||||
|
i2c_cmd_link_delete(cmd);
|
||||||
|
if (ret == ESP_OK) {
|
||||||
|
for (int k = 0; k < size; k++) {
|
||||||
|
printf("%02x ", data[k]);
|
||||||
|
block[j + k] = data[k];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (int k = 0; k < size; k++) {
|
||||||
|
printf("XX ");
|
||||||
|
block[j + k] = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf(" ");
|
||||||
|
for (int k = 0; k < 16; k++) {
|
||||||
|
if (block[k] < 0) {
|
||||||
|
printf("X");
|
||||||
|
}
|
||||||
|
if ((block[k] & 0xff) == 0x00 || (block[k] & 0xff) == 0xff) {
|
||||||
|
printf(".");
|
||||||
|
} else if ((block[k] & 0xff) < 32 || (block[k] & 0xff) >= 127) {
|
||||||
|
printf("?");
|
||||||
|
} else {
|
||||||
|
printf("%c", block[k] & 0xff);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("\r\n");
|
||||||
|
}
|
||||||
|
i2c_driver_delete(i2c_port);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void register_i2cdump(void)
|
||||||
|
{
|
||||||
|
i2cdump_args.chip_address = arg_int1("c", "chip", "<chip_addr>", "Specify the address of the chip on that bus");
|
||||||
|
i2cdump_args.size = arg_int0("s", "size", "<size>", "Specify the size of each read");
|
||||||
|
i2cdump_args.end = arg_end(1);
|
||||||
|
const esp_console_cmd_t i2cdump_cmd = {
|
||||||
|
.command = "i2cdump",
|
||||||
|
.help = "Examine registers visible through the I2C bus",
|
||||||
|
.hint = NULL,
|
||||||
|
.func = &do_i2cdump_cmd,
|
||||||
|
.argtable = &i2cdump_args
|
||||||
|
};
|
||||||
|
ESP_ERROR_CHECK(esp_console_cmd_register(&i2cdump_cmd));
|
||||||
|
}
|
||||||
|
|
||||||
|
void register_i2ctools(void)
|
||||||
|
{
|
||||||
|
register_i2cconfig();
|
||||||
|
register_i2cdectect();
|
||||||
|
register_i2cget();
|
||||||
|
register_i2cset();
|
||||||
|
register_i2cdump();
|
||||||
|
}
|
||||||
20
part5_i2c_com/lab1_i2c_tools/main/cmd_i2ctools.h
Normal file
20
part5_i2c_com/lab1_i2c_tools/main/cmd_i2ctools.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/* cmd_i2ctools.h
|
||||||
|
|
||||||
|
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, this
|
||||||
|
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||||
|
CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void register_i2ctools(void);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
3
part5_i2c_com/lab1_i2c_tools/main/component.mk
Normal file
3
part5_i2c_com/lab1_i2c_tools/main/component.mk
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#
|
||||||
|
# Main Makefile. This is basically the same as a component makefile.
|
||||||
|
#
|
||||||
81
part5_i2c_com/lab1_i2c_tools/main/i2ctools_example_main.c
Normal file
81
part5_i2c_com/lab1_i2c_tools/main/i2ctools_example_main.c
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
/* i2c-tools example
|
||||||
|
|
||||||
|
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, this
|
||||||
|
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||||
|
CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "sdkconfig.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include "esp_console.h"
|
||||||
|
#include "esp_vfs_fat.h"
|
||||||
|
#include "cmd_system.h"
|
||||||
|
#include "cmd_i2ctools.h"
|
||||||
|
|
||||||
|
static const char *TAG = "i2c-tools";
|
||||||
|
|
||||||
|
#if CONFIG_EXAMPLE_STORE_HISTORY
|
||||||
|
|
||||||
|
#define MOUNT_PATH "/data"
|
||||||
|
#define HISTORY_PATH MOUNT_PATH "/history.txt"
|
||||||
|
|
||||||
|
static void initialize_filesystem(void)
|
||||||
|
{
|
||||||
|
static wl_handle_t wl_handle;
|
||||||
|
const esp_vfs_fat_mount_config_t mount_config = {
|
||||||
|
.max_files = 4,
|
||||||
|
.format_if_mount_failed = true
|
||||||
|
};
|
||||||
|
esp_err_t err = esp_vfs_fat_spiflash_mount(MOUNT_PATH, "storage", &mount_config, &wl_handle);
|
||||||
|
if (err != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "Failed to mount FATFS (%s)", esp_err_to_name(err));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif // CONFIG_EXAMPLE_STORE_HISTORY
|
||||||
|
|
||||||
|
void app_main(void)
|
||||||
|
{
|
||||||
|
esp_console_repl_t *repl = NULL;
|
||||||
|
esp_console_repl_config_t repl_config = ESP_CONSOLE_REPL_CONFIG_DEFAULT();
|
||||||
|
|
||||||
|
#if CONFIG_EXAMPLE_STORE_HISTORY
|
||||||
|
initialize_filesystem();
|
||||||
|
repl_config.history_save_path = HISTORY_PATH;
|
||||||
|
#endif
|
||||||
|
repl_config.prompt = "i2c-tools>";
|
||||||
|
|
||||||
|
// install console REPL environment
|
||||||
|
#if CONFIG_ESP_CONSOLE_UART
|
||||||
|
esp_console_dev_uart_config_t uart_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT();
|
||||||
|
ESP_ERROR_CHECK(esp_console_new_repl_uart(&uart_config, &repl_config, &repl));
|
||||||
|
#elif CONFIG_ESP_CONSOLE_USB_CDC
|
||||||
|
esp_console_dev_usb_cdc_config_t cdc_config = ESP_CONSOLE_DEV_CDC_CONFIG_DEFAULT();
|
||||||
|
ESP_ERROR_CHECK(esp_console_new_repl_usb_cdc(&cdc_config, &repl_config, &repl));
|
||||||
|
#elif CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
|
||||||
|
esp_console_dev_usb_serial_jtag_config_t usbjtag_config = ESP_CONSOLE_DEV_USB_SERIAL_JTAG_CONFIG_DEFAULT();
|
||||||
|
ESP_ERROR_CHECK(esp_console_new_repl_usb_serial_jtag(&usbjtag_config, &repl_config, &repl));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
register_i2ctools();
|
||||||
|
register_system();
|
||||||
|
|
||||||
|
printf("\n ==============================================================\n");
|
||||||
|
printf(" | Steps to Use i2c-tools |\n");
|
||||||
|
printf(" | |\n");
|
||||||
|
printf(" | 1. Try 'help', check all supported commands |\n");
|
||||||
|
printf(" | 2. Try 'i2cconfig' to configure your I2C bus |\n");
|
||||||
|
printf(" | 3. Try 'i2cdetect' to scan devices on the bus |\n");
|
||||||
|
printf(" | 4. Try 'i2cget' to get the content of specific register |\n");
|
||||||
|
printf(" | 5. Try 'i2cset' to set the value of specific register |\n");
|
||||||
|
printf(" | 6. Try 'i2cdump' to dump all the register (Experiment) |\n");
|
||||||
|
printf(" | |\n");
|
||||||
|
printf(" ==============================================================\n\n");
|
||||||
|
|
||||||
|
// start console REPL
|
||||||
|
ESP_ERROR_CHECK(esp_console_start_repl(repl));
|
||||||
|
}
|
||||||
6
part5_i2c_com/lab1_i2c_tools/partitions_example.csv
Normal file
6
part5_i2c_com/lab1_i2c_tools/partitions_example.csv
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# Name, Type, SubType, Offset, Size, Flags
|
||||||
|
# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
|
||||||
|
nvs, data, nvs, 0x9000, 0x6000,
|
||||||
|
phy_init, data, phy, 0xf000, 0x1000,
|
||||||
|
factory, app, factory, 0x10000, 1M,
|
||||||
|
storage, data, fat, , 1M,
|
||||||
|
1394
part5_i2c_com/lab1_i2c_tools/sdkconfig
Normal file
1394
part5_i2c_com/lab1_i2c_tools/sdkconfig
Normal file
File diff suppressed because it is too large
Load Diff
17
part5_i2c_com/lab1_i2c_tools/sdkconfig.defaults
Normal file
17
part5_i2c_com/lab1_i2c_tools/sdkconfig.defaults
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# Reduce bootloader log verbosity
|
||||||
|
CONFIG_BOOTLOADER_LOG_LEVEL_WARN=y
|
||||||
|
CONFIG_BOOTLOADER_LOG_LEVEL=2
|
||||||
|
|
||||||
|
# Increase main task stack size
|
||||||
|
CONFIG_ESP_MAIN_TASK_STACK_SIZE=7168
|
||||||
|
|
||||||
|
# Enable filesystem
|
||||||
|
CONFIG_PARTITION_TABLE_CUSTOM=y
|
||||||
|
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_example.csv"
|
||||||
|
CONFIG_PARTITION_TABLE_FILENAME="partitions_example.csv"
|
||||||
|
|
||||||
|
# Enable FreeRTOS stats formatting functions, needed for 'tasks' command
|
||||||
|
CONFIG_FREERTOS_USE_TRACE_FACILITY=y
|
||||||
|
CONFIG_FREERTOS_USE_STATS_FORMATTING_FUNCTIONS=y
|
||||||
|
|
||||||
|
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
|
||||||
10
part5_i2c_com/lab2-1_temp_sensor/.gitignore
vendored
Normal file
10
part5_i2c_com/lab2-1_temp_sensor/.gitignore
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
|
||||||
|
# Configuration files
|
||||||
|
sdkconfig
|
||||||
|
sdkconfig.old
|
||||||
|
|
||||||
|
# Production folder
|
||||||
|
build/
|
||||||
|
|
||||||
|
# HTML documentation
|
||||||
|
html_doc/
|
||||||
6
part5_i2c_com/lab2-1_temp_sensor/CMakeLists.txt
Normal file
6
part5_i2c_com/lab2-1_temp_sensor/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
part5_i2c_com/lab2-1_temp_sensor/Doxyfile
Normal file
2494
part5_i2c_com/lab2-1_temp_sensor/Doxyfile
Normal file
File diff suppressed because it is too large
Load Diff
3
part5_i2c_com/lab2-1_temp_sensor/Makefile
Normal file
3
part5_i2c_com/lab2-1_temp_sensor/Makefile
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
PROJECT_NAME := main
|
||||||
|
|
||||||
|
include $(IDF_PATH)/make/project.mk
|
||||||
22
part5_i2c_com/lab2-1_temp_sensor/ftdi_ft2232.cfg
Normal file
22
part5_i2c_com/lab2-1_temp_sensor/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
part5_i2c_com/lab2-1_temp_sensor/main/CMakeLists.txt
Normal file
3
part5_i2c_com/lab2-1_temp_sensor/main/CMakeLists.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
idf_component_register(
|
||||||
|
SRC_DIRS "."
|
||||||
|
INCLUDE_DIRS ".")
|
||||||
110
part5_i2c_com/lab2-1_temp_sensor/main/LM75A.c
Normal file
110
part5_i2c_com/lab2-1_temp_sensor/main/LM75A.c
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* Copyright (C) 2021 by Fabrice Muller *
|
||||||
|
* *
|
||||||
|
* This file is useful for ESP32 Design course. *
|
||||||
|
* *
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file LM75A.c
|
||||||
|
* @author Fabrice Muller
|
||||||
|
* @date 12 Nov. 2021
|
||||||
|
* @brief File containing the lab2-1 of Part 5.
|
||||||
|
*
|
||||||
|
* @see https://github.com/fmuller-pns/esp32-vscode-project-template
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "LM75A.h"
|
||||||
|
#include "math.h"
|
||||||
|
|
||||||
|
/* Local variables */
|
||||||
|
static uint8_t i2c_port;
|
||||||
|
static uint8_t i2c_addr;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Init the LM75a device
|
||||||
|
*
|
||||||
|
* @param i2c_port_ port number
|
||||||
|
* @param i2c_addr_ address of device
|
||||||
|
*/
|
||||||
|
void lm75a_init(uint8_t i2c_port_, uint8_t i2c_addr_) {
|
||||||
|
i2c_port = i2c_port_;
|
||||||
|
i2c_addr = i2c_addr_;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Read 2 bytes of the LM75a register
|
||||||
|
*
|
||||||
|
* @param raw array of 2 bytes
|
||||||
|
* @return esp_err_t ESP_OK if no error
|
||||||
|
*/
|
||||||
|
esp_err_t lm75a_readRegister(uint8_t *raw) {
|
||||||
|
|
||||||
|
esp_err_t result;
|
||||||
|
i2c_cmd_handle_t cmd_handle;
|
||||||
|
|
||||||
|
// Create and init command link
|
||||||
|
cmd_handle = i2c_cmd_link_create();
|
||||||
|
|
||||||
|
// Start
|
||||||
|
// i2c_master_start()
|
||||||
|
if ((result = i2c_master_start(cmd_handle)) != ESP_OK)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
// Write with ack : the READ command : at i2c_addr (7 bits) & READ (1 bit)
|
||||||
|
i2c_master_write_byte(cmd_handle, (i2c_addr << 1) | I2C_MASTER_READ, true);
|
||||||
|
|
||||||
|
|
||||||
|
// Read 2 bytes with NACK for the last byte (master)
|
||||||
|
i2c_master_read(cmd_handle,raw,2, I2C_MASTER_LAST_NACK);
|
||||||
|
|
||||||
|
|
||||||
|
// Stop
|
||||||
|
i2c_master_stop(cmd_handle);
|
||||||
|
|
||||||
|
|
||||||
|
// Execute the cmd handle on timeout (1s)
|
||||||
|
i2c_master_cmd_begin(0,cmd_handle, pdMS_TO_TICKS(1000));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Free memory
|
||||||
|
i2c_cmd_link_delete(cmd_handle);
|
||||||
|
|
||||||
|
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Convert the raw (2 bytes) to the temperature
|
||||||
|
*
|
||||||
|
* @param raw array of 2 bytes of the LM75a register
|
||||||
|
* @return float temperature value
|
||||||
|
*/
|
||||||
|
float convertRawToTemperature(uint8_t *raw) {
|
||||||
|
/* Compute temperature value */
|
||||||
|
uint16_t data;
|
||||||
|
data = raw[0]<<8 |raw[1];
|
||||||
|
data = data >>5;
|
||||||
|
return (float)data*0.125;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the temperature of the LM75a
|
||||||
|
*
|
||||||
|
* @param temperature pointer to the temperature
|
||||||
|
* @return esp_err_t ESP_OK if no error
|
||||||
|
*/
|
||||||
|
esp_err_t lm75a_getTemperatureInDegree(float *temperature) {
|
||||||
|
esp_err_t result;
|
||||||
|
uint8_t raw[2] = {0,0};
|
||||||
|
|
||||||
|
/* Read Temperature register */
|
||||||
|
if ((result = lm75a_readRegister(raw)) != ESP_OK)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
/* Compute temprature */
|
||||||
|
*temperature = convertRawToTemperature(raw);
|
||||||
|
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
39
part5_i2c_com/lab2-1_temp_sensor/main/LM75A.h
Normal file
39
part5_i2c_com/lab2-1_temp_sensor/main/LM75A.h
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* Copyright (C) 2021 by Fabrice Muller *
|
||||||
|
* *
|
||||||
|
* This file is useful for ESP32 Design course. *
|
||||||
|
* *
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file LM75A.h
|
||||||
|
* @author Fabrice Muller
|
||||||
|
* @date 12 Nov. 2021
|
||||||
|
* @brief File containing the lab2-1 of Part 5.
|
||||||
|
*
|
||||||
|
* @see https://github.com/fmuller-pns/esp32-vscode-project-template
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _LM75A_H_
|
||||||
|
#define _LM75A_H_
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "driver/i2c.h"
|
||||||
|
|
||||||
|
// slave address
|
||||||
|
#define LM75A_ADDRESS 0x48
|
||||||
|
|
||||||
|
// Registers
|
||||||
|
#define TEMP_REG_OFFSET 0
|
||||||
|
#define CONF_REG_OFFSET 1
|
||||||
|
#define THYST_REG_OFFSET 2
|
||||||
|
#define TOS_REG_OFFSET 3
|
||||||
|
|
||||||
|
void lm75a_init(uint8_t i2c_port_, uint8_t i2c_addr_);
|
||||||
|
|
||||||
|
esp_err_t lm75a_readRegister(uint8_t *raw);
|
||||||
|
|
||||||
|
esp_err_t lm75a_getTemperatureInDegree(float *temperature);
|
||||||
|
float convertRawToTemperature(uint8_t *raw);
|
||||||
|
|
||||||
|
#endif
|
||||||
2
part5_i2c_com/lab2-1_temp_sensor/main/component.mk
Normal file
2
part5_i2c_com/lab2-1_temp_sensor/main/component.mk
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
COMPONENT_SRCDIRS := .
|
||||||
|
COMPONENT_ADD_INCLUDEDIRS := .
|
||||||
80
part5_i2c_com/lab2-1_temp_sensor/main/main.c
Normal file
80
part5_i2c_com/lab2-1_temp_sensor/main/main.c
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* Copyright (C) 2021 by Fabrice Muller *
|
||||||
|
* *
|
||||||
|
* This file is useful for ESP32 Design course. *
|
||||||
|
* *
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file main.c
|
||||||
|
* @author Fabrice Muller
|
||||||
|
* @date 12 Nov. 2021
|
||||||
|
* @brief File containing the lab2-1 of Part 5.
|
||||||
|
*
|
||||||
|
* @see https://github.com/fmuller-pns/esp32-vscode-project-template
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "freertos/task.h"
|
||||||
|
#include "driver/i2c.h"
|
||||||
|
#include "esp_types.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
|
||||||
|
#include "LM75A.h"
|
||||||
|
|
||||||
|
static const char *TAG = "MAIN";
|
||||||
|
|
||||||
|
/*
|
||||||
|
* I2C Pins
|
||||||
|
* SDA: GPIO26, SCL: GPIO25
|
||||||
|
*/
|
||||||
|
#define SDA_GPIO 26
|
||||||
|
#define SCL_GPIO 25
|
||||||
|
|
||||||
|
// I2C port number : N°0
|
||||||
|
#define LM75A_PORT_NUM 0
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Starting point function
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
void app_main(void) {
|
||||||
|
|
||||||
|
/* Install I2C driver : MASTER mode, GPIO SDA/SCL, SDA/SCL Pullup enable (GPIO_PULLUP ... constant), Freq=10KHz */
|
||||||
|
i2c_config_t i2c_config = {
|
||||||
|
.mode = I2C_MODE_MASTER,
|
||||||
|
.sda_io_num = SDA_GPIO,
|
||||||
|
.scl_io_num = SCL_GPIO,
|
||||||
|
.sda_pullup_en = true,
|
||||||
|
.scl_pullup_en = true,
|
||||||
|
.master.clk_speed = 10000};
|
||||||
|
i2c_param_config(LM75A_PORT_NUM, &i2c_config);
|
||||||
|
i2c_driver_install(LM75A_PORT_NUM, I2C_MODE_MASTER, 0, 0, 0);
|
||||||
|
|
||||||
|
/* Init LM75a for i2c */
|
||||||
|
lm75a_init(LM75A_PORT_NUM, LM75A_ADDRESS);
|
||||||
|
|
||||||
|
esp_err_t result;
|
||||||
|
uint8_t raw[2];
|
||||||
|
float temperature = 0;
|
||||||
|
|
||||||
|
/* Get Temperature each 2 seconds */
|
||||||
|
for (;;) {
|
||||||
|
// Waiting for 2 seconds
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(2000));
|
||||||
|
|
||||||
|
/* Read Temperature register */
|
||||||
|
lm75a_readRegister(&raw);
|
||||||
|
|
||||||
|
/* Compute temperature */
|
||||||
|
temperature = convertRawToTemperature(&raw);
|
||||||
|
|
||||||
|
/* Print temprature */
|
||||||
|
printf("Temperature: %.2f °C\n", temperature);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
294
part5_i2c_com/lab2-1_temp_sensor/readme.md
Normal file
294
part5_i2c_com/lab2-1_temp_sensor/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`
|
||||||
|
|
||||||
3
part5_i2c_com/lab2-1_temp_sensor/sdkconfig(2).defaults
Normal file
3
part5_i2c_com/lab2-1_temp_sensor/sdkconfig(2).defaults
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
|
||||||
|
CONFIG_ESPTOOLPY_FLASHSIZE="4MB"
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user