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.
This commit is contained in:
parent
9a9584aee0
commit
80654779e1
@ -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 \
|
||||
|
@ -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);
|
||||
}
|
||||
|
61
atmel-samd/asf4/patches/samd21/flash-const.patch
Normal file
61
atmel-samd/asf4/patches/samd21/flash-const.patch
Normal file
@ -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;
|
13
atmel-samd/asf4/patches/samd51/array-bounds.patch
Normal file
13
atmel-samd/asf4/patches/samd51/array-bounds.patch
Normal file
@ -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
|
||||
}
|
@ -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;
|
||||
|
63
atmel-samd/asf4/patches/samd51/flash-const.patch
Normal file
63
atmel-samd/asf4/patches/samd51/flash-const.patch
Normal file
@ -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;
|
@ -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
|
||||
*
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
||||
|
@ -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
|
||||
*
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
38
atmel-samd/asf4_conf/samd21/hpl_nvmctrl_config.h
Normal file
38
atmel-samd/asf4_conf/samd21/hpl_nvmctrl_config.h
Normal file
@ -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
|
36
atmel-samd/asf4_conf/samd51/hpl_nvmctrl_config.h
Normal file
36
atmel-samd/asf4_conf/samd51/hpl_nvmctrl_config.h
Normal file
@ -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
|
27
atmel-samd/asf4_conf/samd51/hpl_trng_config.h
Normal file
27
atmel-samd/asf4_conf/samd51/hpl_trng_config.h
Normal file
@ -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
|
@ -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.
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
GNU linker script for SAMD21
|
||||
GNU linker script for SAMD51
|
||||
*/
|
||||
|
||||
/* Specify the memory areas */
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
GNU linker script for SAMD21
|
||||
GNU linker script for SAMD51
|
||||
*/
|
||||
|
||||
/* Specify the memory areas */
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
GNU linker script for SAMD21
|
||||
GNU linker script for SAMD51
|
||||
*/
|
||||
|
||||
/* Specify the memory areas */
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
GNU linker script for SAMD21
|
||||
GNU linker script for SAMD51
|
||||
*/
|
||||
|
||||
/* Specify the memory areas */
|
||||
|
81
atmel-samd/boards/samd51x20.ld
Normal file
81
atmel-samd/boards/samd51x20.ld
Normal file
@ -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) }
|
||||
}
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -30,11 +30,19 @@
|
||||
|
||||
#include "mpconfigport.h"
|
||||
|
||||
#include "sam.h"
|
||||
|
||||
#define FLASH_ROOT_POINTERS
|
||||
|
||||
#define TOTAL_INTERNAL_FLASH_SIZE 0x010000
|
||||
#ifdef SAMD51
|
||||
#define TOTAL_INTERNAL_FLASH_SIZE (FLASH_SIZE / 2)
|
||||
#endif
|
||||
|
||||
#define INTERNAL_FLASH_MEM_SEG1_START_ADDR (0x00040000 - TOTAL_INTERNAL_FLASH_SIZE - CIRCUITPY_INTERNAL_NVM_SIZE)
|
||||
#ifdef SAMD21
|
||||
#define TOTAL_INTERNAL_FLASH_SIZE 0x010000
|
||||
#endif
|
||||
|
||||
#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)
|
||||
|
||||
|
@ -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)µcontroller_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
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user