Skip to content

Commit 0b761f6

Browse files
authored
Merge pull request #2404 from hierophect/stm32-meowbit
STM32: Meowbit support
2 parents 5b6b4eb + 1a25d3c commit 0b761f6

File tree

36 files changed

+2233
-46
lines changed

36 files changed

+2233
-46
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ jobs:
170170
- "kicksat-sprite"
171171
- "makerdiary_nrf52840_mdk"
172172
- "makerdiary_nrf52840_mdk_usb_dongle"
173+
- "meowbit_v121"
173174
- "meowmeow"
174175
- "metro_m0_express"
175176
- "metro_m4_airlift_lite"

main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
#include "supervisor/shared/stack.h"
5858
#include "supervisor/serial.h"
5959

60+
#include "boards/board.h"
61+
6062
#if CIRCUITPY_DISPLAYIO
6163
#include "shared-module/displayio/__init__.h"
6264
#endif
@@ -425,6 +427,9 @@ int __attribute__((used)) main(void) {
425427
// no SPI flash filesystem, and we might erase the existing one.
426428
filesystem_init(safe_mode == NO_SAFE_MODE, false);
427429

430+
// displays init after filesystem, since they could share the flash SPI
431+
board_init();
432+
428433
// Reset everything and prep MicroPython to run boot.py.
429434
reset_port();
430435
reset_board();

ports/atmel-samd/supervisor/port.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,6 @@ safe_mode_t port_init(void) {
232232
// Reset everything into a known state before board_init.
233233
reset_port();
234234

235-
// Init the board last so everything else is ready
236-
board_init();
237-
238235
#ifdef SAMD21
239236
if (PM->RCAUSE.bit.BOD33 == 1 || PM->RCAUSE.bit.BOD12 == 1) {
240237
return BROWNOUT;

ports/mimxrt10xx/supervisor/port.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,6 @@ safe_mode_t port_init(void) {
256256
// Reset everything into a known state before board_init.
257257
reset_port();
258258

259-
// Init the board last so everything else is ready
260-
board_init();
261-
262259
if (board_requests_safe_mode()) {
263260
return USER_SAFE_MODE;
264261
}

ports/nrf/supervisor/port.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,6 @@ safe_mode_t port_init(void) {
9292
rtc_init();
9393
#endif
9494

95-
// Will do usb_init() if chip supports USB.
96-
board_init();
97-
9895
return NO_SAFE_MODE;
9996
}
10097

ports/stm32f4/Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2323
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2424
# THE SOFTWARE.
25-
DEBUG = 1
25+
# DEBUG = 1
2626

2727
# Select the board to build for.
2828
ifeq ($(BOARD),)
@@ -85,10 +85,15 @@ ifeq ($(DEBUG), 1)
8585
CFLAGS += -fno-inline -fno-ipa-sra
8686
else
8787
CFLAGS += -Os -DNDEBUG
88+
CFLAGS += -ggdb
8889
# TODO: Test with -flto
8990
### CFLAGS += -flto
9091
endif
9192

93+
ifndef BOOTLOADER_OFFSET
94+
BOOTLOADER_OFFSET := 0x8000000
95+
endif
96+
9297
C_DEFS = -DMCU_PACKAGE=$(MCU_PACKAGE) -DUSE_HAL_DRIVER -DUSE_FULL_LL_DRIVER -D$(CMSIS_MCU)
9398

9499
CFLAGS += $(INC) -Werror -Wall -std=gnu11 -nostdlib $(BASE_CFLAGS) $(C_DEFS) $(CFLAGS_MOD) $(COPT)
@@ -256,7 +261,7 @@ $(BUILD)/firmware.hex: $(BUILD)/firmware.elf
256261

257262
$(BUILD)/firmware.uf2: $(BUILD)/firmware.hex
258263
$(ECHO) "Create $@"
259-
$(PYTHON3) $(TOP)/tools/uf2/utils/uf2conv.py -f 0xADA52840 -c -o "$(BUILD)/firmware.uf2" $^
264+
$(PYTHON3) $(TOP)/tools/uf2/utils/uf2conv.py -f 0x57755a57 -b $(BOOTLOADER_OFFSET) -c -o "$(BUILD)/firmware.uf2" $^
260265

261266
include $(TOP)/py/mkrules.mk
262267

ports/stm32f4/boards/STM32F401.ld

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/*
2+
GNU linker script for STM32F401 with bootloader (from Meowbit Micropython)
3+
Doesn't work:
4+
5+
Traceback (most recent call last):
6+
File "../../tools/build_memory_info.py", line 64, in <module>
7+
regions[region] = int(eval(space))
8+
File "<string>", line 1, in <module>
9+
NameError: name 'FLASH_ISR' is not defined
10+
*/
11+
12+
/* Specify the memory areas */
13+
/* FLASH_FS (rx) : ORIGIN = 0x08020000, LENGTH = 128K */
14+
/* sectors 5 128K */
15+
MEMORY
16+
{
17+
FLASH (rx) : ORIGIN = 0x08010000, LENGTH = 512K - 64K /* entire flash */
18+
FLASH_ISR (rx) : ORIGIN = 0x08010000, LENGTH = 64K /* sector 4, sec 0~3 reserved for booloader */
19+
FLASH_TEXT (rx) : ORIGIN = 0x08020000, LENGTH = 384K /* sectors 5, 6,7 are 128K */
20+
RAM (xrw) : ORIGIN = 0x20000194, LENGTH = 96K - 0x194
21+
}
22+
23+
/* produce a link error if there is not this amount of RAM for these sections */
24+
_minimum_stack_size = 2K;
25+
_minimum_heap_size = 16K;
26+
27+
/* Define the stack. The stack is full descending so begins just above last byte
28+
of RAM. Note that EABI requires the stack to be 8-byte aligned for a call. */
29+
_estack = ORIGIN(RAM) + LENGTH(RAM) - _estack_reserve;
30+
_sstack = _estack - 16K; /* tunable */
31+
32+
/* RAM extents for the garbage collector */
33+
_ram_start = ORIGIN(RAM);
34+
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
35+
_heap_start = _ebss; /* heap starts just after statically allocated memory */
36+
_heap_end = _sstack;
37+
38+
ENTRY(Reset_Handler)
39+
40+
/* define output sections */
41+
SECTIONS
42+
{
43+
/* The startup code goes first into FLASH */
44+
.isr_vector :
45+
{
46+
. = ALIGN(4);
47+
KEEP(*(.isr_vector)) /* Startup code */
48+
49+
/* This first flash block is 16K annd the isr vectors only take up
50+
about 400 bytes. So we pull in a couple of object files to pad it
51+
out. */
52+
53+
. = ALIGN(4);
54+
55+
/* NOTE: If you update the list of files contained in .isr_vector,
56+
then be sure to also update smhal/Makefile where it forcibly
57+
builds each of these files with -Os */
58+
59+
*/ff.o(.text*)
60+
*/vfs_fat_*.o(.text*)
61+
*/py/formatfloat.o(.text*)
62+
*/py/parsenum.o(.text*)
63+
*/py/mpprint.o(.text*)
64+
65+
*/py/compile.o(.text*)
66+
*/py/objset.o(.text*)
67+
*/py/mpz.o(.text*)
68+
*/py/vm.o(.text*)
69+
70+
. = ALIGN(4);
71+
} >FLASH_ISR
72+
73+
/* The program code and other data goes into FLASH */
74+
.text :
75+
{
76+
. = ALIGN(4);
77+
*(.text*) /* .text* sections (code) */
78+
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
79+
/* *(.glue_7) */ /* glue arm to thumb code */
80+
/* *(.glue_7t) */ /* glue thumb to arm code */
81+
82+
. = ALIGN(4);
83+
_etext = .; /* define a global symbol at end of code */
84+
} >FLASH_TEXT
85+
86+
/* used by the startup to initialize data */
87+
_sidata = LOADADDR(.data);
88+
89+
/* This is the initialized data section
90+
The program executes knowing that the data is in the RAM
91+
but the loader puts the initial values in the FLASH (inidata).
92+
It is one task of the startup to copy the initial values from FLASH to RAM. */
93+
.data :
94+
{
95+
. = ALIGN(4);
96+
_sdata = .; /* create a global symbol at data start; used by startup code in order to initialise the .data section in RAM */
97+
*(.data*) /* .data* sections */
98+
99+
. = ALIGN(4);
100+
_edata = .; /* define a global symbol at data end; used by startup code in order to initialise the .data section in RAM */
101+
} >RAM AT> FLASH_TEXT
102+
103+
/* Uninitialized data section */
104+
.bss :
105+
{
106+
. = ALIGN(4);
107+
_sbss = .; /* define a global symbol at bss start; used by startup code */
108+
*(.bss*)
109+
*(COMMON)
110+
111+
. = ALIGN(4);
112+
_ebss = .; /* define a global symbol at bss end; used by startup code and GC */
113+
} >RAM
114+
115+
/* this is to define the start of the heap, and make sure we have a minimum size */
116+
.heap :
117+
{
118+
. = ALIGN(4);
119+
. = . + _minimum_heap_size;
120+
. = ALIGN(4);
121+
} >RAM
122+
123+
/* this just checks there is enough RAM for the stack */
124+
.stack :
125+
{
126+
. = ALIGN(4);
127+
. = . + _minimum_stack_size;
128+
. = ALIGN(4);
129+
} >RAM
130+
131+
.ARM.attributes 0 : { *(.ARM.attributes) }
132+
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
GNU linker script for STM32F401 with bootloader (such as the Meowbit)
3+
*/
4+
5+
/* Specify the memory areas */
6+
MEMORY
7+
{
8+
FLASH (rx) : ORIGIN = 0x08010000, LENGTH = 512K - 64K /* entire flash */
9+
FLASH_ISR (rx) : ORIGIN = 0x08010000, LENGTH = 64K
10+
FLASH_TEXT (rx) : ORIGIN = 0x08020000, LENGTH = 384K /* sector 4 is 64K, sectors 5,6,7 are 128K */
11+
RAM (xrw) : ORIGIN = 0x20000194, LENGTH = 96K - 0x194
12+
}
13+
14+
/* produce a link error if there is not this amount of RAM for these sections */
15+
_minimum_stack_size = 2K;
16+
_minimum_heap_size = 16K;
17+
18+
/* Define tho top end of the stack. The stack is full descending so begins just
19+
above last byte of RAM. Note that EABI requires the stack to be 8-byte
20+
aligned for a call. */
21+
_estack = ORIGIN(RAM) + LENGTH(RAM);
22+
23+
/* RAM extents for the garbage collector */
24+
_ram_start = ORIGIN(RAM);
25+
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
26+
27+
ENTRY(Reset_Handler)
28+
29+
/* define output sections */
30+
SECTIONS
31+
{
32+
/* The startup code goes first into FLASH */
33+
.isr_vector :
34+
{
35+
. = ALIGN(4);
36+
KEEP(*(.isr_vector)) /* Startup code */
37+
38+
/* This first flash block is 16K annd the isr vectors only take up
39+
about 400 bytes. Micropython pads this with files, but this didn't
40+
work with the size of Circuitpython's ff object. */
41+
42+
. = ALIGN(4);
43+
} >FLASH_ISR
44+
45+
/* The program code and other data goes into FLASH */
46+
.text :
47+
{
48+
. = ALIGN(4);
49+
*(.text*) /* .text* sections (code) */
50+
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
51+
/* *(.glue_7) */ /* glue arm to thumb code */
52+
/* *(.glue_7t) */ /* glue thumb to arm code */
53+
54+
. = ALIGN(4);
55+
_etext = .; /* define a global symbol at end of code */
56+
} >FLASH_TEXT
57+
58+
/* used by the startup to initialize data */
59+
_sidata = LOADADDR(.data);
60+
61+
/* This is the initialized data section
62+
The program executes knowing that the data is in the RAM
63+
but the loader puts the initial values in the FLASH (inidata).
64+
It is one task of the startup to copy the initial values from FLASH to RAM. */
65+
.data :
66+
{
67+
. = ALIGN(4);
68+
_sdata = .; /* create a global symbol at data start; used by startup code in order to initialise the .data section in RAM */
69+
*(.data*) /* .data* sections */
70+
71+
. = ALIGN(4);
72+
_edata = .; /* define a global symbol at data end; used by startup code in order to initialise the .data section in RAM */
73+
} >RAM AT> FLASH_TEXT
74+
75+
/* Uninitialized data section */
76+
.bss :
77+
{
78+
. = ALIGN(4);
79+
_sbss = .; /* define a global symbol at bss start; used by startup code */
80+
*(.bss*)
81+
*(COMMON)
82+
83+
. = ALIGN(4);
84+
_ebss = .; /* define a global symbol at bss end; used by startup code and GC */
85+
} >RAM
86+
87+
/* this is to define the start of the heap, and make sure we have a minimum size */
88+
.heap :
89+
{
90+
. = ALIGN(4);
91+
. = . + _minimum_heap_size;
92+
. = ALIGN(4);
93+
} >RAM
94+
95+
/* this just checks there is enough RAM for the stack */
96+
.stack :
97+
{
98+
. = ALIGN(4);
99+
. = . + _minimum_stack_size;
100+
. = ALIGN(4);
101+
} >RAM
102+
103+
.ARM.attributes 0 : { *(.ARM.attributes) }
104+
}
105+
106+

0 commit comments

Comments
 (0)