Skip to content

Commit c6feed9

Browse files
committed
Initial changes to compile under ESP-IDF v5.1
1 parent f1b06d2 commit c6feed9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+265
-581
lines changed

CMakeLists.txt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
# export ARDUINO_SKIP_IDF_VERSION_CHECK=1
66
# idf.py build
77

8-
set(min_supported_idf_version "4.4.0")
9-
set(max_supported_idf_version "4.4.99")
8+
set(min_supported_idf_version "5.1.0")
9+
set(max_supported_idf_version "5.1.99")
1010
set(idf_version "${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}.${IDF_VERSION_PATCH}")
1111

1212
if ("${idf_version}" AND NOT "$ENV{ARDUINO_SKIP_IDF_VERSION_CHECK}")
@@ -121,7 +121,6 @@ set(LIBRARY_SRCS
121121
libraries/WebServer/src/Parsing.cpp
122122
libraries/WebServer/src/detail/mimetable.cpp
123123
libraries/WiFiClientSecure/src/ssl_client.cpp
124-
libraries/WiFiClientSecure/src/esp_crt_bundle.c
125124
libraries/WiFiClientSecure/src/WiFiClientSecure.cpp
126125
libraries/WiFi/src/WiFiAP.cpp
127126
libraries/WiFi/src/WiFiClient.cpp
@@ -207,8 +206,8 @@ set(includedirs
207206

208207
set(srcs ${CORE_SRCS} ${LIBRARY_SRCS} ${BLE_SRCS})
209208
set(priv_includes cores/esp32/libb64)
210-
set(requires spi_flash mbedtls mdns esp_adc_cal wifi_provisioning nghttp wpa_supplicant)
211-
set(priv_requires fatfs nvs_flash app_update spiffs bootloader_support openssl bt esp_ipc esp_hid)
209+
set(requires spi_flash mbedtls mdns wifi_provisioning wpa_supplicant esp_adc esp_eth http_parser)
210+
set(priv_requires fatfs nvs_flash app_update spiffs bootloader_support bt esp_hid esp_insights)
212211

213212
idf_component_register(INCLUDE_DIRS ${includedirs} PRIV_INCLUDE_DIRS ${priv_includes} SRCS ${srcs} REQUIRES ${requires} PRIV_REQUIRES ${priv_requires})
214213

cores/esp32/Arduino.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
173173
#include "Udp.h"
174174
#include "HardwareSerial.h"
175175
#include "Esp.h"
176-
#include "esp32/spiram.h"
177176

178177
// Use float-compatible stl abs() and round(), we don't use Arduino macros to avoid issues with the C++ libraries
179178
using std::abs;
@@ -192,7 +191,8 @@ size_t getArduinoLoopTaskStackSize(void);
192191
#define SET_LOOP_TASK_STACK_SIZE(sz) size_t getArduinoLoopTaskStackSize() { return sz;}
193192

194193
// allows user to bypass esp_spiram_test()
195-
#define BYPASS_SPIRAM_TEST(bypass) bool testSPIRAM(void) { if (bypass) return true; else return esp_spiram_test(); }
194+
bool esp_psram_extram_test(void);
195+
#define BYPASS_SPIRAM_TEST(bypass) bool testSPIRAM(void) { if (bypass) return true; else return esp_psram_extram_test(); }
196196

197197
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
198198
unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);

cores/esp32/Esp.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "Arduino.h"
2121
#include "Esp.h"
2222
#include "esp_sleep.h"
23-
#include "esp_spi_flash.h"
23+
#include "spi_flash_mmap.h"
2424
#include <memory>
2525
#include <soc/soc.h>
2626
#include <esp_partition.h>
@@ -32,6 +32,9 @@ extern "C" {
3232

3333
#include "soc/spi_reg.h"
3434
#include "esp_system.h"
35+
#include "esp_chip_info.h"
36+
#include "esp_mac.h"
37+
#include "esp_flash.h"
3538
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
3639
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
3740
#include "esp32/rom/spi_flash.h"
@@ -330,7 +333,7 @@ uint32_t EspClass::getFlashChipSize(void)
330333
uint32_t EspClass::getFlashChipSpeed(void)
331334
{
332335
esp_image_header_t fhdr;
333-
if(flashRead(ESP_FLASH_IMAGE_BASE, (uint32_t*)&fhdr, sizeof(esp_image_header_t)) && fhdr.magic != ESP_IMAGE_HEADER_MAGIC) {
336+
if(esp_flash_read(esp_flash_default_chip, (void*)&fhdr, ESP_FLASH_IMAGE_BASE, sizeof(esp_image_header_t)) && fhdr.magic != ESP_IMAGE_HEADER_MAGIC) {
334337
return 0;
335338
}
336339
return magicFlashChipSpeed(fhdr.spi_speed);
@@ -405,18 +408,18 @@ FlashMode_t EspClass::magicFlashChipMode(uint8_t byte)
405408

406409
bool EspClass::flashEraseSector(uint32_t sector)
407410
{
408-
return spi_flash_erase_sector(sector) == ESP_OK;
411+
return esp_flash_erase_region(esp_flash_default_chip, sector * SPI_FLASH_SEC_SIZE, SPI_FLASH_SEC_SIZE) == ESP_OK;
409412
}
410413

411414
// Warning: These functions do not work with encrypted flash
412415
bool EspClass::flashWrite(uint32_t offset, uint32_t *data, size_t size)
413416
{
414-
return spi_flash_write(offset, (uint32_t*) data, size) == ESP_OK;
417+
return esp_flash_write(esp_flash_default_chip, (const void*) data, offset, size) == ESP_OK;
415418
}
416419

417420
bool EspClass::flashRead(uint32_t offset, uint32_t *data, size_t size)
418421
{
419-
return spi_flash_read(offset, (uint32_t*) data, size) == ESP_OK;
422+
return esp_flash_read(esp_flash_default_chip, (void*) data, offset, size) == ESP_OK;
420423
}
421424

422425
bool EspClass::partitionEraseRange(const esp_partition_t *partition, uint32_t offset, size_t size)

cores/esp32/Esp.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <Arduino.h>
2424
#include <esp_partition.h>
2525
#include <hal/cpu_hal.h>
26+
#include "esp_cpu.h"
2627

2728
/**
2829
* AVR macros for WDT managment
@@ -111,7 +112,7 @@ class EspClass
111112

112113
uint32_t ARDUINO_ISR_ATTR EspClass::getCycleCount()
113114
{
114-
return cpu_hal_get_cycle_count();
115+
return (uint32_t)esp_cpu_get_cycle_count();
115116
}
116117

117118
extern EspClass ESP;

cores/esp32/FirmwareMSC.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
#include <cstring>
1919
#include "esp_partition.h"
2020
#include "esp_ota_ops.h"
21+
#include "esp_image_format.h"
2122
#include "esp32-hal.h"
2223
#include "pins_arduino.h"
2324
#include "firmware_msc_fat.h"
25+
#include "spi_flash_mmap.h"
2426

2527
#ifndef USB_FW_MSC_VENDOR_ID
2628
#define USB_FW_MSC_VENDOR_ID "ESP32" //max 8 chars

cores/esp32/HWCDC.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "esp_intr_alloc.h"
2424
#include "soc/periph_defs.h"
2525
#include "hal/usb_serial_jtag_ll.h"
26+
#include "rom/ets_sys.h"
2627

2728
ESP_EVENT_DEFINE_BASE(ARDUINO_HW_CDC_EVENTS);
2829

cores/esp32/USB.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "esp32-hal-tinyusb.h"
2121
#include "common/tusb_common.h"
2222
#include "StreamString.h"
23+
#include "rom/ets_sys.h"
24+
#include "esp_mac.h"
2325

2426
#ifndef USB_VID
2527
#define USB_VID USB_ESPRESSIF_VID

cores/esp32/USBCDC.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "USBCDC.h"
1818
#include "esp32-hal-tinyusb.h"
19+
#include "rom/ets_sys.h"
1920

2021
ESP_EVENT_DEFINE_BASE(ARDUINO_USB_CDC_EVENTS);
2122
esp_err_t arduino_usb_event_post(esp_event_base_t event_base, int32_t event_id, void *event_data, size_t event_data_size, TickType_t ticks_to_wait);

cores/esp32/WMath.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ extern "C" {
2828
#include "esp_system.h"
2929
}
3030
#include "esp32-hal-log.h"
31+
#include "esp_random.h"
3132

3233
void randomSeed(unsigned long seed)
3334
{

cores/esp32/esp32-hal-adc.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
static uint8_t __analogAttenuation = 3;//11db
2828
static uint8_t __analogWidth = ADC_WIDTH_MAX - 1; //3 for ESP32/ESP32C3; 4 for ESP32S2
29-
static uint8_t __analogReturnedWidth = SOC_ADC_MAX_BITWIDTH; //12 for ESP32/ESP32C3; 13 for ESP32S2
29+
static uint8_t __analogReturnedWidth = SOC_ADC_RTC_MAX_BITWIDTH; //12 for ESP32/ESP32C3; 13 for ESP32S2
3030
static uint8_t __analogClockDiv = 1;
3131
static adc_attenuation_t __pin_attenuation[SOC_GPIO_PIN_COUNT];
3232

@@ -256,13 +256,6 @@ void __analogSetVRefPin(uint8_t pin){
256256
__analogVRefPin = pin;
257257
}
258258

259-
int __hallRead() //hall sensor using idf read
260-
{
261-
pinMode(36, ANALOG);
262-
pinMode(39, ANALOG);
263-
__analogSetWidth(12);
264-
return hall_sensor_read();
265-
}
266259
#endif
267260

268261
extern uint16_t analogRead(uint8_t pin) __attribute__ ((weak, alias("__analogRead")));
@@ -277,5 +270,4 @@ extern bool adcAttachPin(uint8_t pin) __attribute__ ((weak, alias("__adcAttachPi
277270
#if CONFIG_IDF_TARGET_ESP32
278271
extern void analogSetVRefPin(uint8_t pin) __attribute__ ((weak, alias("__analogSetVRefPin")));
279272
extern void analogSetWidth(uint8_t bits) __attribute__ ((weak, alias("__analogSetWidth")));
280-
extern int hallRead() __attribute__ ((weak, alias("__hallRead")));
281273
#endif

cores/esp32/esp32-hal-adc.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,6 @@ void analogSetWidth(uint8_t bits);
9090
* */
9191
void analogSetVRefPin(uint8_t pin);
9292

93-
/*
94-
* Get value for HALL sensor (without LNA)
95-
* connected to pins 36(SVP) and 39(SVN)
96-
* */
97-
int hallRead();
9893
#endif
9994

10095
#ifdef __cplusplus

cores/esp32/esp32-hal-dac.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#define NODAC
2020
#else
2121
#include "soc/dac_channel.h"
22-
#include "driver/dac_common.h"
22+
#include "driver/dac.h"
2323

2424
void ARDUINO_ISR_ATTR __dacWrite(uint8_t pin, uint8_t value)
2525
{

cores/esp32/esp32-hal-i2c-slave.c

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ esp_err_t i2cSlaveInit(uint8_t num, int sda, int scl, uint16_t slaveID, uint32_t
320320
}
321321

322322
i2c_ll_disable_intr_mask(i2c->dev, I2C_LL_INTR_MASK);
323-
i2c_ll_clr_intsts_mask(i2c->dev, I2C_LL_INTR_MASK);
323+
i2c_ll_clear_intr_mask(i2c->dev, I2C_LL_INTR_MASK);
324324
i2c_ll_set_fifo_mode(i2c->dev, true);
325325

326326
if (!i2c->intr_handle) {
@@ -377,7 +377,7 @@ size_t i2cSlaveWrite(uint8_t num, const uint8_t *buf, uint32_t len, uint32_t tim
377377
log_e("Invalid port num: %u", num);
378378
return 0;
379379
}
380-
size_t to_queue = 0, to_fifo = 0;
380+
uint32_t to_queue = 0, to_fifo = 0;
381381
i2c_slave_struct_t * i2c = &_i2c_bus_array[num];
382382
#if !CONFIG_DISABLE_HAL_LOCKS
383383
if(!i2c->lock){
@@ -391,35 +391,39 @@ size_t i2cSlaveWrite(uint8_t num, const uint8_t *buf, uint32_t len, uint32_t tim
391391
I2C_SLAVE_MUTEX_LOCK();
392392
#if CONFIG_IDF_TARGET_ESP32
393393
i2c_ll_slave_disable_tx_it(i2c->dev);
394-
if (i2c_ll_get_txfifo_len(i2c->dev) < SOC_I2C_FIFO_LEN) {
394+
uint32_t txfifo_len = 0;
395+
i2c_ll_get_txfifo_len(i2c->dev, &txfifo_len);
396+
if (txfifo_len < SOC_I2C_FIFO_LEN) {
395397
i2c_ll_txfifo_rst(i2c->dev);
396398
}
397399
#endif
398-
to_fifo = i2c_ll_get_txfifo_len(i2c->dev);
399-
if(len < to_fifo){
400-
to_fifo = len;
401-
}
402-
i2c_ll_write_txfifo(i2c->dev, (uint8_t*)buf, to_fifo);
403-
buf += to_fifo;
404-
len -= to_fifo;
405-
//reset tx_queue
406-
xQueueReset(i2c->tx_queue);
407-
//write the rest of the bytes to the queue
408-
if(len){
409-
to_queue = uxQueueSpacesAvailable(i2c->tx_queue);
410-
if(len < to_queue){
411-
to_queue = len;
400+
i2c_ll_get_txfifo_len(i2c->dev, &to_fifo);
401+
if(to_fifo){
402+
if(len < to_fifo){
403+
to_fifo = len;
412404
}
413-
for (size_t i = 0; i < to_queue; i++) {
414-
if (xQueueSend(i2c->tx_queue, &buf[i], timeout_ms / portTICK_RATE_MS) != pdTRUE) {
415-
xQueueReset(i2c->tx_queue);
416-
to_queue = 0;
417-
break;
405+
i2c_ll_write_txfifo(i2c->dev, (uint8_t*)buf, to_fifo);
406+
buf += to_fifo;
407+
len -= to_fifo;
408+
//reset tx_queue
409+
xQueueReset(i2c->tx_queue);
410+
//write the rest of the bytes to the queue
411+
if(len){
412+
to_queue = uxQueueSpacesAvailable(i2c->tx_queue);
413+
if(len < to_queue){
414+
to_queue = len;
415+
}
416+
for (size_t i = 0; i < to_queue; i++) {
417+
if (xQueueSend(i2c->tx_queue, &buf[i], timeout_ms / portTICK_RATE_MS) != pdTRUE) {
418+
xQueueReset(i2c->tx_queue);
419+
to_queue = 0;
420+
break;
421+
}
422+
}
423+
//no need to enable TX_EMPTY if tx_queue is empty
424+
if(to_queue){
425+
i2c_ll_slave_enable_tx_it(i2c->dev);
418426
}
419-
}
420-
//no need to enable TX_EMPTY if tx_queue is empty
421-
if(to_queue){
422-
i2c_ll_slave_enable_tx_it(i2c->dev);
423427
}
424428
}
425429
I2C_SLAVE_MUTEX_UNLOCK();
@@ -434,7 +438,7 @@ static void i2c_slave_free_resources(i2c_slave_struct_t * i2c){
434438
i2c_slave_detach_gpio(i2c);
435439
i2c_ll_set_slave_addr(i2c->dev, 0, false);
436440
i2c_ll_disable_intr_mask(i2c->dev, I2C_LL_INTR_MASK);
437-
i2c_ll_clr_intsts_mask(i2c->dev, I2C_LL_INTR_MASK);
441+
i2c_ll_clear_intr_mask(i2c->dev, I2C_LL_INTR_MASK);
438442

439443
if (i2c->intr_handle) {
440444
esp_intr_free(i2c->intr_handle);
@@ -485,13 +489,13 @@ static bool i2c_slave_set_frequency(i2c_slave_struct_t * i2c, uint32_t clk_speed
485489
uint32_t a = (clk_speed / 50000L) + 2;
486490
log_d("Fifo thresholds: rx_fifo_full = %d, tx_fifo_empty = %d", SOC_I2C_FIFO_LEN - a, a);
487491

488-
i2c_clk_cal_t clk_cal;
492+
i2c_hal_clk_config_t clk_cal;
489493
#if SOC_I2C_SUPPORT_APB
490494
i2c_ll_cal_bus_clk(APB_CLK_FREQ, clk_speed, &clk_cal);
491-
i2c_ll_set_source_clk(i2c->dev, I2C_SCLK_APB); /*!< I2C source clock from APB, 80M*/
495+
i2c_ll_set_source_clk(i2c->dev, SOC_MOD_CLK_APB); /*!< I2C source clock from APB, 80M*/
492496
#elif SOC_I2C_SUPPORT_XTAL
493497
i2c_ll_cal_bus_clk(XTAL_CLK_FREQ, clk_speed, &clk_cal);
494-
i2c_ll_set_source_clk(i2c->dev, I2C_SCLK_XTAL); /*!< I2C source clock from XTAL, 40M */
498+
i2c_ll_set_source_clk(i2c->dev, SOC_MOD_CLK_XTAL); /*!< I2C source clock from XTAL, 40M */
495499
#endif
496500
i2c_ll_set_txfifo_empty_thr(i2c->dev, a);
497501
i2c_ll_set_rxfifo_full_thr(i2c->dev, SOC_I2C_FIFO_LEN - a);
@@ -630,7 +634,8 @@ static bool i2c_slave_send_event(i2c_slave_struct_t * i2c, i2c_slave_queue_event
630634
static bool i2c_slave_handle_tx_fifo_empty(i2c_slave_struct_t * i2c)
631635
{
632636
bool pxHigherPriorityTaskWoken = false;
633-
uint32_t d = 0, moveCnt = i2c_ll_get_txfifo_len(i2c->dev);
637+
uint32_t d = 0, moveCnt = 0;
638+
i2c_ll_get_txfifo_len(i2c->dev, &moveCnt);
634639
while (moveCnt > 0) { // read tx queue until Fifo is full or queue is empty
635640
if(xQueueReceiveFromISR(i2c->tx_queue, &d, (BaseType_t * const)&pxHigherPriorityTaskWoken) == pdTRUE){
636641
i2c_ll_write_txfifo(i2c->dev, (uint8_t*)&d, 1);
@@ -680,9 +685,11 @@ static void i2c_slave_isr_handler(void* arg)
680685
bool pxHigherPriorityTaskWoken = false;
681686
i2c_slave_struct_t * i2c = (i2c_slave_struct_t *) arg; // recover data
682687

683-
uint32_t activeInt = i2c_ll_get_intsts_mask(i2c->dev);
684-
i2c_ll_clr_intsts_mask(i2c->dev, activeInt);
685-
uint8_t rx_fifo_len = i2c_ll_get_rxfifo_cnt(i2c->dev);
688+
uint32_t activeInt = 0;
689+
i2c_ll_get_intr_mask(i2c->dev, &activeInt);
690+
i2c_ll_clear_intr_mask(i2c->dev, activeInt);
691+
uint32_t rx_fifo_len = 0;
692+
i2c_ll_get_rxfifo_cnt(i2c->dev, &rx_fifo_len);
686693
bool slave_rw = i2c_ll_slave_rw(i2c->dev);
687694

688695
if(activeInt & I2C_RXFIFO_WM_INT_ENA){ // RX FiFo Full

0 commit comments

Comments
 (0)