|
33 | 33 | #include "soc/uart_reg.h"
|
34 | 34 |
|
35 | 35 | #include "led.h"
|
| 36 | +#elif defined(ESP32C3) |
| 37 | +#include "esp32c3/rom/efuse.h" |
| 38 | +#include "esp32c3/rom/miniz.h" |
| 39 | +#include "esp32c3/rom/spi_flash.h" |
| 40 | +#include "soc/spi_mem_reg.h" |
| 41 | +#include "soc/uart_reg.h" |
36 | 42 | #endif
|
37 | 43 |
|
38 | 44 | #include "slip.h"
|
@@ -68,6 +74,18 @@ extern uint32_t _bss_start, _bss_end;
|
68 | 74 | #define SPI_USER_REG(i) (REG_SPI_BASE(i) + 0x1C)
|
69 | 75 |
|
70 | 76 | #define SPI_W0_REG(i) (REG_SPI_BASE(i) + 0x40)
|
| 77 | +#elif defined(ESP32C3) |
| 78 | +#define SPI_CMD_REG(i) SPI_MEM_CMD_REG(i) |
| 79 | +#define SPI_FLASH_WREN SPI_MEM_FLASH_WREN |
| 80 | +#define SPI_FLASH_RDID SPI_MEM_FLASH_RDID |
| 81 | +#define SPI_FLASH_SE SPI_MEM_FLASH_SE |
| 82 | +#define SPI_FLASH_BE SPI_MEM_FLASH_BE |
| 83 | + |
| 84 | +#define SPI_ADDR_REG(i) SPI_MEM_ADDR_REG(i) |
| 85 | + |
| 86 | +#define SPI_USER_REG(i) SPI_MEM_USER_REG(i) |
| 87 | + |
| 88 | +#define SPI_W0_REG(i) SPI_MEM_W0_REG(i) |
71 | 89 | #endif
|
72 | 90 |
|
73 | 91 | enum read_state {
|
@@ -95,7 +113,11 @@ struct uart_buf {
|
95 | 113 |
|
96 | 114 | static inline uint32_t ccount(void) {
|
97 | 115 | uint32_t r;
|
| 116 | +#if defined(ESP32C3) |
| 117 | + __asm volatile ("csrr %0, 0x7e2" : "=r"(r)); |
| 118 | +#else |
98 | 119 | __asm volatile("rsr.ccount %0" : "=a"(r));
|
| 120 | +#endif |
99 | 121 | return r;
|
100 | 122 | }
|
101 | 123 |
|
@@ -232,6 +254,19 @@ esp_rom_spiflash_result_t esp_rom_spiflash_erase_start(uint32_t addr,
|
232 | 254 |
|
233 | 255 | return ESP_ROM_SPIFLASH_RESULT_OK;
|
234 | 256 | }
|
| 257 | +#elif defined(ESP32C3) |
| 258 | +esp_rom_spiflash_result_t esp_rom_spiflash_erase_start(uint32_t addr, |
| 259 | + uint32_t cmd) { |
| 260 | + uint32_t length = 0; |
| 261 | + |
| 262 | + if (cmd == SPI_FLASH_BE) { |
| 263 | + length = FLASH_BLOCK_SIZE; |
| 264 | + } else if (cmd == SPI_FLASH_SE) { |
| 265 | + length = FLASH_SECTOR_SIZE; |
| 266 | + } |
| 267 | + |
| 268 | + return esp_rom_spiflash_erase_area(addr, length); |
| 269 | +} |
235 | 270 | #endif
|
236 | 271 |
|
237 | 272 | int do_flash_write(uint32_t addr, uint32_t len, uint32_t erase) {
|
@@ -570,10 +605,18 @@ uint32_t _stack[3072];
|
570 | 605 | void stub_main(void) {
|
571 | 606 | memset(&_bss_start, 0, (&_bss_end - &_bss_start));
|
572 | 607 | uint32_t *stack_end = &_stack[3071];
|
| 608 | +#if defined(ESP32C3) |
| 609 | + __asm volatile("mv sp, %0\n" |
| 610 | + : // output |
| 611 | + : "r"(stack_end) // input |
| 612 | + : // scratch |
| 613 | + ); |
| 614 | +#else |
573 | 615 | __asm volatile("mov a1, %0\n"
|
574 | 616 | : // output
|
575 | 617 | : "a"(stack_end) // input
|
576 | 618 | : // scratch
|
577 | 619 | );
|
| 620 | +#endif |
578 | 621 | stub_main1();
|
579 | 622 | }
|
0 commit comments