Skip to content

Commit

Permalink
Update to esp-idf 5.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Hougaard22 committed Nov 26, 2023
1 parent d3a55fe commit 8704caf
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 54 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The following lines of boilerplate have to be in your project's CMakeLists
# in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.16)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(esp32_nat_router)
10 changes: 5 additions & 5 deletions components/cmd_nvs/cmd_nvs.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,12 @@ static esp_err_t get_value_from_nvs(const char *key, const char *str_type)
} else if (type == NVS_TYPE_I32) {
int32_t value;
if ((err = nvs_get_i32(nvs, key, &value)) == ESP_OK) {
printf("%d\n", value);
printf("%ld\n", value);
}
} else if (type == NVS_TYPE_U32) {
uint32_t value;
if ((err = nvs_get_u32(nvs, key, &value)) == ESP_OK) {
printf("%u\n", value);
printf("%lu\n", value);
}
} else if (type == NVS_TYPE_I64) {
int64_t value;
Expand Down Expand Up @@ -373,8 +373,8 @@ static esp_err_t erase_all(const char *name)
static int list(const char *part, const char *name, const char *str_type)
{
nvs_type_t type = str_to_type(str_type);

nvs_iterator_t it = nvs_entry_find(part, NULL, type);
nvs_iterator_t it = NULL;
esp_err_t nvs_entry_find(part, name, type, it);
if (it == NULL) {
ESP_LOGE(TAG, "No such enty was found");
return 1;
Expand All @@ -383,7 +383,7 @@ static int list(const char *part, const char *name, const char *str_type)
do {
nvs_entry_info_t info;
nvs_entry_info(it, &info);
it = nvs_entry_next(it);
esp_err_t nvs_entry_next(it);

printf("namespace '%s', key '%s', type '%s' \n",
info.namespace_name, info.key, type_to_str(info.type));
Expand Down
2 changes: 1 addition & 1 deletion components/cmd_router/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
idf_component_register(SRCS "cmd_router.c"
INCLUDE_DIRS .
REQUIRES console nvs_flash)
REQUIRES console nvs_flash esp_wifi driver)
2 changes: 1 addition & 1 deletion components/cmd_router/cmd_router.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "esp_console.h"
#include "esp_system.h"
#include "esp_sleep.h"
#include "esp_spi_flash.h"
#include "spi_flash_mmap.h"
#include "driver/rtc_io.h"
#include "driver/uart.h"
#include "argtable3/argtable3.h"
Expand Down
4 changes: 2 additions & 2 deletions components/cmd_router/router_globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ esp_err_t get_config_param_int(char* name, int* param);
esp_err_t get_config_param_str(char* name, char** param);

void print_portmap_tab();
esp_err_t add_portmap(u8_t proto, u16_t mport, u32_t daddr, u16_t dport);
esp_err_t del_portmap(u8_t proto, u16_t mport);
esp_err_t add_portmap(uint8_t proto, uint16_t mport, uint32_t daddr, uint16_t dport);
esp_err_t del_portmap(uint8_t proto, uint16_t mport);

#ifdef __cplusplus
}
Expand Down
2 changes: 1 addition & 1 deletion components/cmd_system/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
idf_component_register(SRCS "cmd_system.c"
INCLUDE_DIRS .
REQUIRES console spi_flash)
REQUIRES console spi_flash driver)
17 changes: 10 additions & 7 deletions components/cmd_system/cmd_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
#include "esp_console.h"
#include "esp_system.h"
#include "esp_sleep.h"
#include "esp_spi_flash.h"
#include "driver/rtc_io.h"
#include "esp_flash.h"
#include "esp_chip_info.h"
#include "driver/uart.h"
#include "argtable3/argtable3.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "cmd_system.h"
#include "sdkconfig.h"
#include "driver/gpio.h"

#ifdef CONFIG_FREERTOS_USE_STATS_FORMATTING_FUNCTIONS
#define WITH_TASKS_INFO 1
Expand Down Expand Up @@ -57,16 +58,18 @@ static int get_version(int argc, char **argv)
{
esp_chip_info_t info;
esp_chip_info(&info);
uint32_t size_flash_chip;
esp_flash_get_size(NULL, &size_flash_chip);
printf("IDF Version:%s\r\n", esp_get_idf_version());
printf("Chip info:\r\n");
printf("\tmodel:%s\r\n", info.model == CHIP_ESP32 ? "ESP32" : "Unknow");
printf("\tcores:%d\r\n", info.cores);
printf("\tfeature:%s%s%s%s%d%s\r\n",
printf("\tfeature:%s%s%s%s%lu%s\r\n",
info.features & CHIP_FEATURE_WIFI_BGN ? "/802.11bgn" : "",
info.features & CHIP_FEATURE_BLE ? "/BLE" : "",
info.features & CHIP_FEATURE_BT ? "/BT" : "",
info.features & CHIP_FEATURE_EMB_FLASH ? "/Embedded-Flash:" : "/External-Flash:",
spi_flash_get_chip_size() / (1024 * 1024), " MB");
size_flash_chip / (1024 * 1024), " MB");
printf("\trevision number:%d\r\n", info.revision);
return 0;
}
Expand Down Expand Up @@ -105,7 +108,7 @@ static void register_restart(void)

static int free_mem(int argc, char **argv)
{
printf("%d\n", esp_get_free_heap_size());
printf("%lu\n", esp_get_free_heap_size());
return 0;
}

Expand All @@ -124,7 +127,7 @@ static void register_free(void)
static int heap_size(int argc, char **argv)
{
uint32_t heap_size = heap_caps_get_minimum_free_size(MALLOC_CAP_DEFAULT);
ESP_LOGI(TAG, "min heap size: %u", heap_size);
ESP_LOGI(TAG, "min heap size: %lu", heap_size);
return 0;
}

Expand Down Expand Up @@ -199,7 +202,7 @@ static int deep_sleep(int argc, char **argv)
}
if (deep_sleep_args.wakeup_gpio_num->count) {
int io_num = deep_sleep_args.wakeup_gpio_num->ival[0];
if (!rtc_gpio_is_valid_gpio(io_num)) {
if (!GPIO_IS_VALID_DIGITAL_IO_PAD(io_num)) {
ESP_LOGE(TAG, "GPIO %d is not an RTC IO", io_num);
return 1;
}
Expand Down
46 changes: 24 additions & 22 deletions main/esp32_nat_router.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
#include "lwip/err.h"
#include "lwip/sys.h"

#include "dhcpserver/dhcpserver.h"
#include "dhcpserver/dhcpserver_options.h"

#include "cmd_decl.h"
#include <esp_http_server.h>

Expand Down Expand Up @@ -92,7 +95,7 @@ static void initialize_filesystem(void)
.max_files = 4,
.format_if_mount_failed = true
};
esp_err_t err = esp_vfs_fat_spiflash_mount(MOUNT_PATH, "storage", &mount_config, &wl_handle);
esp_err_t err = esp_vfs_fat_spiflash_mount_rw_wl(MOUNT_PATH, "storage", &mount_config, &wl_handle);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to mount FATFS (%s)", esp_err_to_name(err));
return;
Expand Down Expand Up @@ -317,7 +320,6 @@ static void wifi_event_handler(void* arg, esp_event_base_t event_base,
int32_t event_id, void* event_data)
{
esp_netif_dns_info_t dns;
ip_addr_t dnsserver;

if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START)
{
Expand All @@ -341,10 +343,8 @@ static void wifi_event_handler(void* arg, esp_event_base_t event_base,
apply_portmap_tab();
if (esp_netif_get_dns_info(wifiSTA, ESP_NETIF_DNS_MAIN, &dns) == ESP_OK)
{
dnsserver.type = IPADDR_TYPE_V4;
dnsserver.u_addr.ip4.addr = dns.ip.u_addr.ip4.addr;
dhcps_dns_setserver(&dnsserver);
ESP_LOGI(TAG, "set dns to:" IPSTR, IP2STR(&(dnsserver.u_addr.ip4)));
esp_netif_set_dns_info(wifiAP, ESP_NETIF_DNS_MAIN, &dns);
ESP_LOGI(TAG, "set dns to:" IPSTR, IP2STR(&(dns.ip.u_addr.ip4)));
}
xEventGroupSetBits(wifi_event_group, WIFI_CONNECTED_BIT);
}
Expand All @@ -363,35 +363,33 @@ static void wifi_event_handler(void* arg, esp_event_base_t event_base,
const int CONNECTED_BIT = BIT0;
#define JOIN_TIMEOUT_MS (2000)


void wifi_init(const char* ssid, const char* ent_username, const char* ent_identity, const char* passwd, const char* static_ip, const char* subnet_mask, const char* gateway_addr, const char* ap_ssid, const char* ap_passwd, const char* ap_ip)
{
ip_addr_t dnsserver;
//tcpip_adapter_dns_info_t dnsinfo;

wifi_event_group = xEventGroupCreate();

esp_netif_init();
ESP_ERROR_CHECK(esp_event_loop_create_default());
wifiAP = esp_netif_create_default_wifi_ap();
wifiSTA = esp_netif_create_default_wifi_sta();

tcpip_adapter_ip_info_t ipInfo_sta;
esp_netif_ip_info_t ipInfo_sta;
if ((strlen(ssid) > 0) && (strlen(static_ip) > 0) && (strlen(subnet_mask) > 0) && (strlen(gateway_addr) > 0)) {
has_static_ip = true;
my_ip = ipInfo_sta.ip.addr = ipaddr_addr(static_ip);
ipInfo_sta.ip.addr = ipaddr_addr(static_ip);
ipInfo_sta.gw.addr = ipaddr_addr(gateway_addr);
ipInfo_sta.netmask.addr = ipaddr_addr(subnet_mask);
tcpip_adapter_dhcpc_stop(TCPIP_ADAPTER_IF_STA); // Don't run a DHCP client
tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_STA, &ipInfo_sta);
esp_netif_dhcpc_stop(ESP_IF_WIFI_STA); // Don't run a DHCP client
esp_netif_set_ip_info(ESP_IF_WIFI_STA, &ipInfo_sta);
apply_portmap_tab();
}

my_ap_ip = ipaddr_addr(ap_ip);
my_ap_ip = esp_ip4addr_aton(ap_ip);

esp_netif_ip_info_t ipInfo_ap;
ipInfo_ap.ip.addr = my_ap_ip;
ipInfo_ap.gw.addr = my_ap_ip;
IP4_ADDR(&ipInfo_ap.netmask, 255,255,255,0);
esp_netif_set_ip4_addr(&ipInfo_ap.netmask, 255,255,255,0);
esp_netif_dhcps_stop(wifiAP); // stop before setting ip WifiAP
esp_netif_set_ip_info(wifiAP, &ipInfo_ap);
esp_netif_dhcps_start(wifiAP);
Expand Down Expand Up @@ -460,17 +458,21 @@ void wifi_init(const char* ssid, const char* ent_username, const char* ent_ident
ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_AP, &ap_config) );
}



// Enable DNS (offer) for dhcp server
dhcps_offer_t dhcps_dns_value = OFFER_DNS;
dhcps_set_option_info(6, &dhcps_dns_value, sizeof(dhcps_dns_value));
esp_netif_dhcps_option(wifiAP,ESP_NETIF_OP_SET, ESP_NETIF_DOMAIN_NAME_SERVER, &dhcps_dns_value, sizeof(dhcps_dns_value));

// Set custom dns server address for dhcp server
dnsserver.u_addr.ip4.addr = ipaddr_addr(DEFAULT_DNS);;
dnsserver.type = IPADDR_TYPE_V4;
dhcps_dns_setserver(&dnsserver);
// // Set custom dns server address for dhcp server
// ip_addr_t dnsserver;
// dnsserver.u_addr.ip4.addr = ipaddr_addr(DEFAULT_DNS);;
// dnsserver.type = IPADDR_TYPE_V4;
// esp_netif_set_dns_info(wifiAP, ESP_NETIF_DNS_MAIN, &dns);

// tcpip_adapter_get_dns_info(TCPIP_ADAPTER_IF_AP, TCPIP_ADAPTER_DNS_MAIN, &dnsinfo);
// ESP_LOGI(TAG, "DNS IP:" IPSTR, IP2STR(&dnsinfo.ip.u_addr.ip4));
// esp_netif_dns_info_t dnsinfo;
// esp_netif_get_dns_info(ESP_IF_WIFI_AP, ESP_NETIF_DNS_MAIN, &dnsinfo);
// ESP_LOGI(TAG, "DNS IP:" IPSTR, IP2STR(&dnsinfo.ip.u_addr.ip4));

xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT,
pdFALSE, pdTRUE, JOIN_TIMEOUT_MS / portTICK_PERIOD_MS);
Expand Down
6 changes: 6 additions & 0 deletions partitions_4mb.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Name, Type, SubType, Offset, Size, Flags
# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
nvs, data, nvs, 0x9000, 0x6000,
phy_init, data, phy, 0xf000, 0x1000,
factory, app, factory, 0x10000, 2M,
storage, data, fat, , 1M,
6 changes: 6 additions & 0 deletions partitions_8mb.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Name, Type, SubType, Offset, Size, Flags
# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
nvs, data, nvs, 0x9000, 0x6000,
phy_init, data, phy, 0xf000, 0x1000,
factory, app, factory, 0x10000, 6M,
storage, data, fat, , 1M,
23 changes: 9 additions & 14 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,23 @@
[platformio]
src_dir = main

[env:ttgo-lora32-v1]
platform = espressif32
framework = espidf
board = ttgo-lora32-v1

monitor_speed = 115200
monitor_flags = --raw

[env:esp32dev]
platform = espressif32
platform = espressif32@6.4.0
framework = espidf
board = esp32dev

monitor_speed = 115200
monitor_flags = --raw

[env:esp32-c3-devkitm-1]
platform = espressif32
platform = espressif32@6.4.0
board = esp32-c3-devkitm-1
framework = espidf

monitor_speed = 115200
monitor_flags = --raw
board_build.partitions = partitions_4mb.csv

[env:esp32-s3]
platform = espressif32@6.4.0
framework = espidf
board = esp32s3box
monitor_speed = 115200

; build_flags = -I C:\Users\Marci\.platformio\packages\framework-espidf\components\bt\host\bluedroid\api\include\api

0 comments on commit 8704caf

Please sign in to comment.