summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2017-10-10 11:36:00 -0700
committerDan Halbert <halbert@halwitz.org>2017-10-10 14:36:00 -0400
commit80654779e1ad98f5818186746e00b6b642dca3db (patch)
tree7b33b6b86f093751567a21f2ca0098e2b6f14901
parent9a9584aee0d3ca48fa5641f736c0c043df0505ff (diff)
atmel-samd: Add support for internal filesystems. (#311)
* atmel-samd: Add support for internal filesystems. This allows us to re-enable `os`. `random` is also enabled because it solely depends on `os`. Fixes #266. Its also a pre-requisite for #260. * atmel-samd: Update SAMD51 linker script comments and MICROPY_MAX_STACK_USAGE enabling.
-rw-r--r--atmel-samd/Makefile26
-rw-r--r--atmel-samd/asf4/patches/samd21/cast-align.patch24
-rw-r--r--atmel-samd/asf4/patches/samd21/flash-const.patch61
-rw-r--r--atmel-samd/asf4/patches/samd51/array-bounds.patch13
-rw-r--r--atmel-samd/asf4/patches/samd51/cast-align.patch37
-rw-r--r--atmel-samd/asf4/patches/samd51/flash-const.patch63
-rw-r--r--atmel-samd/asf4/samd21/hal/include/hal_flash.h2
-rw-r--r--atmel-samd/asf4/samd21/hal/include/hpl_flash.h4
-rw-r--r--atmel-samd/asf4/samd21/hal/src/hal_flash.c8
-rw-r--r--atmel-samd/asf4/samd21/hpl/nvmctrl/hpl_nvmctrl.c4
-rw-r--r--atmel-samd/asf4/samd51/CMSIS/Include/core_cm4.h4
-rw-r--r--atmel-samd/asf4/samd51/hal/include/hal_flash.h2
-rw-r--r--atmel-samd/asf4/samd51/hal/include/hpl_flash.h4
-rw-r--r--atmel-samd/asf4/samd51/hal/src/hal_flash.c8
-rw-r--r--atmel-samd/asf4/samd51/hpl/nvmctrl/hpl_nvmctrl.c7
-rw-r--r--atmel-samd/asf4_conf/samd21/hpl_nvmctrl_config.h38
-rw-r--r--atmel-samd/asf4_conf/samd51/hpl_nvmctrl_config.h36
-rw-r--r--atmel-samd/asf4_conf/samd51/hpl_trng_config.h27
-rw-r--r--atmel-samd/boards/circuitplayground_express/mpconfigboard.h3
-rw-r--r--atmel-samd/boards/circuitplayground_express/mpconfigboard.mk5
-rw-r--r--atmel-samd/boards/feather_m0_express/mpconfigboard.h3
-rw-r--r--atmel-samd/boards/feather_m0_express/mpconfigboard.mk5
-rw-r--r--atmel-samd/boards/metro_m0_express/mpconfigboard.h3
-rw-r--r--atmel-samd/boards/metro_m0_express/mpconfigboard.mk5
-rw-r--r--atmel-samd/boards/metro_m4_express/mpconfigboard.mk5
-rw-r--r--atmel-samd/boards/samd51x18-bootloader-external-flash.ld2
-rw-r--r--atmel-samd/boards/samd51x19-bootloader-external-flash.ld2
-rw-r--r--atmel-samd/boards/samd51x20-bootloader-external-flash.ld2
-rw-r--r--atmel-samd/boards/samd51x20-external-flash.ld2
-rw-r--r--atmel-samd/boards/samd51x20.ld81
-rw-r--r--atmel-samd/common-hal/os/__init__.c24
-rw-r--r--atmel-samd/internal_flash.c63
-rw-r--r--atmel-samd/internal_flash.h10
-rw-r--r--atmel-samd/mpconfigport.h12
-rw-r--r--atmel-samd/supervisor/filesystem.c83
-rw-r--r--atmel-samd/usb.c1
-rw-r--r--supervisor/supervisor.mk2
37 files changed, 567 insertions, 114 deletions
diff --git a/atmel-samd/Makefile b/atmel-samd/Makefile
index 49bd08722..2c51342d5 100644
--- a/atmel-samd/Makefile
+++ b/atmel-samd/Makefile
@@ -79,18 +79,25 @@ BASE_CFLAGS = \
-fshort-enums \
--param max-inline-insns-single=500
+# NDEBUG disables assert() statements. This reduces code size pretty dramatically, per tannewt.
+ifeq ($(CHIP_FAMILY), samd21)
+CFLAGS = -Os -DNDEBUG -finline-limit=49
+endif
+ifeq ($(CHIP_FAMILY), samd51)
+CFLAGS = -O2 -DNDEBUG
+endif
+
#Debugging/Optimization
ifeq ($(DEBUG), 1)
-# NDEBUG disables assert() statements. This reduces code size pretty dramatically, per tannewt.
# Turn on Python modules useful for debugging (e.g. uheap, ustack).
-CFLAGS = -O1 -ggdb -DNDEBUG
+CFLAGS += -ggdb
ifeq ($(CHIP_FAMILY), samd21)
-CFLAGS += -DENABLE_MICRO_TRACE_BUFFER
+CFLAGS += -DNDEBUG -DENABLE_MICRO_TRACE_BUFFER
endif
else
# -finline-limit can shrink the image size. -finline-limit=80 or so is similar to not having it on.
# There is no simple default value, though.
-CFLAGS = -Os -DNDEBUG -flto -finline-limit=49
+CFLAGS += -DNDEBUG -flto -finline-limit=49
endif
CFLAGS += $(INC) -Wall -Werror -std=gnu11 -nostdlib $(BASE_CFLAGS) $(CFLAGS_MOD) $(COPT)
@@ -109,8 +116,9 @@ CFLAGS += \
-mthumb \
-mabi=aapcs-linux \
-mlong-calls \
+ -mtune=cortex-m4 \
-mcpu=cortex-m4 \
- -mfloat-abi=softfp \
+ -mfloat-abi=hard \
-mfpu=fpv4-sp-d16 \
-DSAMD51
endif
@@ -150,11 +158,13 @@ SRC_ASF := \
gcc/system_$(CHIP_FAMILY).c \
hal/src/hal_atomic.c \
hal/src/hal_delay.c \
+ hal/src/hal_flash.c \
hal/src/hal_sleep.c \
hal/src/hal_timer.c \
hal/src/hal_usb_device.c \
hpl/core/hpl_init.c \
hpl/gclk/hpl_gclk.c \
+ hpl/nvmctrl/hpl_nvmctrl.c \
hpl/pm/hpl_pm.c \
hpl/rtc/hpl_rtc.c \
hpl/systick/hpl_systick.c \
@@ -172,10 +182,12 @@ SRC_ASF += \
else ifeq ($(CHIP_FAMILY), samd51)
SRC_ASF += \
+ hal/src/hal_rand_sync.c \
hpl/core/hpl_core_m4.c \
hpl/mclk/hpl_mclk.c \
hpl/osc32kctrl/hpl_osc32kctrl.c \
hpl/oscctrl/hpl_oscctrl.c \
+ hpl/trng/hpl_trng.c \
endif
@@ -184,7 +196,6 @@ SRC_ASF := $(addprefix asf4/$(CHIP_FAMILY)/, $(SRC_ASF))
# Skip this source for now.
# access_vfs.c \
shared_dma.c \
- $(FLASH_IMPL) \
SRC_C = \
background.c \
@@ -195,6 +206,7 @@ SRC_C = \
$(CHIP_FAMILY)_pins.c \
tick.c \
usb.c \
+ $(FLASH_IMPL) \
bindings/samd/__init__.c \
boards/$(BOARD)/board.c \
boards/$(BOARD)/pins.c \
@@ -218,6 +230,7 @@ SRC_COMMON_HAL = \
microcontroller/__init__.c \
microcontroller/Pin.c \
microcontroller/Processor.c \
+ os/__init__.c \
time/__init__.c
# analogio/__init__.c \
analogio/AnalogIn.c \
@@ -233,7 +246,6 @@ SRC_COMMON_HAL = \
neopixel_write/__init__.c \
nvm/__init__.c \
nvm/ByteArray.c \
- os/__init__.c \
pulseio/__init__.c \
pulseio/PulseIn.c \
pulseio/PulseOut.c \
diff --git a/atmel-samd/asf4/patches/samd21/cast-align.patch b/atmel-samd/asf4/patches/samd21/cast-align.patch
index 04ddf9bf5..2059867e4 100644
--- a/atmel-samd/asf4/patches/samd21/cast-align.patch
+++ b/atmel-samd/asf4/patches/samd21/cast-align.patch
@@ -10,3 +10,27 @@
+ #pragma GCC diagnostic pop
struct timer_task * it = (struct timer_task *)list_get_head(&timer->tasks);
uint32_t time = ++timer->time;
+--- a/hal/src/hal_flash.c
++++ b/hal/src/hal_flash.c
+@@ -304,7 +304,10 @@ static int32_t flash_is_address_aligned(struct flash_descriptor *flash, const ui
+ */
+ static void flash_ready(struct _flash_device *device)
+ {
++ #pragma GCC diagnostic push
++ #pragma GCC diagnostic ignored "-Wcast-align"
+ struct flash_descriptor *const descr = CONTAINER_OF(device, struct flash_descriptor, dev);
++ #pragma GCC diagnostic pop
+ if (descr->callbacks.cb_ready) {
+ descr->callbacks.cb_ready(descr);
+ }
+@@ -317,7 +320,10 @@ static void flash_ready(struct _flash_device *device)
+ */
+ static void flash_error(struct _flash_device *device)
+ {
++ #pragma GCC diagnostic push
++ #pragma GCC diagnostic ignored "-Wcast-align"
+ struct flash_descriptor *const descr = CONTAINER_OF(device, struct flash_descriptor, dev);
++ #pragma GCC diagnostic pop
+ if (descr->callbacks.cb_error) {
+ descr->callbacks.cb_error(descr);
+ }
diff --git a/atmel-samd/asf4/patches/samd21/flash-const.patch b/atmel-samd/asf4/patches/samd21/flash-const.patch
new file mode 100644
index 000000000..cac428ab3
--- /dev/null
+++ b/atmel-samd/asf4/patches/samd21/flash-const.patch
@@ -0,0 +1,61 @@
+--- a/hal/include/hal_flash.h
++++ b/hal/include/hal_flash.h
+@@ -132,7 +132,7 @@ int32_t flash_write(struct flash_descriptor *flash, uint32_t dst_addr, uint8_t *
+ * \param[in] length Number of bytes to append
+ * \return Append status.
+ */
+-int32_t flash_append(struct flash_descriptor *flash, uint32_t dst_addr, uint8_t *buffer, uint32_t length);
++int32_t flash_append(struct flash_descriptor *flash, uint32_t dst_addr, const uint8_t *buffer, uint32_t length);
+
+ /** \brief Reads a number of bytes to a page in the internal Flash
+ *
+--- a/hal/include/hpl_flash.h
++++ b/hal/include/hpl_flash.h
+@@ -125,7 +125,7 @@ void _flash_read(struct _flash_device *const device, const uint32_t src_addr, ui
+ * write is stored
+ * \param[in] length Number of bytes to write
+ */
+-void _flash_write(struct _flash_device *const device, const uint32_t dst_addr, uint8_t *buffer, uint32_t length);
++void _flash_write(struct _flash_device *const device, const uint32_t dst_addr, const uint8_t *buffer, uint32_t length);
+
+ /**
+ * \brief Appends a number of bytes in the internal Flash.
+@@ -135,7 +135,7 @@ void _flash_write(struct _flash_device *const device, const uint32_t dst_addr, u
+ * \param[in] buffer Pointer to buffer with data to write to flash
+ * \param[in] length Number of bytes to write
+ */
+-void _flash_append(struct _flash_device *const device, const uint32_t dst_addr, uint8_t *buffer, uint32_t length);
++void _flash_append(struct _flash_device *const device, const uint32_t dst_addr, const uint8_t *buffer, uint32_t length);
+
+ /** \brief Execute lock in the internal flash
+ * \param[in] device The pointer to FLASH device instance
+--- a/hal/src/hal_flash.c
++++ b/hal/src/hal_flash.c
+@@ -135,7 +135,7 @@ int32_t flash_write(struct flash_descriptor *flash, uint32_t dst_addr, uint8_t *
+ /**
+ * \brief Appends a number of bytes to a page in the internal Flash
+ */
+-int32_t flash_append(struct flash_descriptor *flash, uint32_t dst_addr, uint8_t *buffer, uint32_t length)
++int32_t flash_append(struct flash_descriptor *flash, uint32_t dst_addr, const uint8_t *buffer, uint32_t length)
+ {
+ ASSERT(flash && buffer && length);
+--- a/hpl/nvmctrl/hpl_nvmctrl.c
++++ b/hpl/nvmctrl/hpl_nvmctrl.c
+@@ -175,7 +175,7 @@ void _flash_read(struct _flash_device *const device, const uint32_t src_addr, ui
+ /**
+ * \brief Writes a number of bytes to a page in the internal Flash.
+ */
+-void _flash_write(struct _flash_device *const device, const uint32_t dst_addr, uint8_t *buffer, uint32_t length)
++void _flash_write(struct _flash_device *const device, const uint32_t dst_addr, const uint8_t *buffer, uint32_t length)
+ {
+ uint8_t tmp_buffer[NVMCTRL_ROW_PAGES][NVMCTRL_PAGE_SIZE];
+ uint32_t row_start_addr, row_end_addr;
+@@ -219,7 +219,7 @@ void _flash_write(struct _flash_device *const device, const uint32_t dst_addr, u
+ /**
+ * \brief Appends a number of bytes in the internal Flash.
+ */
+-void _flash_append(struct _flash_device *const device, const uint32_t dst_addr, uint8_t *buffer, uint32_t length)
++void _flash_append(struct _flash_device *const device, const uint32_t dst_addr, const uint8_t *buffer, uint32_t length)
+ {
+ uint32_t page_start_addr = dst_addr & ~(NVMCTRL_PAGE_SIZE - 1);
+ uint32_t size;
diff --git a/atmel-samd/asf4/patches/samd51/array-bounds.patch b/atmel-samd/asf4/patches/samd51/array-bounds.patch
new file mode 100644
index 000000000..30f40cb79
--- /dev/null
+++ b/atmel-samd/asf4/patches/samd51/array-bounds.patch
@@ -0,0 +1,13 @@
+--- a/CMSIS/Include/core_cm4.h
++++ b/CMSIS/Include/core_cm4.h
+@@ -1493,8 +1493,12 @@ __STATIC_INLINE uint32_t NVIC_GetPriorityGrouping(void)
+ */
+ __STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
+ {
++
++ #pragma GCC diagnostic push
++ #pragma GCC diagnostic ignored "-Warray-bounds"
+ /* NVIC->ISER[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); enable interrupt */
+ NVIC->ISER[(uint32_t)((int32_t)IRQn) >> 5] = (uint32_t)(1 << ((uint32_t)((int32_t)IRQn) & (uint32_t)0x1F)); /* enable interrupt */
++ #pragma GCC diagnostic pop
+ }
diff --git a/atmel-samd/asf4/patches/samd51/cast-align.patch b/atmel-samd/asf4/patches/samd51/cast-align.patch
index 1418c9fb1..399c1ff80 100644
--- a/atmel-samd/asf4/patches/samd51/cast-align.patch
+++ b/atmel-samd/asf4/patches/samd51/cast-align.patch
@@ -10,3 +10,40 @@
+ #pragma GCC diagnostic pop
struct timer_task * it = (struct timer_task *)list_get_head(&timer->tasks);
uint32_t time = ++timer->time;
+
+--- a/hal/src/hal_flash.c
++++ b/hal/src/hal_flash.c
+@@ -304,7 +304,10 @@ static int32_t flash_is_address_aligned(struct flash_descriptor *flash, const ui
+ */
+ static void flash_ready(struct _flash_device *device)
+ {
++ #pragma GCC diagnostic push
++ #pragma GCC diagnostic ignored "-Wcast-align"
+ struct flash_descriptor *const descr = CONTAINER_OF(device, struct flash_descriptor, dev);
++ #pragma GCC diagnostic pop
+ if (descr->callbacks.cb_ready) {
+ descr->callbacks.cb_ready(descr);
+ }
+@@ -317,7 +320,10 @@ static void flash_ready(struct _flash_device *device)
+ */
+ static void flash_error(struct _flash_device *device)
+ {
++ #pragma GCC diagnostic push
++ #pragma GCC diagnostic ignored "-Wcast-align"
+ struct flash_descriptor *const descr = CONTAINER_OF(device, struct flash_descriptor, dev);
++ #pragma GCC diagnostic pop
+ if (descr->callbacks.cb_error) {
+ descr->callbacks.cb_error(descr);
+ }
+--- a/hpl/nvmctrl/hpl_nvmctrl.c
++++ b/hpl/nvmctrl/hpl_nvmctrl.c
+@@ -386,7 +386,10 @@ static void _flash_erase_block(void *const hw, const uint32_t dst_addr)
+ */
+ static void _flash_program(void *const hw, const uint32_t dst_addr, const uint8_t *buffer, const uint16_t size)
+ {
++ #pragma GCC diagnostic push
++ #pragma GCC diagnostic ignored "-Wcast-align"
+ uint32_t *ptr_read = (uint32_t *)buffer;
++ #pragma GCC diagnostic pop
+ uint32_t nvm_address = dst_addr / 4;
+ uint16_t i;
diff --git a/atmel-samd/asf4/patches/samd51/flash-const.patch b/atmel-samd/asf4/patches/samd51/flash-const.patch
new file mode 100644
index 000000000..087581ff0
--- /dev/null
+++ b/atmel-samd/asf4/patches/samd51/flash-const.patch
@@ -0,0 +1,63 @@
+--- a/hal/include/hal_flash.h
++++ b/hal/include/hal_flash.h
+@@ -132,7 +132,7 @@ int32_t flash_write(struct flash_descriptor *flash, uint32_t dst_addr, uint8_t *
+ * \param[in] length Number of bytes to append
+ * \return Append status.
+ */
+-int32_t flash_append(struct flash_descriptor *flash, uint32_t dst_addr, uint8_t *buffer, uint32_t length);
++int32_t flash_append(struct flash_descriptor *flash, uint32_t dst_addr, const uint8_t *buffer, uint32_t length);
+
+ /** \brief Reads a number of bytes to a page in the internal Flash
+ *
+--- a/hal/include/hpl_flash.h
++++ b/hal/include/hpl_flash.h
+@@ -125,7 +125,7 @@ void _flash_read(struct _flash_device *const device, const uint32_t src_addr, ui
+ * write is stored
+ * \param[in] length Number of bytes to write
+ */
+-void _flash_write(struct _flash_device *const device, const uint32_t dst_addr, uint8_t *buffer, uint32_t length);
++void _flash_write(struct _flash_device *const device, const uint32_t dst_addr, const uint8_t *buffer, uint32_t length);
+
+ /**
+ * \brief Appends a number of bytes in the internal Flash.
+@@ -135,7 +135,7 @@ void _flash_write(struct _flash_device *const device, const uint32_t dst_addr, u
+ * \param[in] buffer Pointer to buffer with data to write to flash
+ * \param[in] length Number of bytes to write
+ */
+-void _flash_append(struct _flash_device *const device, const uint32_t dst_addr, uint8_t *buffer, uint32_t length);
++void _flash_append(struct _flash_device *const device, const uint32_t dst_addr, const uint8_t *buffer, uint32_t length);
+
+ /** \brief Execute lock in the internal flash
+ * \param[in] device The pointer to FLASH device instance
+
+--- a/hal/src/hal_flash.c
++++ b/hal/src/hal_flash.c
+@@ -135,7 +135,7 @@ int32_t flash_write(struct flash_descriptor *flash, uint32_t dst_addr, uint8_t *
+ /**
+ * \brief Appends a number of bytes to a page in the internal Flash
+ */
+-int32_t flash_append(struct flash_descriptor *flash, uint32_t dst_addr, uint8_t *buffer, uint32_t length)
++int32_t flash_append(struct flash_descriptor *flash, uint32_t dst_addr, const uint8_t *buffer, uint32_t length)
+ {
+ ASSERT(flash && buffer && length);
+
+--- a/hpl/nvmctrl/hpl_nvmctrl.c
++++ b/hpl/nvmctrl/hpl_nvmctrl.c
+@@ -167,7 +167,7 @@ void _flash_read(struct _flash_device *const device, const uint32_t src_addr, ui
+ /**
+ * \brief Writes a number of bytes to a page in the internal Flash.
+ */
+-void _flash_write(struct _flash_device *const device, const uint32_t dst_addr, uint8_t *buffer, uint32_t length)
++void _flash_write(struct _flash_device *const device, const uint32_t dst_addr, const uint8_t *buffer, uint32_t length)
+ {
+ uint8_t tmp_buffer[NVMCTRL_BLOCK_PAGES][NVMCTRL_PAGE_SIZE];
+ uint32_t block_start_addr, block_end_addr;
+@@ -212,7 +212,7 @@ void _flash_write(struct _flash_device *const device, const uint32_t dst_addr, u
+ /**
+ * \brief Appends a number of bytes in the internal Flash.
+ */
+-void _flash_append(struct _flash_device *const device, const uint32_t dst_addr, uint8_t *buffer, uint32_t length)
++void _flash_append(struct _flash_device *const device, const uint32_t dst_addr, const uint8_t *buffer, uint32_t length)
+ {
+ uint32_t page_start_addr = dst_addr & ~(NVMCTRL_PAGE_SIZE - 1);
+ uint32_t size;
diff --git a/atmel-samd/asf4/samd21/hal/include/hal_flash.h b/atmel-samd/asf4/samd21/hal/include/hal_flash.h
index 2e6286389..ffba519de 100644
--- a/atmel-samd/asf4/samd21/hal/include/hal_flash.h
+++ b/atmel-samd/asf4/samd21/hal/include/hal_flash.h
@@ -132,7 +132,7 @@ int32_t flash_write(struct flash_descriptor *flash, uint32_t dst_addr, uint8_t *
* \param[in] length Number of bytes to append
* \return Append status.
*/
-int32_t flash_append(struct flash_descriptor *flash, uint32_t dst_addr, uint8_t *buffer, uint32_t length);
+int32_t flash_append(struct flash_descriptor *flash, uint32_t dst_addr, const uint8_t *buffer, uint32_t length);
/** \brief Reads a number of bytes to a page in the internal Flash
*
diff --git a/atmel-samd/asf4/samd21/hal/include/hpl_flash.h b/atmel-samd/asf4/samd21/hal/include/hpl_flash.h
index 774bb5e0b..6a59f757c 100644
--- a/atmel-samd/asf4/samd21/hal/include/hpl_flash.h
+++ b/atmel-samd/asf4/samd21/hal/include/hpl_flash.h
@@ -125,7 +125,7 @@ void _flash_read(struct _flash_device *const device, const uint32_t src_addr, ui
* write is stored
* \param[in] length Number of bytes to write
*/
-void _flash_write(struct _flash_device *const device, const uint32_t dst_addr, uint8_t *buffer, uint32_t length);
+void _flash_write(struct _flash_device *const device, const uint32_t dst_addr, const uint8_t *buffer, uint32_t length);
/**
* \brief Appends a number of bytes in the internal Flash.
@@ -135,7 +135,7 @@ void _flash_write(struct _flash_device *const device, const uint32_t dst_addr, u
* \param[in] buffer Pointer to buffer with data to write to flash
* \param[in] length Number of bytes to write
*/
-void _flash_append(struct _flash_device *const device, const uint32_t dst_addr, uint8_t *buffer, uint32_t length);
+void _flash_append(struct _flash_device *const device, const uint32_t dst_addr, const uint8_t *buffer, uint32_t length);
/** \brief Execute lock in the internal flash
* \param[in] device The pointer to FLASH device instance
diff --git a/atmel-samd/asf4/samd21/hal/src/hal_flash.c b/atmel-samd/asf4/samd21/hal/src/hal_flash.c
index f3cc4bbfe..165d46d89 100644
--- a/atmel-samd/asf4/samd21/hal/src/hal_flash.c
+++ b/atmel-samd/asf4/samd21/hal/src/hal_flash.c
@@ -135,7 +135,7 @@ int32_t flash_write(struct flash_descriptor *flash, uint32_t dst_addr, uint8_t *
/**
* \brief Appends a number of bytes to a page in the internal Flash
*/
-int32_t flash_append(struct flash_descriptor *flash, uint32_t dst_addr, uint8_t *buffer, uint32_t length)
+int32_t flash_append(struct flash_descriptor *flash, uint32_t dst_addr, const uint8_t *buffer, uint32_t length)
{
ASSERT(flash && buffer && length);
@@ -304,7 +304,10 @@ static int32_t flash_is_address_aligned(struct flash_descriptor *flash, const ui
*/
static void flash_ready(struct _flash_device *device)
{
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wcast-align"
struct flash_descriptor *const descr = CONTAINER_OF(device, struct flash_descriptor, dev);
+ #pragma GCC diagnostic pop
if (descr->callbacks.cb_ready) {
descr->callbacks.cb_ready(descr);
}
@@ -317,7 +320,10 @@ static void flash_ready(struct _flash_device *device)
*/
static void flash_error(struct _flash_device *device)
{
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wcast-align"
struct flash_descriptor *const descr = CONTAINER_OF(device, struct flash_descriptor, dev);
+ #pragma GCC diagnostic pop
if (descr->callbacks.cb_error) {
descr->callbacks.cb_error(descr);
}
diff --git a/atmel-samd/asf4/samd21/hpl/nvmctrl/hpl_nvmctrl.c b/atmel-samd/asf4/samd21/hpl/nvmctrl/hpl_nvmctrl.c
index 2c9131a1a..3e751e3d5 100644
--- a/atmel-samd/asf4/samd21/hpl/nvmctrl/hpl_nvmctrl.c
+++ b/atmel-samd/asf4/samd21/hpl/nvmctrl/hpl_nvmctrl.c
@@ -175,7 +175,7 @@ void _flash_read(struct _flash_device *const device, const uint32_t src_addr, ui
/**
* \brief Writes a number of bytes to a page in the internal Flash.
*/
-void _flash_write(struct _flash_device *const device, const uint32_t dst_addr, uint8_t *buffer, uint32_t length)
+void _flash_write(struct _flash_device *const device, const uint32_t dst_addr, const uint8_t *buffer, uint32_t length)
{
uint8_t tmp_buffer[NVMCTRL_ROW_PAGES][NVMCTRL_PAGE_SIZE];
uint32_t row_start_addr, row_end_addr;
@@ -219,7 +219,7 @@ void _flash_write(struct _flash_device *const device, const uint32_t dst_addr, u
/**
* \brief Appends a number of bytes in the internal Flash.
*/
-void _flash_append(struct _flash_device *const device, const uint32_t dst_addr, uint8_t *buffer, uint32_t length)
+void _flash_append(struct _flash_device *const device, const uint32_t dst_addr, const uint8_t *buffer, uint32_t length)
{
uint32_t page_start_addr = dst_addr & ~(NVMCTRL_PAGE_SIZE - 1);
uint32_t size;
diff --git a/atmel-samd/asf4/samd51/CMSIS/Include/core_cm4.h b/atmel-samd/asf4/samd51/CMSIS/Include/core_cm4.h
index bb6be1305..2ebde319d 100644
--- a/atmel-samd/asf4/samd51/CMSIS/Include/core_cm4.h
+++ b/atmel-samd/asf4/samd51/CMSIS/Include/core_cm4.h
@@ -1493,8 +1493,12 @@ __STATIC_INLINE uint32_t NVIC_GetPriorityGrouping(void)
*/
__STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
{
+
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Warray-bounds"
/* NVIC->ISER[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); enable interrupt */
NVIC->ISER[(uint32_t)((int32_t)IRQn) >> 5] = (uint32_t)(1 << ((uint32_t)((int32_t)IRQn) & (uint32_t)0x1F)); /* enable interrupt */
+ #pragma GCC diagnostic pop
}
diff --git a/atmel-samd/asf4/samd51/hal/include/hal_flash.h b/atmel-samd/asf4/samd51/hal/include/hal_flash.h
index 2e6286389..ffba519de 100644
--- a/atmel-samd/asf4/samd51/hal/include/hal_flash.h
+++ b/atmel-samd/asf4/samd51/hal/include/hal_flash.h
@@ -132,7 +132,7 @@ int32_t flash_write(struct flash_descriptor *flash, uint32_t dst_addr, uint8_t *
* \param[in] length Number of bytes to append
* \return Append status.
*/
-int32_t flash_append(struct flash_descriptor *flash, uint32_t dst_addr, uint8_t *buffer, uint32_t length);
+int32_t flash_append(struct flash_descriptor *flash, uint32_t dst_addr, const uint8_t *buffer, uint32_t length);
/** \brief Reads a number of bytes to a page in the internal Flash
*
diff --git a/atmel-samd/asf4/samd51/hal/include/hpl_flash.h b/atmel-samd/asf4/samd51/hal/include/hpl_flash.h
index 774bb5e0b..6a59f757c 100644
--- a/atmel-samd/asf4/samd51/hal/include/hpl_flash.h
+++ b/atmel-samd/asf4/samd51/hal/include/hpl_flash.h
@@ -125,7 +125,7 @@ void _flash_read(struct _flash_device *const device, const uint32_t src_addr, ui
* write is stored
* \param[in] length Number of bytes to write
*/
-void _flash_write(struct _flash_device *const device, const uint32_t dst_addr, uint8_t *buffer, uint32_t length);
+void _flash_write(struct _flash_device *const device, const uint32_t dst_addr, const uint8_t *buffer, uint32_t length);
/**
* \brief Appends a number of bytes in the internal Flash.
@@ -135,7 +135,7 @@ void _flash_write(struct _flash_device *const device, const uint32_t dst_addr, u
* \param[in] buffer Pointer to buffer with data to write to flash
* \param[in] length Number of bytes to write
*/
-void _flash_append(struct _flash_device *const device, const uint32_t dst_addr, uint8_t *buffer, uint32_t length);
+void _flash_append(struct _flash_device *const device, const uint32_t dst_addr, const uint8_t *buffer, uint32_t length);
/** \brief Execute lock in the internal flash
* \param[in] device The pointer to FLASH device instance
diff --git a/atmel-samd/asf4/samd51/hal/src/hal_flash.c b/atmel-samd/asf4/samd51/hal/src/hal_flash.c
index f3cc4bbfe..165d46d89 100644
--- a/atmel-samd/asf4/samd51/hal/src/hal_flash.c
+++ b/atmel-samd/asf4/samd51/hal/src/hal_flash.c
@@ -135,7 +135,7 @@ int32_t flash_write(struct flash_descriptor *flash, uint32_t dst_addr, uint8_t *
/**
* \brief Appends a number of bytes to a page in the internal Flash
*/
-int32_t flash_append(struct flash_descriptor *flash, uint32_t dst_addr, uint8_t *buffer, uint32_t length)
+int32_t flash_append(struct flash_descriptor *flash, uint32_t dst_addr, const uint8_t *buffer, uint32_t length)
{
ASSERT(flash && buffer && length);
@@ -304,7 +304,10 @@ static int32_t flash_is_address_aligned(struct flash_descriptor *flash, const ui
*/
static void flash_ready(struct _flash_device *device)
{
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wcast-align"
struct flash_descriptor *const descr = CONTAINER_OF(device, struct flash_descriptor, dev);
+ #pragma GCC diagnostic pop
if (descr->callbacks.cb_ready) {
descr->callbacks.cb_ready(descr);
}
@@ -317,7 +320,10 @@ static void flash_ready(struct _flash_device *device)
*/
static void flash_error(struct _flash_device *device)
{
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wcast-align"
struct flash_descriptor *const descr = CONTAINER_OF(device, struct flash_descriptor, dev);
+ #pragma GCC diagnostic pop
if (descr->callbacks.cb_error) {
descr->callbacks.cb_error(descr);
}
diff --git a/atmel-samd/asf4/samd51/hpl/nvmctrl/hpl_nvmctrl.c b/atmel-samd/asf4/samd51/hpl/nvmctrl/hpl_nvmctrl.c
index 2f7f01d5e..3d9df6db4 100644
--- a/atmel-samd/asf4/samd51/hpl/nvmctrl/hpl_nvmctrl.c
+++ b/atmel-samd/asf4/samd51/hpl/nvmctrl/hpl_nvmctrl.c
@@ -167,7 +167,7 @@ void _flash_read(struct _flash_device *const device, const uint32_t src_addr, ui
/**
* \brief Writes a number of bytes to a page in the internal Flash.
*/
-void _flash_write(struct _flash_device *const device, const uint32_t dst_addr, uint8_t *buffer, uint32_t length)
+void _flash_write(struct _flash_device *const device, const uint32_t dst_addr, const uint8_t *buffer, uint32_t length)
{
uint8_t tmp_buffer[NVMCTRL_BLOCK_PAGES][NVMCTRL_PAGE_SIZE];
uint32_t block_start_addr, block_end_addr;
@@ -212,7 +212,7 @@ void _flash_write(struct _flash_device *const device, const uint32_t dst_addr, u
/**
* \brief Appends a number of bytes in the internal Flash.
*/
-void _flash_append(struct _flash_device *const device, const uint32_t dst_addr, uint8_t *buffer, uint32_t length)
+void _flash_append(struct _flash_device *const device, const uint32_t dst_addr, const uint8_t *buffer, uint32_t length)
{
uint32_t page_start_addr = dst_addr & ~(NVMCTRL_PAGE_SIZE - 1);
uint32_t size;
@@ -386,7 +386,10 @@ static void _flash_erase_block(void *const hw, const uint32_t dst_addr)
*/
static void _flash_program(void *const hw, const uint32_t dst_addr, const uint8_t *buffer, const uint16_t size)
{
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wcast-align"
uint32_t *ptr_read = (uint32_t *)buffer;
+ #pragma GCC diagnostic pop
uint32_t nvm_address = dst_addr / 4;
uint16_t i;
diff --git a/atmel-samd/asf4_conf/samd21/hpl_nvmctrl_config.h b/atmel-samd/asf4_conf/samd21/hpl_nvmctrl_config.h
new file mode 100644
index 000000000..88d6bb93f
--- /dev/null
+++ b/atmel-samd/asf4_conf/samd21/hpl_nvmctrl_config.h
@@ -0,0 +1,38 @@
+/* Auto-generated config file hpl_nvmctrl_config.h */
+#ifndef HPL_NVMCTRL_CONFIG_H
+#define HPL_NVMCTRL_CONFIG_H
+
+// <<< Use Configuration Wizard in Context Menu >>>
+
+// <h> Basic Settings
+
+// <o> Read Mode Selection
+// <0x00=> No Miss Penalty
+// <0x01=> Low Power
+// <0x02=> Deterministic
+// <id> nvm_arch_read_mode
+#ifndef CONF_NVM_READ_MODE
+#define CONF_NVM_READ_MODE 0
+#endif
+
+// <o> Power Reduction Mode During Sleep
+// <0x00=> Wake On Access
+// <0x01=> Wake Up Instant
+// <0x03=> Disabled
+// <id> nvm_arch_sleepprm
+#ifndef CONF_NVM_SLEEPPRM
+#define CONF_NVM_SLEEPPRM 0
+#endif
+
+// <q> Cache Disable
+// <i> Indicate whether cache is disable or not
+// <id> nvm_arch_cache
+#ifndef CONF_NVM_CACHE
+#define CONF_NVM_CACHE 0
+#endif
+
+// </h>
+
+// <<< end of configuration section >>>
+
+#endif // HPL_NVMCTRL_CONFIG_H
diff --git a/atmel-samd/asf4_conf/samd51/hpl_nvmctrl_config.h b/atmel-samd/asf4_conf/samd51/hpl_nvmctrl_config.h
new file mode 100644
index 000000000..daaba85d4
--- /dev/null
+++ b/atmel-samd/asf4_conf/samd51/hpl_nvmctrl_config.h
@@ -0,0 +1,36 @@
+/* Auto-generated config file hpl_nvmctrl_config.h */
+#ifndef HPL_NVMCTRL_CONFIG_H
+#define HPL_NVMCTRL_CONFIG_H
+
+// <<< Use Configuration Wizard in Context Menu >>>
+
+// <h> Basic Settings
+
+// <o> Power Reduction Mode During Sleep
+// <0x00=> Wake On Access
+// <0x01=> Wake Up Instant
+// <0x03=> Disabled
+// <id> nvm_arch_sleepprm
+#ifndef CONF_NVM_SLEEPPRM
+#define CONF_NVM_SLEEPPRM 0
+#endif
+
+// <q> AHB0 Cache Disable
+// <i> Indicate whether AHB0 cache is disable or not
+// <id> nvm_arch_cache0
+#ifndef CONF_NVM_CACHE0
+#define CONF_NVM_CACHE0 0
+#endif
+
+// <q> AHB1 Cache Disable
+// <i> Indicate whether AHB1 cache is disable or not
+// <id> nvm_arch_cache1
+#ifndef CONF_NVM_CACHE1
+#define CONF_NVM_CACHE1 0
+#endif
+
+// </h>
+
+// <<< end of configuration section >>>
+
+#endif // HPL_NVMCTRL_CONFIG_H
diff --git a/atmel-samd/asf4_conf/samd51/hpl_trng_config.h b/atmel-samd/asf4_conf/samd51/hpl_trng_config.h
new file mode 100644
index 000000000..ba9014989
--- /dev/null
+++ b/atmel-samd/asf4_conf/samd51/hpl_trng_config.h
@@ -0,0 +1,27 @@
+/* Auto-generated config file hpl_trng_config.h */
+#ifndef HPL_TRNG_CONFIG_H
+#define HPL_TRNG_CONFIG_H
+
+// <<< Use Configuration Wizard in Context Menu >>>
+
+// <h> Advanced configurations
+
+// <q> Run In Standby
+// <i> Indicates whether the TRNG works in standby mode
+// <id> trng_runstdby
+#ifndef CONF_TRNG_RUNSTDBY
+#define CONF_TRNG_RUNSTDBY 0
+#endif
+
+// <q> Data Ready Event Output Enable
+// <i> Indicates whether the TRNG generates event on Data Ready
+// <id> trng_datardyeo
+#ifndef CONF_TRNG_DATARDYEO
+#define CONF_TRNG_DATARDYEO 0
+#endif
+
+// </h>
+
+// <<< end of configuration section >>>
+
+#endif // HPL_TRNG_CONFIG_H
diff --git a/atmel-samd/boards/circuitplayground_express/mpconfigboard.h b/atmel-samd/boards/circuitplayground_express/mpconfigboard.h
index a12ac51a0..e1056ae94 100644
--- a/atmel-samd/boards/circuitplayground_express/mpconfigboard.h
+++ b/atmel-samd/boards/circuitplayground_express/mpconfigboard.h
@@ -24,7 +24,8 @@
#define SPEAKER_ENABLE_PIN (&pin_PA30)
-#include "spi_flash.h"
+#include "internal_flash.h"
+//#include "spi_flash.h"
// If you change this, then make sure to update the linker scripts as well to
// make sure you don't overwrite code.
diff --git a/atmel-samd/boards/circuitplayground_express/mpconfigboard.mk b/atmel-samd/boards/circuitplayground_express/mpconfigboard.mk
index 0a93ccddc..538a737db 100644
--- a/atmel-samd/boards/circuitplayground_express/mpconfigboard.mk
+++ b/atmel-samd/boards/circuitplayground_express/mpconfigboard.mk
@@ -1,8 +1,9 @@
-LD_FILE = boards/samd21x18-bootloader-external-flash-crystalless.ld
+LD_FILE = boards/samd21x18-bootloader-crystalless.ld
USB_VID = 0x239A
USB_PID = 0x8019
-FLASH_IMPL = spi_flash.c
+#FLASH_IMPL = spi_flash.c
+FLASH_IMPL = internal_flash.c
CHIP_VARIANT = SAMD21G18A
CHIP_FAMILY = samd21
diff --git a/atmel-samd/boards/feather_m0_express/mpconfigboard.h b/atmel-samd/boards/feather_m0_express/mpconfigboard.h
index 9f9c25a7d..39706e260 100644
--- a/atmel-samd/boards/feather_m0_express/mpconfigboard.h
+++ b/atmel-samd/boards/feather_m0_express/mpconfigboard.h
@@ -20,7 +20,8 @@
#define MICROPY_PORT_B ( 0 )
#define MICROPY_PORT_C ( 0 )
-#include "spi_flash.h"
+#include "internal_flash.h"
+//#include "spi_flash.h"
// If you change this, then make sure to update the linker scripts as well to
// make sure you don't overwrite code.
diff --git a/atmel-samd/boards/feather_m0_express/mpconfigboard.mk b/atmel-samd/boards/feather_m0_express/mpconfigboard.mk
index 5840a5cf9..cdcfd4108 100644
--- a/atmel-samd/boards/feather_m0_express/mpconfigboard.mk
+++ b/atmel-samd/boards/feather_m0_express/mpconfigboard.mk
@@ -1,8 +1,9 @@
-LD_FILE = boards/samd21x18-bootloader-external-flash.ld
+LD_FILE = boards/samd21x18-bootloader.ld
USB_VID = 0x239A
USB_PID = 0x801b
-FLASH_IMPL = spi_flash.c
+#FLASH_IMPL = spi_flash.c
+FLASH_IMPL = internal_flash.c
CHIP_VARIANT = SAMD21G18A
CHIP_FAMILY = samd21
diff --git a/atmel-samd/boards/metro_m0_express/mpconfigboard.h b/atmel-samd/boards/metro_m0_express/mpconfigboard.h
index 291967c88..de3cf29da 100644
--- a/atmel-samd/boards/metro_m0_express/mpconfigboard.h
+++ b/atmel-samd/boards/metro_m0_express/mpconfigboard.h
@@ -24,7 +24,8 @@
#define MICROPY_PORT_B (PORT_PB03 | PORT_PB22 | PORT_PB23)
#define MICROPY_PORT_C (0)
-#include "spi_flash.h"
+#include "internal_flash.h"
+//#include "spi_flash.h"
// If you change this, then make sure to update the linker scripts as well to
// make sure you don't overwrite code.
diff --git a/atmel-samd/boards/metro_m0_express/mpconfigboard.mk b/atmel-samd/boards/metro_m0_express/mpconfigboard.mk
index 763738748..82d673f02 100644
--- a/atmel-samd/boards/metro_m0_express/mpconfigboard.mk
+++ b/atmel-samd/boards/metro_m0_express/mpconfigboard.mk
@@ -1,8 +1,9 @@
-LD_FILE = boards/samd21x18-bootloader-external-flash.ld
+LD_FILE = boards/samd21x18-bootloader.ld
USB_VID = 0x239A
USB_PID = 0x8014
-FLASH_IMPL = spi_flash.c
+#FLASH_IMPL = spi_flash.c
+FLASH_IMPL = internal_flash.c
CHIP_VARIANT = SAMD21G18A
CHIP_FAMILY = samd21
diff --git a/atmel-samd/boards/metro_m4_express/mpconfigboard.mk b/atmel-samd/boards/metro_m4_express/mpconfigboard.mk
index fd299c7f9..a21be5138 100644
--- a/atmel-samd/boards/metro_m4_express/mpconfigboard.mk
+++ b/atmel-samd/boards/metro_m4_express/mpconfigboard.mk
@@ -1,8 +1,9 @@
-LD_FILE = boards/samd51x20-bootloader-external-flash.ld
+LD_FILE = boards/samd51x20.ld
USB_VID = 0x239A
USB_PID = 0x8015
-FLASH_IMPL = spi_flash.c
+#FLASH_IMPL = spi_flash.c
+FLASH_IMPL = internal_flash.c
CHIP_VARIANT = SAMD51J20A
CHIP_FAMILY = samd51
diff --git a/atmel-samd/boards/samd51x18-bootloader-external-flash.ld b/atmel-samd/boards/samd51x18-bootloader-external-flash.ld
index b009de640..f4ad37c20 100644
--- a/atmel-samd/boards/samd51x18-bootloader-external-flash.ld
+++ b/atmel-samd/boards/samd51x18-bootloader-external-flash.ld
@@ -1,5 +1,5 @@
/*
- GNU linker script for SAMD21
+ GNU linker script for SAMD51
*/
/* Specify the memory areas */
diff --git a/atmel-samd/boards/samd51x19-bootloader-external-flash.ld b/atmel-samd/boards/samd51x19-bootloader-external-flash.ld
index bea575797..4e4e8b002 100644
--- a/atmel-samd/boards/samd51x19-bootloader-external-flash.ld
+++ b/atmel-samd/boards/samd51x19-bootloader-external-flash.ld
@@ -1,5 +1,5 @@
/*
- GNU linker script for SAMD21
+ GNU linker script for SAMD51
*/
/* Specify the memory areas */
diff --git a/atmel-samd/boards/samd51x20-bootloader-external-flash.ld b/atmel-samd/boards/samd51x20-bootloader-external-flash.ld
index e9c67de97..57bf299fb 100644
--- a/atmel-samd/boards/samd51x20-bootloader-external-flash.ld
+++ b/atmel-samd/boards/samd51x20-bootloader-external-flash.ld
@@ -1,5 +1,5 @@
/*
- GNU linker script for SAMD21
+ GNU linker script for SAMD51
*/
/* Specify the memory areas */
diff --git a/atmel-samd/boards/samd51x20-external-flash.ld b/atmel-samd/boards/samd51x20-external-flash.ld
index 701e24762..b0a118507 100644
--- a/atmel-samd/boards/samd51x20-external-flash.ld
+++ b/atmel-samd/boards/samd51x20-external-flash.ld
@@ -1,5 +1,5 @@
/*
- GNU linker script for SAMD21
+ GNU linker script for SAMD51
*/
/* Specify the memory areas */
diff --git a/atmel-samd/boards/samd51x20.ld b/atmel-samd/boards/samd51x20.ld
new file mode 100644
index 000000000..4d2da5d13
--- /dev/null
+++ b/atmel-samd/boards/samd51x20.ld
@@ -0,0 +1,81 @@
+/*
+ GNU linker script for SAMD51
+*/
+
+/* Specify the memory areas */
+MEMORY
+{
+ FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x00100000 - 0x80000 /* 1024 KiB mius 512KiB for the internal file system. */
+ RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 0x00040000 /* 256 KiB */
+}
+
+/* top end of the stack */
+_estack = ORIGIN(RAM) + LENGTH(RAM);
+
+/* define output sections */
+SECTIONS
+{
+ /* The program code and other data goes into FLASH */
+ .text :
+ {
+ . = ALIGN(4);
+ _sfixed = .;
+ KEEP(*(.vectors)) /* isr vector table */
+ *(.text) /* .text sections (code) */
+ *(.text*) /* .text* sections (code) */
+ *(.rodata) /* .rodata sections (constants, strings, etc.) */
+ *(.rodata*) /* .rodata* sections (constants, strings, etc.) */
+
+ . = ALIGN(4);
+ _etext = .; /* define a global symbol at end of code */
+ } >FLASH
+
+ .ARM.exidx :
+ {
+ *(.ARM.exidx*)
+ *(.gnu.linkonce.armexidx.*)
+ _sidata = .; /* This is used by the startup in order to initialize the .data section */
+ } > FLASH
+
+ /* This is the initialized data section
+ The program executes knowing that the data is in the RAM
+ but the loader puts the initial values in the FLASH (inidata).
+ It is one task of the startup to copy the initial values from FLASH to RAM. */
+ .data : AT ( _sidata )
+ {
+ . = ALIGN(4);
+ _srelocate = .; /* create a global symbol at data start; used by startup code in order to initialise the .data section in RAM */
+ *(.ramfunc)
+ *(.ramfunc*)
+ *(.data) /* .data sections */
+ *(.data*) /* .data* sections */
+
+ . = ALIGN(4);
+ _erelocate = .; /* define a global symbol at data end; used by startup code in order to initialise the .data section in RAM */
+ } >RAM
+
+ /* Uninitialized data section */
+ .bss :
+ {
+ . = ALIGN(4);
+ _sbss = .;
+ _szero = .; /* define a global symbol at bss start; used by startup code */
+ *(.bss)
+ *(.bss*)
+ *(COMMON)
+
+ . = ALIGN(4);
+ _ezero = .; /* define a global symbol at bss end; used by startup code */
+ _ebss = .;
+ } >RAM
+
+ /* this just checks there is enough RAM for a minimal stack */
+ .stack :
+ {
+ . = ALIGN(4);
+ . = . + 0x800; /* Reserve a minimum of 2K for the stack. */
+ . = ALIGN(4);
+ } >RAM
+
+ .ARM.attributes 0 : { *(.ARM.attributes) }
+}
diff --git a/atmel-samd/common-hal/os/__init__.c b/atmel-samd/common-hal/os/__init__.c
index 2df4e40ff..eeba29dfa 100644
--- a/atmel-samd/common-hal/os/__init__.c
+++ b/atmel-samd/common-hal/os/__init__.c
@@ -30,12 +30,22 @@
#include "py/objtuple.h"
#include "py/qstr.h"
+#ifdef SAMD51
+#include "hal/include/hal_rand_sync.h"
+#endif
+
STATIC const qstr os_uname_info_fields[] = {
MP_QSTR_sysname, MP_QSTR_nodename,
MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine
};
+#ifdef SAMD21
STATIC const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, "samd21");
STATIC const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, "samd21");
+#endif
+#ifdef SAMD51
+STATIC const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, "samd51");
+STATIC const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, "samd51");
+#endif
STATIC const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING);
STATIC const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE);
STATIC const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME);
@@ -57,5 +67,19 @@ mp_obj_t common_hal_os_uname(void) {
}
bool common_hal_os_urandom(uint8_t* buffer, uint32_t length) {
+ #ifdef SAMD51
+ hri_mclk_set_APBCMASK_TRNG_bit(MCLK);
+ struct rand_sync_desc random;
+ rand_sync_init(&random, TRNG);
+ rand_sync_enable(&random);
+
+ rand_sync_read_buf8(&random, buffer, length);
+
+ rand_sync_disable(&random);
+ rand_sync_deinit(&random);
+ hri_mclk_clear_APBCMASK_TRNG_bit(MCLK);
+ return true;
+ #else
return false;
+ #endif
}
diff --git a/atmel-samd/internal_flash.c b/atmel-samd/internal_flash.c
index 4447f15d6..53a0a0c24 100644
--- a/atmel-samd/internal_flash.c
+++ b/atmel-samd/internal_flash.c
@@ -35,10 +35,14 @@
#include "py/runtime.h"
#include "lib/oofatfs/ff.h"
-#include "asf/sam0/drivers/nvm/nvm.h"
-#include "asf/sam0/drivers/port/port.h"
+#ifdef SAMD21
+#include "hpl/pm/hpl_pm_base.h"
+#endif
+#include "hal/include/hal_flash.h"
-#include "rgb_led_status.h"
+#include "supervisor/shared/rgb_led_status.h"
+
+static struct flash_descriptor internal_flash_desc;
void internal_flash_init(void) {
// Activity LED for flash writes.
@@ -50,6 +54,14 @@ void internal_flash_init(void) {
port_pin_set_config(MICROPY_HW_LED_MSC, &pin_conf);
port_pin_set_output_level(MICROPY_HW_LED_MSC, false);
#endif
+
+ #ifdef SAMD51
+ hri_mclk_set_AHBMASK_NVMCTRL_bit(MCLK);
+ #endif
+ #ifdef SAMD21
+ _pm_enable_bus_clock(PM_BUS_APBB, NVMCTRL);
+ #endif
+ flash_init(&internal_flash_desc, NVMCTRL);
}
uint32_t internal_flash_get_block_size(void) {
@@ -138,18 +150,8 @@ bool internal_flash_read_block(uint8_t *dest, uint32_t block) {
// bad block number
return false;
}
- enum status_code error_code;
- // A block is made up of multiple pages. Read each page
- // sequentially.
- for (int i = 0; i < FILESYSTEM_BLOCK_SIZE / NVMCTRL_PAGE_SIZE; i++) {
- do
- {
- error_code = nvm_read_buffer(src + i * NVMCTRL_PAGE_SIZE,
- dest + i * NVMCTRL_PAGE_SIZE,
- NVMCTRL_PAGE_SIZE);
- } while (error_code == STATUS_BUSY);
- }
- return true;
+ int32_t error_code = flash_read(&internal_flash_desc, src, dest, FILESYSTEM_BLOCK_SIZE);
+ return error_code == ERR_NONE;
}
}
@@ -169,36 +171,21 @@ bool internal_flash_write_block(const uint8_t *src, uint32_t block) {
// bad block number
return false;
}
- enum status_code error_code;
+ int32_t error_code;
// A block is formed by two rows of flash. We must erase each row
// before we write back to it.
- do
- {
- error_code = nvm_erase_row(dest);
- } while (error_code == STATUS_BUSY);
- if (error_code != STATUS_OK) {
- return false;
- }
- do
- {
- error_code = nvm_erase_row(dest + NVMCTRL_ROW_SIZE);
- } while (error_code == STATUS_BUSY);
- if (error_code != STATUS_OK) {
+ error_code = flash_erase(&internal_flash_desc,
+ dest,
+ FILESYSTEM_BLOCK_SIZE / flash_get_page_size(&internal_flash_desc));
+ if (error_code != ERR_NONE) {
return false;
}
// A block is made up of multiple pages. Write each page
// sequentially.
- for (int i = 0; i < FILESYSTEM_BLOCK_SIZE / NVMCTRL_PAGE_SIZE; i++) {
- do
- {
- error_code = nvm_write_buffer(dest + i * NVMCTRL_PAGE_SIZE,
- src + i * NVMCTRL_PAGE_SIZE,
- NVMCTRL_PAGE_SIZE);
- } while (error_code == STATUS_BUSY);
- if (error_code != STATUS_OK) {
- return false;
- }
+ error_code = flash_append(&internal_flash_desc, dest, src, FILESYSTEM_BLOCK_SIZE);
+ if (error_code != ERR_NONE) {
+ return false;
}
clear_temp_status();
#ifdef MICROPY_HW_LED_MSC
diff --git a/atmel-samd/internal_flash.h b/atmel-samd/internal_flash.h
index 3de831f63..88c105386 100644
--- a/atmel-samd/internal_flash.h
+++ b/atmel-samd/internal_flash.h
@@ -30,11 +30,19 @@
#include "mpconfigport.h"
+#include "sam.h"
+
#define FLASH_ROOT_POINTERS
+#ifdef SAMD51
+#define TOTAL_INTERNAL_FLASH_SIZE (FLASH_SIZE / 2)
+#endif
+
+#ifdef SAMD21
#define TOTAL_INTERNAL_FLASH_SIZE 0x010000
+#endif
-#define INTERNAL_FLASH_MEM_SEG1_START_ADDR (0x00040000 - TOTAL_INTERNAL_FLASH_SIZE - CIRCUITPY_INTERNAL_NVM_SIZE)
+#define INTERNAL_FLASH_MEM_SEG1_START_ADDR (FLASH_SIZE - TOTAL_INTERNAL_FLASH_SIZE - CIRCUITPY_INTERNAL_NVM_SIZE)
#define INTERNAL_FLASH_PART1_START_BLOCK (0x1)
#define INTERNAL_FLASH_PART1_NUM_BLOCKS (TOTAL_INTERNAL_FLASH_SIZE / FILESYSTEM_BLOCK_SIZE)
diff --git a/atmel-samd/mpconfigport.h b/atmel-samd/mpconfigport.h
index 8881803e4..3bdf3bfbd 100644
--- a/atmel-samd/mpconfigport.h
+++ b/atmel-samd/mpconfigport.h
@@ -3,10 +3,6 @@
#ifndef __INCLUDED_MPCONFIGPORT_H
#define __INCLUDED_MPCONFIGPORT_H
-#define PORT_HEAP_SIZE (16384 + 4096)
-
-#define MICROPY_PY_SYS_PLATFORM "Atmel SAMD21"
-
#define MICROPY_OBJ_REPR (MICROPY_OBJ_REPR_C)
// options to control how MicroPython is built
@@ -138,10 +134,14 @@ typedef long mp_off_t;
#ifdef SAMD21
#define CIRCUITPY_MCU_FAMILY samd21
+#define MICROPY_PY_SYS_PLATFORM "Atmel SAMD21"
+#define PORT_HEAP_SIZE (16384 + 4096)
#endif
#ifdef SAMD51
#define CIRCUITPY_MCU_FAMILY samd51
+#define MICROPY_PY_SYS_PLATFORM "MicroChip SAMD51"
+#define PORT_HEAP_SIZE (0x20000) // 128KiB
#endif
// extra built in modules to add to the list of known ones
@@ -205,8 +205,6 @@ extern const struct _mp_obj_module_t usb_hid_module;
// { MP_OBJ_NEW_QSTR(MP_QSTR_busio), (mp_obj_t)&busio_module },
// { MP_OBJ_NEW_QSTR(MP_QSTR_neopixel_write),(mp_obj_t)&neopixel_write_module },
// { MP_OBJ_NEW_QSTR(MP_QSTR_usb_hid),(mp_obj_t)&usb_hid_module },
-// { MP_OBJ_NEW_QSTR(MP_QSTR_os), (mp_obj_t)&os_module },
-// { MP_OBJ_NEW_QSTR(MP_QSTR_random), (mp_obj_t)&random_module },
// { MP_OBJ_NEW_QSTR(MP_QSTR_storage), (mp_obj_t)&storage_module },
// { MP_OBJ_NEW_QSTR(MP_QSTR_samd),(mp_obj_t)&samd_module },
@@ -215,6 +213,8 @@ extern const struct _mp_obj_module_t usb_hid_module;
{ MP_OBJ_NEW_QSTR(MP_QSTR_board), (mp_obj_t)&board_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_digitalio), (mp_obj_t)&digitalio_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_microcontroller), (mp_obj_t)&microcontroller_module }, \
+ { MP_OBJ_NEW_QSTR(MP_QSTR_os), (mp_obj_t)&os_module }, \
+ { MP_OBJ_NEW_QSTR(MP_QSTR_random), (mp_obj_t)&random_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&time_module },
EXTRA_BUILTIN_MODULES
diff --git a/atmel-samd/supervisor/filesystem.c b/atmel-samd/supervisor/filesystem.c
index a25a4b9e5..2dfb2bfd3 100644
--- a/atmel-samd/supervisor/filesystem.c
+++ b/atmel-samd/supervisor/filesystem.c
@@ -28,6 +28,10 @@
#include "lib/oofatfs/ff.h"
#include "lib/oofatfs/diskio.h"
+#include "py/mpstate.h"
+
+#include "flash_api.h"
+
#ifdef EXPRESS_BOARD
// #include "common-hal/touchio/TouchIn.h"
#define INTERNAL_CIRCUITPY_CONFIG_START_ADDR (0x00040000 - 0x100 - CIRCUITPY_INTERNAL_NVM_SIZE)
@@ -41,38 +45,49 @@ mp_vfs_mount_t mp_vfs_mount_flash;
// we don't make this function static because it needs a lot of stack and we
// want it to be executed without using stack within main() function
void filesystem_init(void) {
- // // init the vfs object
- // fs_user_mount_t *vfs_fat = &fs_user_mount_flash;
- // vfs_fat->flags = 0;
- // flash_init_vfs(vfs_fat);
- //
- // // try to mount the flash
- // FRESULT res = f_mount(&vfs_fat->fatfs);
- //
- // if (res == FR_NO_FILESYSTEM) {
- // // no filesystem so create a fresh one
- //
- // uint8_t working_buf[_MAX_SS];
- // res = f_mkfs(&vfs_fat->fatfs, FM_FAT, 0, working_buf, sizeof(working_buf));
- // // Flush the new file system to make sure its repaired immediately.
- // flash_flush();
- // if (res != FR_OK) {
- // return;
- // }
- //
- // // set label
- // f_setlabel(&vfs_fat->fatfs, "CIRCUITPY");
- // } else if (res != FR_OK) {
- // return;
- // }
- // mp_vfs_mount_t *vfs = &mp_vfs_mount_flash;
- // vfs->str = "/";
- // vfs->len = 1;
- // vfs->obj = MP_OBJ_FROM_PTR(vfs_fat);
- // vfs->next = NULL;
- // MP_STATE_VM(vfs_mount_table) = vfs;
- //
- // // The current directory is used as the boot up directory.
- // // It is set to the internal flash filesystem by default.
- // MP_STATE_PORT(vfs_cur) = vfs;
+ // init the vfs object
+ fs_user_mount_t *vfs_fat = &fs_user_mount_flash;
+ vfs_fat->flags = 0;
+ flash_init_vfs(vfs_fat);
+
+ // try to mount the flash
+ FRESULT res = f_mount(&vfs_fat->fatfs);
+
+ if (res == FR_NO_FILESYSTEM) {
+ // no filesystem so create a fresh one
+ uint8_t working_buf[_MAX_SS];
+ res = f_mkfs(&vfs_fat->fatfs, FM_FAT, 0, working_buf, sizeof(working_buf));
+ // Flush the new file system to make sure its repaired immediately.
+ flash_flush();
+ if (res != FR_OK) {
+ return;
+ }
+
+ // set label
+ f_setlabel(&vfs_fat->fatfs, "CIRCUITPY");
+ } else if (res != FR_OK) {
+ return;
+ }
+ mp_vfs_mount_t *vfs = &mp_vfs_mount_flash;
+ vfs->str = "/";
+ vfs->len = 1;
+ vfs->obj = MP_OBJ_FROM_PTR(vfs_fat);
+ vfs->next = NULL;
+ MP_STATE_VM(vfs_mount_table) = vfs;
+
+ // The current directory is used as the boot up directory.
+ // It is set to the internal flash filesystem by default.
+ MP_STATE_PORT(vfs_cur) = vfs;
+}
+
+void filesystem_flush(void) {
+ flash_flush();
+}
+
+void filesystem_default_writeable(bool writeable) {
+ flash_set_usb_writeable(writeable);
+}
+
+bool filesystem_present(void) {
+ return true;
}
diff --git a/atmel-samd/usb.c b/atmel-samd/usb.c
index 8d7870a2a..11a3d4eb9 100644
--- a/atmel-samd/usb.c
+++ b/atmel-samd/usb.c
@@ -123,6 +123,7 @@ static bool usb_device_cb_bulk_out(const uint8_t ep, const enum usb_xfer_code rc
uint8_t buf[count];
int32_t result = cdcdf_acm_read(buf, count);
if (result != ERR_NONE) {
+ atomic_leave_critical(&flags);
return true;
}
diff --git a/supervisor/supervisor.mk b/supervisor/supervisor.mk
index f67439a97..c56557197 100644
--- a/supervisor/supervisor.mk
+++ b/supervisor/supervisor.mk
@@ -4,7 +4,7 @@ SRC_SUPERVISOR = \
supervisor/shared/autoreload.c \
supervisor/shared/rgb_led_status.c
-ifeq ($(wildcard supervisor/filesystem.c),)
+ifeq ($(wildcard atmel-samd/supervisor/filesystem.c),)
SRC_SUPERVISOR += supervisor/filesystem.c
else
SRC_SUPERVISOR += supervisor/stub/filesystem.c