summaryrefslogtreecommitdiff
path: root/supervisor
diff options
context:
space:
mode:
authorSabas <sabasjimenez@gmail.com>2020-04-09 17:05:11 -0500
committerGitHub <noreply@github.com>2020-04-09 17:05:11 -0500
commitcac4fb0318015f344e191e3077e99ffdce347515 (patch)
treed96c5d7010563f9db3f4e5fb2f981e5bb75c6345 /supervisor
parent2a47623283911c8ebac6152560affc8c419dbddf (diff)
parentb3b8b5ca71dc58415083180d04b407185514c216 (diff)
Merge branch 'master' into nfc_copy
Diffstat (limited to 'supervisor')
-rwxr-xr-xsupervisor/linker.h42
-rw-r--r--supervisor/port.h6
-rw-r--r--supervisor/shared/bluetooth.c13
-rw-r--r--supervisor/shared/board.c49
-rw-r--r--supervisor/shared/board.h38
-rw-r--r--supervisor/shared/external_flash/devices.h54
-rw-r--r--supervisor/shared/external_flash/spi_flash.c32
-rw-r--r--supervisor/shared/filesystem.c6
-rwxr-xr-xsupervisor/shared/memory.c7
-rw-r--r--supervisor/shared/rgb_led_status.c4
-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
-rw-r--r--supervisor/shared/usb/usb_msc_flash.c16
-rw-r--r--supervisor/spi_flash_api.h4
-rw-r--r--supervisor/supervisor.mk1
-rw-r--r--supervisor/usb.h1
18 files changed, 264 insertions, 28 deletions
diff --git a/supervisor/linker.h b/supervisor/linker.h
new file mode 100755
index 000000000..d68be2437
--- /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) || defined(FOMU)
+#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/bluetooth.c b/supervisor/shared/bluetooth.c
index 18caa2eb4..b463160cf 100644
--- a/supervisor/shared/bluetooth.c
+++ b/supervisor/shared/bluetooth.c
@@ -64,6 +64,9 @@ mp_obj_list_t characteristic_list;
mp_obj_t characteristic_list_items[4];
void supervisor_bluetooth_start_advertising(void) {
+ #if !CIRCUITPY_BLE_FILE_SERVICE
+ return;
+ #endif
bool is_connected = common_hal_bleio_adapter_get_connected(&common_hal_bleio_adapter_obj);
if (is_connected) {
return;
@@ -79,6 +82,10 @@ void supervisor_bluetooth_start_advertising(void) {
}
void supervisor_start_bluetooth(void) {
+ #if !CIRCUITPY_BLE_FILE_SERVICE
+ return;
+ #endif
+
common_hal_bleio_adapter_set_enabled(&common_hal_bleio_adapter_obj, true);
supervisor_ble_service_uuid.base.type = &bleio_uuid_type;
@@ -203,6 +210,9 @@ uint32_t current_command[1024 / sizeof(uint32_t)];
volatile size_t current_offset;
void supervisor_bluetooth_background(void) {
+ #if !CIRCUITPY_BLE_FILE_SERVICE
+ return;
+ #endif
if (!run_ble_background) {
return;
}
@@ -296,6 +306,9 @@ void supervisor_bluetooth_background(void) {
// This happens in an interrupt so we need to be quick.
bool supervisor_bluetooth_hook(ble_evt_t *ble_evt) {
+ #if !CIRCUITPY_BLE_FILE_SERVICE
+ return false;
+ #endif
// Catch writes to filename or contents. Length is read-only.
bool done = false;
diff --git a/supervisor/shared/board.c b/supervisor/shared/board.c
new file mode 100644
index 000000000..e3eb8fd0d
--- /dev/null
+++ b/supervisor/shared/board.c
@@ -0,0 +1,49 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2020 Dan Halbert 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.
+ */
+
+#include "supervisor/shared/board.h"
+
+#include "shared-bindings/digitalio/DigitalInOut.h"
+#include "shared-bindings/neopixel_write/__init__.h"
+
+#ifdef USER_NEOPIXELS_PIN
+
+// The maximum number of user neopixels right now is 10, on Circuit Playgrounds.
+// PyBadge and PyGamer have max 5
+#define USER_NEOPIXELS_MAX_COUNT 10
+
+void board_reset_user_neopixels(void) {
+ // Turn off on-board NeoPixel string
+ uint8_t empty[USER_NEOPIXELS_MAX_COUNT * 3] = { 0 };
+ digitalio_digitalinout_obj_t neopixel_pin;
+ common_hal_digitalio_digitalinout_construct(&neopixel_pin, USER_NEOPIXELS_PIN);
+ common_hal_digitalio_digitalinout_switch_to_output(&neopixel_pin, false,
+ DRIVE_MODE_PUSH_PULL);
+ common_hal_neopixel_write(&neopixel_pin, empty, USER_NEOPIXELS_MAX_COUNT * 3);
+ common_hal_digitalio_digitalinout_deinit(&neopixel_pin);
+}
+
+#endif
diff --git a/supervisor/shared/board.h b/supervisor/shared/board.h
new file mode 100644
index 000000000..0e4d73455
--- /dev/null
+++ b/supervisor/shared/board.h
@@ -0,0 +1,38 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2020 Dan Halbert 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.
+ */
+
+#ifndef MICROPY_INCLUDED_SUPERVISOR_BOARD_H
+#define MICROPY_INCLUDED_SUPERVISOR_BOARD_H
+
+#include "py/mpconfig.h"
+
+#ifdef USER_NEOPIXELS_PIN
+
+void board_reset_user_neopixels(void);
+
+#endif
+
+#endif // MICROPY_INCLUDED_SUPERVISOR_BOARD_H
diff --git a/supervisor/shared/external_flash/devices.h b/supervisor/shared/external_flash/devices.h
index 08d0a78fd..fd9224f56 100644
--- a/supervisor/shared/external_flash/devices.h
+++ b/supervisor/shared/external_flash/devices.h
@@ -105,6 +105,25 @@ typedef struct {
.single_status_byte = false, \
}
+// Settings for the Adesto Tech AT25SF041 1MiB SPI flash. It's on the SparkFun
+// SAMD51 Thing Plus board
+// Datasheet: https://www.adestotech.com/wp-content/uploads/DS-AT25SF041_044.pdf
+#define AT25SF041A {\
+ .total_size = (1 << 19), /* 512 KiB */ \
+ .start_up_time_us = 10000, \
+ .manufacturer_id = 0x1f, \
+ .memory_type = 0x84, \
+ .capacity = 0x01, \
+ .max_clock_speed_mhz = 85, \
+ .quad_enable_bit_mask = 0x00, \
+ .has_sector_protection = false, \
+ .supports_fast_read = true, \
+ .supports_qspi = false, \
+ .supports_qspi_writes = false, \
+ .write_status_register_split = false, \
+ .single_status_byte = false, \
+}
+
// Settings for the Gigadevice GD25Q16C 2MiB SPI flash.
// Datasheet: http://www.gigadevice.com/datasheet/gd25q16c/
#define GD25Q16C {\
@@ -371,6 +390,23 @@ typedef struct {
.single_status_byte = false, \
}
+// Settings for the Winbond W25Q80DV 1MiB SPI flash.. Note that W25Q80DL has a different memory type (0x60)
+// Datasheet: https://www.winbond.com/resource-files/w25q80dv%20dl_revh_10022015.pdf
+#define W25Q80DV {\
+ .total_size = (1 << 20), /* 1 MiB */ \
+ .start_up_time_us = 5000, \
+ .manufacturer_id = 0xef, \
+ .memory_type = 0x40, \
+ .capacity = 0x14, \
+ .max_clock_speed_mhz = 104, \
+ .quad_enable_bit_mask = 0x02, \
+ .has_sector_protection = false, \
+ .supports_fast_read = true, \
+ .supports_qspi = true, \
+ .supports_qspi_writes = false, \
+ .write_status_register_split = false, \
+ .single_status_byte = false, \
+}
// Settings for the Winbond W25Q128JV-SQ 16MiB SPI flash. Note that JV-IM has a different .memory_type (0x70)
// Datasheet: https://www.winbond.com/resource-files/w25q128jv%20revf%2003272018%20plus.pdf
@@ -445,6 +481,24 @@ typedef struct {
.single_status_byte = true, \
}
+// Settings for the Macronix MX25L51245G 64MiB SPI flash.
+// Datasheet: https://www.macronix.com/Lists/Datasheet/Attachments/7437/MX25L51245G,%203V,%20512Mb,%20v1.6.pdf
+#define MX25L51245G {\
+ .total_size = (1 << 26), /* 64 MiB */ \
+ .start_up_time_us = 5000, \
+ .manufacturer_id = 0xc2, \
+ .memory_type = 0x20, \
+ .capacity = 0x1a, \
+ .max_clock_speed_mhz = 133, \
+ .quad_enable_bit_mask = 0x40, \
+ .has_sector_protection = false, \
+ .supports_fast_read = true, \
+ .supports_qspi = true, \
+ .supports_qspi_writes = true, \
+ .write_status_register_split = false, \
+ .single_status_byte = true, \
+}
+
// Settings for the Winbond W25Q128JV-PM 16MiB SPI flash. Note that JV-IM has a different .memory_type (0x70)
// Datasheet: https://www.winbond.com/resource-files/w25q128jv%20revf%2003272018%20plus.pdf
#define W25Q128JV_PM {\
diff --git a/supervisor/shared/external_flash/spi_flash.c b/supervisor/shared/external_flash/spi_flash.c
index 12888f2d3..67e64c970 100644
--- a/supervisor/shared/external_flash/spi_flash.c
+++ b/supervisor/shared/external_flash/spi_flash.c
@@ -36,33 +36,33 @@
#include "py/mpconfig.h"
digitalio_digitalinout_obj_t cs_pin;
-busio_spi_obj_t spi;
+busio_spi_obj_t supervisor_flash_spi_bus;
const external_flash_device* flash_device;
uint32_t spi_flash_baudrate;
// Enable the flash over SPI.
static void flash_enable(void) {
- while (!common_hal_busio_spi_try_lock(&spi)) {}
+ while (!common_hal_busio_spi_try_lock(&supervisor_flash_spi_bus)) {}
common_hal_digitalio_digitalinout_set_value(&cs_pin, false);
}
// Disable the flash over SPI.
static void flash_disable(void) {
common_hal_digitalio_digitalinout_set_value(&cs_pin, true);
- common_hal_busio_spi_unlock(&spi);
+ common_hal_busio_spi_unlock(&supervisor_flash_spi_bus);
}
static bool transfer(uint8_t* command, uint32_t command_length, uint8_t* data_in, uint8_t* data_out, uint32_t data_length) {
flash_enable();
- bool status = common_hal_busio_spi_write(&spi, command, command_length);
+ bool status = common_hal_busio_spi_write(&supervisor_flash_spi_bus, command, command_length);
if (status) {
if (data_in != NULL && data_out != NULL) {
- status = common_hal_busio_spi_transfer(&spi, data_out, data_in, data_length);
+ status = common_hal_busio_spi_transfer(&supervisor_flash_spi_bus, data_out, data_in, data_length);
} else if (data_out != NULL) {
- status = common_hal_busio_spi_read(&spi, data_out, data_length, 0xff);
+ status = common_hal_busio_spi_read(&supervisor_flash_spi_bus, data_out, data_length, 0xff);
} else if (data_in != NULL) {
- status = common_hal_busio_spi_write(&spi, data_in, data_length);
+ status = common_hal_busio_spi_write(&supervisor_flash_spi_bus, data_in, data_length);
}
}
flash_disable();
@@ -103,10 +103,10 @@ bool spi_flash_write_data(uint32_t address, uint8_t* data, uint32_t data_length)
// Write the SPI flash write address into the bytes following the command byte.
address_to_bytes(address, request + 1);
flash_enable();
- common_hal_busio_spi_configure(&spi, spi_flash_baudrate, 0, 0, 8);
- bool status = common_hal_busio_spi_write(&spi, request, 4);
+ common_hal_busio_spi_configure(&supervisor_flash_spi_bus, spi_flash_baudrate, 0, 0, 8);
+ bool status = common_hal_busio_spi_write(&supervisor_flash_spi_bus, request, 4);
if (status) {
- status = common_hal_busio_spi_write(&spi, data, data_length);
+ status = common_hal_busio_spi_write(&supervisor_flash_spi_bus, data, data_length);
}
flash_disable();
return status;
@@ -122,10 +122,10 @@ bool spi_flash_read_data(uint32_t address, uint8_t* data, uint32_t data_length)
// Write the SPI flash write address into the bytes following the command byte.
address_to_bytes(address, request + 1);
flash_enable();
- common_hal_busio_spi_configure(&spi, spi_flash_baudrate, 0, 0, 8);
- bool status = common_hal_busio_spi_write(&spi, request, command_length);
+ common_hal_busio_spi_configure(&supervisor_flash_spi_bus, spi_flash_baudrate, 0, 0, 8);
+ bool status = common_hal_busio_spi_write(&supervisor_flash_spi_bus, request, command_length);
if (status) {
- status = common_hal_busio_spi_read(&spi, data, data_length, 0xff);
+ status = common_hal_busio_spi_read(&supervisor_flash_spi_bus, data, data_length, 0xff);
}
flash_disable();
return status;
@@ -140,9 +140,9 @@ void spi_flash_init(void) {
common_hal_digitalio_digitalinout_switch_to_output(&cs_pin, true, DRIVE_MODE_PUSH_PULL);
common_hal_digitalio_digitalinout_never_reset(&cs_pin);
- spi.base.type = &busio_spi_type;
- common_hal_busio_spi_construct(&spi, SPI_FLASH_SCK_PIN, SPI_FLASH_MOSI_PIN, SPI_FLASH_MISO_PIN);
- common_hal_busio_spi_never_reset(&spi);
+ supervisor_flash_spi_bus.base.type = &busio_spi_type;
+ common_hal_busio_spi_construct(&supervisor_flash_spi_bus, SPI_FLASH_SCK_PIN, SPI_FLASH_MOSI_PIN, SPI_FLASH_MISO_PIN);
+ common_hal_busio_spi_never_reset(&supervisor_flash_spi_bus);
}
void spi_flash_init_device(const external_flash_device* device) {
diff --git a/supervisor/shared/filesystem.c b/supervisor/shared/filesystem.c
index 92727f6fb..f6b94e38b 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);
@@ -104,7 +104,11 @@ void filesystem_init(bool create_allowed, bool force_create) {
}
// set label
+#ifdef CIRCUITPY_DRIVE_LABEL
+ f_setlabel(&vfs_fat->fatfs, CIRCUITPY_DRIVE_LABEL);
+#else
f_setlabel(&vfs_fat->fatfs, "CIRCUITPY");
+#endif
// inhibit file indexing on MacOS
f_mkdir(&vfs_fat->fatfs, "/.fseventsd");
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/rgb_led_status.c b/supervisor/shared/rgb_led_status.c
index f751a7ffd..f3c210647 100644
--- a/supervisor/shared/rgb_led_status.c
+++ b/supervisor/shared/rgb_led_status.c
@@ -115,7 +115,7 @@ void rgb_led_status_init() {
shared_module_bitbangio_spi_construct(&status_apa102,
MICROPY_HW_APA102_SCK,
MICROPY_HW_APA102_MOSI,
- mp_const_none);
+ NULL);
#else
if (!common_hal_busio_spi_deinited(&status_apa102)) {
// This may call us recursively if common_hal_reset_pin() is called,
@@ -125,7 +125,7 @@ void rgb_led_status_init() {
common_hal_busio_spi_construct(&status_apa102,
MICROPY_HW_APA102_SCK,
MICROPY_HW_APA102_MOSI,
- mp_const_none);
+ NULL);
common_hal_busio_spi_never_reset(&status_apa102);
#endif
// Pretend we aren't using the pins. bitbangio.SPI will
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) {
diff --git a/supervisor/shared/usb/usb_msc_flash.c b/supervisor/shared/usb/usb_msc_flash.c
index 0376cfc1d..7532b6aea 100644
--- a/supervisor/shared/usb/usb_msc_flash.c
+++ b/supervisor/shared/usb/usb_msc_flash.c
@@ -39,7 +39,7 @@
#define MSC_FLASH_BLOCK_SIZE 512
-static bool ejected[1];
+static bool ejected[1] = {true};
void usb_msc_mount(void) {
// Reset the ejection tracking every time we're plugged into USB. This allows for us to battery
@@ -53,6 +53,14 @@ void usb_msc_umount(void) {
}
+bool usb_msc_ejected(void) {
+ bool all_ejected = true;
+ for (uint8_t i = 0; i < sizeof(ejected); i++) {
+ all_ejected &= ejected[i];
+ }
+ return all_ejected;
+}
+
// The root FS is always at the end of the list.
static fs_user_mount_t* get_vfs(int lun) {
// TODO(tannewt): Return the mount which matches the lun where 0 is the end
@@ -200,6 +208,8 @@ bool tud_msc_test_unit_ready_cb(uint8_t lun) {
return false;
}
if (ejected[lun]) {
+ // Set 0x3a for media not present.
+ tud_msc_set_sense(lun, SCSI_SENSE_NOT_READY, 0x3A, 0x00);
return false;
}
@@ -235,10 +245,8 @@ bool tud_msc_start_stop_cb(uint8_t lun, uint8_t power_condition, bool start, boo
if (disk_ioctl(current_mount, CTRL_SYNC, NULL) != RES_OK) {
return false;
}
- } else {
- // Start the unit, but only if not ejected.
- return !ejected[lun];
}
+ // Always start the unit, even if ejected. Whether media is present is a separate check.
}
return true;
diff --git a/supervisor/spi_flash_api.h b/supervisor/spi_flash_api.h
index 28cccb1b1..f59346e25 100644
--- a/supervisor/spi_flash_api.h
+++ b/supervisor/spi_flash_api.h
@@ -31,6 +31,10 @@
#include "supervisor/shared/external_flash/devices.h"
+#include "shared-bindings/busio/SPI.h"
+
+extern busio_spi_obj_t supervisor_flash_spi_bus; //Used to share SPI bus on some boards
+
// This API is implemented for both normal SPI peripherals and QSPI peripherals.
bool spi_flash_command(uint8_t command);
diff --git a/supervisor/supervisor.mk b/supervisor/supervisor.mk
index 96a14c25b..52d60b52b 100644
--- a/supervisor/supervisor.mk
+++ b/supervisor/supervisor.mk
@@ -2,6 +2,7 @@ SRC_SUPERVISOR = \
main.c \
supervisor/port.c \
supervisor/shared/autoreload.c \
+ supervisor/shared/board.c \
supervisor/shared/display.c \
supervisor/shared/filesystem.c \
supervisor/shared/flash.c \
diff --git a/supervisor/usb.h b/supervisor/usb.h
index 0cc361619..29280c725 100644
--- a/supervisor/usb.h
+++ b/supervisor/usb.h
@@ -44,5 +44,6 @@ void usb_init(void);
// Propagate plug/unplug events to the MSC logic.
void usb_msc_mount(void);
void usb_msc_umount(void);
+bool usb_msc_ejected(void);
#endif // MICROPY_INCLUDED_SUPERVISOR_USB_H