Skip to content

Commit 10aac29

Browse files
committed
Initial ESP32C3 hal support
1 parent 371f382 commit 10aac29

26 files changed

+745
-89
lines changed

Diff for: CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ set(BLE_SRCS
124124

125125

126126
set(includedirs
127-
variants/esp32/
127+
variants/${IDF_TARGET}/
128128
cores/esp32/
129129
libraries/ArduinoOTA/src
130130
libraries/AsyncUDP/src

Diff for: cores/esp32/Esp.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ extern "C" {
3737
#include "soc/efuse_reg.h"
3838
#elif CONFIG_IDF_TARGET_ESP32S2
3939
#include "esp32s2/rom/spi_flash.h"
40+
#elif CONFIG_IDF_TARGET_ESP32C3
41+
#include "esp32c3/rom/spi_flash.h"
4042
#else
4143
#error Target CONFIG_IDF_TARGET is not supported
4244
#endif
@@ -265,6 +267,10 @@ const char * EspClass::getChipModel(void)
265267
}
266268
#elif CONFIG_IDF_TARGET_ESP32S2
267269
return "ESP32-S2";
270+
#elif CONFIG_IDF_TARGET_ESP32S3
271+
return "ESP32-S3";
272+
#elif CONFIG_IDF_TARGET_ESP32C3
273+
return "ESP32-C3";
268274
#endif
269275
}
270276

Diff for: cores/esp32/HardwareSerial.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in
6666
#elif CONFIG_IDF_TARGET_ESP32S2
6767
rxPin = 44;
6868
txPin = 43;
69+
#elif CONFIG_IDF_TARGET_ESP32C3
70+
rxPin = 20;
71+
txPin = 21;
6972
#endif
7073
}
7174
if(_uart_nr == 1 && rxPin < 0 && txPin < 0) {

Diff for: cores/esp32/MD5Builder.h

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#include "esp32/rom/md5_hash.h"
2929
#elif CONFIG_IDF_TARGET_ESP32S2
3030
#include "esp32s2/rom/md5_hash.h"
31+
#elif CONFIG_IDF_TARGET_ESP32C3
32+
#include "esp32c3/rom/md5_hash.h"
3133
#else
3234
#error Target CONFIG_IDF_TARGET is not supported
3335
#endif

Diff for: cores/esp32/esp32-hal-adc.c

+12-4
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,15 @@
1616
#include "freertos/FreeRTOS.h"
1717
#include "freertos/task.h"
1818
#include "esp_attr.h"
19-
#include "soc/rtc_io_reg.h"
2019
#include "soc/rtc_cntl_reg.h"
21-
#include "soc/sens_reg.h"
22-
2320
#include "driver/adc.h"
2421

2522
#include "esp_system.h"
2623
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
2724
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
2825
#include "esp_adc_cal.h"
26+
#include "soc/sens_reg.h"
27+
#include "soc/rtc_io_reg.h"
2928
#include "esp32/rom/ets_sys.h"
3029
#include "esp_intr_alloc.h"
3130
#define DEFAULT_VREF 1100
@@ -34,6 +33,10 @@ static uint16_t __analogVRef = 0;
3433
static uint8_t __analogVRefPin = 0;
3534
#elif CONFIG_IDF_TARGET_ESP32S2
3635
#include "esp32s2/rom/ets_sys.h"
36+
#include "soc/sens_reg.h"
37+
#include "soc/rtc_io_reg.h"
38+
#elif CONFIG_IDF_TARGET_ESP32C3
39+
#include "esp32c3/rom/ets_sys.h"
3740
#else
3841
#error Target CONFIG_IDF_TARGET is not supported
3942
#endif
@@ -51,7 +54,9 @@ void __analogSetClockDiv(uint8_t clockDiv){
5154
clockDiv = 1;
5255
}
5356
__analogClockDiv = clockDiv;
57+
#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2
5458
adc_set_clk_div(__analogClockDiv);
59+
#endif
5560
}
5661

5762
void __analogSetAttenuation(adc_attenuation_t attenuation)
@@ -114,11 +119,14 @@ bool __adcAttachPin(uint8_t pin){
114119
WRITE_PERI_REG(SENS_SAR_TOUCH_ENABLE_REG, touch);
115120
}
116121
#endif
117-
} else if(pin == 25){
122+
}
123+
#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2
124+
else if(pin == 25){
118125
CLEAR_PERI_REG_MASK(RTC_IO_PAD_DAC1_REG, RTC_IO_PDAC1_XPD_DAC | RTC_IO_PDAC1_DAC_XPD_FORCE);//stop dac1
119126
} else if(pin == 26){
120127
CLEAR_PERI_REG_MASK(RTC_IO_PAD_DAC2_REG, RTC_IO_PDAC2_XPD_DAC | RTC_IO_PDAC2_DAC_XPD_FORCE);//stop dac2
121128
}
129+
#endif
122130

123131
pinMode(pin, ANALOG);
124132
__analogSetPinAttenuation(pin, __analogAttenuation);

Diff for: cores/esp32/esp32-hal-cpu.c

+12-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "freertos/FreeRTOS.h"
1717
#include "freertos/semphr.h"
1818
#include "freertos/task.h"
19-
#include "freertos/xtensa_timer.h"
2019
#include "esp_attr.h"
2120
#include "esp_log.h"
2221
#include "soc/rtc.h"
@@ -29,9 +28,13 @@
2928
#include "esp_system.h"
3029
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
3130
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
31+
#include "freertos/xtensa_timer.h"
3232
#include "esp32/rom/rtc.h"
3333
#elif CONFIG_IDF_TARGET_ESP32S2
34+
#include "freertos/xtensa_timer.h"
3435
#include "esp32s2/rom/rtc.h"
36+
#elif CONFIG_IDF_TARGET_ESP32C3
37+
#include "esp32c3/rom/rtc.h"
3538
#else
3639
#error Target CONFIG_IDF_TARGET is not supported
3740
#endif
@@ -141,10 +144,14 @@ bool removeApbChangeCallback(void * arg, apb_change_cb_t cb){
141144
}
142145

143146
static uint32_t calculateApb(rtc_cpu_freq_config_t * conf){
147+
#if CONFIG_IDF_TARGET_ESP32C3
148+
return APB_CLK_FREQ;
149+
#else
144150
if(conf->freq_mhz >= 80){
145151
return 80 * MHZ;
146152
}
147153
return (conf->source_freq_mhz * MHZ) / conf->div;
154+
#endif
148155
}
149156

150157
void esp_timer_impl_update_apb_freq(uint32_t apb_ticks_per_us); //private in IDF
@@ -219,8 +226,12 @@ bool setCpuFrequencyMhz(uint32_t cpu_freq_mhz){
219226
esp_timer_impl_update_apb_freq(apb / MHZ);
220227
}
221228
//Update FreeRTOS Tick Divisor
229+
#if CONFIG_IDF_TARGET_ESP32C3
230+
231+
#else
222232
uint32_t fcpu = (conf.freq_mhz >= 80)?(conf.freq_mhz * MHZ):(apb);
223233
_xt_tick_divisor = fcpu / XT_TICK_PER_SEC;
234+
#endif
224235
//Call peripheral functions after the APB change
225236
if(apb_change_callbacks){
226237
triggerApbChangeCallback(APB_AFTER_CHANGE, capb, apb);

Diff for: cores/esp32/esp32-hal-dac.c

+14-7
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,29 @@
1313
// limitations under the License.
1414

1515
#include "esp32-hal.h"
16-
#include "esp_attr.h"
17-
#include "soc/rtc_io_reg.h"
18-
#include "soc/rtc_cntl_reg.h"
19-
#include "soc/rtc_io_periph.h"
20-
#include "soc/sens_reg.h"
21-
#include "soc/sens_struct.h"
22-
#include "driver/dac.h"
2316

2417
#if CONFIG_IDF_TARGET_ESP32
18+
#include "soc/rtc_io_reg.h"
2519
#define DAC1 25
2620
#define DAC2 26
2721
#elif CONFIG_IDF_TARGET_ESP32S2
22+
#include "soc/rtc_io_reg.h"
2823
#define DAC1 17
2924
#define DAC2 18
25+
#elif CONFIG_IDF_TARGET_ESP32C3
26+
#define NODAC
3027
#else
3128
#error Target CONFIG_IDF_TARGET is not supported
3229
#endif
3330

31+
#ifndef NODAC
32+
#include "esp_attr.h"
33+
#include "soc/rtc_cntl_reg.h"
34+
#include "soc/rtc_io_periph.h"
35+
#include "soc/sens_reg.h"
36+
#include "soc/sens_struct.h"
37+
#include "driver/dac.h"
38+
3439
void ARDUINO_ISR_ATTR __dacWrite(uint8_t pin, uint8_t value)
3540
{
3641
if(pin < DAC1 || pin > DAC2){
@@ -54,3 +59,5 @@ void ARDUINO_ISR_ATTR __dacWrite(uint8_t pin, uint8_t value)
5459
}
5560

5661
extern void dacWrite(uint8_t pin, uint8_t value) __attribute__ ((weak, alias("__dacWrite")));
62+
63+
#endif

0 commit comments

Comments
 (0)