summaryrefslogtreecommitdiff
path: root/supervisor
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2020-01-08 20:32:45 -0800
committerScott Shawcroft <scott@tannewt.org>2020-01-17 17:36:08 -0800
commit7d8dac9211dab92d750a0351335b4ad3fffc05e2 (patch)
tree819d63e5495931042b433e2b67eee9848bf47ec1 /supervisor
parent85c731734a0388c28c8e3895ec1cecd1d9491e0c (diff)
Refine iMX RT memory layout and add three boards
Introduces a way to place CircuitPython code and data into tightly coupled memory (TCM) which is accessible by the CPU in a single cycle. It also frees up room in the corresponding cache for intermittent data. Loading from external flash is slow! The data cache is also now enabled. Adds support for the iMX RT 1021 chip. Adds three new boards: * iMX RT 1020 EVK * iMX RT 1060 EVK * Teensy 4.0 Related to #2492, #2472 and #2477. Fixes #2475.
Diffstat (limited to 'supervisor')
-rwxr-xr-xsupervisor/linker.h42
-rw-r--r--supervisor/port.h6
-rw-r--r--supervisor/shared/filesystem.c2
-rwxr-xr-xsupervisor/shared/memory.c7
-rw-r--r--supervisor/shared/safe_mode.c3
-rw-r--r--supervisor/shared/safe_mode.h1
-rwxr-xr-xsupervisor/shared/stack.c7
-rw-r--r--supervisor/shared/tick.c8
8 files changed, 70 insertions, 6 deletions
diff --git a/supervisor/linker.h b/supervisor/linker.h
new file mode 100755
index 000000000..b58414433
--- /dev/null
+++ b/supervisor/linker.h
@@ -0,0 +1,42 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+// These macros are used to place code and data into different linking sections.
+
+#ifndef MICROPY_INCLUDED_SUPERVISOR_LINKER_H
+#define MICROPY_INCLUDED_SUPERVISOR_LINKER_H
+
+#if defined(IMXRT10XX)
+#define PLACE_IN_DTCM_DATA(name) name __attribute__((section(".dtcm_data." #name )))
+#define PLACE_IN_DTCM_BSS(name) name __attribute__((section(".dtcm_bss." #name )))
+#define PLACE_IN_ITCM(name) __attribute__((section(".itcm." #name ))) name
+#else
+#define PLACE_IN_DTCM_DATA(name) name
+#define PLACE_IN_DTCM_BSS(name) name
+#define PLACE_IN_ITCM(name) name
+#endif
+
+#endif // MICROPY_INCLUDED_SUPERVISOR_LINKER_H
diff --git a/supervisor/port.h b/supervisor/port.h
index c8a011978..b289583dd 100644
--- a/supervisor/port.h
+++ b/supervisor/port.h
@@ -60,6 +60,12 @@ uint32_t *port_stack_get_limit(void);
// Get stack top address
uint32_t *port_stack_get_top(void);
+// Get heap bottom address
+uint32_t *port_heap_get_bottom(void);
+
+// Get heap top address
+uint32_t *port_heap_get_top(void);
+
// Save and retrieve a word from memory that is preserved over reset. Used for safe mode.
void port_set_saved_word(uint32_t);
uint32_t port_get_saved_word(void);
diff --git a/supervisor/shared/filesystem.c b/supervisor/shared/filesystem.c
index 92727f6fb..3b799619f 100644
--- a/supervisor/shared/filesystem.c
+++ b/supervisor/shared/filesystem.c
@@ -75,7 +75,7 @@ static void make_sample_code_file(FATFS *fatfs) {
FIL fs;
UINT char_written = 0;
const byte buffer[] = "print('Hello World!')\n";
- //Create or modify existing code.py file
+ //Create or modify existing code.py file
f_open(fatfs, &fs, "/code.py", FA_WRITE | FA_CREATE_ALWAYS);
f_write(&fs, buffer, sizeof(buffer) - 1, &char_written);
f_close(&fs);
diff --git a/supervisor/shared/memory.c b/supervisor/shared/memory.c
index 38040d11d..14c3b4979 100755
--- a/supervisor/shared/memory.c
+++ b/supervisor/shared/memory.c
@@ -39,11 +39,14 @@ uint32_t* low_address;
uint32_t* high_address;
void memory_init(void) {
- low_address = port_stack_get_limit();
- high_address = port_stack_get_top();
+ low_address = port_heap_get_bottom();
+ high_address = port_heap_get_top();
}
void free_memory(supervisor_allocation* allocation) {
+ if (allocation == NULL) {
+ return;
+ }
int32_t index = 0;
bool found = false;
for (index = 0; index < CIRCUITPY_SUPERVISOR_ALLOC_COUNT; index++) {
diff --git a/supervisor/shared/safe_mode.c b/supervisor/shared/safe_mode.c
index aba31e9c9..c957aee53 100644
--- a/supervisor/shared/safe_mode.c
+++ b/supervisor/shared/safe_mode.c
@@ -157,6 +157,9 @@ void print_safe_mode_message(safe_mode_t reason) {
case FLASH_WRITE_FAIL:
serial_write_compressed(translate("Failed to write internal flash."));
break;
+ case MEM_MANAGE:
+ serial_write_compressed(translate("Invalid memory access."));
+ break;
default:
serial_write_compressed(translate("Unknown reason."));
break;
diff --git a/supervisor/shared/safe_mode.h b/supervisor/shared/safe_mode.h
index e05fca0e4..5b09c4b54 100644
--- a/supervisor/shared/safe_mode.h
+++ b/supervisor/shared/safe_mode.h
@@ -40,6 +40,7 @@ typedef enum {
PROGRAMMATIC_SAFE_MODE,
NORDIC_SOFT_DEVICE_ASSERT,
FLASH_WRITE_FAIL,
+ MEM_MANAGE,
} safe_mode_t;
safe_mode_t wait_for_safe_mode_reset(void);
diff --git a/supervisor/shared/stack.c b/supervisor/shared/stack.c
index dcecf2067..2b7b1c03a 100755
--- a/supervisor/shared/stack.c
+++ b/supervisor/shared/stack.c
@@ -46,6 +46,10 @@ void allocate_stack(void) {
mp_uint_t c_size = (uint32_t) port_stack_get_top() - sp;
+ if (port_stack_get_top() != port_heap_get_top()) {
+ return;
+ }
+
stack_alloc = allocate_memory(c_size + next_stack_size + EXCEPTION_STACK_SIZE, true);
if (stack_alloc == NULL) {
stack_alloc = allocate_memory(c_size + CIRCUITPY_DEFAULT_STACK_SIZE + EXCEPTION_STACK_SIZE, true);
@@ -71,6 +75,9 @@ void stack_init(void) {
}
void stack_resize(void) {
+ if (stack_alloc == NULL) {
+ return;
+ }
if (next_stack_size == current_stack_size) {
*stack_alloc->ptr = STACK_CANARY_VALUE;
return;
diff --git a/supervisor/shared/tick.c b/supervisor/shared/tick.c
index 69256081c..5668f8fa1 100644
--- a/supervisor/shared/tick.c
+++ b/supervisor/shared/tick.c
@@ -25,11 +25,13 @@
*/
#include "supervisor/shared/tick.h"
+
+#include "supervisor/linker.h"
#include "supervisor/filesystem.h"
#include "supervisor/shared/autoreload.h"
-static volatile uint64_t ticks_ms;
-static volatile uint32_t background_ticks_ms32;
+static volatile uint64_t PLACE_IN_DTCM_BSS(ticks_ms);
+static volatile uint32_t PLACE_IN_DTCM_BSS(background_ticks_ms32);
#if CIRCUITPY_GAMEPAD
#include "shared-module/gamepad/__init__.h"
@@ -77,7 +79,7 @@ uint32_t supervisor_ticks_ms32() {
extern void run_background_tasks(void);
-void supervisor_run_background_tasks_if_tick() {
+void PLACE_IN_ITCM(supervisor_run_background_tasks_if_tick)() {
uint32_t now32 = ticks_ms;
if (now32 == background_ticks_ms32) {