Skip to content

Commit a47fb40

Browse files
committed
docs(esp_tinyuf2): add api reference
1 parent d18abca commit a47fb40

File tree

12 files changed

+269
-115
lines changed

12 files changed

+269
-115
lines changed

.gitlab/ci/rules.yml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,18 @@
308308
- "**/*.md"
309309

310310
.patterns-docs_inc: &patterns-docs_inc
311+
311312
- "components/audio/dac_audio/include/dac_audio.h"
312313
- "components/audio/pwm_audio/include/pwm_audio.h"
313314
- "components/bluetooth/ble_conn_mgr/include/esp_ble_conn_mgr.h"
315+
- "components/bluetooth/ble_conn_mgr/include/esp_ble_conn_mgr.h"
314316
- "components/bluetooth/ble_hci/include/ble_hci.h"
317+
- "components/bluetooth/ble_services/ans/include/esp_ans.h"
318+
- "components/bluetooth/ble_services/bas/include/esp_bas.h"
319+
- "components/bluetooth/ble_services/dis/include/esp_dis.h"
320+
- "components/bluetooth/ble_services/hrs/include/esp_hrs.h"
321+
- "components/bluetooth/ble_services/hts/include/esp_hts.h"
322+
- "components/bluetooth/ble_services/tps/include/esp_tps.h"
315323
- "components/bus/include/spi_bus.h"
316324
- "components/button/include/iot_button.h"
317325
- "components/display/screen/interface_driver/scr_interface_driver.h"
@@ -329,28 +337,21 @@
329337
- "components/motor/esp_sensorless_bldc_control/user_cfg/bldc_user_cfg.h"
330338
- "components/motor/servo/include/iot_servo.h"
331339
- "components/openai/include/OpenAI.h"
340+
- "components/sensors/ntc_driver/include/ntc_driver.h"
341+
- "components/sensors/power_monitor/ina236/include/ina236.h"
332342
- "components/sensors/sensor_hub/include/hal/humiture_hal.h"
333343
- "components/sensors/sensor_hub/include/hal/imu_hal.h"
334344
- "components/sensors/sensor_hub/include/hal/light_sensor_hal.h"
335345
- "components/sensors/sensor_hub/include/iot_sensor_hub.h"
336346
- "components/sensors/sensor_hub/include/sensor_type.h"
337-
- "components/sensors/ntc_driver/include/ntc_driver.h"
338-
- "components/sensors/power_monitor/ina236/include/ina236.h"
339347
- "components/touch/touch_proximity_sensor/include/touch_proximity_sensor.h"
340348
- "components/usb/esp_msc_ota/include/esp_msc_ota.h"
349+
- "components/usb/esp_tinyuf2/esp_tinyuf2.h"
341350
- "components/usb/iot_usbh_cdc/include/iot_usbh_cdc.h"
342351
- "components/usb/usb_device_uac/include/usb_device_uac.h"
343352
- "components/usb/usb_device_uvc/include/usb_device_uvc.h"
344353
- "components/usb/usb_stream/include/usb_stream.h"
345354
- "components/zero_detection/include/zero_detection.h"
346-
- "components/bluetooth/ble_conn_mgr/include/esp_ble_conn_mgr.h"
347-
- "components/bluetooth/ble_services/ans/include/esp_ans.h"
348-
- "components/bluetooth/ble_services/bas/include/esp_bas.h"
349-
- "components/bluetooth/ble_services/dis/include/esp_dis.h"
350-
- "components/bluetooth/ble_services/hrs/include/esp_hrs.h"
351-
- "components/bluetooth/ble_services/hts/include/esp_hts.h"
352-
- "components/bluetooth/ble_services/tps/include/esp_tps.h"
353-
354355
# examples folder, in the alphabetic order
355356
.patterns-example_audio_wav_player: &patterns-example_audio_wav_player
356357
- "examples/audio/**/*"
Lines changed: 7 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,15 @@
11
## ESP TinyUF2
22

3-
The enhanced version of [TinyUF2](https://github.com/adafruit/tinyuf2) for ESP32Sx, which supports over-the-air (OTA) updates for APP. **and supports dumping NVS key-value pairs to the config file, users can modify and write back to NVS**.
3+
`esp_tinyuf2` is an enhanced version of [TinyUF2](https://github.com/adafruit/tinyuf2) for ESP chips with USB-OTG support. Which features:
44

5-
UF2 is a file format developed by Microsoft for [PXT](https://github.com/Microsoft/pxt), that is particularly suitable for flashing microcontrollers over MSC (Mass Storage Class). For a more friendly explanation, check out [this blog post](https://makecode.com/blog/one-chip-to-flash-them-all).
5+
- support over-the-air (OTA) updates through the virtual USB drive
6+
- support dumping NVS key-value pairs to ini file in the virtual USB drive
7+
- support modify ini file and write back to NVS
68

7-
## Support UF2 OTA/NVS in Your Project
9+
![](./uf2_disk.png)
810

9-
1. Add the component to your project using `idf.py add_dependency` command.
1011

11-
```sh
12-
idf.py add-dependency "esp_tinyuf2"
13-
```
12+
### How to use
1413

15-
2. Customer your partition table. Like other OTA solutions, you need to reserve at least two OTA app partitions. Please refer to [Partition Tables](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/partition-tables.html) and [usb_uf2_ota](../../../examples/usb/device/usb_uf2_ota/) example for details.
14+
[esp_tinyuf2 user guide]()
1615

17-
```
18-
# Partition Table Example
19-
# Name, Type, SubType, Offset, Size, Flags
20-
nvs, data, nvs, , 0x4000,
21-
otadata, data, ota, , 0x2000,
22-
phy_init, data, phy, , 0x1000,
23-
ota_0, app, ota_0, , 1500K,
24-
ota_1, app, ota_1, , 1500K,
25-
```
26-
27-
3. Using `idf.py menuconfig` to config the component's behavior in `(Top) → Component config → TinyUF2 Config`
28-
29-
* `USB Virtual Disk size(MB)`: The size of the virtual U-disk shows in File Explorer, 8MB by default
30-
* `Max APP size(MB)`: Maximum APP size, 4MB by default
31-
* `Flash cache size(KB)`: Cache size used for writing Flash efficiently, 32KB by default
32-
* `USB Device VID`: Espressif VID (0x303A) by default
33-
* `USB Device PID`: Espressif test PID (0x8000) by default, refer [esp-usb-pid](https://github.com/espressif/usb-pids) to apply new.
34-
* `USB Disk Name`: The name of the virtual U-disk shows in File Explorer, "ESP32Sx-UF2" by default
35-
* `USB Device Manufacture`: "Espressif" by default
36-
* `Product Name`: "ESP TinyUF2" by default
37-
* `Product ID`: 12345678 by default
38-
* `Product URL`: A `index` file will be added to the U-disk, users can click to goto the webpage, "https://products.espressif.com/" by default
39-
* `UF2 NVS ini file size`: The `ini` file size prepares for NVS function
40-
41-
4. Install tinyuf2 function like below, for more details, please refer example `usb_uf2_nvs` and `usb_uf2_ota`
42-
43-
```c
44-
/* install UF2 OTA */
45-
tinyuf2_ota_config_t ota_config = DEFAULT_TINYUF2_OTA_CONFIG();
46-
ota_config.complete_cb = uf2_update_complete_cb;
47-
/* disable auto restart, if false manual restart later */
48-
ota_config.if_restart = false;
49-
/* install UF2 NVS */
50-
tinyuf2_nvs_config_t nvs_config = DEFAULT_TINYUF2_NVS_CONFIG();
51-
nvs_config.part_name = "nvs";
52-
nvs_config.namespace_name = "myuf2";
53-
nvs_config.modified_cb = uf2_nvs_modified_cb;
54-
esp_tinyuf2_install(&ota_config, &nvs_config);
55-
```
56-
57-
5. Run `idf.py build flash` for the initial download, later `idf.py uf2-ota` can be used to generate new `uf2` app bin
58-
59-
6. Drag and drop UF2 format file to the disk, to upgrade to new `uf2` app bin
60-
61-
![UF2 Disk](./uf2_disk.png)
62-
63-
## Enable UF2 USB Console
64-
65-
If enable UF2 USB console `(Top) → Component config → TinyUF2 Config → Enable USB Console For log`, the log will be output to the USB Serial port (Output to UART by default).
66-
67-
68-
## Build APP to UF2 format
69-
70-
The new command `idf.py uf2-ota` is added by this component, which can be used to build the APP to UF2 format. After the build is complete, the UF2 file (`${PROJECT_NAME}.uf2`) will be generated in the current `project` directory.
71-
72-
```sh
73-
idf.py uf2-ota
74-
```
75-
76-
## Convert Existing APP to UF2 Format
77-
78-
To convert your existing APP binary to UF2 format, simply use the [uf2conv.py](./utils/uf2conv.py) on a `.bin` file, specifying the family id as `ESP32S2`, `ESP32S3` or their magic number as follows. And you must specify the address of 0x00 with the `-b` switch, the tinyuf2 will use it as offset to write to the OTA partition.
79-
80-
1. convert as follows
81-
82-
using:
83-
84-
```sh
85-
$ENV{UF2_UTILS_PATH}/uf2conv.py your_firmware.bin -c -b 0x00 -f ESP32S3
86-
```
87-
88-
or:
89-
90-
```sh
91-
$ENV{UF2_UTILS_PATH}/uf2conv.py your_firmware.bin -c -b 0x00 -f 0xc47e5767
92-
```
93-
94-
## Note
95-
96-
* To use the UF2 OTA function continuously, the TinyUF2 function must be enabled in the updated APP.

components/usb/esp_tinyuf2/esp_tinyuf2.h

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,29 @@ typedef void (*nvs_modified_cb_t)(void);
4141
*
4242
*/
4343
typedef struct {
44-
esp_partition_subtype_t subtype; /*! Partition subtype. if ESP_PARTITION_SUBTYPE_ANY will use the next_update_partition by default. */
45-
const char *label; /*! Partition label. Set this value if looking for partition with a specific name. if subtype==ESP_PARTITION_SUBTYPE_ANY, label default to NULL.*/
46-
bool if_restart; /*! if restart system to new app partition after UF2 flashing done */
47-
update_complete_cb_t complete_cb; /*! user callback called after uf2 update complete */
44+
esp_partition_subtype_t subtype; /*!< Partition subtype. if ESP_PARTITION_SUBTYPE_ANY will use the next_update_partition by default. */
45+
const char *label; /*!< Partition label. Set this value if looking for partition with a specific name. if subtype==ESP_PARTITION_SUBTYPE_ANY, label default to NULL.*/
46+
bool if_restart; /*!< if restart system to new app partition after UF2 flashing done */
47+
update_complete_cb_t complete_cb; /*!< user callback called after uf2 update complete */
4848
} tinyuf2_ota_config_t;
4949

5050
/**
5151
* @brief tinyuf2 nvs configurations
5252
*
5353
*/
5454
typedef struct {
55-
const char *part_name; /*! Partition name. */
56-
const char *namespace_name; /*! Namespace name. */
57-
nvs_modified_cb_t modified_cb; /*! user callback called after uf2 update complete */
55+
const char *part_name; /*!< Partition name. */
56+
const char *namespace_name; /*!< Namespace name. */
57+
nvs_modified_cb_t modified_cb; /*!< user callback called after uf2 update complete */
5858
} tinyuf2_nvs_config_t;
5959

60+
/**
61+
* @brief tinyuf2 current state
62+
*/
6063
typedef enum {
61-
TINYUF2_STATE_NOT_INSTALLED = 0,
62-
TINYUF2_STATE_INSTALLED,
63-
TINYUF2_STATE_MOUNTED,
64+
TINYUF2_STATE_NOT_INSTALLED = 0, /*!< tinyuf2 driver not installed */
65+
TINYUF2_STATE_INSTALLED, /*!< tinyuf2 driver installed */
66+
TINYUF2_STATE_MOUNTED, /*!< USB mounted */
6467
} tinyuf2_state_t;
6568

6669
/**
@@ -81,6 +84,7 @@ esp_err_t esp_tinyuf2_install(tinyuf2_ota_config_t *ota_config, tinyuf2_nvs_conf
8184
* @note not release memory due to tinyusb not support teardown
8285
*
8386
* @return esp_err_t
87+
* - ESP_ERR_INVALID_STATE tinyuf2 not installed
8488
* - ESP_OK Success
8589
*/
8690
esp_err_t esp_tinyuf2_uninstall(void);

components/usb/esp_tinyuf2/idf_component.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
version: "0.2.2"
1+
version: "1.0.0"
22
targets:
33
- esp32s2
44
- esp32s3
55

66
description: Enhanced TinyUF2 for ESP32Sx, support OTA update and NVS operate through USB MSC
77
url: https://github.com/espressif/esp-iot-solution
88
repository: https://github.com/espressif/esp-iot-solution.git
9+
documentation: https://docs.espressif.com/projects/esp-iot-solution/en/latest/usb/usb_device/esp_tinyuf2.html
910
issues: https://github.com/espressif/esp-iot-solution/issues
1011

1112
dependencies:

docs/Doxyfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,16 @@ INPUT = \
5252
$(PROJECT_PATH)/components/motor/esp_sensorless_bldc_control/user_cfg/bldc_user_cfg.h \
5353
$(PROJECT_PATH)/components/motor/servo/include/iot_servo.h \
5454
$(PROJECT_PATH)/components/openai/include/OpenAI.h \
55+
$(PROJECT_PATH)/components/sensors/ntc_driver/include/ntc_driver.h \
56+
$(PROJECT_PATH)/components/sensors/power_monitor/ina236/include/ina236.h \
5557
$(PROJECT_PATH)/components/sensors/sensor_hub/include/hal/humiture_hal.h \
5658
$(PROJECT_PATH)/components/sensors/sensor_hub/include/hal/imu_hal.h \
5759
$(PROJECT_PATH)/components/sensors/sensor_hub/include/hal/light_sensor_hal.h \
5860
$(PROJECT_PATH)/components/sensors/sensor_hub/include/iot_sensor_hub.h \
5961
$(PROJECT_PATH)/components/sensors/sensor_hub/include/sensor_type.h \
60-
$(PROJECT_PATH)/components/sensors/ntc_driver/include/ntc_driver.h \
61-
$(PROJECT_PATH)/components/sensors/power_monitor/ina236/include/ina236.h \
6262
$(PROJECT_PATH)/components/touch/touch_proximity_sensor/include/touch_proximity_sensor.h \
6363
$(PROJECT_PATH)/components/usb/esp_msc_ota/include/esp_msc_ota.h \
64+
$(PROJECT_PATH)/components/usb/esp_tinyuf2/esp_tinyuf2.h \
6465
$(PROJECT_PATH)/components/usb/iot_usbh_cdc/include/iot_usbh_cdc.h \
6566
$(PROJECT_PATH)/components/usb/usb_device_uac/include/usb_device_uac.h \
6667
$(PROJECT_PATH)/components/usb/usb_device_uvc/include/usb_device_uvc.h \

docs/_static/usb/uf2_disk.png

3.92 KB
Loading
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
ESP TinyUF2
2+
============
3+
4+
:link_to_translation:`zh_CN:[中文]`
5+
6+
``esp_tinyuf2`` is an enhanced version of `TinyUF2 <https://github.com/adafruit/tinyuf2>`__ for ESP chips with USB support. Which features:
7+
8+
- support over-the-air (OTA) updates through the virtual USB drive
9+
- support dumping NVS key-value pairs to ini file in the virtual USB drive
10+
- support modify ini file and write back to NVS
11+
12+
UF2 is a file format developed by Microsoft for `PXT <https://github.com/Microsoft/pxt>`__, that is particularly suitable for flashing microcontrollers over MSC (Mass Storage Class). For a more friendly explanation, check out `the blog post <https://makecode.com/blog/one-chip-to-flash-them-all>`__.
13+
14+
Support UF2 OTA/NVS in Your Project
15+
-----------------------------------
16+
17+
1. Add the component to your project using ``idf.py add_dependency`` command.
18+
19+
.. code:: sh
20+
21+
idf.py add-dependency "esp_tinyuf2"
22+
23+
2. Customer your partition table. Like other OTA solutions, you need to reserve at least two OTA app partitions. Please refer to `Partition Tables <https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/partition-tables.html>`__ and `usb_uf2_ota <https://github.com/espressif/esp-iot-solution/tree/master/examples/usb/device/usb_uf2_ota>`__ example for details.
24+
25+
::
26+
27+
# Partition Table Example
28+
# Name, Type, SubType, Offset, Size, Flags
29+
nvs, data, nvs, , 0x4000,
30+
otadata, data, ota, , 0x2000,
31+
phy_init, data, phy, , 0x1000,
32+
ota_0, app, ota_0, , 1500K,
33+
ota_1, app, ota_1, , 1500K,
34+
35+
3. Using ``idf.py menuconfig`` to config the component’s behavior in ``(Top) → Component config → TinyUF2 Config``
36+
37+
- ``USB Virtual Disk size(MB)``: The size of the virtual U-disk shows in File Explorer, 8MB by default
38+
- ``Max APP size(MB)``: Maximum APP size, 4MB by default
39+
- ``Flash cache size(KB)``: Cache size used for writing Flash efficiently, 32KB by default
40+
- ``USB Device VID``: Espressif VID (0x303A) by default
41+
- ``USB Device PID``: Espressif test PID (0x8000) by default, refer `esp-usb-pid <https://github.com/espressif/usb-pids>`__ to apply new.
42+
- ``USB Disk Name``: The name of the virtual U-disk shows in File Explorer, ``ESP32Sx-UF2`` by default
43+
- ``USB Device Manufacture``: ``Espressif`` by default
44+
- ``Product Name``: ``ESP TinyUF2`` by default
45+
- ``Product ID``: ``12345678`` by default
46+
- ``Product URL``: A ``index`` file will be added to the U-disk, users can click to goto the webpage, ``https://products.espressif.com/`` by default
47+
- ``UF2 NVS ini file size``: The ``ini`` file size prepares for NVS function
48+
49+
4. Install tinyuf2 function like below, for more details, please refer example `usb_uf2_nvs <https://github.com/espressif/esp-iot-solution/tree/master/examples/usb/device/usb_uf2_nvs>`__ and `usb_uf2_ota <https://github.com/espressif/esp-iot-solution/tree/master/examples/usb/device/usb_uf2_ota>`__
50+
51+
.. code:: c
52+
53+
/* install UF2 OTA */
54+
tinyuf2_ota_config_t ota_config = DEFAULT_TINYUF2_OTA_CONFIG();
55+
ota_config.complete_cb = uf2_update_complete_cb;
56+
/* disable auto restart, if false manual restart later */
57+
ota_config.if_restart = false;
58+
/* install UF2 NVS */
59+
tinyuf2_nvs_config_t nvs_config = DEFAULT_TINYUF2_NVS_CONFIG();
60+
nvs_config.part_name = "nvs";
61+
nvs_config.namespace_name = "myuf2";
62+
nvs_config.modified_cb = uf2_nvs_modified_cb;
63+
esp_tinyuf2_install(&ota_config, &nvs_config);
64+
65+
5. Run ``idf.py build flash`` for the initial download, later ``idf.py uf2-ota`` can be used to generate new ``uf2`` app bin
66+
67+
6. Drag and drop UF2 format file to the disk, to upgrade to new ``uf2`` app bin
68+
69+
.. figure:: ../../../_static/usb/uf2_disk.png
70+
:alt: UF2 Disk
71+
72+
Enable UF2 USB Console
73+
-----------------------
74+
75+
Through menuconfig ``(Top) → Component config → TinyUF2 Config → Enable USB Console For log``, the log will be output to the USB Serial port (Output to UART by default).
76+
77+
Build APP to UF2 format
78+
-----------------------
79+
80+
The new command ``idf.py uf2-ota`` is added by this component, which can be used to build the APP to UF2 format. After the build is complete, the UF2 file (``${PROJECT_NAME}.uf2``) will be generated in the current ``project`` directory.
81+
82+
.. code:: sh
83+
84+
idf.py uf2-ota
85+
86+
Convert Existing APP to UF2 Format
87+
----------------------------------
88+
89+
To convert your existing APP binary to UF2 format, simply use the `uf2conv.py <https://github.com/espressif/esp-iot-solution/blob/master/components/usb/esp_tinyuf2/utils/uf2conv.py>`__ on a ``.bin`` file, specifying the family id as ``ESP32S2``, ``ESP32S3`` or their magic number as follows. And you must specify the address of 0x00 with the ``-b`` switch, the tinyuf2 will use it as offset to write to the OTA partition.
90+
91+
1. convert as follows
92+
93+
using:
94+
95+
.. code:: sh
96+
97+
uf2conv.py your_firmware.bin -c -b 0x00 -f ESP32S3
98+
99+
or:
100+
101+
.. code:: sh
102+
103+
uf2conv.py your_firmware.bin -c -b 0x00 -f 0xc47e5767
104+
105+
Note
106+
----
107+
108+
- To use the UF2 OTA function continuously, the TinyUF2 function must be enabled in the updated APP.
109+
110+
API Reference
111+
-------------
112+
113+
.. include-build-file:: inc/esp_tinyuf2.inc

docs/en/usb/usb_device/usb_driver_index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ USB Device Drivers
77
:maxdepth: 1
88

99
USB UVC Device <usb_device_uvc>
10-
USB UAC Device <usb_device_uac>
10+
USB UAC Device <usb_device_uac>
11+
USB UF2 Device <esp_tinyuf2>

0 commit comments

Comments
 (0)