### Configure, Install, and Start TWAI Driver Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-reference/peripherals/twai.html Demonstrates the basic setup of the TWAI driver using configuration structures, macro initializers, and the `twai_driver_install()` and `twai_start()` functions. Ensure correct GPIO pins are assigned for TX and RX. ```c #include "driver/gpio.h" #include "driver/twai.h" void app_main() { // Initialize configuration structures using macro initializers twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT(GPIO_NUM_21, GPIO_NUM_22, TWAI_MODE_NORMAL); twai_timing_config_t t_config = TWAI_TIMING_CONFIG_500KBITS(); twai_filter_config_t f_config = TWAI_FILTER_CONFIG_ACCEPT_ALL(); // Install TWAI driver if (twai_driver_install(&g_config, &t_config, &f_config) == ESP_OK) { printf("Driver installed\n"); } else { printf("Failed to install driver\n"); return; } // Start TWAI driver if (twai_start() == ESP_OK) { printf("Driver started\n"); } else { printf("Failed to start driver\n"); return; } ... } ``` -------------------------------- ### TWAI Driver Installation and Start Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-reference/peripherals/twai.html Demonstrates how to configure, install, and start a single TWAI driver instance using default configurations and the `twai_driver_install()` and `twai_start()` functions. ```APIDOC ## TWAI Driver Installation and Start ### Description This section shows how to configure and install a TWAI driver instance and then start it. It uses macro initializers for configuration structures and the `twai_driver_install()` and `twai_start()` functions. ### Functions Used - `twai_driver_install()`: Installs the TWAI driver. - `twai_start()`: Starts the TWAI driver. ### Configuration Structures - `twai_general_config_t` - `twai_timing_config_t` - `twai_filter_config_t` ### Code Example ```c #include "driver/gpio.h" #include "driver/twai.h" void app_main() { // Initialize configuration structures using macro initializers twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT(GPIO_NUM_21, GPIO_NUM_22, TWAI_MODE_NORMAL); twai_timing_config_t t_config = TWAI_TIMING_CONFIG_500KBITS(); twai_filter_config_t f_config = TWAI_FILTER_CONFIG_ACCEPT_ALL(); // Install TWAI driver if (twai_driver_install(&g_config, &t_config, &f_config) == ESP_OK) { printf("Driver installed\n"); } else { printf("Failed to install driver\n"); return; } // Start TWAI driver if (twai_start() == ESP_OK) { printf("Driver started\n"); } else { printf("Failed to start driver\n"); return; } ... } ``` ``` -------------------------------- ### Install and Start Multiple TWAI Instances Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-reference/peripherals/twai.html Shows how to install and start multiple TWAI instances using the `twai_driver_install_v2()` and `twai_start_v2()` functions. Each instance requires a unique `controller_id` and can have its own GPIO pins configured. ```c #include "driver/gpio.h" #include "driver/twai.h" void app_main() { twai_handle_t twai_bus_0; twai_handle_t twai_bus_1; // Initialize configuration structures using macro initializers twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT(GPIO_NUM_0, GPIO_NUM_1, TWAI_MODE_NORMAL); twai_timing_config_t t_config = TWAI_TIMING_CONFIG_500KBITS(); twai_filter_config_t f_config = TWAI_FILTER_CONFIG_ACCEPT_ALL(); // Install driver for TWAI bus 0 g_config.controller_id = 0; if (twai_driver_install_v2(&g_config, &t_config, &f_config, &twai_bus_0) == ESP_OK) { printf("Driver installed\n"); } else { printf("Failed to install driver\n"); return; } // Start TWAI driver if (twai_start_v2(twai_bus_0) == ESP_OK) { printf("Driver started\n"); } else { printf("Failed to start driver\n"); return; } // Install driver for TWAI bus 1 g_config.controller_id = 1; g_config.tx_io = GPIO_NUM_2; g_config.rx_io = GPIO_NUM_3; if (twai_driver_install_v2(&g_config, &t_config, &f_config, &twai_bus_1) == ESP_OK) { printf("Driver installed\n"); } else { printf("Failed to install driver\n"); return; } // Start TWAI driver if (twai_start_v2(twai_bus_1) == ESP_OK) { printf("Driver started\n"); } else { printf("Failed to start driver\n"); return; } // Other Driver operations must use version 2 API as well ... } ``` -------------------------------- ### Copy Example Project Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/get-started/windows-start-project.html Copies the 'hello_world' example project to your local directory. Ensure ESP-IDF is installed and the IDF_PATH environment variable is set. ```batch cd %userprofile%\esp xcopy /e /i %IDF_PATH%\examples\get-started\hello_world hello_world ``` -------------------------------- ### Navigate to NimBLE_Beacon Example Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-guides/ble/get-started/ble-device-discovery.html Change directory to the NimBLE_Beacon example folder. Replace with your local ESP-IDF installation path. ```bash cd /examples/bluetooth/ble_get_started/nimble/NimBLE_Beacon ``` -------------------------------- ### Install Multiple TWAI Instances Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-reference/peripherals/twai.html Demonstrates how to install and start multiple TWAI driver instances using the `twai_driver_install_v2()` and `twai_start_v2()` functions, allowing for the creation of up to two functional TWAI instances on ESP32-C6. ```APIDOC ## Install Multiple TWAI Instances ### Description This section illustrates how to install and manage multiple TWAI instances on the ESP32-C6, which supports up to two physical TWAI controllers. It utilizes the `twai_driver_install_v2()` and `twai_start_v2()` functions for this purpose. ### Functions Used - `twai_driver_install_v2()`: Installs a TWAI driver instance, returning a handle. - `twai_start_v2()`: Starts a specific TWAI driver instance using its handle. ### Notes - The ESP32-C6 has 2 physical TWAI controllers. - Subsequent driver operations must use the version 2 API when multiple instances are installed. ### Code Example ```c #include "driver/gpio.h" #include "driver/twai.h" void app_main() { twai_handle_t twai_bus_0; twai_handle_t twai_bus_1; // Initialize configuration structures using macro initializers twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT(GPIO_NUM_0, GPIO_NUM_1, TWAI_MODE_NORMAL); twai_timing_config_t t_config = TWAI_TIMING_CONFIG_500KBITS(); twai_filter_config_t f_config = TWAI_FILTER_CONFIG_ACCEPT_ALL(); // Install driver for TWAI bus 0 g_config.controller_id = 0; if (twai_driver_install_v2(&g_config, &t_config, &f_config, &twai_bus_0) == ESP_OK) { printf("Driver installed\n"); } else { printf("Failed to install driver\n"); return; } // Start TWAI driver if (twai_start_v2(twai_bus_0) == ESP_OK) { printf("Driver started\n"); } else { printf("Failed to start driver\n"); return; } // Install driver for TWAI bus 1 g_config.controller_id = 1; g_config.tx_io = GPIO_NUM_2; g_config.rx_io = GPIO_NUM_3; if (twai_driver_install_v2(&g_config, &t_config, &f_config, &twai_bus_1) == ESP_OK) { printf("Driver installed\n"); } else { printf("Failed to install driver\n"); return; } // Start TWAI driver if (twai_start_v2(twai_bus_1) == ESP_OK) { printf("Driver started\n"); } else { printf("Failed to start driver\n"); return; } // Other Driver operations must use version 2 API as well ... } ``` ``` -------------------------------- ### Default Event Handler Setup Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-reference/network/esp_netif_driver.html Sets up default event handlers for a network interface based on driver lifecycle events. This example registers 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; } ``` -------------------------------- ### HTTP Server URI Handlers and Server Control Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-reference/protocols/esp_http_server.html This example demonstrates how to define URI handlers for GET and POST requests, and functions to start and stop the HTTP server. It includes configurations for default server settings and registration of handlers. ```c /* Our URI handler function to be called during GET /uri request */ esp_err_t get_handler(httpd_req_t *req) { /* Send a simple response */ const char resp[] = "URI GET Response"; httpd_resp_send(req, resp, HTTPD_RESP_USE_STRLEN); return ESP_OK; } /* Our URI handler function to be called during POST /uri request */ esp_err_t post_handler(httpd_req_t *req) { /* Destination buffer for content of HTTP POST request. * httpd_req_recv() accepts char* only, but content could * as well be any binary data (needs type casting). * In case of string data, null termination will be absent, and * content length would give length of string */ char content[100]; /* Truncate if content length larger than the buffer */ size_t recv_size = MIN(req->content_len, sizeof(content)); int ret = httpd_req_recv(req, content, recv_size); if (ret <= 0) { /* 0 return value indicates connection closed */ /* Check if timeout occurred */ if (ret == HTTPD_SOCK_ERR_TIMEOUT) { /* In case of timeout one can choose to retry calling * httpd_req_recv(), but to keep it simple, here we * respond with an HTTP 408 (Request Timeout) error */ httpd_resp_send_408(req); } /* In case of error, returning ESP_FAIL will * ensure that the underlying socket is closed */ return ESP_FAIL; } /* Send a simple response */ const char resp[] = "URI POST Response"; httpd_resp_send(req, resp, HTTPD_RESP_USE_STRLEN); return ESP_OK; } /* URI handler structure for GET /uri */ httpd_uri_t uri_get = { .uri = "/uri", .method = HTTP_GET, .handler = get_handler, .user_ctx = NULL }; /* URI handler structure for POST /uri */ httpd_uri_t uri_post = { .uri = "/uri", .method = HTTP_POST, .handler = post_handler, .user_ctx = NULL }; /* Function for starting the webserver */ httpd_handle_t start_webserver(void) { /* Generate default configuration */ httpd_config_t config = HTTPD_DEFAULT_CONFIG(); /* Empty handle to esp_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; } /* Function for stopping the webserver */ void stop_webserver(httpd_handle_t server) { if (server) { /* Stop the httpd server */ httpd_stop(server); } } ``` -------------------------------- ### Web Server Start and Stop Functions Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-reference/protocols/esp_http_server.html Example C functions demonstrating how to start and stop the HTTP web server. ```APIDOC ## start_webserver() ### Description Initializes and starts the HTTP server with default configuration and registers predefined URI handlers. ### Returns - `httpd_handle_t`: A handle to the started HTTP server instance, or `NULL` if the server failed to start. ``` ```APIDOC ## stop_webserver() ### Description Stops the HTTP server if it is running. ### Parameters - `httpd_handle_t server`: The handle of the HTTP server to stop. ``` -------------------------------- ### Initialize MQTT Client with URI Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-reference/protocols/mqtt.html Configure the MQTT client to connect to a broker using a URI. This example shows a basic setup for MQTT over TCP. ```c const esp_mqtt_client_config_t mqtt_cfg = { .broker.address.uri = "mqtt://mqtt.eclipseprojects.io", }; esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt_cfg); esp_mqtt_client_register_event(client, ESP_EVENT_ANY_ID, mqtt_event_handler, client); esp_mqtt_client_start(client); ``` -------------------------------- ### Example Handler Functions Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-reference/protocols/esp_http_server.html Example C functions demonstrating how to implement handlers for GET and POST requests. ```APIDOC ## GET Handler Example ### Description Example handler function for a GET request to a specific URI. ### Function Signature `esp_err_t get_handler(httpd_req_t *req)` ### Usage This function sends a simple string response back to the client. ``` ```APIDOC ## POST Handler Example ### Description Example handler function for a POST request, demonstrating how to receive and process request content. ### Function Signature `esp_err_t post_handler(httpd_req_t *req)` ### Usage This function receives data from the POST request, processes it (up to a buffer limit), and sends a response. It includes basic error handling for timeouts and connection issues. ``` -------------------------------- ### Create Project from Example Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-guides/tools/idf-component-manager.html Use `idf.py create-project-from-example` to create a new project from a component's example. Specify the component and example name in the format `namespace/name=version:example`. ```bash idf.py create-project-from-example EXAMPLE ``` -------------------------------- ### ESP-IDF Windows Installer Command-Line Parameters Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-guides/tools/idf-windows-installer.html Lists available command-line parameters for the `esp-idf-tools-setup` installer to customize the installation process. These parameters allow overriding default configurations, specifying installation paths, and controlling Git repository behavior. ```bash esp-idf-tools-setup-x.x.exe /CONFIG=[PATH] /GITCLEAN=[yes|no] /GITRECURSIVE=[yes|no] /GITREPO=[URL|PATH] /GITRESET=[yes|no] /HELP /IDFDIR=[PATH] /IDFVERSION=[v4.3|v4.1|master] /IDFVERSIONSURL=[URL] /LOG=[PATH] /OFFLINE=[yes|no] /USEEMBEDDEDPYTHON=[yes|no] /PYTHONNOUSERSITE=[yes|no] /PYTHONWHEELSURL=[URL] /SKIPSYSTEMCHECK=[yes|no] /VERYSILENT /SUPPRESSMSGBOXES /SP- /NOCANCEL ``` -------------------------------- ### Example Post-Attach Callback Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-reference/network/esp_netif_driver.html A sample post-attach callback function for an I/O driver. It sets up the driver configuration, registers it with ESP-NETIF, and starts the driver. ```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; } ``` -------------------------------- ### Start ESP HTTP Server Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-reference/protocols/esp_http_server.html Use this function to create and start an HTTP server instance with a specified configuration. Ensure the handle is checked for NULL after starting. ```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; } ``` -------------------------------- ### Install Script for Building Documentation Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/contribute/documenting-code.html Command to execute the install script with the --enable-docs flag to set up the necessary tools and install the 'esp-docs' Python package for building documentation. ```bash ./install.sh --enable-docs ``` -------------------------------- ### GDB Command Line Example Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-guides/jtag-debugging/debugging-examples.html A sample output from the GDB command line interface, showing a temporary breakpoint hit at the start of the `app_main` function. ```gdb Temporary breakpoint 1, app_main () at /home/user-name/esp/blink/main/./blink.c:43 43 xTaskCreate(&blink_task, "blink_task", configMINIMAL_STACK_SIZE, NULL, 5, NULL); (gdb) ``` -------------------------------- ### Install ESP-IDF Tools using install.ps1 Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/get-started/windows-setup-update.html Execute this command in PowerShell to download and install the required ESP-IDF tools. The installation will not proceed if the tools are already present. ```powershell install.ps1 ``` -------------------------------- ### Start ESP-WIFI-MESH Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-reference/network/esp-wifi-mesh.html This snippet demonstrates how to start the ESP-WIFI-MESH network using the `esp_mesh_start()` function. After starting, applications should monitor for connection events and can then use `esp_mesh_send()` and `esp_mesh_recv()` for data transmission. ```APIDOC ## Start ESP-WIFI-MESH ### Description Starts the ESP-WIFI-MESH network. After this call, the application should listen for connection events and can then use `esp_mesh_send()` and `esp_mesh_recv()` for communication. ### Function Signature `esp_err_t esp_mesh_start()` ### Request Example ```c /* mesh start */ ESP_ERROR_CHECK(esp_mesh_start()); ``` ### Response #### Success Response (ESP_OK) Indicates the mesh network has started successfully. #### Error Response - **ESP_ERR_MESH_START_FAILED**: Failed to start the mesh network. ``` -------------------------------- ### Install ESP-IDF Tools using install.bat Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/get-started/windows-setup-update.html Run this command from the Windows Command Prompt to download and install necessary ESP-IDF tools. If the tools are already installed, no action will be taken. ```batch install.bat ``` -------------------------------- ### Copy Example Project Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/get-started/linux-macos-start-project.html Copy the 'hello_world' example project to your desired directory. Ensure there are no spaces in the path to ESP-IDF or your project. ```bash cd ~/ esp cp -r $IDF_PATH/examples/get-started/hello_world . ``` -------------------------------- ### Copy Hello World Project Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/get-started/linux-macos-setup.html Copies the 'hello_world' example project to your local directory. Ensure there are no spaces in your ESP-IDF or project paths. ```bash cd ~/esp cp -r $IDF_PATH/examples/get-started/hello_world . ``` -------------------------------- ### Start Timer as a Wall Clock Example Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-reference/peripherals/gptimer.html Example demonstrating how to enable and start the GPTimer to function as a wall clock, and how to retrieve the current raw count. ```APIDOC ## Example: Start Timer as a Wall Clock ### Description This example shows the basic steps to enable and start a GPTimer to operate as a free-running counter (wall clock) and how to read its current value. ### Code ```c ESP_ERROR_CHECK(gptimer_enable(gptimer)); ESP_ERROR_CHECK(gptimer_start(gptimer)); // Retrieve the timestamp at any time uint64_t count; ESP_ERROR_CHECK(gptimer_get_raw_count(gptimer, &count)); ``` ### Parameters - **gptimer** (gptimer_handle_t) - Handle of the GPTimer instance. ``` -------------------------------- ### Navigate to NimBLE_GATT_Server Example Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-guides/ble/get-started/ble-introduction.html Use this command to navigate to the example directory for the NimBLE_GATT_Server project. Replace with your local ESP-IDF folder path. ```bash $ cd /examples/bluetooth/ble_get_started/nimble/NimBLE_GATT_Server ``` -------------------------------- ### Initialize Network Interface Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-reference/network/esp_netif.html This code demonstrates the typical network startup sequence, including initializing the TCP/IP stack, creating the event loop, and setting up a network interface with its driver and event handlers. Ensure these steps are performed in the exact order shown. ```c esp_netif_init(); esp_event_loop_create_default(); // 1) Create the network interface handle esp_netif = esp_netif_new(&config); // 2) Create the network interface driver (e.g., Ethernet) and it's network layer glue // and register the ESP-NETIF event (e.g., to bring the interface up upon link-up event) esp_netif_glue_t glue = driver_glue(driver); // 3) Attach the driver's glue layer to the network interface handle esp_netif_attach(esp_netif, glue); // 4) Register user-side event handlers esp_event_handler_register(DRIVER_EVENT, ...); // to observe driver states, e.g., link-up esp_event_handler_register(IP_EVENT, ...); // to observe ESP-NETIF states, e.g., get an IP ``` -------------------------------- ### httpd_start Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/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** (const 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 ### Example Usage ```c //Function for starting the webserver 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; } ``` ``` -------------------------------- ### Navigate to NimBLE_Connection Example Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-guides/ble/get-started/ble-connection.html Navigate to the NimBLE_Connection example directory. Replace with your local ESP-IDF folder path. ```bash cd /examples/bluetooth/ble_get_started/nimble/NimBLE_Connection ``` -------------------------------- ### Start Ethernet Driver Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-reference/network/esp_eth.html Starts the Ethernet driver's state machine after it has been installed. This is a necessary step to enable Ethernet communication. ```c esp_eth_start(eth_handle); // start Ethernet driver state machine ``` -------------------------------- ### Start Graphical Configuration Tool Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-guides/tools/idf-py.html Launches the menuconfig graphical interface for configuring project settings. ```bash idf.py menuconfig ``` -------------------------------- ### Start RFC2217 Server on Windows Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/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 accessing serial ports within a Docker container. ```bash esp_rfc2217_server -v -p 4000 COM3 ``` -------------------------------- ### GDB Debugging Session Example Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-guides/jtag-debugging/using-debugger.html An example of a GDB session output, showing symbol loading, connection to the target, and halting at a breakpoint in the app_main function. This indicates a successful setup for debugging. ```bash riscv32-esp-elf-gdb -q -x build/gdbinit/symbols -x build/gdbinit/prefix_map -x build/gdbinit/connect build/blink.elf user-name@computer-name:~/esp-idf/examples/get-started/blink$ riscv32-esp-elf-gdb -q -x build/gdbinit/symbols -x build/gdbinit/connect build/blink.elf Reading symbols from build/blink.elf... add symbol table from file "/home/user-name/esp-idf/examples/get-started/blink/build/bootloader/bootloader.elf" [Switching to Thread 1070141764] app_main () at /home/user-name/esp-idf/examples/get-started/blink/main/blink_example_main.c:95 95 configure_led(); add symbol table from file "/home/alex/.espressif/tools/esp-rom-elfs/20241011/esp32c6_rev0_rom.elf" JTAG tap: esp32c6.tap0 tap/device found: 0x00005c25 (mfg: 0x612 (Espressif Systems), part: 0x0005, ver: 0x0) [esp32c6] Reset cause (3) - (Software core reset) Hardware assisted breakpoint 1 at 0x42009436: file /home/user-name/esp-idf/examples/get-started/blink/main/blink_example_main.c, line 92. [Switching to Thread 1070139884] Thread 2 "main" hit Temporary breakpoint 1, app_main () at /home/user-name/esp-idf/examples/get-started/blink/main/blink_example_main.c:92 92 { (gdb) ``` -------------------------------- ### Implementing `get_property_values` Handler Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-reference/protocols/esp_local_ctrl.html Example implementation of a handler function to retrieve property values, specifically demonstrating how to get a timestamp. ```APIDOC ## Implementing `get_property_values` Handler This handler is invoked when a request is made to retrieve property values. ### Example: Retrieving Timestamp ```c static esp_err_t get_property_values(size_t props_count, const esp_local_ctrl_prop_t *props, esp_local_ctrl_prop_val_t *prop_values, void *usr_ctx) { for (uint32_t i = 0; i < props_count; i++) { ESP_LOGI(TAG, "Reading %s", props[i].name); if (props[i].type == TYPE_TIMESTAMP) { /* Obtain the timer function from ctx */ int32_t (*func_get_time)(void) = props[i].ctx; /* Use static variable for saving the value. This is essential because the value has to be valid even after this function returns. Alternative is to use dynamic allocation and set the free_fn field */ static int32_t ts = func_get_time(); prop_values[i].data = &ts; } } return ESP_OK; } ``` ``` -------------------------------- ### Start gdbgui with idf.py Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-guides/jtag-debugging/using-debugger.html Launches the gdbgui debugger frontend, which opens in a browser window. Ensure gdbgui is enabled during installation. ```bash idf.py gdbgui ``` -------------------------------- ### Initialize Wi-Fi and Event Loop Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-reference/network/esp-wifi-mesh.html Demonstrates the prerequisite steps for initializing LwIP, the default event loop, and Wi-Fi before starting ESP-WIFI-MESH. Includes Wi-Fi initialization, IP event handler registration, and Wi-Fi start. ```c ESP_ERROR_CHECK(esp_netif_init()); /* event initialization */ ESP_ERROR_CHECK(esp_event_loop_create_default()); /* Wi-Fi initialization */ wifi_init_config_t config = WIFI_INIT_CONFIG_DEFAULT(); ESP_ERROR_CHECK(esp_wifi_init(&config)); /* register IP events handler */ ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &ip_event_handler, NULL)); ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_FLASH)); ESP_ERROR_CHECK(esp_wifi_start()); ``` -------------------------------- ### Get Current Tick Count Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-reference/system/freertos_idf.html Retrieves the number of ticks that have elapsed since the scheduler was started. This function is safe to call from any context. ```c TickType_t xTaskGetTickCount(void) ``` -------------------------------- ### Command-line Interface Examples Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-reference/system/ota.html Examples demonstrating how to use the otatool.py command-line interface to perform OTA operations. ```APIDOC ## Command-line Interface The `otatool.py` can be invoked from the shell with specific subcommands and arguments. ### Erase otadata partition ```bash otatool.py --port "/dev/ttyUSB1" erase_otadata ``` ### Erase OTA partition by slot number ```bash otatool.py --port "/dev/ttyUSB1" erase_ota_partition --slot 0 ``` ### Switch OTA partition by slot number ```bash otatool.py --port "/dev/ttyUSB1" switch_ota_partition --slot 1 ``` ### Read OTA partition by name to a file ```bash otatool.py --port "/dev/ttyUSB1" read_ota_partition --name=ota_3 --output=ota_3.bin ``` ### Help To get help on available commands and arguments: ```bash # Display possible subcommands and main command argument descriptions otatool.py --help # Show descriptions for specific subcommand arguments otatool.py [subcommand] --help ``` ``` -------------------------------- ### Open Project in VSCode Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-guides/ble/get-started/ble-connection.html Open the NimBLE_Connection project in VSCode after navigating to the example directory. This command assumes VSCode is installed and in your system's PATH. ```bash code . ``` -------------------------------- ### esp_https_ota_begin Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-reference/system/esp_https_ota.html Initializes the ESP HTTPS OTA context and establishes the HTTPS connection. This function must be called first. If successful, `esp_https_ota_perform` should be called next, followed by `esp_https_ota_finish` upon completion or failure. URL redirection is supported, but differing CA certs require appending to `cert_pem`. In case of error, `handle` is set to NULL. This API is blocking; `is_async` in `http_config` must be false. ```APIDOC ## esp_https_ota_begin ### Description Initializes the ESP HTTPS OTA context and establishes the HTTPS connection. This function must be called first. If successful, `esp_https_ota_perform` should be called next, followed by `esp_https_ota_finish` upon completion or failure. URL redirection is supported, but differing CA certs require appending to `cert_pem`. In case of error, `handle` is set to NULL. This API is blocking; `is_async` in `http_config` must be false. ### Function Signature ```c esp_err_t esp_https_ota_begin(const esp_https_ota_config_t *ota_config, esp_https_ota_handle_t *handle) ``` ### Parameters #### Parameters - **ota_config** (const esp_https_ota_config_t *) - [in] pointer to esp_https_ota_config_t structure. - **handle** (esp_https_ota_handle_t *) - [out] pointer to an allocated data of type `esp_https_ota_handle_t` which will be initialised in this function. ### Returns - **ESP_OK**: HTTPS OTA Firmware upgrade context initialised and HTTPS connection established. - **ESP_FAIL**: For generic failure. - **ESP_ERR_INVALID_ARG**: Invalid argument (missing/incorrect config, certificate, etc.). - For other return codes, refer documentation in app_update component and esp_http_client component in esp-idf. ``` -------------------------------- ### Enable Temperature Sensor Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-reference/peripherals/temp_sensor.html Enables the temperature sensor, allowing it to start taking measurements. This function must be called after installation and before reading temperature data. ```APIDOC ## temperature_sensor_enable ### Description Enable the temperature sensor. ### Parameters #### Path Parameters * **tsens** (temperature_sensor_handle_t) - Required - The handle created by `temperature_sensor_install()`. ### Returns * ESP_OK Success * ESP_ERR_INVALID_STATE if temperature sensor is enabled already. ``` -------------------------------- ### Configure ESP32-C6 Project Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/get-started/linux-macos-setup.html Navigates to the project directory, sets the target chip to ESP32-C6, and opens the project configuration utility. Existing builds and configurations are cleared and initialized. ```bash cd ~/esp/hello_world idf.py set-target esp32c6 idf.py menuconfig ``` -------------------------------- ### esp_mqtt_client_start Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-reference/protocols/mqtt.html Starts the MQTT client using an already created client handle. ```APIDOC ## esp_mqtt_client_start ### Description Starts the MQTT client with an already created client handle. ### Parameters #### Parameters - **client** (esp_mqtt_client_handle_t) - MQTT client handle ### Returns - ESP_OK on success - ESP_ERR_INVALID_ARG on wrong initialization - ESP_FAIL on other errors ``` -------------------------------- ### Get Ethernet Driver Attributes Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-reference/network/esp_eth.html Retrieves the MAC address and PHY address of the Ethernet driver using the esp_eth_ioctl function. These commands are used 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); ``` -------------------------------- ### eFuse CSV Field Description Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-reference/system/efuse.html This is an example of a CSV file format used to describe eFuse fields. It specifies the field name, block, starting bit, bit count, and a description. ```csv USER_DATA, EFUSE_BLK3, 0, 256, User data USER_DATA.FIELD1, EFUSE_BLK3, 16, 16, Field1 ID, EFUSE_BLK4, 8, 3, ID bit[0..2] , EFUSE_BLK4, 16, 2, ID bit[3..4] , EFUSE_BLK4, 32, 3, ID bit[5..7] ``` -------------------------------- ### Configure Project and Set Target Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/get-started/linux-macos-start-project.html Navigate to your project directory, set the target chip to ESP32-C6, and launch the project configuration utility. This clears existing builds and configurations. ```bash cd ~/esp/hello_world idf.py set-target esp32c6 idf.py menuconfig ``` -------------------------------- ### Partition API Examples Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-reference/storage/index.html Examples providing an overview of API functions to look up partitions, perform I/O operations, use partitions via CPU memory mapping, and Python-based tooling for partition images. ```APIDOC ## Partition API Examples ### 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. ``` -------------------------------- ### Get Input Channel Offset Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-reference/peripherals/dedic_gpio.html Retrieves the channel offset for the input direction of a GPIO bundle. This offset indicates the starting channel within the bank for the bundle's input GPIOs. ```APIDOC ## dedic_gpio_get_in_offset ### Description Gets the channel offset for the input direction of a GPIO bundle. This offset represents the starting channel within the bank for the bundle's input GPIOs. ### Parameters #### Path Parameters - **bundle** (dedic_gpio_bundle_handle_t) - Input - Handle of the GPIO bundle obtained from `dedic_gpio_new_bundle`. - **offset** (uint32_t *) - Output - Pointer to store the returned offset value for the input direction. ### Returns - ESP_OK: Get channel offset successfully. - ESP_ERR_INVALID_ARG: Get channel offset failed because of invalid argument. - ESP_FAIL: Get channel offset failed because of other error. ``` -------------------------------- ### Launch GDB with Initialization Files Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-guides/jtag-debugging/using-debugger.html Start the GDB debugger, loading necessary initialization files for symbols, prefix mapping, and connection, then specify the ELF file for debugging. ```bash riscv32-esp-elf-gdb -q -x build/gdbinit/symbols -x build/gdbinit/prefix_map -x build/gdbinit/connect build/blink.elf ``` -------------------------------- ### Get Output Channel Offset Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-reference/peripherals/dedic_gpio.html Retrieves the channel offset for the output direction of a GPIO bundle. This offset indicates the starting channel within the bank for the bundle's output GPIOs. ```APIDOC ## dedic_gpio_get_out_offset ### Description Gets the channel offset for the output direction of a GPIO bundle. This offset represents the starting channel within the bank for the bundle's output GPIOs. ### Parameters #### Path Parameters - **bundle** (dedic_gpio_bundle_handle_t) - Input - Handle of the GPIO bundle obtained from `dedic_gpio_new_bundle`. - **offset** (uint32_t *) - Output - Pointer to store the returned offset value for the output direction. ### Returns - ESP_OK: Get channel offset successfully. - ESP_ERR_INVALID_ARG: Get channel offset failed because of invalid argument. - ESP_FAIL: Get channel offset failed because of other error. ``` -------------------------------- ### esp_console_new_repl_usb_serial_jtag Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-reference/system/console.html Establishes a console REPL environment over USB-SERIAL-JTAG. Similar to the UART version, this function is intended for examples and simplifies REPL setup by initializing linenoise and spawning a background REPL thread. ```APIDOC esp_err_t esp_console_new_repl_usb_serial_jtag(const esp_console_dev_usb_serial_jtag_config_t *dev_config, const esp_console_repl_config_t *repl_config, esp_console_repl_t **ret_repl) ``` -------------------------------- ### Configure ESP32-C6 Project on Windows Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/get-started/windows-start-project.html Navigates to the project directory, sets the target chip to ESP32-C6, and opens the project configuration utility. This process clears and initializes existing builds. ```batch cd %userprofile%\esp\hello_world idf.py set-target esp32c6 idf.py menuconfig ``` -------------------------------- ### Example Sections Fragment Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-guides/linker-script-generation.html Provides a concrete example of a 'sections' fragment, demonstrating the non-preferred method of explicitly listing sections and wildcard patterns. ```linker-script # Non-preferred [sections:text] entries: .text .text.* .literal .literal.* ``` -------------------------------- ### Send SAR Configuration Client Message Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-reference/bluetooth/esp-ble-mesh.html Sends a message for the SAR Configuration Client model. This is used to interact with the SAR Configuration Server model, for example, to get or set state values. ```APIDOC ## esp_ble_mesh_sar_client_send ### Description Sends a message for the SAR Configuration Client model. This function is used to send requests to the SAR Configuration Server model. ### Parameters * **params** (esp_ble_mesh_client_common_param_t *) - Pointer to BLE Mesh common client parameters. * **msg** (esp_ble_mesh_sar_client_msg_t *) - Pointer to SAR Configuration Client message. ### Returns * ESP_OK on success or error code otherwise. ``` -------------------------------- ### LittleFS Component Example Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/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 ``` -------------------------------- ### Install I2C master bus with LP I2C Peripheral Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-reference/peripherals/i2c.html Configures and installs an I2C master bus using the Low Power (LP) I2C peripheral. This example demonstrates setting up the bus configuration, including clock source, port number, IO pins, and glitch ignore count, before creating the bus handle and adding a device to it. ```APIDOC ## i2c_new_master_bus() and i2c_master_bus_add_device() ### Description Installs an I2C master bus using the LP I2C peripheral and adds a device to the bus. ### Function Signatures i2c_master_bus_handle_t i2c_new_master_bus(const i2c_master_bus_config_t *config, i2c_master_bus_handle_t *bus_handle); i2c_master_dev_handle_t i2c_master_bus_add_device(i2c_master_bus_handle_t bus_handle, const i2c_device_config_t *device_config, i2c_master_dev_handle_t *dev_handle); ### Parameters #### `i2c_new_master_bus` Parameters - **config** (i2c_master_bus_config_t *) - Required - Configuration structure for the I2C master bus. - **clk_source** (i2c_clock_source_t) - Clock source for LP I2C. - **i2c_port** (i2c_port_t) - Assigned LP I2C port number. - **scl_io_num** (gpio_num_t) - SCL IO number. - **sda_io_num** (gpio_num_t) - SDA IO number. - **glitch_ignore_cnt** (uint8_t) - Number of glitches to ignore. - **flags.enable_internal_pullup** (bool) - Enable internal pull-up resistors. - **bus_handle** (i2c_master_bus_handle_t *) - Required - Pointer to store the created bus handle. #### `i2c_master_bus_add_device` Parameters - **bus_handle** (i2c_master_bus_handle_t) - Required - Handle of the I2C master bus. - **device_config** (i2c_device_config_t *) - Required - Configuration structure for the I2C device. - **dev_addr_length** (i2c_addr_bit_length_t) - Address length of the device (e.g., I2C_ADDR_BIT_LEN_7). - **device_address** (uint16_t) - The 7-bit or 10-bit address of the I2C device. - **scl_speed_hz** (uint32_t) - Clock speed of the I2C bus in Hz. - **dev_handle** (i2c_master_dev_handle_t *) - Required - Pointer to store the created device handle. ### Request Example ```c i2c_master_bus_config_t i2c_mst_config = { .clk_source = LP_I2C_SCLK_DEFAULT, .i2c_port = LP_I2C_NUM_0, .scl_io_num = 7, .sda_io_num = 6, .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)); ``` ### Response #### Success Response (ESP_OK) Successfully installed the I2C master bus and added the device. #### Error Response (ESP_ERR_INVALID_ARG, ESP_ERR_NO_MEM, ESP_ERR_NOT_FOUND) Indicates an invalid argument, insufficient memory, or that the specified port was not found. ``` -------------------------------- ### Basic Firmware Upgrade Example Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-reference/system/esp_https_ota.html This example demonstrates a basic firmware upgrade process using the `esp_https_ota` function. It configures the HTTP client with the firmware URL and server certificate, then initiates the OTA update. If successful, the device restarts. ```APIDOC ## do_firmware_upgrade() ### Description Performs a firmware upgrade over HTTPS. ### Function Signature ```c esp_err_t do_firmware_upgrade() ``` ### Usage Example ```c esp_err_t ret = do_firmware_upgrade(); if (ret == ESP_OK) { // Firmware upgrade successful, device will restart } else { // Firmware upgrade failed } ``` ### Configuration Notes - Ensure `CONFIG_FIRMWARE_UPGRADE_URL` is set to the correct firmware URL. - Provide the server's root certificate in PEM format to `server_cert_pem_start`. - For enhanced security, consider using `esp_http_client_config_t::crt_bundle_attach` for verification with the ESP x509 Certificate Bundle. ``` -------------------------------- ### eFuse Record Format Example Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-reference/system/efuse.html Defines the structure for eFuse records, specifying field name, block, bit start, bit count, and a comment. This format allows for flexible eFuse field definition. ```csv # field_name, efuse_block(EFUSE_BLK0..EFUSE_BLK10), bit_start(0..255), bit_count(1..256), comment ``` -------------------------------- ### OpenOCD Command Line with Application Image Offset Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-guides/jtag-debugging/tips-and-quirks.html This is an example of how to pass the `esp appimage_offset` command to OpenOCD via its command line when starting the debugger. Ensure the configuration file and offset are correctly specified. ```bash openocd -f board/esp32c6-builtin.cfg -c "init; halt; esp appimage_offset 0x210000" ``` -------------------------------- ### Open Project in VSCode Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-guides/ble/get-started/ble-introduction.html After navigating to the example directory, you can open the project in VSCode using this command. ```bash $ code . ``` -------------------------------- ### start_select Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-reference/storage/vfs.html Sets up synchronous I/O multiplexing for file descriptors in the given VFS. ```APIDOC ## start_select ### Description Sets up synchronous I/O multiplexing for file descriptors in the given VFS. ### Function Signature `esp_err_t (*start_select)(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, esp_vfs_select_sem_t sem, void **end_select_args)` ``` -------------------------------- ### Start BLE Advertising - ESP-IDF Source: https://docs.espressif.com/projects/esp-idf/en/v5.4.3/esp32c6/api-guides/ble/get-started/ble-device-discovery.html Initiates BLE advertising to make the device discoverable. Configures advertising parameters like connection mode and discoverability. Ensure necessary setup is done before calling this function. ```c static void start_advertising(void) { ... struct ble_gap_adv_params adv_params = {0}; ... /* Set non-connetable and general discoverable mode to be a beacon */ adv_params.conn_mode = BLE_GAP_CONN_MODE_NON; adv_params.disc_mode = BLE_GAP_DISC_MODE_GEN; /* Start advertising */ rc = ble_gap_adv_start(own_addr_type, NULL, BLE_HS_FOREVER, &adv_params, NULL, NULL); if (rc != 0) { ESP_LOGE(TAG, "failed to start advertising, error code: %d", rc); return; } ESP_LOGI(TAG, "advertising started!"); } ```