Skip to content

Turn on SAMD51 instruction/data cache #783

@dhalbert

Description

@dhalbert

The SAMD51 has an instruction/data cache. It's off by default, which we didn't realize. The simple patch below to port.c will turn it on.

When it's on, for i in range(n): pass runs 1.6x faster. However, turning it on causes the spi_flash code to loop during CPy start up. If I comment out the filesystem startup code, I can get to the REPL.

So this needs to be added, and then new bugs that crop up will need to be fixed, and we'll need to retest a lot of I/O stuff to find other timing-related bugs.

diff --git a/ports/atmel-samd/supervisor/port.c b/ports/atmel-samd/supervisor/port.c
index 3ac9cbfc9..00ddf2800 100644
--- a/ports/atmel-samd/supervisor/port.c
+++ b/ports/atmel-samd/supervisor/port.c
@@ -90,6 +90,11 @@ safe_mode_t port_init(void) {
     #endif
 #endif
 
+    // Turn on instruction/data cache.
+#ifdef SAMD51
+    hri_cmcc_write_CTRL_reg(CMCC, 1);
+#endif
+

Thanks @WestfW for noticing the equivalent issue for Arduino in adafruit/ArduinoCore-samd#37.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions