summaryrefslogtreecommitdiff
path: root/ports
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2019-10-28 18:15:02 -0400
committerDan Halbert <halbert@halwitz.org>2019-10-28 18:15:02 -0400
commit1505da784f228d43df41a773cfe504e7e4da330a (patch)
tree67381e6cc5e9a63b7374b008ff9bfff36f9f680b /ports
parent7b79ac37399927070e1931022f5759393202ed3d (diff)
wip
Diffstat (limited to 'ports')
-rw-r--r--ports/atmel-samd/boards/common.template.ld10
-rw-r--r--ports/atmel-samd/boards/sam32/mpconfigboard.h2
-rw-r--r--ports/atmel-samd/ld_defines.c7
-rw-r--r--ports/atmel-samd/mpconfigport.h36
-rw-r--r--ports/atmel-samd/supervisor/internal_flash.c2
-rw-r--r--ports/atmel-samd/supervisor/internal_flash.h11
6 files changed, 40 insertions, 28 deletions
diff --git a/ports/atmel-samd/boards/common.template.ld b/ports/atmel-samd/boards/common.template.ld
index e02bbfab0..aebda87c2 100644
--- a/ports/atmel-samd/boards/common.template.ld
+++ b/ports/atmel-samd/boards/common.template.ld
@@ -3,15 +3,7 @@
/* Specify the memory areas */
MEMORY
{
- /* CIRCUITPY_BOOTLOADER_SIZE is size of bootloader, if any.
- * SAMD21 Arduino and UF2 bootloaders are 8KiB. SAMD51 UF2 is 6KiB.
- * FLASH_SIZE is defined in ASF4.
- * RAM_SIZE is defined in mpconfigport.h, from constants from ASF4.
- * CIRCUITPY_INTERNAL_CONFIG_SIZE is size of an optional hidden config area, used currently
- * for crystalless USB timing calibration.
- * CIRCUITPY_INTERNAL_NVM_SIZE is the size of microntroller.nvm.
- */
- FLASH (rx) : ORIGIN = 0x00000000 + ${BOOTLOADER_SIZE}, LENGTH = ${FLASH_SIZE} - ${BOOTLOADER_SIZE} - ${CIRCUITPY_INTERNAL_CONFIG_SIZE} - ${CIRCUITPY_INTERNAL_NVM_SIZE}
+ FLASH (rx) : ORIGIN = 0x00000000 + ${BOOTLOADER_SIZE}, LENGTH = ${CIRCUITPY_FIRMWARE_SIZE}
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = ${RAM_SIZE}
}
diff --git a/ports/atmel-samd/boards/sam32/mpconfigboard.h b/ports/atmel-samd/boards/sam32/mpconfigboard.h
index 3c6f52ebc..bd9f5e398 100644
--- a/ports/atmel-samd/boards/sam32/mpconfigboard.h
+++ b/ports/atmel-samd/boards/sam32/mpconfigboard.h
@@ -9,7 +9,7 @@
#define MICROPY_PORT_A (PORT_PA24 | PORT_PA25)
#define MICROPY_PORT_B (0)
#define MICROPY_PORT_C (0)
-#define MICROPY_PORT_D (0)
+#define MICROPY_PORT_D (0)
// No microcontroller.nvm
#define CIRCUITPY_INTERNAL_NVM_SIZE 0
diff --git a/ports/atmel-samd/ld_defines.c b/ports/atmel-samd/ld_defines.c
index 62838ca4b..d8a7a209b 100644
--- a/ports/atmel-samd/ld_defines.c
+++ b/ports/atmel-samd/ld_defines.c
@@ -7,8 +7,7 @@
// This will be post-processed by tools/gen_ld_files.py to extract the name and vlaue.
BOOTLOADER_SIZE; ///DEFINE_VALUE BOOTLOADER_SIZE
-RAM_SIZE; ///DEFINE_VALUE RAM_SIZE lambda f: f.rstrip("UL")
-FLASH_SIZE; ///DEFINE_VALUE FLASH_SIZE lambda f: f.rstrip("UL")
-CIRCUITPY_INTERNAL_CONFIG_SIZE; ///DEFINE_VALUE CIRCUITPY_INTERNAL_CONFIG_SIZE
-CIRCUITPY_INTERNAL_NVM_SIZE; ///DEFINE_VALUE CIRCUITPY_INTERNAL_NVM_SIZE
+RAM_SIZE; ///DEFINE_VALUE RAM_SIZE def noUL(expr): import re; return re.sub(
+FLASH_SIZE; ///DEFINE_VALUE FLASH_SIZE lambda expr: expr.rstrip("UL")
+CIRCUITPY_FIRMWARE_SIZE; ///DEFINE_VALUE CIRCUITPY_FIRMWARE_SIZE
CIRCUITPY_DEFAULT_STACK_SIZE; ///DEFINE_VALUE CIRCUITPY_DEFAULT_STACK_SIZE
diff --git a/ports/atmel-samd/mpconfigport.h b/ports/atmel-samd/mpconfigport.h
index 21adb1002..3334ce153 100644
--- a/ports/atmel-samd/mpconfigport.h
+++ b/ports/atmel-samd/mpconfigport.h
@@ -32,10 +32,10 @@
#ifdef SAMD21
-// Default is 0, set by py/circuitpy_mpconfig.h
#if INTERNAL_FLASH_FILESYSTEM
-// 64kB
-#define INTERNAL_FLASH_FILESYSTEM_SIZE (64*1024)
+#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (64*1024)
+#else
+#define CIRCUITPYINTERNAL_FLASH_FILESYSTEM_SIZE (0)
#endif
#ifndef CIRCUITPY_INTERNAL_NVM_SIZE
@@ -86,6 +86,15 @@
#define CIRCUITPY_INTERNAL_NVM_SIZE (8192)
#endif
+// If CIRCUITPY is internal, use half of flash for it.
+#ifndef CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE
+ #if INTERNAL_FLASH_FILESYSTEM
+ #define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (FLASH_SIZE/2)
+ #else
+ #define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (0)
+ #endif
+#endif
+
// HSRAM_SIZE is defined in the ASF4 include files for each SAMD51 chip.
#define RAM_SIZE HSRAM_SIZE
#define BOOTLOADER_SIZE (16*1024)
@@ -104,6 +113,27 @@
#endif // SAMD51
+// Flash layout, starting at 0x00000000
+//
+// bootloader (8 or 16kB)
+// firmware
+// internal config, used to store crystalless clock calibration info (optional)
+// microntroller.nvm (optional)
+// internal CIRCUITPY flash filesystem (optional)
+
+// Bootloader starts at 0x00000000.
+#define CIRCUITPY_FIRMWARE_START_ADDR BOOTLOADER_SIZE
+
+// Total space available for code, after subtracting size of other regions used for non-code.
+#define CIRCUITPY_FIRMWARE_SIZE \
+ (FLASH_SIZE - BOOTLOADER_SIZE - CIRCUITPY_INTERNAL_CONFIG_SIZE - CIRCUITPY_INTERNAL_NVM_SIZE - \
+ CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE)
+
+#define CIRCUITPY_INTERNAL_CONFIG_START_ADDR (CIRCUITPY_FIRMWARE_START_ADDR + CIRCUITPY_FIRMWARE_SIZE)
+#define CIRCUITPY_INTERNAL_NVM_START_ADDR (CIRCUITPY_INTERNAL_CONFIG_START_ADDR + CIRCUITPY_INTERNAL_CONFIG_SIZE)
+#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR \
+ (CIRCUITPY_INTERNAL_NVM_START_ADDR + CIRCUITPY_INTERNAL_NVM_SIZE)
+
// Turning off audioio, audiobusio, and touchio as necessary
// due to limitations of chips is handled in mpconfigboard.mk
diff --git a/ports/atmel-samd/supervisor/internal_flash.c b/ports/atmel-samd/supervisor/internal_flash.c
index 6dd5ac0a7..a8ff5adfa 100644
--- a/ports/atmel-samd/supervisor/internal_flash.c
+++ b/ports/atmel-samd/supervisor/internal_flash.c
@@ -86,7 +86,7 @@ void flash_flush(void) {
static int32_t convert_block_to_flash_addr(uint32_t block) {
if (0 <= block && block < INTERNAL_FLASH_PART1_NUM_BLOCKS) {
// a block in partition 1
- return INTERNAL_FLASH_MEM_SEG1_START_ADDR + block * FILESYSTEM_BLOCK_SIZE;
+ return CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR + block * FILESYSTEM_BLOCK_SIZE;
}
// bad block
return -1;
diff --git a/ports/atmel-samd/supervisor/internal_flash.h b/ports/atmel-samd/supervisor/internal_flash.h
index 0939a3454..df8b495cc 100644
--- a/ports/atmel-samd/supervisor/internal_flash.h
+++ b/ports/atmel-samd/supervisor/internal_flash.h
@@ -32,16 +32,7 @@
#include "sam.h"
-#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 (FLASH_SIZE - TOTAL_INTERNAL_FLASH_SIZE - CIRCUITPY_INTERNAL_NVM_SIZE)
-#define INTERNAL_FLASH_PART1_NUM_BLOCKS (TOTAL_INTERNAL_FLASH_SIZE / FILESYSTEM_BLOCK_SIZE)
+#define INTERNAL_FLASH_PART1_NUM_BLOCKS (CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE / FILESYSTEM_BLOCK_SIZE)
#define INTERNAL_FLASH_SYSTICK_MASK (0x1ff) // 512ms
#define INTERNAL_FLASH_IDLE_TICK(tick) (((tick) & INTERNAL_FLASH_SYSTICK_MASK) == 2)