Skip to content

Commit c468fa5

Browse files
andryblacksalkinium
authored andcommitted
[rp] Add core support for RP2040 device
1 parent e695e17 commit c468fa5

File tree

19 files changed

+813
-20
lines changed

19 files changed

+813
-20
lines changed

.github/workflows/linux.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ jobs:
225225
- name: Quick compile HAL for Cortex-M Part 1
226226
if: always()
227227
run: |
228-
(cd test/all && python3 run_all.py stm32 sam --quick --split 4 --part 0)
228+
(cd test/all && python3 run_all.py stm32 sam rp --quick --split 4 --part 0)
229229
- name: Upload log artifacts
230230
uses: actions/upload-artifact@v2
231231
with:
@@ -245,7 +245,7 @@ jobs:
245245
- name: Quick compile HAL for Cortex-M Part 2
246246
if: always()
247247
run: |
248-
(cd test/all && python3 run_all.py stm32 sam --quick --split 4 --part 1)
248+
(cd test/all && python3 run_all.py stm32 sam rp --quick --split 4 --part 1)
249249
- name: Upload log artifacts
250250
uses: actions/upload-artifact@v2
251251
with:
@@ -265,7 +265,7 @@ jobs:
265265
- name: Quick compile HAL for Cortex-M Part 3
266266
if: always()
267267
run: |
268-
(cd test/all && python3 run_all.py stm32 sam --quick --split 4 --part 2)
268+
(cd test/all && python3 run_all.py stm32 sam rp --quick --split 4 --part 2)
269269
- name: Upload log artifacts
270270
uses: actions/upload-artifact@v2
271271
with:
@@ -285,7 +285,7 @@ jobs:
285285
- name: Quick compile HAL for Cortex-M Part 4
286286
if: always()
287287
run: |
288-
(cd test/all && python3 run_all.py stm32 sam --quick --split 4 --part 3)
288+
(cd test/all && python3 run_all.py stm32 sam rp --quick --split 4 --part 3)
289289
- name: Upload log artifacts
290290
uses: actions/upload-artifact@v2
291291
with:

repo.lb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class DevicesCache(dict):
8787
"stm32l0", "stm32l1", "stm32l4", "stm32l5",
8888
"at90", "attiny", "atmega",
8989
"samd21", "samg55", "samv70",
90+
"rp2040",
9091
"hosted"]
9192
device_file_names = [dfn for dfn in device_file_names if any(s in dfn for s in supported)]
9293
# These files are ignored due to various issues
@@ -178,7 +179,7 @@ class TargetOption(EnumerationOption):
178179
targets = self._enumeration.keys()
179180

180181
# check if input string is part of keys OR longer
181-
while(len(target) > len("attiny4-")):
182+
while(len(target) >= len("rp2040")):
182183
if target in targets:
183184
target = self._enumeration[target]
184185
target._identifier.set("revision", revision.lower())

src/modm/platform/clock/systick/module.lb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ def build(env):
4646
# H742/43: Prescaler not implemented in revY
4747
elif target.family == "h7" and target.name in ["42", "43", "50", "53"] and target.revision == "y":
4848
div = 1
49+
# RP2040 external reference clock need additional configuration
50+
elif target.platform == "rp":
51+
div = 1
4952

5053
env.substitutions = {
5154
"systick_frequency": env.get(":freertos:frequency", freq),

src/modm/platform/core/cortex/atomic_lock_impl.hpp.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,18 @@
1616

1717
#include "../device.hpp"
1818
#include <modm/architecture/utils.hpp>
19+
%% if with_multicore
20+
#include "multicore.hpp"
21+
%% endif
1922

2023
/// @cond
2124
namespace modm::atomic
2225
{
2326

2427
class Lock
28+
%% if with_multicore
29+
: public modm::platform::multicore::CoreLock
30+
%% endif
2531
{
2632
public:
2733
modm_always_inline

src/modm/platform/core/cortex/linker.macros

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,20 @@ MAIN_STACK_SIZE = {{ options[":platform:cortex-m:main_stack_size"] }};
6969
%% endmacro
7070

7171

72-
%% macro section_stack(memory, start=None)
73-
/* Main stack in {{memory}} */
74-
.stack (NOLOAD) :
72+
%% macro section_stack(memory, start=None, suffix="")
73+
/* Main stack{{suffix}} in {{memory}} */
74+
.stack{{suffix}} (NOLOAD) :
7575
{
7676
%% if start != None
77-
. += {{ start }};
77+
. += {{start}};
7878
%% endif
79-
__stack_start = .;
79+
__stack{{suffix}}_start = .;
8080

8181
. += MAIN_STACK_SIZE;
8282
. = ALIGN(8);
83-
__main_stack_top = .;
83+
__main{{suffix}}_stack_top = .;
8484

85-
__stack_end = .;
85+
__stack{{suffix}}_end = .;
8686
} >{{memory}}
8787
%% endmacro
8888

src/modm/platform/core/cortex/module.lb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ def build(env):
286286
"with_memory_traits": env.has_module(":architecture:memory"),
287287
"with_assert": env.has_module(":architecture:assert"),
288288
"with_fpu": env.get("float-abi", "soft") != "soft",
289+
"with_multicore": env.has_module(":platform:multicore"),
289290
})
290291
env.outbasepath = "modm/src/modm/platform/core"
291292

src/modm/platform/core/cortex/module.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,9 @@ The following macros are available:
142142
- `section_load(memory, table_copy, sections)`: place each `.{section}` in
143143
`sections` into `memory` and add them the copy table.
144144
145-
- `section_stack(memory, start=None)`: place the main stack into `memory` after
146-
moving the location counter to `start`.
145+
- `section_stack(memory, start=None, suffix="")`: place the main stack into
146+
`memory` after moving the location counter to `start`. `suffix` can be used
147+
to add multiple `.stack{suffix}` sections.
147148
148149
- `section_heap(memory, name, placement=None, sections=[])`: Add the noload
149150
`sections` to `memory` and fill up remaining space in `memory` with heap

src/modm/platform/core/rp/flash.ld.in

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
%% import "../cortex/linker.macros" as linker with context
2+
{{ linker.copyright() }}
3+
4+
{{ linker.prefix() }}
5+
%% set table_heap = []
6+
%% set table_copy = []
7+
%% set table_zero = []
8+
9+
SECTIONS
10+
{
11+
{{ linker.section_rom_start("FLASH") }}
12+
13+
.boot2 :
14+
{
15+
__boot2_start__ = .;
16+
KEEP (*(.boot2))
17+
__boot2_end__ = .;
18+
} > FLASH
19+
ASSERT(__boot2_end__ - __boot2_start__ == 256,
20+
"ERROR: Pico second stage bootloader must be 256 bytes in size!")
21+
22+
.text :
23+
{
24+
__vector_table_rom_start = .;
25+
__vector_table_ram_load = .;
26+
KEEP(*(.vector_rom))
27+
__vector_table_rom_end = .;
28+
} > FLASH
29+
30+
{{ linker.section_rom("FLASH") }}
31+
32+
33+
%% if vector_table_location == "ram"
34+
{{ linker.section_vector_ram("RAM", table_copy) }}
35+
%% endif
36+
37+
{{ linker.section_ram(cont_ram_regions[0].cont_name|upper, "FLASH", table_copy, table_zero,
38+
sections_data=["fastdata", "fastcode", "data_" + cont_ram_regions[0].contains[0].name],
39+
sections_bss=["bss_" + cont_ram_regions[0].contains[0].name],
40+
sections_noinit=["faststack"]) }}
41+
42+
{{ linker.all_heap_sections(table_copy, table_zero, table_heap) }}
43+
44+
%% if with_crashcatcher
45+
%#
46+
/* Bottom of crash stack for `modm:platform:fault` */
47+
g_crashCatcherStack = . - 500;
48+
%#
49+
%% endif
50+
51+
%% macro section_mem_bank(memory, section, alt_name)
52+
/* Sections in {{memory}} */
53+
.data_{{memory | lower}} :
54+
{
55+
__{{section}}_data_load = LOADADDR(.data_{{memory | lower}});
56+
__{{section}}_data_start = .;
57+
*(.data_{{section}} .data_{{section}}.*)
58+
*(.{{alt_name}})
59+
. = ALIGN(4);
60+
__{{section}}_data_end = .;
61+
} >{{memory}} AT > FLASH
62+
%% do table_copy.append(section + "_data")
63+
%#
64+
.bss_{{memory | lower}} (NOLOAD) :
65+
{
66+
__{{section}}_bss_start = . ;
67+
*(.bss_{{section}} .bss_{{section}}.*)
68+
. = ALIGN(4);
69+
__{{section}}_bss_end = . ;
70+
} >{{memory}}
71+
%% do table_zero.append(section + "_bss")
72+
%#
73+
.noinit_{{memory | lower}} (NOLOAD) :
74+
{
75+
__{{section}}_noinit_start = . ;
76+
*(.noinit_{{section}} .noinit_{{section}}.*)
77+
. = ALIGN(4);
78+
__{{section}}_noinit_end = . ;
79+
} >{{memory}}
80+
%% endmacro
81+
82+
%% if with_multicore
83+
{{ linker.section_stack("CORE1", suffix="1") }}
84+
%% endif
85+
{{ section_mem_bank("CORE1", "core1", "scratch_x") }}
86+
87+
88+
{{ linker.section_stack("CORE0") }}
89+
90+
{{ section_mem_bank("CORE0", "core0", "scratch_y") }}
91+
92+
%% if linkerscript_sections
93+
{{ linkerscript_sections | indent(first=True) }}
94+
%#
95+
%% endif
96+
97+
{{ linker.section_tables("FLASH", table_copy, table_zero, table_heap) }}
98+
99+
{{ linker.section_rom_end("FLASH") }}
100+
101+
{{ linker.section_debug() }}
102+
}

src/modm/platform/core/rp/module.lb

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Copyright (c) 2019, Ethan Slattery
5+
# Copyright (c) 2021, Niklas Hauser
6+
# Copyright (c) 2022, Andrey Kunitsyn
7+
#
8+
# This file is part of the modm project.
9+
#
10+
# This Source Code Form is subject to the terms of the Mozilla Public
11+
# License, v. 2.0. If a copy of the MPL was not distributed with this
12+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
13+
# -----------------------------------------------------------------------------
14+
15+
import math
16+
17+
def init(module):
18+
module.name = ":platform:core"
19+
module.description = FileReader("module.md")
20+
21+
def prepare(module, options):
22+
if options[":target"].identifier.platform != "rp":
23+
return False
24+
25+
module.depends(":platform:cortex-m")
26+
module.add_option(
27+
EnumerationOption(
28+
name="boot2",
29+
description="Second-stage bootloader variant",
30+
enumeration=["generic_03h", "at25sf128a", "is25lp080", "w25q080", "w25x10cl"],
31+
default="generic_03h"))
32+
return True
33+
34+
35+
def build(env):
36+
target = env[":target"].identifier
37+
38+
env.substitutions = {"with_multicore": env.has_module(":platform:multicore")}
39+
env.outbasepath = "modm/src/modm/platform/core"
40+
# startup helper code
41+
env.template("startup_platform.cpp.in")
42+
43+
# delay code that must be tuned for each family
44+
# (cycles per loop, setup cost in loops, max CPU freq)
45+
tuning = {
46+
"20": (3, 4, 133000000)
47+
}[target.family]
48+
49+
# us_shift is an optimization to limit error via fractional math
50+
us_shift = 32 - math.ceil(math.log2(tuning[2]))
51+
52+
env.substitutions.update({
53+
"with_cm0": env[":target"].has_driver("core:cortex-m0*"),
54+
"with_cm7": env[":target"].has_driver("core:cortex-m7*"),
55+
"loop": tuning[0],
56+
"shift": int(math.log2(tuning[1])),
57+
"us_shift": us_shift,
58+
"with_assert": env.has_module(":architecture:assert")
59+
})
60+
env.template("../cortex/delay_ns.cpp.in", "delay_ns.cpp")
61+
env.template("../cortex/delay_ns.hpp.in", "delay_ns.hpp")
62+
env.template("../cortex/delay_impl.hpp.in", "delay_impl.hpp")
63+
env.copy("resets.hpp")
64+
65+
env.copy(repopath("ext/rp/pico-sdk/src/boot2_{}.cpp".format(env["boot2"])),"boot2.cpp")
66+
67+
68+
def post_build(env):
69+
env.substitutions = env.query("::cortex-m:linkerscript")
70+
env.substitutions.update(env.query("::cortex-m:vector_table"))
71+
env.substitutions["with_multicore"] = env.has_module(":platform:multicore")
72+
env.outbasepath = "modm/link"
73+
env.template("flash.ld.in", "linkerscript.ld")

0 commit comments

Comments
 (0)