Skip to content

Commit

Permalink
feat(esp32s3) add support for esp32s3 (#72)
Browse files Browse the repository at this point in the history
* feat(esp32s3) add support for esp32s3

* reformat coding style

* fix(spi_switch) esp32s3: remove IOMUX SPI pin definition from DAP_config and hardcode it

* fix(workflows) remove 'uses' while already having run

* reformat spaces and remove unsed include
  • Loading branch information
kerms committed Apr 21, 2024
1 parent fa3e6ec commit 46fa164
Show file tree
Hide file tree
Showing 13 changed files with 284 additions and 13 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
continue-on-error: false
strategy:
matrix:
target-hardware: [esp8266, esp32, esp32c3]
target-hardware: [esp8266, esp32, esp32c3, esp32s3]


steps:
Expand Down Expand Up @@ -92,6 +92,13 @@ jobs:
sudo python3 ./esptool/esptool.py --chip ${{ matrix.target-hardware }} merge_bin -o build/wireless_esp_dap_full.bin 0x0 build/bootloader/bootloader.bin 0x8000 build/partition_table/partition-table.bin 0x10000 build/wireless_esp_dap.bin
sudo mv build/wireless_esp_dap.bin build/wireless_esp_dap_app.bin
- name: merge bin files (esp32s3)
if: matrix.target-hardware == 'esp32s3'
run: |
git clone https://github.com/espressif/esptool.git
git -C ./esptool/ checkout tags/v4.6.2 -b merge_wirless_bin
sudo python3 ./esptool/esptool.py --chip ${{ matrix.target-hardware }} merge_bin -o build/wireless_esp_dap_full.bin 0x0 build/bootloader/bootloader.bin 0x8000 build/partition_table/partition-table.bin 0x10000 build/wireless_esp_dap.bin
sudo mv build/wireless_esp_dap.bin build/wireless_esp_dap_app.bin
- name: Upload firmware
uses: actions/upload-artifact@v2
Expand Down
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ For Keil users, we now also support [elaphureLink](https://github.com/windowsair
- [x] ESP8266/8285
- [x] ESP32
- [x] ESP32C3
- [x] ESP32S3

2. Debug Communication Mode
- [x] SWD
Expand Down Expand Up @@ -191,6 +192,34 @@ There is built-in ipv4 only mDNS server. You can access the device using `dap.lo
</details>


<details>
<summary>ESP32S3</summary>

| SWD | |
|----------------|--------|
| SWCLK | GPIO12 |
| SWDIO | GPIO11 |
| TVCC | 3V3 |
| GND | GND |


--------------


| JTAG | |
|--------------------|--------|
| TCK | GPIO12 |
| TMS | GPIO11 |
| TDI | GPIO10 |
| TDO | GPIO9 |
| nTRST \(optional\) | GPIO14 |
| nRESET | GPIO13 |
| TVCC | 3V3 |
| GND | GND |


</details>

----

## Hardware Reference
Expand Down
27 changes: 27 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- [x] ESP8266/8285
- [x] ESP32
- [x] ESP32C3
- [x] ESP32S3

2. 支持的调试接口:
- [x] SWD
Expand Down Expand Up @@ -181,6 +182,32 @@

</details>

<details>
<summary>ESP32S3</summary>

| SWD | |
|----------------|--------|
| SWCLK | GPIO12 |
| SWDIO | GPIO11 |
| TVCC | 3V3 |
| GND | GND |


--------------


| JTAG | |
|--------------------|--------|
| TCK | GPIO12 |
| TMS | GPIO11 |
| TDI | GPIO10 |
| TDO | GPIO9 |
| nTRST \(optional\) | GPIO14 |
| nRESET | GPIO13 |
| TVCC | 3V3 |
| GND | GND |



----

Expand Down
53 changes: 52 additions & 1 deletion components/DAP/config/DAP_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
#include "esp8266/pin_mux_register.h"
#elif defined CONFIG_IDF_TARGET_ESP32
#elif defined CONFIG_IDF_TARGET_ESP32C3
#elif defined CONFIG_IDF_TARGET_ESP32S3
#else
#error unknown hardware
#endif
Expand Down Expand Up @@ -100,6 +101,8 @@ This information includes:
#elif defined CONFIG_IDF_TARGET_ESP32C3
#define CPU_CLOCK 16000000
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<160MHz
#elif defined CONFIG_IDF_TARGET_ESP32S3
#define CPU_CLOCK 240000000
#endif


Expand Down Expand Up @@ -375,7 +378,19 @@ __STATIC_INLINE uint8_t DAP_GetProductFirmwareVersionString (char *str) {

#define PIN_LED_CONNECTED _ // won't be used
#define PIN_LED_RUNNING _ // won't be used
#elif defined CONFIG_IDF_TARGET_ESP32S3
#define PIN_SWDIO _ // SPI MISO
#define PIN_SWDIO_MOSI 11 // SPI MOSI
#define PIN_SWCLK 12
#define PIN_TDO 9 // device TDO -> Host Data Input
#define PIN_TDI 10
#define PIN_nTRST 14 // optional
#define PIN_nRESET 13

#define PIN_LED_CONNECTED _ // won't be used
#define PIN_LED_RUNNING _ // won't be used
#else
#error "not a supported target"
#endif


Expand Down Expand Up @@ -535,6 +550,29 @@ __STATIC_INLINE void PORT_JTAG_SETUP(void)
GPIO_PULL_UP_ONLY_SET(PIN_nTRST);
GPIO_PULL_UP_ONLY_SET(PIN_nRESET);
}
#elif defined CONFIG_IDF_TARGET_ESP32S3
__STATIC_INLINE void PORT_JTAG_SETUP(void)
{
// set TCK, TMS pin

// PIN_TDO output disable
gpio_ll_output_disable(&GPIO, PIN_TDO);
// PIN_TDO input enable
gpio_ll_input_enable(&GPIO, PIN_TDO);

// PIN_TDI output
gpio_ll_output_enable(&GPIO, PIN_TDI);
gpio_ll_od_disable(&GPIO, PIN_TDI);
gpio_ll_pulldown_dis(&GPIO, PIN_TDI);

gpio_ll_output_enable(&GPIO, PIN_nTRST);
gpio_ll_od_enable(&GPIO, PIN_nTRST);
gpio_ll_output_enable(&GPIO, PIN_nRESET);
gpio_ll_od_enable(&GPIO, PIN_nRESET);

GPIO_PULL_UP_ONLY_SET(PIN_nTRST);
GPIO_PULL_UP_ONLY_SET(PIN_nRESET);
}
#endif

/**
Expand Down Expand Up @@ -585,6 +623,11 @@ __STATIC_INLINE void PORT_OFF(void)

// gpio_set_pull_mode(PIN_nTRST, GPIO_PULLUP_ONLY);
GPIO_PULL_UP_ONLY_SET(PIN_nRESET);
#elif defined CONFIG_IDF_TARGET_ESP32S3
gpio_ll_output_enable(&GPIO, PIN_nRESET);
gpio_ll_od_enable(&GPIO, PIN_nRESET);
GPIO_PULL_UP_ONLY_SET(PIN_nRESET);
gpio_ll_set_level(&GPIO, PIN_nRESET, 1);
#endif
}

Expand Down Expand Up @@ -728,6 +771,10 @@ __STATIC_FORCEINLINE void PIN_SWDIO_OUT_DISABLE(void)
// Note that the input of esp32c3 is not always connected.
PIN_INPUT_ENABLE(GPIO_PIN_MUX_REG[PIN_SWDIO_MOSI]);
GPIO.out_w1ts.out_w1ts = (0x1 << PIN_SWDIO_MOSI);
#elif defined CONFIG_IDF_TARGET_ESP32S3
// Note that the input is not always connected.
gpio_ll_input_enable(&GPIO, PIN_SWDIO_MOSI);
gpio_ll_set_level(&GPIO, PIN_SWDIO_MOSI, 1);
#endif
}

Expand Down Expand Up @@ -776,7 +823,7 @@ __STATIC_FORCEINLINE uint32_t PIN_TDO_IN(void)
return READ_PERI_REG(RTC_GPIO_IN_DATA) & 0x1;
#elif defined CONFIG_IDF_TARGET_ESP32
return ((GPIO.in >> PIN_TDO) & 0x1) ? 1 : 0;
#elif defined CONFIG_IDF_TARGET_ESP32C3
#elif defined CONFIG_IDF_TARGET_ESP32C3 || defined CONFIG_IDF_TARGET_ESP32S3
return GPIO_GET_LEVEL(PIN_TDO);
#endif
}
Expand Down Expand Up @@ -837,6 +884,8 @@ __STATIC_FORCEINLINE void PIN_nRESET_OUT(uint32_t bit)
GPIO.enable_w1tc |= (0x01 << PIN_nRESET);
#elif defined CONFIG_IDF_TARGET_ESP32C3
GPIO.enable_w1tc.enable_w1tc |= (0x01 << PIN_nRESET);
#elif defined CONFIG_IDF_TARGET_ESP32S3
gpio_ll_output_disable(&GPIO, PIN_nRESET);
#endif
}
else
Expand All @@ -846,6 +895,8 @@ __STATIC_FORCEINLINE void PIN_nRESET_OUT(uint32_t bit)
GPIO.enable_w1ts |= (0x01 << PIN_nRESET);
#elif defined CONFIG_IDF_TARGET_ESP32C3
GPIO.enable_w1ts.enable_w1ts |= (0x01 << PIN_nRESET);
#elif defined CONFIG_IDF_TARGET_ESP32S3
gpio_ll_output_enable(&GPIO, PIN_nRESET);
#endif
GPIO_SET_LEVEL_LOW(PIN_nRESET);
}
Expand Down
2 changes: 1 addition & 1 deletion components/DAP/include/DAP.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ extern void DAP_Setup (void);
;
}
#else
#if defined CONFIG_IDF_TARGET_ESP8266 || CONFIG_IDF_TARGET_ESP32
#if defined CONFIG_IDF_TARGET_ESP8266 || defined CONFIG_IDF_TARGET_ESP32 || defined CONFIG_IDF_TARGET_ESP32S3
__STATIC_FORCEINLINE void PIN_DELAY_SLOW(int32_t delay)
{
__asm__ volatile(
Expand Down
11 changes: 11 additions & 0 deletions components/DAP/include/gpio_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@
#include "soc/esp32c3/include/soc/io_mux_reg.h"
#include "soc/esp32c3/include/soc/spi_struct.h"
#include "soc/esp32c3/include/soc/spi_reg.h"
#elif defined CONFIG_IDF_TARGET_ESP32S3
#include "soc/esp32s3/include/soc/gpio_struct.h"
#include "hal/esp32s3/include/hal/gpio_ll.h"
#include "hal/esp32s3/include/hal/clk_gate_ll.h"
#include "soc/esp32s3/include/soc/gpio_struct.h"
#include "soc/esp32s3/include/soc/dport_access.h"
#include "soc/esp32s3/include/soc/periph_defs.h"
#include "soc/esp32s3/include/soc/usb_serial_jtag_reg.h"
#include "soc/esp32s3/include/soc/io_mux_reg.h"
#include "soc/esp32s3/include/soc/spi_struct.h"
#include "soc/esp32s3/include/soc/spi_reg.h"
#else
#error unknown hardware
#endif
Expand Down
24 changes: 22 additions & 2 deletions components/DAP/include/gpio_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ __STATIC_INLINE __UNUSED void GPIO_FUNCTION_SET(int io_num)
}
PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[io_num], PIN_FUNC_GPIO);
}
#elif defined CONFIG_IDF_TARGET_ESP32S3
__STATIC_INLINE __UNUSED void GPIO_FUNCTION_SET(int io_num)
{
gpio_ll_iomux_func_sel(GPIO_PIN_MUX_REG[io_num], PIN_FUNC_GPIO);
}
#endif


Expand All @@ -77,6 +82,13 @@ __STATIC_INLINE __UNUSED void GPIO_SET_DIRECTION_NORMAL_OUT(int io_num)
// PP out
GPIO.pin[io_num].pad_driver = 0;
}
#elif defined CONFIG_IDF_TARGET_ESP32S3
__STATIC_INLINE __UNUSED void GPIO_SET_DIRECTION_NORMAL_OUT(int io_num)
{
gpio_ll_output_enable(&GPIO, io_num);
// PP out
gpio_ll_od_disable(&GPIO, io_num);
}
#endif


Expand All @@ -90,7 +102,7 @@ __STATIC_INLINE __UNUSED void GPIO_SET_LEVEL_LOW(int io_num)
{
GPIO.out_w1tc |= (0x1 << io_num);
}
#elif defined CONFIG_IDF_TARGET_ESP32C3
#elif defined CONFIG_IDF_TARGET_ESP32C3 || defined CONFIG_IDF_TARGET_ESP32S3
__STATIC_INLINE __UNUSED void GPIO_SET_LEVEL_HIGH(int io_num)
{
gpio_ll_set_level(&GPIO, io_num, 1);
Expand All @@ -107,7 +119,7 @@ __STATIC_INLINE __UNUSED int GPIO_GET_LEVEL(int io_num)
{
return ((GPIO.in >> io_num) & 0x1) ? 1 : 0;
}
#elif defined CONFIG_IDF_TARGET_ESP32C3
#elif defined CONFIG_IDF_TARGET_ESP32C3 || defined CONFIG_IDF_TARGET_ESP32S3
__STATIC_INLINE __UNUSED int GPIO_GET_LEVEL(int io_num)
{
return gpio_ll_get_level(&GPIO, io_num);
Expand All @@ -125,6 +137,14 @@ __STATIC_INLINE __UNUSED void GPIO_PULL_UP_ONLY_SET(int io_num)
// enable pull up
REG_SET_BIT(GPIO_PIN_MUX_REG[io_num], FUN_PU);
}
#elif defined CONFIG_IDF_TARGET_ESP32S3
__STATIC_INLINE __UNUSED void GPIO_PULL_UP_ONLY_SET(int io_num)
{
// disable pull down
gpio_ll_pulldown_dis(&GPIO, io_num);
// enable pull up
gpio_ll_pullup_en(&GPIO, io_num);
}
#elif defined CONFIG_IDF_TARGET_ESP8266
__STATIC_INLINE __UNUSED void GPIO_PULL_UP_ONLY_SET(int io_num)
{
Expand Down
2 changes: 1 addition & 1 deletion components/DAP/source/DAP.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ static uint32_t DAP_SWJ_Clock(const uint8_t *request, uint8_t *response) {

#ifdef CONFIG_IDF_TARGET_ESP8266
#define BUS_CLOCK_FIXED 80000000
#elif defined CONFIG_IDF_TARGET_ESP32
#elif defined CONFIG_IDF_TARGET_ESP32 || defined CONFIG_IDF_TARGET_ESP32S3
#define BUS_CLOCK_FIXED 100000000
#elif defined CONFIG_IDF_TARGET_ESP32C3
#define BUS_CLOCK_FIXED 80000000
Expand Down
2 changes: 1 addition & 1 deletion components/DAP/source/SW_DP.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ static uint8_t SWD_Transfer_SPI (uint32_t request, uint32_t *data) {
else if ((ack == DAP_TRANSFER_WAIT) || (ack == DAP_TRANSFER_FAULT)) {
#if defined CONFIG_IDF_TARGET_ESP8266 || defined CONFIG_IDF_TARGET_ESP32
DAP_SPI_Generate_Cycle(1);
#elif defined CONFIG_IDF_TARGET_ESP32C3
#elif defined CONFIG_IDF_TARGET_ESP32C3 || defined CONFIG_IDF_TARGET_ESP32S3
DAP_SPI_Fast_Cycle();
#endif

Expand Down
12 changes: 7 additions & 5 deletions components/DAP/source/spi_op.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#define DAP_SPI SPI2
#elif defined CONFIG_IDF_TARGET_ESP32C3
#define DAP_SPI GPSPI2
#elif defined CONFIG_IDF_TARGET_ESP32S3
#define DAP_SPI GPSPI2
#else
#error unknown hardware
#endif
Expand All @@ -53,7 +55,7 @@
while (DAP_SPI.cmd.usr) continue; \
} while(0)

#elif defined CONFIG_IDF_TARGET_ESP32C3
#elif defined CONFIG_IDF_TARGET_ESP32C3 || defined CONFIG_IDF_TARGET_ESP32S3
#define SET_MOSI_BIT_LEN(x) DAP_SPI.ms_dlen.ms_data_bitlen = x
#define SET_MISO_BIT_LEN(x) DAP_SPI.ms_dlen.ms_data_bitlen = x
#define START_AND_WAIT_SPI_TRANSMISSION_DONE() \
Expand Down Expand Up @@ -208,7 +210,7 @@ __FORCEINLINE void DAP_SPI_Send_Header(const uint8_t packetHeaderData, uint8_t *
dataBuf = DAP_SPI.data_buf[0];
*ack = (dataBuf >> 1) & 0b111;
} // defined CONFIG_IDF_TARGET_ESP8266 || defined CONFIG_IDF_TARGET_ESP32
#elif defined CONFIG_IDF_TARGET_ESP32C3
#elif defined CONFIG_IDF_TARGET_ESP32C3 || defined CONFIG_IDF_TARGET_ESP32S3
__FORCEINLINE void DAP_SPI_Send_Header(const uint8_t packetHeaderData, uint8_t *ack, uint8_t TrnAfterACK)
{
uint32_t dataBuf;
Expand Down Expand Up @@ -298,7 +300,7 @@ __FORCEINLINE void DAP_SPI_Write_Data(uint32_t data, uint8_t parity)

START_AND_WAIT_SPI_TRANSMISSION_DONE();
}
#elif defined CONFIG_IDF_TARGET_ESP32C3
#elif defined CONFIG_IDF_TARGET_ESP32C3 || defined CONFIG_IDF_TARGET_ESP32S3
__FORCEINLINE void DAP_SPI_Write_Data(uint32_t data, uint8_t parity)
{
DAP_SPI.user.usr_mosi = 1;
Expand All @@ -315,7 +317,7 @@ __FORCEINLINE void DAP_SPI_Write_Data(uint32_t data, uint8_t parity)
#endif


#if defined CONFIG_IDF_TARGET_ESP8266 || defined CONFIG_IDF_TARGET_ESP32
#if defined CONFIG_IDF_TARGET_ESP8266 || defined CONFIG_IDF_TARGET_ESP32 || defined CONFIG_IDF_TARGET_ESP32S3
/**
* @brief Generate Clock Cycle
*
Expand Down Expand Up @@ -346,7 +348,7 @@ __FORCEINLINE void DAP_SPI_Generate_Cycle(uint8_t num)
}
#endif

#if defined CONFIG_IDF_TARGET_ESP32 || defined CONFIG_IDF_TARGET_ESP32C3
#if defined CONFIG_IDF_TARGET_ESP32 || defined CONFIG_IDF_TARGET_ESP32C3 || defined CONFIG_IDF_TARGET_ESP32S3
/**
* @brief Quickly generate 1 clock
*
Expand Down
Loading

0 comments on commit 46fa164

Please sign in to comment.