Skip to content

Commit a5ba689

Browse files
Initial commit pulled in a bunch of stuff - see description
* Add `PICO_MINIMAL_STORED_VECTOR_TABLE` config replacing (`PICO_NO_STORED_VECTOR_TABLE` which was a lie * Add `PICO_NUM_VTABLE_IRQS`` which allows you to limit the number of IRQs included in both the STORED or RAM vector tables, and make the rest of the SDK behave properly based on that * Because these new variables in `pico_crt0` are circularly dependent somewhat with variables in `hardware_irq` hoist all the interdependent variables into a new `pico_platform_common` which is common to all `rp2` platforms * Move some previously duplicated `pico_platform` code into `pico_platform_common` Net effect: 1. if you set PICO_MINIMAL_STORED_VECTOR_TABLE=1, you get a 4 word VTABLE on Arm.. you still get a RAM vector table with up to PICO_NUM_VTABLE_IRQs (defaults to NUM_IRQs) but everything - including things like `isr_pendsv` point to `__unhandled_user_irq`. 2. PICO_NUM_VTABLE_IRQs (default NUM_IRQS) sets the number of IRQs that have handlers in the VTABLE (this affects the space reserved, and what the irq APIs let you touch - at least as far as invalid_params_if!) 3. If you set PICO_MINIMAL_STORED_VECTOR_TABLE=1 for a no flash binary, then PICO_NUM_VTABLE_IRQs is forced to 0 as there is no reserved space for the handlers. Co-authored-by: graham sanderson <graham.sanderson@raspberrypi.com>
1 parent 39fafaa commit a5ba689

File tree

23 files changed

+283
-264
lines changed

23 files changed

+283
-264
lines changed

src/cmake/rp2_common.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ endif()
8282

8383
# Basic bootrom headers
8484
pico_add_subdirectory(rp2_common/boot_bootrom_headers)
85+
pico_add_subdirectory(rp2_common/pico_platform_common)
8586
pico_add_subdirectory(rp2_common/pico_platform_compiler)
8687
pico_add_subdirectory(rp2_common/pico_platform_sections)
8788
pico_add_subdirectory(rp2_common/pico_platform_panic)

src/common/pico_base_headers/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ cc_library(
112112
"//src/rp2_common/hardware_watchdog:__pkg__",
113113
"//src/rp2_common/hardware_xosc:__pkg__",
114114
"//src/rp2_common/pico_crt0:__pkg__",
115+
"//src/rp2_common/pico_platform_common:__pkg__",
115116
"//src/rp2_common/pico_printf:__pkg__",
116117
"//src/rp2_common/pico_runtime:__pkg__",
117118
"//src/rp2_common/pico_runtime_init:__pkg__",

src/host/hardware_irq/include/hardware/irq.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ extern "C" {
128128
typedef void (*irq_handler_t)(void);
129129

130130
static inline void check_irq_param(__unused uint num) {
131-
invalid_params_if(HARDWARE_IRQ, num >= NUM_IRQS);
131+
invalid_params_if(HARDWARE_IRQ, num >= PICO_NUM_VTABLE_IRQS);
132132
}
133133

134134
/*! \brief Set specified interrupt's priority

src/host/hardware_irq/irq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void PICO_WEAK_FUNCTION_IMPL_NAME(irq_init_priorities)() {
9696
}
9797

9898
static uint get_user_irq_claim_index(uint irq_num) {
99-
invalid_params_if(HARDWARE_IRQ, irq_num < FIRST_USER_IRQ || irq_num >= NUM_IRQS);
99+
invalid_params_if(HARDWARE_IRQ, irq_num < FIRST_USER_IRQ || irq_num >= PICO_NUM_VTABLE_IRQS);
100100
// we count backwards from the last, to match the existing hard coded uses of user IRQs in the SDK which were previously using 31
101101
static_assert(NUM_IRQS - FIRST_USER_IRQ <= 8, ""); // we only use a single byte's worth of claim bits today.
102102
return NUM_IRQS - irq_num - 1u;

src/rp2040/pico_platform/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ cc_library(
2727
deps = [
2828
"//src/rp2040/hardware_regs",
2929
"//src/rp2040/hardware_regs:platform_defs",
30+
"//src/rp2_common/pico_platform_common:pico_platform_common_headers",
3031
"//src/rp2_common/pico_platform_compiler",
3132
"//src/rp2_common/pico_platform_panic:pico_platform_panic_headers",
3233
"//src/rp2_common/pico_platform_sections",
@@ -44,6 +45,7 @@ cc_library(
4445
"//src/rp2040/hardware_regs",
4546
"//src/rp2040/hardware_regs:platform_defs",
4647
"//src/rp2_common/hardware_base",
48+
"//src/rp2_common/pico_platform_common",
4749
"//src/rp2_common/pico_platform_compiler",
4850
"//src/rp2_common/pico_platform_panic",
4951
"//src/rp2_common/pico_platform_sections",

src/rp2040/pico_platform/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ if (NOT TARGET pico_platform)
1717

1818
target_link_libraries(pico_platform_headers INTERFACE hardware_regs)
1919
pico_mirrored_target_link_libraries(pico_platform INTERFACE
20+
pico_platform_common
2021
pico_platform_compiler
2122
pico_platform_panic
2223
pico_platform_sections

src/rp2040/pico_platform/include/pico/platform.h

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "pico/platform/compiler.h"
2424
#include "pico/platform/sections.h"
2525
#include "pico/platform/panic.h"
26+
#include "pico/platform/common.h"
2627
#include "hardware/regs/addressmap.h"
2728
#include "hardware/regs/sio.h"
2829

@@ -66,10 +67,6 @@
6667
#define PICO_RP2040_B2_SUPPORTED 1
6768
#endif
6869

69-
#ifndef PICO_RAM_VECTOR_TABLE_SIZE
70-
#define PICO_RAM_VECTOR_TABLE_SIZE (VTABLE_FIRST_IRQ + NUM_IRQS)
71-
#endif
72-
7370
// PICO_CONFIG: PICO_CLKDIV_ROUND_NEAREST, True if floating point clock divisors should be rounded to the nearest possible clock divisor by default rather than rounding down, type=bool, default=1, group=pico_platform
7471
#ifndef PICO_CLKDIV_ROUND_NEAREST
7572
#define PICO_CLKDIV_ROUND_NEAREST 1
@@ -80,16 +77,6 @@
8077
#ifdef __cplusplus
8178
extern "C" {
8279
#endif
83-
84-
/*! \brief No-op function for the body of tight loops
85-
* \ingroup pico_platform
86-
*
87-
* No-op function intended to be called by any tight hardware polling loop. Using this ubiquitously
88-
* makes it much easier to find tight loops, but also in the future \#ifdef-ed support for lockup
89-
* debugging might be added
90-
*/
91-
static __force_inline void tight_loop_contents(void) {}
92-
9380
/*! \brief Helper method to busy-wait for at least the given number of cycles
9481
* \ingroup pico_platform
9582
*
@@ -112,17 +99,6 @@ static inline void busy_wait_at_least_cycles(uint32_t minimum_cycles) {
11299
);
113100
}
114101

115-
// PICO_CONFIG: PICO_NO_FPGA_CHECK, Remove the FPGA platform check for small code size reduction, type=bool, default=1, advanced=true, group=pico_runtime
116-
#ifndef PICO_NO_FPGA_CHECK
117-
#define PICO_NO_FPGA_CHECK 1
118-
#endif
119-
120-
#if PICO_NO_FPGA_CHECK
121-
static inline bool running_on_fpga(void) {return false;}
122-
#else
123-
bool running_on_fpga(void);
124-
#endif
125-
126102
/*! \brief Execute a breakpoint instruction
127103
* \ingroup pico_platform
128104
*/
@@ -158,9 +134,6 @@ static __force_inline uint __get_current_exception(void) {
158134
return exception;
159135
}
160136

161-
#define host_safe_hw_ptr(x) ((uintptr_t)(x))
162-
#define native_safe_hw_ptr(x) host_safe_hw_ptr(x)
163-
164137
/*! \brief Returns the RP2040 chip revision number
165138
* \ingroup pico_platform
166139
* @return the RP2040 chip revision number (1 for B0/B1, 2 for B2)

src/rp2040/pico_platform/platform.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,8 @@
66

77
#include "pico.h"
88
#include "hardware/address_mapped.h"
9-
#include "hardware/regs/tbman.h"
109
#include "hardware/regs/sysinfo.h"
1110

12-
// Note we leave the FPGA check in by default so that we can run bug repro
13-
// binaries coming in from the wild on the FPGA platform. It takes up around
14-
// 48 bytes if you include all the calls, so you can pass PICO_NO_FPGA_CHECK=1
15-
// to remove it. The FPGA check is used to skip initialisation of hardware
16-
// (mainly clock generators and oscillators) that aren't present on FPGA.
17-
18-
#if !PICO_NO_FPGA_CHECK
19-
// Inline stub provided in header if this code is unused (so folding can be
20-
// done in each TU instead of relying on LTO)
21-
bool running_on_fpga(void) {
22-
return (*(io_ro_32 *)TBMAN_BASE) & TBMAN_PLATFORM_FPGA_BITS;
23-
}
24-
#endif
25-
2611
#define MANUFACTURER_RPI 0x927
2712
#define PART_RP2 0x2
2813

src/rp2350/pico_platform/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ cc_library(
2727
deps = [
2828
"//src/rp2350/hardware_regs",
2929
"//src/rp2350/hardware_regs:platform_defs",
30+
"//src/rp2_common/pico_platform_common:pico_platform_common_headers",
3031
"//src/rp2_common/pico_platform_compiler",
3132
"//src/rp2_common/pico_platform_panic:pico_platform_panic_headers",
3233
"//src/rp2_common/pico_platform_sections",
@@ -44,6 +45,7 @@ cc_library(
4445
"//src/rp2350/hardware_regs",
4546
"//src/rp2350/hardware_regs:platform_defs",
4647
"//src/rp2_common/hardware_base",
48+
"//src/rp2_common/pico_platform_common",
4749
"//src/rp2_common/pico_platform_compiler",
4850
"//src/rp2_common/pico_platform_panic",
4951
"//src/rp2_common/pico_platform_sections",

src/rp2350/pico_platform/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ if (NOT TARGET pico_platform)
2323
hardware_regs
2424
)
2525
pico_mirrored_target_link_libraries(pico_platform INTERFACE
26+
pico_platform_common
2627
pico_platform_compiler
2728
pico_platform_panic
2829
pico_platform_sections

src/rp2350/pico_platform/include/pico/platform.h

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@
2323
#include "pico/platform/compiler.h"
2424
#include "pico/platform/sections.h"
2525
#include "pico/platform/panic.h"
26+
#include "pico/platform/common.h"
2627
#include "hardware/regs/addressmap.h"
2728
#include "hardware/regs/sio.h"
2829
#ifdef __riscv
2930
#include "hardware/regs/rvcsr.h"
3031
#endif
3132

32-
// PICO_CONFIG: PICO_RP2350A, Whether the current board has an RP2350 in an A (30 GPIO) package, type=bool, default=Usually provided via board header, group=pico_platform
33+
// PICO_CONFIG: PICO_RP2350A, Whether the current board has an RP2350 in an A (30 GPIO) package - set to 0 for RP2350 in a B (48 GPIO) package, type=bool, default=Usually provided via board header, group=pico_platform
3334
#if 0 // make tooling checks happy
3435
#define PICO_RP2350A 0
3536
#endif
@@ -54,10 +55,6 @@
5455
#define PICO_NO_RAM_VECTOR_TABLE 0
5556
#endif
5657

57-
#ifndef PICO_RAM_VECTOR_TABLE_SIZE
58-
#define PICO_RAM_VECTOR_TABLE_SIZE (VTABLE_FIRST_IRQ + NUM_IRQS)
59-
#endif
60-
6158
// PICO_CONFIG: PICO_USE_STACK_GUARDS, Enable/disable stack guards, type=bool, default=0, advanced=true, group=pico_platform
6259
#ifndef PICO_USE_STACK_GUARDS
6360
#define PICO_USE_STACK_GUARDS 0
@@ -73,16 +70,6 @@
7370
#ifdef __cplusplus
7471
extern "C" {
7572
#endif
76-
77-
/*! \brief No-op function for the body of tight loops
78-
* \ingroup pico_platform
79-
*
80-
* No-op function intended to be called by any tight hardware polling loop. Using this ubiquitously
81-
* makes it much easier to find tight loops, but also in the future \#ifdef-ed support for lockup
82-
* debugging might be added
83-
*/
84-
static __force_inline void tight_loop_contents(void) {}
85-
8673
/*! \brief Helper method to busy-wait for at least the given number of cycles
8774
* \ingroup pico_platform
8875
*
@@ -116,27 +103,6 @@ static inline void busy_wait_at_least_cycles(uint32_t minimum_cycles) {
116103
);
117104
}
118105

119-
// PICO_CONFIG: PICO_NO_FPGA_CHECK, Remove the FPGA platform check for small code size reduction, type=bool, default=1, advanced=true, group=pico_runtime
120-
#ifndef PICO_NO_FPGA_CHECK
121-
#define PICO_NO_FPGA_CHECK 1
122-
#endif
123-
124-
// PICO_CONFIG: PICO_NO_SIM_CHECK, Remove the SIM platform check for small code size reduction, type=bool, default=1, advanced=true, group=pico_runtime
125-
#ifndef PICO_NO_SIM_CHECK
126-
#define PICO_NO_SIM_CHECK 1
127-
#endif
128-
129-
#if PICO_NO_FPGA_CHECK
130-
static inline bool running_on_fpga(void) {return false;}
131-
#else
132-
bool running_on_fpga(void);
133-
#endif
134-
#if PICO_NO_SIM_CHECK
135-
static inline bool running_in_sim(void) {return false;}
136-
#else
137-
bool running_in_sim(void);
138-
#endif
139-
140106
/*! \brief Execute a breakpoint instruction
141107
* \ingroup pico_platform
142108
*/
@@ -221,9 +187,6 @@ __force_inline static bool pico_processor_state_is_nonsecure(void) {
221187
#endif
222188
}
223189

224-
#define host_safe_hw_ptr(x) ((uintptr_t)(x))
225-
#define native_safe_hw_ptr(x) host_safe_hw_ptr(x)
226-
227190
/*! \brief Returns the RP2350 chip revision number
228191
* \ingroup pico_platform
229192
* @return the RP2350 chip revision number (1 for B0/B1, 2 for B2)

src/rp2350/pico_platform/platform.c

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,8 @@
66

77
#include "pico.h"
88
#include "hardware/address_mapped.h"
9-
#include "hardware/regs/tbman.h"
109
#include "hardware/regs/sysinfo.h"
1110

12-
// Note we leave the FPGA check in by default so that we can run bug repro
13-
// binaries coming in from the wild on the FPGA platform. It takes up around
14-
// 48 bytes if you include all the calls, so you can pass PICO_NO_FPGA_CHECK=1
15-
// to remove it. The FPGA check is used to skip initialisation of hardware
16-
// (mainly clock generators and oscillators) that aren't present on FPGA.
17-
18-
#if !PICO_NO_FPGA_CHECK
19-
// Inline stub provided in header if this code is unused (so folding can be
20-
// done in each TU instead of relying on LTO)
21-
bool __attribute__((weak)) running_on_fpga(void) {
22-
return (*(io_ro_32 *)TBMAN_BASE) & TBMAN_PLATFORM_FPGA_BITS;
23-
}
24-
#endif
25-
#if !PICO_NO_SIM_CHECK
26-
bool __attribute__((weak)) running_in_sim(void) {
27-
return (*(io_ro_32 *)TBMAN_BASE) & TBMAN_PLATFORM_HDLSIM_BITS;
28-
}
29-
#endif
30-
3111
#define MANUFACTURER_RPI 0x926
3212
#define PART_RP4 0x4
3313

@@ -36,9 +16,9 @@ uint8_t rp2350_chip_version(void) {
3616
uint32_t chip_id = *((io_ro_32*)(SYSINFO_BASE + SYSINFO_CHIP_ID_OFFSET));
3717
uint32_t __unused manufacturer = chip_id & SYSINFO_CHIP_ID_MANUFACTURER_BITS;
3818
uint32_t __unused part = (chip_id & SYSINFO_CHIP_ID_PART_BITS) >> SYSINFO_CHIP_ID_PART_LSB;
39-
assert(manufacturer == MANUFACTURER_RPI);
40-
assert(part == PART_RP4);
19+
assert(manufacturer == MANUFACTURER_RPI && part == PART_RP4);
4120
// 0 == A0, 1 == A1, 2 == A2
42-
uint version = (chip_id & SYSINFO_CHIP_ID_REVISION_BITS) >> SYSINFO_CHIP_ID_REVISION_LSB;
21+
uint32_t version = (chip_id & SYSINFO_CHIP_ID_REVISION_BITS) >> SYSINFO_CHIP_ID_REVISION_LSB;
22+
version = (version & 3u) | ((version & 8u) >> 1);
4323
return (uint8_t)version;
4424
}

src/rp2_common/hardware_exception/exception.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ static inline exception_handler_t *get_exception_table(void) {
3131
#endif
3232
}
3333

34+
#if !PICO_NO_RAM_VECTOR_TABLE
3435
static void set_raw_exception_handler_and_restore_interrupts(enum exception_number num, exception_handler_t handler, uint32_t save) {
3536
// update vtable (vtable_handler may be same or updated depending on cases, but we do it anyway for compactness)
3637
get_exception_table()[num] = handler;
3738
__dmb();
3839
restore_interrupts_from_disabled(save);
3940
}
41+
#endif
4042

4143
static inline void check_exception_param(__unused enum exception_number num) {
4244
invalid_params_if(HARDWARE_EXCEPTION, num < MIN_EXCEPTION_NUM || num > MAX_EXCEPTION_NUM);
@@ -54,10 +56,12 @@ exception_handler_t exception_set_exclusive_handler(enum exception_number num, e
5456
exception_handler_t current = exception_get_vtable_handler(num);
5557
hard_assert(handler == current || exception_is_compile_time_default(current));
5658
set_raw_exception_handler_and_restore_interrupts(num, handler, save);
59+
return current;
5760
#else
61+
((void)num);
62+
((void)handler);
5863
panic_unsupported();
5964
#endif
60-
return current;
6165
}
6266

6367
void exception_restore_handler(enum exception_number num, exception_handler_t original_handler) {
@@ -66,6 +70,8 @@ void exception_restore_handler(enum exception_number num, exception_handler_t or
6670
uint32_t save = save_and_disable_interrupts();
6771
set_raw_exception_handler_and_restore_interrupts(num, original_handler, save);
6872
#else
73+
((void)num);
74+
((void)original_handler);
6975
panic_unsupported();
7076
#endif
7177
}

src/rp2_common/hardware_irq/include/hardware/irq.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ extern "C" {
195195
typedef void (*irq_handler_t)(void);
196196

197197
static inline void check_irq_param(__unused uint num) {
198-
invalid_params_if(HARDWARE_IRQ, num >= NUM_IRQS);
198+
invalid_params_if(HARDWARE_IRQ, num >= PICO_NUM_VTABLE_IRQS);
199199
}
200200

201201
/*! \brief Set specified interrupt's priority

0 commit comments

Comments
 (0)