|
37 | 37 | #include "riscv_debug.h" |
38 | 38 | #include "spi.h" |
39 | 39 | #include "sfdp.h" |
| 40 | +#include "jep106.h" |
40 | 41 |
|
41 | 42 | #define ESP32_C3_ARCH_ID 0x80000001U |
42 | 43 | #define ESP32_C3_IMPL_ID 0x00000001U |
@@ -149,21 +150,38 @@ static bool esp32c3_exit_flash_mode(target_s *target); |
149 | 150 | static bool esp32c3_spi_flash_erase(target_flash_s *flash, target_addr_t addr, size_t length); |
150 | 151 | static bool esp32c3_spi_flash_write(target_flash_s *flash, target_addr_t dest, const void *src, size_t length); |
151 | 152 |
|
152 | | -bool esp32c3_probe(target_s *const target) |
| 153 | +/* Make an ESP32-C3 ready for probe operations having identified one */ |
| 154 | +bool esp32c3_target_prepare(target_s *const target) |
153 | 155 | { |
154 | 156 | const riscv_hart_s *const hart = riscv_hart_struct(target); |
155 | 157 | /* Seems that the best we can do is check the marchid and mimplid register values */ |
156 | | - if (hart->archid != ESP32_C3_ARCH_ID || hart->implid != ESP32_C3_IMPL_ID) |
| 158 | + if (target->designer_code != JEP106_MANUFACTURER_ESPRESSIF || hart->archid != ESP32_C3_ARCH_ID || |
| 159 | + hart->implid != ESP32_C3_IMPL_ID) |
157 | 160 | return false; |
158 | 161 |
|
| 162 | + /* Allocate the private structure here so we can store the WDT states */ |
159 | 163 | esp32c3_priv_s *const priv = calloc(1, sizeof(esp32c3_priv_s)); |
160 | 164 | if (!priv) { /* calloc failed: heap exhaustion */ |
161 | 165 | DEBUG_ERROR("calloc: failed in %s\n", __func__); |
162 | 166 | return false; |
163 | 167 | } |
164 | 168 | target->target_storage = priv; |
165 | | - target->driver = "ESP32-C3"; |
| 169 | + /* Prepare the target for memory IO */ |
| 170 | + target->mem_read = riscv32_mem_read; |
| 171 | + target->mem_write = riscv32_mem_write; |
| 172 | + /* Now disable the WDTs so the stop causing problems ready for discovering trigger slots, etc */ |
166 | 173 | esp32c3_disable_wdts(target); |
| 174 | + return true; |
| 175 | +} |
| 176 | + |
| 177 | +bool esp32c3_probe(target_s *const target) |
| 178 | +{ |
| 179 | + const riscv_hart_s *const hart = riscv_hart_struct(target); |
| 180 | + /* Seems that the best we can do is check the marchid and mimplid register values */ |
| 181 | + if (hart->archid != ESP32_C3_ARCH_ID || hart->implid != ESP32_C3_IMPL_ID) |
| 182 | + return false; |
| 183 | + |
| 184 | + target->driver = "ESP32-C3"; |
167 | 185 |
|
168 | 186 | /* We have to provide our own halt/resume functions to take care of the WDTs as they cause Problems */ |
169 | 187 | target->halt_request = esp32c3_halt_request; |
|
0 commit comments