Skip to content

Commit f3da3a1

Browse files
author
Jamie Smith
authored
Update RP2040 target to use flash memory bank (#392)
* Add RPi Pico flash bank * Start on linker script changes * Finish linker script * Fix license * It's nice to be on the right side of history
1 parent 44dabfb commit f3da3a1

File tree

5 files changed

+71
-32
lines changed

5 files changed

+71
-32
lines changed

targets/TARGET_RASPBERRYPI/TARGET_RP2040/TOOLCHAIN_GCC_ARM/memmap_default_mbed.ld

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
__stack (== StackTop)
2323
*/
2424

25-
#include "../cmsis_nvic.h"
26-
2725
#if !defined(MBED_CONF_TARGET_BOOT_STACK_SIZE)
2826
/* This value is normally defined by the tools
2927
to 0x1000 for bare metal and 0x400 for RTOS */
@@ -32,15 +30,24 @@
3230

3331
MEMORY
3432
{
35-
FLASH(rx) : ORIGIN = MBED_ROM_START, LENGTH = MBED_ROM_SIZE
36-
RAM(rwx) : ORIGIN = MBED_RAM_START, LENGTH = MBED_RAM_SIZE
33+
FLASH(rx) : ORIGIN = MBED_CONFIGURED_ROM_BANK_QSPI_FLASH_START, LENGTH = MBED_CONFIGURED_ROM_BANK_QSPI_FLASH_SIZE
34+
RAM(rwx) : ORIGIN = MBED_CONFIGURED_RAM_BANK_IRAM1_START, LENGTH = MBED_CONFIGURED_RAM_BANK_IRAM1_SIZE
3735

3836
/*
3937
* Scratch banks are commonly used for critical data and functions accessed only by one core (when only
4038
* one core is accessing the RAM bank, there is no opportunity for stalls).
4139
*/
42-
SCRATCH_X(rwx) : ORIGIN = 0x20040000, LENGTH = 4k
43-
SCRATCH_Y(rwx) : ORIGIN = 0x20041000, LENGTH = 4k
40+
SCRATCH_X(rwx) : ORIGIN = MBED_RAM_BANK_SCRATCH_X_START, LENGTH = MBED_RAM_BANK_SCRATCH_X_SIZE
41+
SCRATCH_Y(rwx) : ORIGIN = MBED_RAM_BANK_SCRATCH_Y_START, LENGTH = MBED_RAM_BANK_SCRATCH_Y_SIZE
42+
43+
/* If we are at the start of RAM, we are core 0. Otherwise we are core 1. */
44+
#if MBED_CONFIGURED_RAM_BANK_IRAM1_START == MBED_RAM_BANK_IRAM1_START
45+
#define STACK_SCRATCH SCRATCH_X
46+
#define STACK_SCRATCH_STATIC_END_SYMBOL __scratch_x_end__
47+
#else
48+
#define STACK_SCRATCH SCRATCH_Y
49+
#define STACK_SCRATCH_STATIC_END_SYMBOL __scratch_y_end__
50+
#endif
4451
}
4552

4653
ENTRY(_entry_point)
@@ -218,23 +225,23 @@ SECTIONS
218225
__end__ = .;
219226
PROVIDE(end = .);
220227
*(.heap*)
221-
. = ORIGIN(RAM) + LENGTH(RAM) - MBED_CONF_TARGET_BOOT_STACK_SIZE;
228+
. = ORIGIN(RAM) + LENGTH(RAM);
222229
__HeapLimit = .;
223230
} > RAM
224231
232+
/* Check if data + heap exceeds RAM limit */
233+
ASSERT(__end__ < ORIGIN(RAM) + LENGTH(RAM), "region RAM overflowed")
234+
225235
.flash_end : {
226236
PROVIDE(__flash_binary_end = .);
227237
} > FLASH
228238
229-
/* stack limit is poorly named, but historically is maximum heap ptr */
230-
__StackTop = ORIGIN(SCRATCH_Y) + LENGTH(SCRATCH_Y);
239+
__StackTop = ORIGIN(STACK_SCRATCH) + LENGTH(STACK_SCRATCH);
231240
__StackLimit = __StackTop - MBED_CONF_TARGET_BOOT_STACK_SIZE;
232241
__StackBottom = __StackLimit;
242+
ASSERT(__StackLimit >= STACK_SCRATCH_STATIC_END_SYMBOL, "stack scratch region overflowed")
233243
PROVIDE(__stack = __StackTop);
234244
235-
/* Check if data + heap + stack exceeds RAM limit */
236-
ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed")
237-
238245
ASSERT( __binary_info_header_end - __logical_binary_start <= 256, "Binary info must be in first 256 bytes of the binary")
239246
/* todo assert on extra code */
240247
}

targets/TARGET_RASPBERRYPI/TARGET_RP2040/cmsis_nvic.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,5 @@
1717
#ifndef MBED_CMSIS_NVIC_H
1818
#define MBED_CMSIS_NVIC_H
1919

20-
#if !defined(MBED_ROM_START)
21-
#define MBED_ROM_START 0x10000000
22-
#endif
23-
24-
#if !defined(MBED_ROM_SIZE)
25-
#if defined(PICO_FLASH_SIZE_BYTES)
26-
#define MBED_ROM_SIZE PICO_FLASH_SIZE_BYTES
27-
#else
28-
#define MBED_ROM_SIZE (2048*1024)
29-
#endif
30-
#endif
31-
32-
#if !defined(MBED_RAM_START)
33-
#define MBED_RAM_START 0x20000000
34-
#endif
35-
36-
#if !defined(MBED_RAM_SIZE)
37-
#define MBED_RAM_SIZE (256*1024)
38-
#endif
3920

4021
#endif

targets/TARGET_RASPBERRYPI/TARGET_RP2040/flash_api.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2024, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
118
/******************************************************************************
219
* INCLUDE
320
******************************************************************************/
@@ -88,7 +105,7 @@ uint32_t flash_get_size(const flash_t *obj)
88105
{
89106
(void)(obj);
90107

91-
return PICO_FLASH_SIZE_BYTES;
108+
return MBED_ROM_BANK_QSPI_FLASH_SIZE;
92109
}
93110

94111
uint32_t flash_get_sector_size(const flash_t *obj, uint32_t address)

targets/TARGET_RASPBERRYPI/TARGET_RP2040/rtc_api.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2024, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
118
#if DEVICE_RTC
219

320
#include "mbed_critical.h"
@@ -81,6 +98,8 @@ void rtc_write(time_t t)
8198
// won't produce the expected result. I wasn't able to find any errata or anything documenting
8299
// this behavior, but it's very consistent, and the RTC tests fail if the below block is removed.
83100
// To fix the error, we just decrease the time by 1 second before writing it to the registers.
101+
// Update 2024: This is now a known, if not officially acknowledged, errata:
102+
// https://forums.raspberrypi.com/viewtopic.php?t=377876
84103
if (t >= 1) {
85104
t -= 1;
86105
}

targets/targets.json5

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9820,6 +9820,21 @@
98209820
// (so the ADC can never read 100%).
98219821
"default-adc-vref": 3.3
98229822
},
9823+
"memory_banks": {
9824+
"QSPI_FLASH": {
9825+
"access": {
9826+
"execute": true,
9827+
"peripheral": false,
9828+
"read": true,
9829+
"secure": false,
9830+
"write": false
9831+
},
9832+
"default": true,
9833+
"startup": true,
9834+
"size": 0x200000, // 2MiB
9835+
"start": 0x10000000
9836+
}
9837+
},
98239838
"image_url": "https://cdn11.bigcommerce.com/s-2fbyfnm8ev/images/stencil/1280x1280/products/1212/4275/Pico3__75642.1611086462.jpg?c=2"
98249839
},
98259840
"RASPBERRY_PI_PICO_SWD": {

0 commit comments

Comments
 (0)