From 5f58f5116f5ec0d807d175c943fea2e4fd53b2e3 Mon Sep 17 00:00:00 2001 From: nopnop2002 Date: Sun, 16 Jul 2023 15:12:43 +0900 Subject: [PATCH] Added ESP32C6 --- README.md | 8 ++++---- main/Kconfig.projbuild | 7 ++++--- main/http_post.c | 19 +++++++++---------- main/main.c | 7 +++---- partitions.csv | 4 ++-- 5 files changed, 22 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 783f6ee..460545d 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,8 @@ It's purpose is to be a bridge between a CAN-Bus and a HTTP-Server. # Software requirement -esp-idf v4.4/v5.0. -This is because this version supports ESP32-C3. +ESP-IDF V4.4/V5.x. +ESP-IDF V5.1 is required when using ESP32C6. # Hardware requirements - SN65HVD23x CAN-BUS Transceiver @@ -18,7 +18,7 @@ This is because this version supports ESP32-C3. I used 150 ohms. # Wireing -|SN65HVD23x||ESP32|ESP32-S2/S3|ESP32-C3|| +|SN65HVD23x||ESP32|ESP32-S2/S3|ESP32-C3/C6|| |:-:|:-:|:-:|:-:|:-:|:-:| |D(CTX)|--|GPIO21|GPIO17|GPIO0|(*1)| |GND|--|GND|GND|GND|| @@ -77,7 +77,7 @@ Check [here](http://www.ti.com/lit/an/slla337/slla337.pdf). ``` git clone https://github.com/nopnop2002/esp-idf-can2http cd esp-idf-can2http -idf.py set-target {esp32/esp32s2/esp32s3/esp32c3} +idf.py set-target {esp32/esp32s2/esp32s3/esp32c3/esp32c6} idf.py menuconfig idf.py flash ``` diff --git a/main/Kconfig.projbuild b/main/Kconfig.projbuild index f524135..8c8f195 100644 --- a/main/Kconfig.projbuild +++ b/main/Kconfig.projbuild @@ -6,6 +6,7 @@ menu "Application Configuration" default 46 if IDF_TARGET_ESP32S2 default 48 if IDF_TARGET_ESP32S3 default 19 if IDF_TARGET_ESP32C3 + default 30 if IDF_TARGET_ESP32C6 menu "CAN Setting" @@ -53,7 +54,7 @@ menu "Application Configuration" range 0 GPIO_RANGE_MAX default 21 if IDF_TARGET_ESP32 default 17 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 - default 0 if IDF_TARGET_ESP32C3 + default 0 # C3 and others help GPIO number (IOxx) to CTX. Some GPIOs are used for other purposes (flash connections, etc.). @@ -64,7 +65,7 @@ menu "Application Configuration" range 0 GPIO_RANGE_MAX default 22 if IDF_TARGET_ESP32 default 18 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 - default 1 if IDF_TARGET_ESP32C3 + default 1 # C3 and others help GPIO number (IOxx) to CRX. Some GPIOs are used for other purposes (flash connections, etc.). @@ -137,7 +138,7 @@ menu "Application Configuration" config WEB_SERVER string "HTTP Server IP or mDNS" - default "httpserver.local" + default "http-server.local" help The host name or IP address of the HTTP server to use. diff --git a/main/http_post.c b/main/http_post.c index 657ab34..cbafebf 100644 --- a/main/http_post.c +++ b/main/http_post.c @@ -1,10 +1,10 @@ -/* ESP HTTP Client Example +/* ESP HTTP Client Example - This example code is in the Public Domain (or CC0 licensed, at your option.) + This example code is in the Public Domain (or CC0 licensed, at your option.) - Unless required by applicable law or agreed to in writing, this - software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - CONDITIONS OF ANY KIND, either express or implied. + Unless required by applicable law or agreed to in writing, this + software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. */ #include @@ -107,6 +107,7 @@ esp_err_t _http_event_handler(esp_http_client_event_t *evt) static void http_rest_with_url(char * path, char * post_data) { + ESP_LOGI(TAG, "path=[%s]", path); char local_response_buffer[MAX_HTTP_OUTPUT_BUFFER] = {0}; /** * NOTE: All the configuration parameters for http_client must be spefied either in URL or as host and path parameters. @@ -115,6 +116,7 @@ static void http_rest_with_url(char * path, char * post_data) * * If URL as well as host and path parameters are specified, values of host and path will be considered. */ +#if 1 esp_http_client_config_t config = { .host = CONFIG_WEB_SERVER, .port = CONFIG_WEB_PORT, @@ -123,11 +125,10 @@ static void http_rest_with_url(char * path, char * post_data) .user_data = local_response_buffer, // Pass address of local buffer to get response .disable_auto_redirect = true, }; - -#if 0 +#else // Same as above esp_http_client_config_t config = { - .url = "http://192.168.10.43:8000/post", + .url = "http://http-server.local:8000/post", .event_handler = _http_event_handler, .user_data = local_response_buffer, // Pass address of local buffer to get response .disable_auto_redirect = true, @@ -142,8 +143,6 @@ static void http_rest_with_url(char * path, char * post_data) esp_http_client_set_header(client, "Content-Type", "application/json"); esp_http_client_set_post_field(client, post_data, strlen(post_data)); esp_err_t err = esp_http_client_perform(client); - // ESP-IDF V4.4 int esp_http_client_get_content_length - // ESP-IDF V5.0 int64_t esp_http_client_get_content_length if (err == ESP_OK) { ESP_LOGI(TAG, "HTTP POST Status = %d, content_length = %lld", esp_http_client_get_status_code(client), diff --git a/main/main.c b/main/main.c index f508a18..be295b7 100644 --- a/main/main.c +++ b/main/main.c @@ -10,6 +10,7 @@ #include #include #include + #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "freertos/queue.h" @@ -174,11 +175,9 @@ void wifi_init_sta() /* xEventGroupWaitBits() returns the bits before the call returned, hence we can test which event actually * happened. */ if (bits & WIFI_CONNECTED_BIT) { - ESP_LOGI(TAG, "connected to ap SSID:%s password:%s", - CONFIG_ESP_WIFI_SSID, CONFIG_ESP_WIFI_PASSWORD); + ESP_LOGI(TAG, "connected to ap SSID:%s password:%s", CONFIG_ESP_WIFI_SSID, CONFIG_ESP_WIFI_PASSWORD); } else if (bits & WIFI_FAIL_BIT) { - ESP_LOGI(TAG, "Failed to connect to SSID:%s, password:%s", - CONFIG_ESP_WIFI_SSID, CONFIG_ESP_WIFI_PASSWORD); + ESP_LOGI(TAG, "Failed to connect to SSID:%s, password:%s", CONFIG_ESP_WIFI_SSID, CONFIG_ESP_WIFI_PASSWORD); } else { ESP_LOGE(TAG, "UNEXPECTED EVENT"); } diff --git a/partitions.csv b/partitions.csv index 6d9ee2e..204caea 100644 --- a/partitions.csv +++ b/partitions.csv @@ -2,5 +2,5 @@ # Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild nvs, data, nvs, 0x9000, 0x6000, phy_init, data, phy, 0xf000, 0x1000, -factory, app, factory, 0x10000, 1M, -storage, data, spiffs, , 0xF0000, +factory, app, factory, 0x10000, 0x120000, +storage, data, spiffs, , 0xD0000,