Skip to content

Commit f45db86

Browse files
Migrate to 2.0.0 SDK (#2336)
* Update to 2.0.0 SDK * Board type needs to be set before earliest SDK setup * Platform includes update * Boot2 files * Simple compilation issues * Build and link * PIO rebuild with version * Newlib wrapper update * Force inclusion of runtime_init_* fcns The linker was dropping all references to the library's included runtime_init_xxx functions and hence things like the IRQ vector table and mutexes and alarms weren't properly set up leading to instant crashes on start up.. Explicitly call out one function from the object file stored in the .A to force the inclusion of all the functions. May be a better way, heppy to hear any ideas. * Fix SPI GPIO calls * Fix Ethernet GPIO * Remove SDK warnings Remove the skipped error messages once the following PR merged: raspberrypi/pico-sdk#1786 * BTStack moved SBC encode/decode paths * Platform.IO fixes * BT No longer has special absolute mouse * Rebuild and update OTA * Rebuild BearSSL, too * Update liker file to latest SDK * Clean up libpicocmake * Clean up LWIP/BT library names
1 parent 16d9609 commit f45db86

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1235
-978
lines changed

boards.txt

Lines changed: 720 additions & 720 deletions
Large diffs are not rendered by default.

cores/rp2040/Arduino.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include <pins_arduino.h>
3131
#include <hardware/gpio.h> // Required for the port*Register macros
3232
#include "debug_internal.h"
33-
#include <RP2040.h> // CMSIS
3433

3534
// Try and make the best of the old Arduino abs() macro. When in C++, use
3635
// the sane std::abs() call, but for C code use their macro since stdlib abs()

cores/rp2040/RP2040USB.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
#include <pico/usb_reset_interface.h>
3636
#include <hardware/watchdog.h>
3737
#include <pico/bootrom.h>
38-
#include "sdkoverride/tusb_absmouse.h"
3938
#include "sdkoverride/tusb_gamepad16.h"
4039
#include <device/usbd_pvt.h>
4140

cores/rp2040/SerialUART.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class SerialUART : public HardwareSerial {
8080
uart_inst_t *_uart;
8181
pin_size_t _tx, _rx;
8282
pin_size_t _rts, _cts;
83-
enum gpio_function _fcnTx, _fcnRx, _fcnRts, _fcnCts;
83+
gpio_function_t _fcnTx, _fcnRx, _fcnRts, _fcnCts;
8484
int _baud;
8585
mutex_t _mutex;
8686
bool _polling = false;

cores/rp2040/ccount.pio.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#define ccount_wrap_target 0
1616
#define ccount_wrap 1
17+
#define ccount_pio_version 0
1718

1819
static const uint16_t ccount_program_instructions[] = {
1920
// .wrap_target
@@ -27,6 +28,10 @@ static const struct pio_program ccount_program = {
2728
.instructions = ccount_program_instructions,
2829
.length = 2,
2930
.origin = -1,
31+
.pio_version = 0,
32+
#if PICO_PIO_VERSION > 0
33+
.used_gpio_ranges = 0x0
34+
#endif
3035
};
3136

3237
static inline pio_sm_config ccount_program_get_default_config(uint offset) {

cores/rp2040/pio_uart.pio.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#define pio_tx_wrap_target 0
1616
#define pio_tx_wrap 5
17+
#define pio_tx_pio_version 0
1718

1819
static const uint16_t pio_tx_program_instructions[] = {
1920
// .wrap_target
@@ -31,6 +32,10 @@ static const struct pio_program pio_tx_program = {
3132
.instructions = pio_tx_program_instructions,
3233
.length = 6,
3334
.origin = -1,
35+
.pio_version = 0,
36+
#if PICO_PIO_VERSION > 0
37+
.used_gpio_ranges = 0x0
38+
#endif
3439
};
3540

3641
static inline pio_sm_config pio_tx_program_get_default_config(uint offset) {
@@ -47,6 +52,7 @@ static inline pio_sm_config pio_tx_program_get_default_config(uint offset) {
4752

4853
#define pio_tx_inv_wrap_target 0
4954
#define pio_tx_inv_wrap 5
55+
#define pio_tx_inv_pio_version 0
5056

5157
static const uint16_t pio_tx_inv_program_instructions[] = {
5258
// .wrap_target
@@ -64,6 +70,10 @@ static const struct pio_program pio_tx_inv_program = {
6470
.instructions = pio_tx_inv_program_instructions,
6571
.length = 6,
6672
.origin = -1,
73+
.pio_version = 0,
74+
#if PICO_PIO_VERSION > 0
75+
.used_gpio_ranges = 0x0
76+
#endif
6777
};
6878

6979
static inline pio_sm_config pio_tx_inv_program_get_default_config(uint offset) {
@@ -100,6 +110,7 @@ static inline void pio_tx_program_init(PIO pio, uint sm, uint offset, uint pin_t
100110

101111
#define pio_rx_wrap_target 0
102112
#define pio_rx_wrap 6
113+
#define pio_rx_pio_version 0
103114

104115
static const uint16_t pio_rx_program_instructions[] = {
105116
// .wrap_target
@@ -118,6 +129,10 @@ static const struct pio_program pio_rx_program = {
118129
.instructions = pio_rx_program_instructions,
119130
.length = 7,
120131
.origin = -1,
132+
.pio_version = 0,
133+
#if PICO_PIO_VERSION > 0
134+
.used_gpio_ranges = 0x0
135+
#endif
121136
};
122137

123138
static inline pio_sm_config pio_rx_program_get_default_config(uint offset) {
@@ -133,6 +148,7 @@ static inline pio_sm_config pio_rx_program_get_default_config(uint offset) {
133148

134149
#define pio_rx_inv_wrap_target 0
135150
#define pio_rx_inv_wrap 6
151+
#define pio_rx_inv_pio_version 0
136152

137153
static const uint16_t pio_rx_inv_program_instructions[] = {
138154
// .wrap_target
@@ -151,6 +167,10 @@ static const struct pio_program pio_rx_inv_program = {
151167
.instructions = pio_rx_inv_program_instructions,
152168
.length = 7,
153169
.origin = -1,
170+
.pio_version = 0,
171+
#if PICO_PIO_VERSION > 0
172+
.used_gpio_ranges = 0x0
173+
#endif
154174
};
155175

156176
static inline pio_sm_config pio_rx_inv_program_get_default_config(uint offset) {
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
/*
2+
Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
3+
4+
SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
#include <stdio.h>
8+
#include <stdarg.h>
9+
#include <sys/stat.h>
10+
#include <sys/time.h>
11+
#include <sys/times.h>
12+
#include <time.h>
13+
#include <unistd.h>
14+
#if PICO_ENTER_USB_BOOT_ON_EXIT
15+
#include "pico/bootrom.h"
16+
#endif
17+
#include "pico/time.h"
18+
#include "pico/runtime_init.h"
19+
20+
#if LIB_PICO_PRINTF_PICO
21+
#include "pico/printf.h"
22+
#else
23+
#define weak_raw_printf printf
24+
#define weak_raw_vprintf vprintf
25+
#endif
26+
#if LIB_PICO_STDIO
27+
#include "pico/stdio.h"
28+
#endif
29+
30+
#if PICO_ENTER_USB_BOOT_ON_EXIT
31+
#include "pico/bootrom.h"
32+
#endif
33+
34+
extern char __StackLimit; /* Set by linker. */
35+
36+
#define STDIO_HANDLE_STDIN 0
37+
#define STDIO_HANDLE_STDOUT 1
38+
#define STDIO_HANDLE_STDERR 2
39+
40+
void __attribute__((noreturn)) __weak _exit(__unused int status) {
41+
#if PICO_ENTER_USB_BOOT_ON_EXIT
42+
reset_usb_boot(0, 0);
43+
#else
44+
while (1) {
45+
__breakpoint();
46+
}
47+
#endif
48+
}
49+
50+
__weak void *_sbrk(int incr) {
51+
extern char end; /* Set by linker. */
52+
static char *heap_end;
53+
char *prev_heap_end;
54+
55+
if (heap_end == 0) {
56+
heap_end = &end;
57+
}
58+
59+
prev_heap_end = heap_end;
60+
char *next_heap_end = heap_end + incr;
61+
62+
if (__builtin_expect(next_heap_end > (&__StackLimit), false)) {
63+
#if PICO_USE_OPTIMISTIC_SBRK
64+
if (heap_end == &__StackLimit) {
65+
// errno = ENOMEM;
66+
return (char *) -1;
67+
}
68+
next_heap_end = &__StackLimit;
69+
#else
70+
return (char *) -1;
71+
#endif
72+
}
73+
74+
heap_end = next_heap_end;
75+
return (void *) prev_heap_end;
76+
}
77+
#if 0
78+
static int64_t epoch_time_us_since_boot;
79+
80+
__weak int _gettimeofday(struct timeval *__restrict tv, __unused void *__restrict tz) {
81+
if (tv) {
82+
int64_t us_since_epoch = ((int64_t)to_us_since_boot(get_absolute_time())) - epoch_time_us_since_boot;
83+
tv->tv_sec = (time_t)(us_since_epoch / 1000000);
84+
tv->tv_usec = (suseconds_t)(us_since_epoch % 1000000);
85+
}
86+
return 0;
87+
}
88+
89+
__weak int settimeofday(__unused const struct timeval *tv, __unused const struct timezone *tz) {
90+
if (tv) {
91+
int64_t us_since_epoch = tv->tv_sec * 1000000 + tv->tv_usec;
92+
epoch_time_us_since_boot = (int64_t)to_us_since_boot(get_absolute_time()) - us_since_epoch;
93+
}
94+
return 0;
95+
}
96+
97+
__weak int _times(struct tms *tms) {
98+
#if CLOCKS_PER_SEC >= 1000000
99+
tms->tms_utime = (clock_t)(to_us_since_boot(get_absolute_time()) * (CLOCKS_PER_SEC / 1000000));
100+
#else
101+
tms->tms_utime = (clock_t)(to_us_since_boot(get_absolute_time()) / (1000000 / CLOCKS_PER_SEC));
102+
#endif
103+
tms->tms_stime = 0;
104+
tms->tms_cutime = 0;
105+
tms->tms_cstime = 0;
106+
return 0;
107+
}
108+
109+
__weak pid_t _getpid(void) {
110+
return 0;
111+
}
112+
113+
__weak int _kill(__unused pid_t pid, __unused int sig) {
114+
return -1;
115+
}
116+
117+
int __attribute__((weak)) _read(int handle, char *buffer, int length) {
118+
#if LIB_PICO_STDIO
119+
if (handle == STDIO_HANDLE_STDIN) {
120+
return stdio_get_until(buffer, length, at_the_end_of_time);
121+
}
122+
#endif
123+
return -1;
124+
}
125+
126+
int __attribute__((weak)) _write(int handle, char *buffer, int length) {
127+
#if LIB_PICO_STDIO
128+
if (handle == STDIO_HANDLE_STDOUT || handle == STDIO_HANDLE_STDERR) {
129+
stdio_put_string(buffer, length, false, true);
130+
return length;
131+
}
132+
#endif
133+
return -1;
134+
}
135+
136+
int __attribute__((weak)) _open(__unused const char *fn, __unused int oflag, ...) {
137+
return -1;
138+
}
139+
140+
int __attribute__((weak)) _close(__unused int fd) {
141+
return -1;
142+
}
143+
144+
off_t __attribute__((weak)) _lseek(__unused int fd, __unused off_t pos, __unused int whence) {
145+
return -1;
146+
}
147+
148+
int __attribute__((weak)) _fstat(__unused int fd, __unused struct stat *buf) {
149+
return -1;
150+
}
151+
152+
int __attribute__((weak)) _isatty(int fd) {
153+
return fd == STDIO_HANDLE_STDIN || fd == STDIO_HANDLE_STDOUT || fd == STDIO_HANDLE_STDERR;
154+
}
155+
156+
// exit is not useful... no desire to pull in __call_exitprocs
157+
void exit(int status) {
158+
_exit(status);
159+
}
160+
161+
// incorrect warning from GCC 6
162+
GCC_Pragma("GCC diagnostic push")
163+
GCC_Pragma("GCC diagnostic ignored \"-Wsuggest-attribute=format\"")
164+
void __weak __assert_func(const char *file, int line, const char *func, const char *failedexpr) {
165+
weak_raw_printf("assertion \"%s\" failed: file \"%s\", line %d%s%s\n",
166+
failedexpr, file, line, func ? ", function: " : "",
167+
func ? func : "");
168+
169+
_exit(1);
170+
}
171+
GCC_Pragma("GCC diagnostic pop")
172+
#endif
173+
void runtime_init(void) {
174+
#ifndef NDEBUG
175+
if (__get_current_exception()) {
176+
// crap; started in exception handler
177+
__breakpoint();
178+
}
179+
#endif
180+
181+
#if !PICO_RUNTIME_SKIP_INIT_PER_CORE_INSTALL_STACK_GUARD
182+
// install core0 stack guard
183+
extern char __StackBottom;
184+
runtime_init_per_core_install_stack_guard(&__StackBottom);
185+
#endif
186+
187+
// todo maybe we want to do this in the future, but it does stuff like register_tm_clones
188+
// which we didn't do in previous SDKs
189+
//extern void __libc_init_array(void);
190+
//__libc_init_array();
191+
192+
// ... so instead just do the __preinit_array
193+
runtime_run_initializers();
194+
// ... and the __init_array
195+
extern void (*__init_array_start)(void);
196+
extern void (*__init_array_end)(void);
197+
for (void (**p)(void) = &__init_array_start; p < &__init_array_end; ++p) {
198+
(*p)();
199+
}
200+
}

0 commit comments

Comments
 (0)