Skip to content

Commit c84fda1

Browse files
authored
Resolve HWDT Reset with core_esp8266_vm (#9025)
* Resolve HWDT Reset with core_esp8266_vm With the newer GCC compiler (after tag 3.0.2), example virtualmem was crashing with a HWDT reset. Reordered some SPI register set lines in spi_init(). New ordering was based on ::begin in SPI.cpp This change may resolve issues describe in #9010 * Added memory barrier to changes spi_ctrl appears to need setting before other SPI registers
1 parent 7fc2caa commit c84fda1

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

cores/esp8266/core_esp8266_vm.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -161,20 +161,21 @@ static struct cache_line *__vm_cache; // Always points to MRU (hence the line be
161161

162162
constexpr int addrmask = ~(sizeof(__vm_cache[0].w)-1); // Helper to mask off bits present in cache entry
163163

164-
165164
static void spi_init(spi_regs *spi1)
166165
{
167166
pinMode(sck, SPECIAL);
168167
pinMode(miso, SPECIAL);
169168
pinMode(mosi, SPECIAL);
170169
pinMode(cs, SPECIAL);
171-
spi1->spi_cmd = 0;
170+
// spi_ctrl appears to need setting before other SPI registers
171+
spi1->spi_ctrl = 0; // MSB first + plain SPI mode
172+
asm("" ::: "memory");
172173
GPMUX &= ~(1 << 9);
173174
spi1->spi_clock = spi_clkval;
174-
spi1->spi_ctrl = 0 ; // MSB first + plain SPI mode
175175
spi1->spi_ctrl1 = 0; // undocumented, clear for safety?
176176
spi1->spi_ctrl2 = 0; // No add'l delays on signals
177177
spi1->spi_user2 = 0; // No insn or insn_bits to set
178+
spi1->spi_cmd = 0;
178179
}
179180

180181
// Note: GCC optimization -O2 and -O3 tried and returned *slower* code than the default

0 commit comments

Comments
 (0)