Skip to content

Commit 1505da7

Browse files
committed
wip
1 parent 7b79ac3 commit 1505da7

7 files changed

Lines changed: 41 additions & 33 deletions

File tree

ports/atmel-samd/boards/common.template.ld

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,7 @@
33
/* Specify the memory areas */
44
MEMORY
55
{
6-
/* CIRCUITPY_BOOTLOADER_SIZE is size of bootloader, if any.
7-
* SAMD21 Arduino and UF2 bootloaders are 8KiB. SAMD51 UF2 is 6KiB.
8-
* FLASH_SIZE is defined in ASF4.
9-
* RAM_SIZE is defined in mpconfigport.h, from constants from ASF4.
10-
* CIRCUITPY_INTERNAL_CONFIG_SIZE is size of an optional hidden config area, used currently
11-
* for crystalless USB timing calibration.
12-
* CIRCUITPY_INTERNAL_NVM_SIZE is the size of microntroller.nvm.
13-
*/
14-
FLASH (rx) : ORIGIN = 0x00000000 + ${BOOTLOADER_SIZE}, LENGTH = ${FLASH_SIZE} - ${BOOTLOADER_SIZE} - ${CIRCUITPY_INTERNAL_CONFIG_SIZE} - ${CIRCUITPY_INTERNAL_NVM_SIZE}
6+
FLASH (rx) : ORIGIN = 0x00000000 + ${BOOTLOADER_SIZE}, LENGTH = ${CIRCUITPY_FIRMWARE_SIZE}
157
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = ${RAM_SIZE}
168
}
179

ports/atmel-samd/boards/sam32/mpconfigboard.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#define MICROPY_PORT_A (PORT_PA24 | PORT_PA25)
1010
#define MICROPY_PORT_B (0)
1111
#define MICROPY_PORT_C (0)
12-
#define MICROPY_PORT_D (0)
12+
#define MICROPY_PORT_D (0)
1313

1414
// No microcontroller.nvm
1515
#define CIRCUITPY_INTERNAL_NVM_SIZE 0

ports/atmel-samd/ld_defines.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
// This will be post-processed by tools/gen_ld_files.py to extract the name and vlaue.
88

99
BOOTLOADER_SIZE; ///DEFINE_VALUE BOOTLOADER_SIZE
10-
RAM_SIZE; ///DEFINE_VALUE RAM_SIZE lambda f: f.rstrip("UL")
11-
FLASH_SIZE; ///DEFINE_VALUE FLASH_SIZE lambda f: f.rstrip("UL")
12-
CIRCUITPY_INTERNAL_CONFIG_SIZE; ///DEFINE_VALUE CIRCUITPY_INTERNAL_CONFIG_SIZE
13-
CIRCUITPY_INTERNAL_NVM_SIZE; ///DEFINE_VALUE CIRCUITPY_INTERNAL_NVM_SIZE
10+
RAM_SIZE; ///DEFINE_VALUE RAM_SIZE def noUL(expr): import re; return re.sub(
11+
FLASH_SIZE; ///DEFINE_VALUE FLASH_SIZE lambda expr: expr.rstrip("UL")
12+
CIRCUITPY_FIRMWARE_SIZE; ///DEFINE_VALUE CIRCUITPY_FIRMWARE_SIZE
1413
CIRCUITPY_DEFAULT_STACK_SIZE; ///DEFINE_VALUE CIRCUITPY_DEFAULT_STACK_SIZE

ports/atmel-samd/mpconfigport.h

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232

3333
#ifdef SAMD21
3434

35-
// Default is 0, set by py/circuitpy_mpconfig.h
3635
#if INTERNAL_FLASH_FILESYSTEM
37-
// 64kB
38-
#define INTERNAL_FLASH_FILESYSTEM_SIZE (64*1024)
36+
#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (64*1024)
37+
#else
38+
#define CIRCUITPYINTERNAL_FLASH_FILESYSTEM_SIZE (0)
3939
#endif
4040

4141
#ifndef CIRCUITPY_INTERNAL_NVM_SIZE
@@ -86,6 +86,15 @@
8686
#define CIRCUITPY_INTERNAL_NVM_SIZE (8192)
8787
#endif
8888

89+
// If CIRCUITPY is internal, use half of flash for it.
90+
#ifndef CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE
91+
#if INTERNAL_FLASH_FILESYSTEM
92+
#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (FLASH_SIZE/2)
93+
#else
94+
#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (0)
95+
#endif
96+
#endif
97+
8998
// HSRAM_SIZE is defined in the ASF4 include files for each SAMD51 chip.
9099
#define RAM_SIZE HSRAM_SIZE
91100
#define BOOTLOADER_SIZE (16*1024)
@@ -104,6 +113,27 @@
104113

105114
#endif // SAMD51
106115

116+
// Flash layout, starting at 0x00000000
117+
//
118+
// bootloader (8 or 16kB)
119+
// firmware
120+
// internal config, used to store crystalless clock calibration info (optional)
121+
// microntroller.nvm (optional)
122+
// internal CIRCUITPY flash filesystem (optional)
123+
124+
// Bootloader starts at 0x00000000.
125+
#define CIRCUITPY_FIRMWARE_START_ADDR BOOTLOADER_SIZE
126+
127+
// Total space available for code, after subtracting size of other regions used for non-code.
128+
#define CIRCUITPY_FIRMWARE_SIZE \
129+
(FLASH_SIZE - BOOTLOADER_SIZE - CIRCUITPY_INTERNAL_CONFIG_SIZE - CIRCUITPY_INTERNAL_NVM_SIZE - \
130+
CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE)
131+
132+
#define CIRCUITPY_INTERNAL_CONFIG_START_ADDR (CIRCUITPY_FIRMWARE_START_ADDR + CIRCUITPY_FIRMWARE_SIZE)
133+
#define CIRCUITPY_INTERNAL_NVM_START_ADDR (CIRCUITPY_INTERNAL_CONFIG_START_ADDR + CIRCUITPY_INTERNAL_CONFIG_SIZE)
134+
#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR \
135+
(CIRCUITPY_INTERNAL_NVM_START_ADDR + CIRCUITPY_INTERNAL_NVM_SIZE)
136+
107137
// Turning off audioio, audiobusio, and touchio as necessary
108138
// due to limitations of chips is handled in mpconfigboard.mk
109139

ports/atmel-samd/supervisor/internal_flash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void flash_flush(void) {
8686
static int32_t convert_block_to_flash_addr(uint32_t block) {
8787
if (0 <= block && block < INTERNAL_FLASH_PART1_NUM_BLOCKS) {
8888
// a block in partition 1
89-
return INTERNAL_FLASH_MEM_SEG1_START_ADDR + block * FILESYSTEM_BLOCK_SIZE;
89+
return CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR + block * FILESYSTEM_BLOCK_SIZE;
9090
}
9191
// bad block
9292
return -1;

ports/atmel-samd/supervisor/internal_flash.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,7 @@
3232

3333
#include "sam.h"
3434

35-
#ifdef SAMD51
36-
#define TOTAL_INTERNAL_FLASH_SIZE (FLASH_SIZE / 2)
37-
#endif
38-
39-
#ifdef SAMD21
40-
#define TOTAL_INTERNAL_FLASH_SIZE 0x010000
41-
#endif
42-
43-
#define INTERNAL_FLASH_MEM_SEG1_START_ADDR (FLASH_SIZE - TOTAL_INTERNAL_FLASH_SIZE - CIRCUITPY_INTERNAL_NVM_SIZE)
44-
#define INTERNAL_FLASH_PART1_NUM_BLOCKS (TOTAL_INTERNAL_FLASH_SIZE / FILESYSTEM_BLOCK_SIZE)
35+
#define INTERNAL_FLASH_PART1_NUM_BLOCKS (CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE / FILESYSTEM_BLOCK_SIZE)
4536

4637
#define INTERNAL_FLASH_SYSTICK_MASK (0x1ff) // 512ms
4738
#define INTERNAL_FLASH_IDLE_TICK(tick) (((tick) & INTERNAL_FLASH_SYSTICK_MASK) == 2)

py/circuitpy_mpconfig.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ typedef long mp_off_t;
167167
#define mp_import_stat mp_vfs_import_stat
168168
#define mp_builtin_open_obj mp_vfs_open_obj
169169

170+
170171
// extra built in names to add to the global namespace
171172
#define MICROPY_PORT_BUILTINS \
172173
{ MP_OBJ_NEW_QSTR(MP_QSTR_help), (mp_obj_t)&mp_builtin_help_obj }, \
@@ -669,11 +670,6 @@ void run_background_tasks(void);
669670
#define CIRCUITPY_FILESYSTEM_FLUSH_INTERVAL_MS 1000
670671
#endif
671672

672-
// Default is no internal flash filesystem.
673-
#ifndef INTERNAL_FLASH_FILESYSTEM_SIZE
674-
#define INTERNAL_FLASH_FILESYSTEM_SIZE (0)
675-
#endif
676-
677673
#define CIRCUITPY_BOOT_OUTPUT_FILE "/boot_out.txt"
678674

679675
#endif // __INCLUDED_MPCONFIG_CIRCUITPY_H

0 commit comments

Comments
 (0)