### FATFS Getting Started Example Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-reference/storage/index.html Demonstrates basic common file API (stdio.h) usage over internal flash using FATFS. ```c fatfs/getting_started ``` -------------------------------- ### Navigate to NimBLE_Connection Example Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-guides/ble/get-started/ble-connection.html Use this command to navigate to the NimBLE_Connection example directory within your ESP-IDF installation. ```bash cd /examples/bluetooth/ble_get_started/nimble/NimBLE_Connection ``` -------------------------------- ### View Application Output in Monitor Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/get-started/linux-macos-start-project.html Example of the expected output from the 'hello_world' application after it starts running on the ESP32-C3, as seen in the IDF Monitor. ```text ... Hello world! Restarting in 10 seconds... This is esp32c3 chip with 1 CPU core(s), WiFi/BLE, silicon revision 0, 2 MB external flash Minimum free heap size: 337332 bytes Restarting in 9 seconds... Restarting in 8 seconds... Restarting in 7 seconds... ``` -------------------------------- ### Navigate to NimBLE_Beacon Example Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-guides/ble/get-started/ble-device-discovery.html Use this command to navigate to the NimBLE_Beacon example directory within your ESP-IDF installation. Replace with your local ESP-IDF folder path. ```bash cd /examples/bluetooth/ble_get_started/nimble/NimBLE_Beacon ``` -------------------------------- ### Create Project from Example Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-guides/tools/idf-component-manager.html Creates a new project from a component example available in the ESP Component Registry. The format specifies the component and example name. ```shell idf.py create-project-from-example namespace/name=1.0.0:example ``` -------------------------------- ### Example Post-Attach Callback Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-reference/network/esp_netif_driver.html A sample post-attach callback function for an I/O driver. It sets up the driver configuration for ESP-NETIF and starts the driver implementation. ```c static esp_err_t my_post_attach_start(esp_netif_t * esp_netif, void * args) { my_netif_driver_t *driver = args; const esp_netif_driver_ifconfig_t driver_ifconfig = { .driver_free_rx_buffer = my_free_rx_buf, .transmit = my_transmit, .handle = driver->driver_impl }; driver->base.netif = esp_netif; ESP_ERROR_CHECK(esp_netif_set_driver_config(esp_netif, &driver_ifconfig)); my_driver_start(driver->driver_impl); return ESP_OK; } ``` -------------------------------- ### Launch Interactive ESP-IDF Installation Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/get-started/linux-setup.html Launches the interactive installation wizard for customizing ESP-IDF installation options. ```bash eim wizard ``` -------------------------------- ### Install Script for Documentation Build Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/contribute/documenting-code.html Shows the command to run the install script to enable building documentation, which installs the 'esp-docs' Python package. ```bash ./install.sh --enable-docs ``` -------------------------------- ### Navigate to BLE GATT Server Example Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-guides/ble/get-started/ble-introduction.html Change directory to the NimBLE_GATT_Server example within the ESP-IDF examples. ```bash $ cd /examples/bluetooth/ble_get_started/nimble/NimBLE_GATT_Server ``` -------------------------------- ### Install ESP-IDF Installation Manager (APT - GUI and CLI) Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/get-started/linux-setup.html Installs both the Graphical User Interface (GUI) and Command Line Interface (CLI) versions of the ESP-IDF Installation Manager (EIM) using APT. ```bash sudo apt install eim ``` -------------------------------- ### Copy Example Project Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/get-started/windows-start-project.html Copies the 'hello_world' example project to your user's 'esp' directory. Ensure there are no spaces in the ESP-IDF or project paths. ```bash cd %userprofile%\esp xcopy /e /i %IDF_PATH%\examples\get-started\hello_world hello_world ``` -------------------------------- ### Start Ethernet Driver Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-reference/network/esp_eth.html Starts the Ethernet driver's state machine after it has been installed. ```c esp_eth_start(eth_handle); // start Ethernet driver state machine ``` -------------------------------- ### Copy Hello World Project Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/get-started/linux-macos-start-project.html Copies the 'hello_world' example project to your `~/esp` directory. Ensure that your ESP-IDF path is correctly set. ```bash cd ~/ esp cp -r $IDF_PATH/examples/get-started/hello_world . ``` -------------------------------- ### Start MCP Server with eim run Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-guides/tools/idf-py.html Use `eim run` to start the MCP server. This is recommended when ESP-IDF is installed via the EIM installer and does not require prior ESP-IDF environment activation. ```bash eim run "idf.py mcp-server" ``` -------------------------------- ### Create a project from the unit-test-app example Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/migration-guides/release-6.x/6.0/tools.html Use this command to create a new project based on the legacy unit-test-app, which is now available on The ESP Component Registry. ```bash idf.py create-project-from-example espressif/unit-test-app:unit-test-app ``` -------------------------------- ### ESP-IDF Installation Success Message Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/get-started/linux-setup.html Example of the success message displayed in the terminal after a successful ESP-IDF installation. ```text 2025-11-03T15:54:12.537993300+08:00 - INFO - Wizard result: %{r} 2025-11-03T15:54:12.544174+08:00 - INFO - Successfully installed IDF 2025-11-03T15:54:12.545913900+08:00 - INFO - Now you can start using IDF tools ``` -------------------------------- ### Open Example Project in VSCode Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-guides/ble/get-started/ble-introduction.html Open the NimBLE_GATT_Server example project in VSCode from the command line. ```bash $ code . ``` -------------------------------- ### Install gdbgui on Windows Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/migration-guides/release-6.x/6.0/tools.html Use this command to install specific versions of gdbgui and its dependencies on Windows when using Python 3.10. Consult the gdbgui installation guide for more details. ```bash pipx install "gdbgui==0.13.2.0" "pygdbmi<=0.9.0.2" "python-socketio<5" "jinja2<3.1" "itsdangerous<2.1" ``` -------------------------------- ### Install Pre-built QEMU Binaries Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-guides/tools/qemu.html Installs the pre-built QEMU binaries for ESP32-C3 emulation. ```bash python $IDF_PATH/tools/idf_tools.py install qemu-xtensa qemu-riscv32 ``` -------------------------------- ### Start ESP HTTP Server Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-reference/protocols/esp_http_server.html Starts the web server by creating an instance and allocating resources based on the provided configuration. Ensure the handle is checked for NULL on error. ```c httpd_handle_t start_webserver(void) { // Generate default configuration httpd_config_t config = HTTPD_DEFAULT_CONFIG(); // Empty handle to http_server httpd_handle_t server = NULL; // Start the httpd server if (httpd_start(&server, &config) == ESP_OK) { // Register URI handlers httpd_register_uri_handler(server, &uri_get); httpd_register_uri_handler(server, &uri_post); } // If server failed to start, handle will be NULL return server; } ``` -------------------------------- ### OpenOCD Version Output Example Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-guides/jtag-debugging/index.html This is an example of the expected output when verifying the OpenOCD installation. The version number may differ. ```text Open On-Chip Debugger v0.12.0-esp32-20240318 (2024-03-18-18:25) Licensed under GNU GPL v2 For bug reports, read http://openocd.org/doc/doxygen/bugs.html ``` -------------------------------- ### httpd_start Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-reference/protocols/esp_http_server.html Starts the web server by creating an instance and allocating resources based on the provided configuration. ```APIDOC ## httpd_start ### Description Starts the web server. Create an instance of HTTP server and allocate memory/resources for it depending upon the specified configuration. ### Parameters #### Path Parameters - **config** (httpd_config_t) - [in] Configuration for new instance of the server - **handle** (httpd_handle_t *) - [out] Handle to newly created instance of the server. NULL on error ### Returns - ESP_OK : Instance created successfully - ESP_ERR_INVALID_ARG : Null argument(s) - ESP_ERR_HTTPD_ALLOC_MEM : Failed to allocate memory for instance - ESP_ERR_HTTPD_TASK : Failed to launch server task ``` -------------------------------- ### Start LEDC Fading Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-reference/peripherals/ledc.html Starts an LEDC fading operation. This function should be called after installing the fade function and setting fade parameters. ```APIDOC ## ledc_fade_start ### Description Start LEDC fading. Call ledc_fade_func_install() once before calling this function. Call this API right after ledc_set_fade_with_time or ledc_set_fade_with_step before to start fading. Starting fade operation with this API is not thread-safe, use with care. For ESP32, hardware does not support any duty change while a fade operation is running in progress on that channel. Other duty operations will have to wait until the fade operation has finished. ### Parameters #### Path Parameters - **speed_mode** (ledc_mode_t) - Select the LEDC channel group with specified speed mode. Note that not all targets support high speed mode. - **channel** (ledc_channel_t) - LEDC channel number - **fade_mode** (ledc_fade_mode_t) - Whether to block until fading done. See ledc_types.h ledc_fade_mode_t for more info. Note that this function will not return until fading to the target duty if LEDC_FADE_WAIT_DONE mode is selected. ### Returns - ESP_OK Success - ESP_ERR_INVALID_STATE Channel not initialized or fade function not installed. - ESP_ERR_INVALID_ARG Parameter error. ``` -------------------------------- ### Install Xcode Command Line Tools Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/get-started/linux-macos-setup-legacy.html Installs Xcode command line tools, which are required if you encounter errors related to missing xcrun during the setup process. ```bash xcode-select --install ``` -------------------------------- ### Build, Flash, and Monitor ESP32-C3 BLE Example Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-guides/ble/get-started/ble-introduction.html Build the firmware, flash it to the ESP32-C3 development board, and monitor the serial output for BLE GATT server activity. ```bash $ idf.py flash monitor ``` -------------------------------- ### Start RFC2217 Server on Windows Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-guides/tools/idf-docker-image.html Install and start the `esp_rfc2217_server` on Windows to enable remote serial port access. This is useful for connecting to serial ports within a Docker container. ```bash esp_rfc2217_server -v -p 4000 COM3 ``` -------------------------------- ### LittleFS Filesystem Example Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-reference/storage/index.html Shows the use of the LittleFS component to initialize the filesystem and work with a file using POSIX functions. ```c littlefs ``` -------------------------------- ### Build System Output Example Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/get-started/windows-start-project.html Example output from the 'idf.py build' command, showing the compilation process and final firmware generation. It also provides alternative commands for flashing. ```bash $ idf.py build Running cmake in directory /path/to/hello_world/build Executing "cmake -G Ninja --warn-uninitialized /path/to/hello_world"... Warn about uninitialized values. -- Found Git: /usr/bin/git (found version "2.17.0") -- Building empty aws_iot component due to configuration -- Component names: ... -- Component paths: ... ... (more lines of build system output) [527/527] Generating hello_world.bin esptool v5.0.2 Project build complete. To flash, run: idf.py flash or idf.py -p PORT flash or esptool -p (PORT) -b 921600 write-flash --flash-mode dio --flash-size detect --flash-freq 40m 0x10000 build/hello_world.bin build 0x1000 build/bootloader/bootloader.bin 0x8000 build/partition_table/partition-table.bin ``` -------------------------------- ### Install I2C master bus and device Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-reference/peripherals/i2c.html This example demonstrates how to install an I2C master bus and add a device to it. It involves configuring the master bus with `i2c_master_bus_config_t` and then adding the device with `i2c_device_config_t`. ```APIDOC ## Install I2C master bus and device The I2C master bus is designed based on bus-device model. So `i2c_master_bus_config_t` and `i2c_device_config_t` are required separately to allocate the I2C master bus instance and I2C device instance. I2C master bus requires the configuration that specified by `i2c_master_bus_config_t`: * `i2c_master_bus_config_t::i2c_port` sets the I2C port used by the controller. * `i2c_master_bus_config_t::sda_io_num` sets the GPIO number for the serial data bus (SDA). * `i2c_master_bus_config_t::scl_io_num` sets the GPIO number for the serial clock bus (SCL). * `i2c_master_bus_config_t::clk_source` selects the source clock for I2C bus. The available clocks are listed in `i2c_clock_source_t`. For the effect on power consumption of different clock source, please refer to Power Management section. * `i2c_master_bus_config_t::glitch_ignore_cnt` sets the glitch period of master bus, if the glitch period on the line is less than this value, it can be filtered out, typically value is 7. * `i2c_master_bus_config_t::intr_priority` sets the priority of the interrupt. If set to `0` , then the driver will use a interrupt with low or medium priority (priority level may be one of 1, 2 or 3), otherwise use the priority indicated by `i2c_master_bus_config_t::intr_priority`. Please use the number form (1, 2, 3) , not the bitmask form ((1<<1), (1<<2), (1<<3)). * `i2c_master_bus_config_t::trans_queue_depth` sets the depth of internal transfer queue. Only valid in asynchronous transaction. * `i2c_master_bus_config_t::enable_internal_pullup` enables internal pullups. Note: This is not strong enough to pullup buses under high-speed frequency. A suitable external pullup is recommended. * `i2c_master_bus_config_t::allow_pd` configures if the driver allows the system to power down the peripheral in light sleep mode. Before entering sleep, the system will backup the I2C register context, which will be restored later when the system exit the sleep mode. Powering down the peripheral can save more power, but at the cost of more memory consumed to save the register context. It's a tradeoff between power consumption and memory consumption. This configuration option relies on specific hardware feature, if you enable it on an unsupported chip, you will see error message like `not able to power down in light sleep`. If the configurations in `i2c_master_bus_config_t` is specified, then `i2c_new_master_bus()` can be called to allocate and initialize an I2C master bus. This function will return an I2C bus handle if it runs correctly. Specifically, when there are no more I2C port available, this function will return `ESP_ERR_NOT_FOUND` error. I2C master device requires the configuration that specified by `i2c_device_config_t`: * `i2c_device_config_t::dev_addr_length` configure the address bit length of the slave device. It can be chosen from enumerator `I2C_ADDR_BIT_LEN_7` or `I2C_ADDR_BIT_LEN_10` (if supported). * `i2c_device_config_t::device_address` sets the I2C device raw address. Please parse the device address to this member directly. For example, the device address is 0x28, then parse 0x28 to `i2c_device_config_t::device_address`, don't carry a write or read bit. * `i2c_device_config_t::scl_speed_hz` sets the SCL line frequency of this device. * `i2c_device_config_t::scl_wait_us` sets the SCL await time (in μs). Usually this value should not be very small because slave stretch will happen in pretty long time (It's possible even stretch for 12 ms). Set `0` means use default register value. Once the `i2c_device_config_t` structure is populated with mandatory parameters, `i2c_master_bus_add_device()` can be called to allocate an I2C device instance and mounted to the master bus then. This function will return an I2C device handle if it runs correctly. Specifically, when the I2C bus is not initialized properly, calling this function will result in a `ESP_ERR_INVALID_ARG` error. ```c #include "driver/i2c_master.h" i2c_master_bus_config_t i2c_mst_config = { .clk_source = I2C_CLK_SRC_DEFAULT, .i2c_port = TEST_I2C_PORT, .scl_io_num = I2C_MASTER_SCL_IO, .sda_io_num = I2C_MASTER_SDA_IO, .glitch_ignore_cnt = 7, .flags.enable_internal_pullup = true, }; i2c_master_bus_handle_t bus_handle; ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_mst_config, &bus_handle)); i2c_device_config_t dev_cfg = { .dev_addr_length = I2C_ADDR_BIT_LEN_7, .device_address = 0x58, .scl_speed_hz = 100000, }; i2c_master_dev_handle_t dev_handle; ESP_ERROR_CHECK(i2c_master_bus_add_device(bus_handle, &dev_cfg, &dev_handle)); ``` ``` -------------------------------- ### Run IDF Application in QEMU with Monitor Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-guides/tools/qemu.html Builds the application, starts QEMU, and opens IDF monitor connected to the emulated UART. ```bash idf.py qemu monitor ``` -------------------------------- ### IDF Monitor Filtering Example 2 Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-guides/tools/idf-monitor.html This example shows a more restrictive filtering setup, enabling 'light_driver' debug messages and 'heap_init' info messages, while suppressing others. The wildcard '*' ensures default verbose logging for any unlisted tags. ```bash --print_filter="light_driver:D esp_image:N boot:N cpu_start:N vfs:N wifi:N *:V" ``` -------------------------------- ### PicolibC vs Newlib File I/O Example Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/migration-guides/release-6.x/6.0/system.html This example demonstrates file I/O operations that can be compiled and compared between Newlib and Picolibc to observe differences in binary size, stack, and heap usage. ```c FILE *f = fopen("/dev/console", "w"); for (int i = 0; i < 10; i++) { fprintf(f, "hello world %s\n", "🤖"); fprintf(f, "%.1000f\n", 3.141592653589793); fprintf(f, "%1000d\n", 42); } ``` -------------------------------- ### Get Minimum Free Heap Size Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-reference/system/misc_system_api.html Returns the minimum amount of heap memory that has ever been available since the system started. ```APIDOC ## esp_get_minimum_free_heap_size ### Description Get the minimum heap that has ever been available. ### Returns Minimum free heap ever available ``` -------------------------------- ### Common Filesystem API Examples Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-reference/storage/index.html Examples demonstrating basic common file API (stdio.h) usage and POSIX API for filesystem manipulation. ```APIDOC ## fatfs/getting_started ### Description Demonstrates basic common file API (stdio.h) usage over internal flash using FATFS. ## fatfs/fs_operations ### Description Demonstrates POSIX API for filesystem manipulation, such as moving, removing and renaming files. ``` -------------------------------- ### CMakeLists.txt for a Component Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-guides/build-system-v2.html This example demonstrates how to define a library, include other components, link dependencies, and set component properties like WHOLE_ARCHIVE, LDFRAGMENTS, and LINKER_SCRIPTS. ```cmake add_library(${COMPONENT_TARGET} STATIC "srcs/esp_target_info.c" ) target_include_directories(${COMPONENT_TARGET} PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include ) idf_component_include(esp_hw_support) idf_component_include(spi_flash) idf_component_include(esp_system) target_link_libraries(${COMPONENT_TARGET} PRIVATE idf::esp_hw_support idf::spi_flash idf::esp_system ) idf_component_set_property(${COMPONENT_TARGET} WHOLE_ARCHIVE TRUE) idf_component_set_property(${COMPONENT_TARGET} LDFRAGMENTS linker.lf APPEND) idf_component_set_property(${COMPONENT_TARGET} LINKER_SCRIPTS esp_target_info.ld APPEND) target_link_options(${COMPONENT_TARGET} INTERFACE "SHELL:-u esp_chip_info") ``` -------------------------------- ### FreeRTOS ISR Example: Buffered IO Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-reference/system/freertos_idf.html Example usage of sending data from an ISR, potentially handling buffered input where multiple values can be obtained per ISR call. This snippet shows the setup for waking a higher priority task if necessary. ```c void vBufferISR( void ) { char cIn; BaseType_t xHigherPriorityTaskWokenByPost; // We have not woken a task at the start of the ISR. ``` -------------------------------- ### Configure Project for ESP32-C3 Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/get-started/windows-start-project.html Navigates to the project directory, sets the target chip to ESP32-C3, and opens the configuration utility. This step initializes the project and clears existing configurations. ```bash cd %userprofile%\esp\hello_world idf.py set-target esp32c3 idf.py menuconfig ``` -------------------------------- ### Get Current Tick Count Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-reference/system/freertos_idf.html Retrieves the current tick count since the scheduler was started. This function is suitable for use in application tasks. ```c TickType_t xTaskGetTickCount(void) ``` -------------------------------- ### Extended Advertising and Scanning Events Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-reference/bluetooth/esp_gap_ble.html Events related to extended advertising operations, including parameter setup, starting, stopping, and receiving reports. ```APIDOC ## Extended Advertising and Scanning Events ### Enumerations - **ESP_GAP_BLE_SET_EXT_SCAN_PARAMS_COMPLETE_EVT** - Description: Indicates that setting extended scan parameters has completed. - **ESP_GAP_BLE_EXT_SCAN_START_COMPLETE_EVT** - Description: Indicates that starting extended scanning has completed. - **ESP_GAP_BLE_EXT_SCAN_STOP_COMPLETE_EVT** - Description: Indicates that stopping extended scanning has completed. - **ESP_GAP_BLE_EXT_ADV_REPORT_EVT** - Description: Indicates that an extended advertising report has been received. - **ESP_GAP_BLE_ADV_TERMINATED_EVT** - Description: Indicates that advertising has been terminated. - **ESP_GAP_BLE_ADV_CLEAR_COMPLETE_EVT** - Description: Indicates that clearing advertising data has completed. ``` -------------------------------- ### Initialize Ethernet Driver and Connect to TCP/IP Stack Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-reference/network/esp_eth.html Initializes the TCP/IP stack, creates a network interface for Ethernet, attaches it to the driver, registers an IP event handler, and starts the Ethernet driver. This should be done after the Ethernet driver is installed and before starting the driver state machine. ```c /** Event handler for IP_EVENT_ETH_GOT_IP */ static void got_ip_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data) { ip_event_got_ip_t *event = (ip_event_got_ip_t *) event_data; const esp_netif_ip_info_t *ip_info = &event->ip_info; ESP_LOGI(TAG, "Ethernet Got IP Address"); ESP_LOGI(TAG, "~~~~~~~~~~~"); ESP_LOGI(TAG, "ETHIP:" IPSTR, IP2STR(&ip_info->ip)); ESP_LOGI(TAG, "ETHMASK:" IPSTR, IP2STR(&ip_info->netmask)); ESP_LOGI(TAG, "ETHGW:" IPSTR, IP2STR(&ip_info->gw)); ESP_LOGI(TAG, "~~~~~~~~~~~"); } esp_netif_init()); // Initialize TCP/IP network interface (should be called only once in application) esp_netif_config_t cfg = ESP_NETIF_DEFAULT_ETH(); // apply default network interface configuration for Ethernet esp_netif_t *eth_netif = esp_netif_new(&cfg); // create network interface for Ethernet driver esp_netif_attach(eth_netif, esp_eth_new_netif_glue(eth_handle)); // attach Ethernet driver to TCP/IP stack esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, &got_ip_event_handler, NULL); // register user defined IP event handlers esp_eth_start(eth_handle); // start Ethernet driver state machine ``` -------------------------------- ### Protocomm Bluetooth LE Transport Example Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-reference/provisioning/protocomm.html This snippet shows how to start and stop a Protocomm instance using Bluetooth LE transport with Security 0. ```APIDOC ## Bluetooth LE Transport Example with Security 0 ### Function: `start_pc` #### Description Initializes and starts a Protocomm instance over Bluetooth LE transport with Security 0. #### Parameters None. #### Returns - `protocomm_t *`: A pointer to the initialized Protocomm instance. ### Function: `stop_pc` #### Description Stops and cleans up a Protocomm instance started with Bluetooth LE transport. #### Parameters - `pc` (protocomm_t *): Pointer to the Protocomm instance to stop. ``` -------------------------------- ### Partition API Examples Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-reference/storage/index.html Examples providing an overview of API functions to look up partitions, perform I/O operations, and use partitions via CPU memory mapping, as well as Python-based tooling for partition images. ```APIDOC ## partition_api ### Description Provides an overview of API functions to look up particular partitions, perform basic I/O operations, and use partitions via CPU memory mapping. ## parttool ### Description Demonstrates the capabilities of Python-based tooling for partition images available on host computers. ``` -------------------------------- ### Protocomm HTTP Transport Example Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-reference/provisioning/protocomm.html This snippet demonstrates how to start and stop a Protocomm instance using an HTTP transport, including setting up security and adding endpoints. ```APIDOC ## SoftAP + HTTP Transport Example with Security 1 ### Function: `echo_req_handler` #### Description An endpoint handler that echoes back received data. It can optionally use private data passed during endpoint creation. #### Parameters - `session_id` (uint32_t): The session identifier. - `inbuf` (const uint8_t *): Pointer to the input buffer containing received data. - `inlen` (ssize_t): Length of the data in the input buffer. - `outbuf` (uint8_t **): Pointer to a buffer where the output data will be stored. Memory for this buffer must be allocated and deallocated externally. - `outlen` (ssize_t *): Pointer to a variable that will store the length of the output data. - `priv_data` (void *): Pointer to private data passed during endpoint creation. #### Returns - `esp_err_t`: `ESP_OK` on success. ### Function: `start_pc` #### Description Initializes and starts a Protocomm instance over HTTP transport with Security 1. #### Parameters - `pop_string` (const char *): The Proof of Possession string for Security 1. #### Returns - `protocomm_t *`: A pointer to the initialized Protocomm instance. ### Function: `stop_pc` #### Description Stops and cleans up a Protocomm instance started with HTTP transport. #### Parameters - `pc` (protocomm_t *): Pointer to the Protocomm instance to stop. ``` -------------------------------- ### Start GDB GUI with idf.py Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-guides/jtag-debugging/using-debugger.html Launches the gdbgui debugger frontend, which offers an out-of-the-box debugging experience in a web browser. Ensure gdbgui is installed via pipx. ```bash idf.py gdbgui ``` -------------------------------- ### SPIFFS API Examples Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-reference/storage/index.html Examples demonstrating the use of the SPIFFS API to initialize the filesystem and work with files using POSIX functions, and Python-based tooling for SPIFFS images. ```APIDOC ## spiffs ### Description Shows the use of the SPIFFS API to initialize the filesystem and work with files using POSIX functions. ## spiffsgen ### Description Demonstrates the capabilities of Python-based tooling for SPIFFS images available on host computers. ``` -------------------------------- ### esp_eth_ioctl() Usage Example: Get Duplex Mode Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/migration-guides/release-5.x/5.0/networking.html Shows how to retrieve the current Ethernet duplex mode using `esp_eth_ioctl()` by passing a pointer to a variable that will store the mode. ```c eth_duplex_t duplex_mode; esp_eth_ioctl(eth_handle, ETH_CMD_G_DUPLEX_MODE, &duplex_mode); ``` -------------------------------- ### Build the Project Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/get-started/windows-start-project.html Compiles the application and all ESP-IDF components, generating necessary binaries like the bootloader and application firmware. ```bash idf.py build ``` -------------------------------- ### Get Ethernet Driver Attributes Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-reference/network/esp_eth.html Retrieves the MAC address and PHY address of the Ethernet driver using ioctl commands. These commands should only be invoked after the Ethernet driver has been installed. ```c /* get MAC address */ uint8_t mac_addr[6]; memset(mac_addr, 0, sizeof(mac_addr)); esp_eth_ioctl(eth_handle, ETH_CMD_G_MAC_ADDR, mac_addr); ESP_LOGI(TAG, "Ethernet MAC Address: %02x:%02x:%02x:%02x:%02x:%02x", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]); /* get PHY address */ int phy_addr = -1; esp_eth_ioctl(eth_handle, ETH_CMD_G_PHY_ADDR, &phy_addr); ESP_LOGI(TAG, "Ethernet PHY Address: %d", phy_addr); ``` -------------------------------- ### Set Default Network Interface Handlers Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-reference/network/esp_netif_driver.html Configures default event handlers for a network interface based on driver lifecycle events. This example sets handlers for start and stop events. ```c esp_err_t my_driver_netif_set_default_handlers(my_netif_driver_t *driver, esp_netif_t * esp_netif) { driver_set_event_handler(driver->driver_impl, esp_netif_action_start, MY_DRV_EVENT_START, esp_netif); driver_set_event_handler(driver->driver_impl, esp_netif_action_stop, MY_DRV_EVENT_STOP, esp_netif); return ESP_OK; } ``` -------------------------------- ### Create and Configure GPIO Bundle Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-reference/peripherals/dedic_gpio.html Demonstrates how to create a new GPIO bundle for output operations, specifying the GPIOs to be included and enabling output functionality. ```APIDOC ## Create/Destroy GPIO Bundle A GPIO bundle is a group of GPIOs, which can be manipulated at the same time in one CPU cycle. The maximal number of GPIOs that a bundle can contain is limited by each CPU. What's more, the GPIO bundle has a strong relevance to the CPU which it derives from. **Any operations on the GPIO bundle should be put inside a task which is running on the same CPU core to the GPIO bundle belongs to.** Likewise, only those ISRs who are installed on the same CPU core are allowed to do operations on that GPIO bundle. To install a GPIO bundle, one needs to call `dedic_gpio_new_bundle()` to allocate the software resources and connect the dedicated channels to user selected GPIOs. Configurations for a GPIO bundle are covered in `dedic_gpio_bundle_config_t` structure: * `dedic_gpio_bundle_config_t::gpio_array`: An array that contains GPIO number. * `dedic_gpio_bundle_config_t::array_size`: Element number of `dedic_gpio_bundle_config_t::gpio_array`. * `dedic_gpio_bundle_config_t::in_en` and `dedic_gpio_bundle_config_t::out_en` are used to configure whether to enable the input and output ability of the GPIO(s). * `dedic_gpio_bundle_config_t::in_invert` and `dedic_gpio_bundle_config_t::out_invert` are used to configure whether to invert the GPIO signal. The following code shows how to install an output only GPIO bundle: ```c // Create bundleA, output only dedic_gpio_bundle_handle_t bundleA = NULL; dedic_gpio_bundle_config_t bundleA_config = { .gpio_array = bundleA_gpios, .array_size = sizeof(bundleA_gpios) / sizeof(bundleA_gpios[0]), .flags = { .out_en = 1, }, }; ESP_ERROR_CHECK(dedic_gpio_new_bundle(&bundleA_config, &bundleA)); ``` To uninstall the GPIO bundle, you should call `dedic_gpio_del_bundle()`. ``` -------------------------------- ### Get Next Update Partition Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-reference/system/ota.html Finds and returns the next available OTA application partition for firmware updates. It searches round-robin, starting from a specified partition or the currently running one. ```APIDOC ## esp_ota_get_next_update_partition ### Description Return the next OTA app partition which should be written with a new firmware. Call this function to find an OTA app partition which can be passed to esp_ota_begin(). Finds next partition round-robin, starting from the current running partition. ### Parameters #### Path Parameters - **start_from** (const esp_partition_t *) - If set, treat this partition info as describing the current running partition. Can be NULL, in which case esp_ota_get_running_partition() is used to find the currently running partition. The result of this function is never the same as this argument. ### Returns Pointer to info for partition which should be updated next. NULL result indicates invalid OTA data partition, or that no eligible OTA app slot partition was found. ``` -------------------------------- ### NVS Bootloader API Example Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-reference/storage/index.html Shows how to use the NVS API within the bootloader code to read NVS data. ```c nvs_bootloader ``` -------------------------------- ### Build, Flash, and Monitor Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-guides/ble/get-started/ble-connection.html This command builds the firmware, flashes it to the development board, and monitors the serial output. Ensure your board is connected. ```bash idf.py flash monitor ``` -------------------------------- ### Getting Session Transport Context Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-reference/protocols/esp_http_server.html Retrieves the session 'transport' context associated with a given socket descriptor. This context is typically used by send/receive functions, for example, to manage SSL contexts. ```APIDOC ## httpd_sess_get_transport_ctx ### Description Get session 'transport' context by socket descriptor. ### Parameters * **handle** - [in] Handle to server returned by httpd_start * **sockfd** - [in] The socket descriptor for which the context should be extracted. ### Returns * void* : Pointer to the transport context associated with this session * NULL : Empty context / Invalid handle / Invalid socket fd ``` -------------------------------- ### Install I2C Master Bus and Device Source: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-reference/peripherals/i2c.html Initializes an I2C master bus with specified configurations and adds a device to it. Ensure `TEST_I2C_PORT`, `I2C_MASTER_SCL_IO`, and `I2C_MASTER_SDA_IO` are defined according to your hardware setup. ```c #include "driver/i2c_master.h" i2c_master_bus_config_t i2c_mst_config = { .clk_source = I2C_CLK_SRC_DEFAULT, .i2c_port = TEST_I2C_PORT, .scl_io_num = I2C_MASTER_SCL_IO, .sda_io_num = I2C_MASTER_SDA_IO, .glitch_ignore_cnt = 7, .flags.enable_internal_pullup = true, }; i2c_master_bus_handle_t bus_handle; ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_mst_config, &bus_handle)); i2c_device_config_t dev_cfg = { .dev_addr_length = I2C_ADDR_BIT_LEN_7, .device_address = 0x58, .scl_speed_hz = 100000, }; i2c_master_dev_handle_t dev_handle; ESP_ERROR_CHECK(i2c_master_bus_add_device(bus_handle, &dev_cfg, &dev_handle)); ```