Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pico SDK to v2.1.0 with RP2350 support #2918

Merged
merged 20 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
variant: [esp8266, host, rp2040]
variant: [esp8266, host, rp2040, rp2350]
toolchain: [gcc]
include:
- variant: esp8266
Expand All @@ -31,6 +31,8 @@ jobs:
toolchain: gcc64
- variant: rp2040
arch: Rp2040
- variant: rp2350
arch: Rp2040

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ toJson(matrix) }}
Expand Down
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@

[submodule "Rp2040.picotool"]
path = Sming/Arch/Rp2040/Components/picotool/picotool
url = /~https://github.com/mikee47/picotool
url = /~https://github.com/raspberrypi/picotool
ignore = dirty

[submodule "Rp2040.Sdk"]
Expand Down
16 changes: 9 additions & 7 deletions Sming/Arch/Rp2040/Components/driver/hw_timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace
{
void IRAM_ATTR timer1_isr()
{
hw_clear_bits(&timer_hw->intr, BIT(0));
hw_clear_bits(&timer_hw->intr, BIT(0));
auto& p = hw_timer_private;
if(p.timer1_callback != nullptr) {
p.timer1_callback(p.timer1_arg);
Expand All @@ -33,20 +33,22 @@ void IRAM_ATTR timer1_isr()
void IRAM_ATTR hw_timer1_attach_interrupt(hw_timer_source_type_t source_type, hw_timer_callback_t callback, void* arg)
{
(void)source_type;
auto irq_num = TIMER_ALARM_IRQ_NUM(HW_TIMER_NUM, 0);
irq_set_enabled(irq_num, false);
auto& p = hw_timer_private;
irq_set_enabled(TIMER_IRQ_0, false);
p.timer1_callback = callback;
p.timer1_arg = arg;
irq_set_exclusive_handler(TIMER_IRQ_0, timer1_isr);
irq_set_exclusive_handler(irq_num, timer1_isr);
hw_set_bits(&timer_hw->inte, BIT(0));
irq_set_enabled(TIMER_IRQ_0, true);
irq_set_enabled(irq_num, true);
}

void hw_timer1_detach_interrupt()
{
hw_clear_bits(&timer_hw->inte, BIT(0));
irq_set_enabled(TIMER_IRQ_0, false);
irq_remove_handler(TIMER_IRQ_0, timer1_isr);
auto irq_num = TIMER_ALARM_IRQ_NUM(HW_TIMER_NUM, 0);
irq_set_enabled(irq_num, false);
irq_remove_handler(irq_num, timer1_isr);
}

void IRAM_ATTR hw_timer1_enable(hw_timer_clkdiv_t div, hw_timer_intr_type_t intr_type, bool auto_load)
Expand All @@ -59,5 +61,5 @@ void IRAM_ATTR hw_timer1_enable(hw_timer_clkdiv_t div, hw_timer_intr_type_t intr

void hw_timer_init()
{
// hardware_alarm_claim(0);
timer_hardware_alarm_claim(HW_TIMER_INST, 0);
}
13 changes: 8 additions & 5 deletions Sming/Arch/Rp2040/Components/driver/include/driver/hw_timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@
#pragma once

#include <esp_systemapi.h>
#include <hardware/structs/timer.h>
#include <hardware/timer.h>

#ifdef __cplusplus
extern "C" {
#endif

#define HW_TIMER_BASE_CLK 1000000U

#define HW_TIMER_NUM 0
#define HW_TIMER_INST TIMER_INSTANCE(HW_TIMER_NUM)

/**
* @defgroup hw_timer Hardware Timer Driver
* @ingroup drivers
Expand All @@ -36,7 +39,7 @@ extern "C" {
*/
__forceinline uint32_t IRAM_ATTR hw_timer_ticks()
{
return timer_hw->timerawl;
return timer_time_us_32(HW_TIMER_INST);
}

/*************************************
Expand Down Expand Up @@ -116,15 +119,15 @@ __forceinline void IRAM_ATTR hw_timer1_write(uint32_t ticks)
{
ticks <<= hw_timer_private.timer1_clkdiv;
hw_timer_private.timer1_ticks = ticks;
timer_hw->alarm[0] = hw_timer_ticks() + ticks;
HW_TIMER_INST->alarm[0] = hw_timer_ticks() + ticks;
}

/**
* @brief Disable the timer
*/
__forceinline void IRAM_ATTR hw_timer1_disable()
{
timer_hw->armed = BIT(0);
HW_TIMER_INST->armed = BIT(0);
}

/**
Expand All @@ -133,7 +136,7 @@ __forceinline void IRAM_ATTR hw_timer1_disable()
*/
__forceinline uint32_t hw_timer1_read()
{
int time = hw_timer_ticks() - timer_hw->alarm[0];
int time = hw_timer_ticks() - HW_TIMER_INST->alarm[0];
return (time > 0) ? (time >> hw_timer_private.timer1_clkdiv) : 0;
}

Expand Down
8 changes: 4 additions & 4 deletions Sming/Arch/Rp2040/Components/driver/os_timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,16 @@ void IRAM_ATTR timer_schedule()
if(timer_list == nullptr) {
debug_tmr("cancel");
// Cancel hardware timer
timer_hw->armed = BIT(1);
HW_TIMER_INST->armed = BIT(1);
return;
}

constexpr int TIMER2_MIN_US{50};
auto now = hw_timer2_read();
if(int(timer_list->timer_expire - now) < TIMER2_MIN_US) {
timer_hw->alarm[1] = now + TIMER2_MIN_US;
HW_TIMER_INST->alarm[1] = now + TIMER2_MIN_US;
} else {
timer_hw->alarm[1] = timer_list->timer_expire;
HW_TIMER_INST->alarm[1] = timer_list->timer_expire;
}
}

Expand All @@ -95,7 +95,7 @@ os_timer_t* find_expired_timer()
}

// Using Timer2 hardware to schedule software timers
if(timer_hw->armed & BIT(1)) {
if(HW_TIMER_INST->armed & BIT(1)) {
return nullptr;
}

Expand Down
10 changes: 8 additions & 2 deletions Sming/Arch/Rp2040/Components/driver/uart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
#include <hardware/resets.h>
#include <hardware/gpio.h>

#ifdef ARCH_RP2040
#define UART_FUNCSEL_NUM(gpio) GPIO_FUNC_UART
#else
#define UART_FUNCSEL_NUM(gpio) ((gpio) & 0x2 ? GPIO_FUNC_UART_AUX : GPIO_FUNC_UART)
#endif

namespace
{
using uart_dev_t = uart_hw_t;
Expand Down Expand Up @@ -97,22 +103,22 @@

void IRAM_ATTR handleInterrupt(smg_uart_t* uart, uart_dev_t* dev)
{
auto mis = dev->mis;

Check failure on line 106 in Sming/Arch/Rp2040/Components/driver/uart.cpp

View workflow job for this annotation

GitHub Actions / Check spelling

mis ==> miss, mist

Check failure on line 106 in Sming/Arch/Rp2040/Components/driver/uart.cpp

View workflow job for this annotation

GitHub Actions / Check spelling

mis ==> miss, mist

// If status is clear there's no interrupt to service on this UART
if(mis == 0) {

Check failure on line 109 in Sming/Arch/Rp2040/Components/driver/uart.cpp

View workflow job for this annotation

GitHub Actions / Check spelling

mis ==> miss, mist
return;
}

// Value to be passed to callback
auto user_is = mis;

Check failure on line 114 in Sming/Arch/Rp2040/Components/driver/uart.cpp

View workflow job for this annotation

GitHub Actions / Check spelling

mis ==> miss, mist

// Deal with the event, unless we're in raw mode
if(!bitRead(uart->options, UART_OPT_CALLBACK_RAW)) {
// Rx FIFO full, timeout or receive overflow
auto rxfifo_full = mis & UART_UARTMIS_RXMIS_BITS;

Check failure on line 119 in Sming/Arch/Rp2040/Components/driver/uart.cpp

View workflow job for this annotation

GitHub Actions / Check spelling

mis ==> miss, mist
auto rxfifo_tout = mis & UART_UARTMIS_RTMIS_BITS;

Check failure on line 120 in Sming/Arch/Rp2040/Components/driver/uart.cpp

View workflow job for this annotation

GitHub Actions / Check spelling

mis ==> miss, mist
auto rxfifo_ovf = mis & UART_UARTMIS_OEMIS_BITS;

Check failure on line 121 in Sming/Arch/Rp2040/Components/driver/uart.cpp

View workflow job for this annotation

GitHub Actions / Check spelling

mis ==> miss, mist
if(rxfifo_full || rxfifo_tout || rxfifo_ovf) {
bool read{false};

Expand Down Expand Up @@ -143,7 +149,7 @@
}
}

auto txfifo_empty = mis & UART_UARTMIS_TXMIS_BITS;

Check failure on line 152 in Sming/Arch/Rp2040/Components/driver/uart.cpp

View workflow job for this annotation

GitHub Actions / Check spelling

mis ==> miss, mist
if(txfifo_empty) {
// Dump as much data as we can from buffer into the TX FIFO
if(uart->tx_buffer != nullptr) {
Expand Down Expand Up @@ -189,7 +195,7 @@
}

// Final step is to clear status flags
dev->icr = mis;

Check failure on line 198 in Sming/Arch/Rp2040/Components/driver/uart.cpp

View workflow job for this annotation

GitHub Actions / Check spelling

mis ==> miss, mist
}

void IRAM_ATTR uart0_isr()
Expand Down Expand Up @@ -721,15 +727,15 @@
if(uart->tx_pin != UART_PIN_DEFAULT) {
gpio_set_function(uart->tx_pin, GPIO_FUNC_NULL);
}
gpio_set_function(tx_pin, GPIO_FUNC_UART);
gpio_set_function(tx_pin, UART_FUNCSEL_NUM(tx_pin));
uart->tx_pin = tx_pin;
}

if(rx_pin != UART_PIN_NO_CHANGE) {
if(uart->rx_pin != UART_PIN_DEFAULT) {
gpio_set_function(uart->rx_pin, GPIO_FUNC_NULL);
}
gpio_set_function(rx_pin, GPIO_FUNC_UART);
gpio_set_function(rx_pin, UART_FUNCSEL_NUM(rx_pin));
uart->rx_pin = rx_pin;
}

Expand Down
16 changes: 0 additions & 16 deletions Sming/Arch/Rp2040/Components/libc/src/heap.c

This file was deleted.

58 changes: 58 additions & 0 deletions Sming/Arch/Rp2040/Components/libc/src/heap.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* heap.c
*/

#include "include/heap.h"
#include <malloc.h>
#include <cstdlib>
#include <new>

extern "C" uint32_t system_get_free_heap_size(void)
{
// These are set by linker
extern char __end__;
extern char __StackLimit;
uint32_t maxHeap = (uint32_t)&__StackLimit - (uint32_t)&__end__;
struct mallinfo m = mallinfo();
return maxHeap - m.uordblks;
}

void* operator new(size_t size)
{
return malloc(size);
}

void* operator new(size_t size, const std::nothrow_t&)
{
return malloc(size);
}

void* operator new[](size_t size)
{
return malloc(size);
}

void* operator new[](size_t size, const std::nothrow_t&)
{
return malloc(size);
}

void operator delete(void* ptr)
{
free(ptr);
}

void operator delete[](void* ptr)
{
free(ptr);
}

void operator delete(void* ptr, size_t)
{
free(ptr);
}

void operator delete[](void* ptr, size_t)
{
free(ptr);
}
4 changes: 4 additions & 0 deletions Sming/Arch/Rp2040/Components/libc/src/include/sys/pgmspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ extern "C" {
/**
* @brief Simple check to determine if a pointer refers to flash memory
*/
#ifdef XIP_END
#define isFlashPtr(ptr) ((uint32_t)(ptr) >= XIP_BASE && (uint32_t)(ptr) < XIP_END)
#else
#define isFlashPtr(ptr) ((uint32_t)(ptr) >= XIP_MAIN_BASE && (uint32_t)(ptr) < XIP_NOALLOC_BASE)
#endif

#define PROGMEM STORE_ATTR ICACHE_RODATA_ATTR
#define PROGMEM_PSTR PROGMEM
Expand Down
8 changes: 7 additions & 1 deletion Sming/Arch/Rp2040/Components/picotool/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@ Picotool

Picotool is a tool for inspecting RP2040 binaries, and interacting with RP2040 devices when they are in BOOTSEL mode.

Note for full documentation see https://rptl.io/pico-get-started Appendix B.
See https://rptl.io/pico-get-started Appendix B for an introduction to this tool.

Sming builds picotool from source and uses it to read back flash memory with build targets such as ``make readpart``.

The tool can be invoked directly like this::

make picotool CMD="info -a"
45 changes: 42 additions & 3 deletions Sming/Arch/Rp2040/Components/picotool/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,49 @@ $(COMPONENT_RULE)$(PICOTOOL):
$(Q) mkdir -p $(@D)
$(Q) cd $(@D) && $(CMAKE) $(PICOTOOL_CMAKE_OPTIONS) $(PICOTOOL_SRC) && $(MAKE)

##@Flashing

.PHONY: picotool
picotool: ##Pass options to picotool, e.g. `make picotool -- help`
$(Q) $(PICOTOOL) $(CMD)

comma := ,
XIP_BASE := 0x10000000

define CalcHex
$$(printf "0x%x" $$(( $1 )))
endef

define RangeStart
$(call CalcHex,$(XIP_BASE) + $(firstword $(subst $(comma), ,$1)))
endef

define RangeEnd
$(call CalcHex,$(XIP_BASE) + $(firstword $(subst $(comma), ,$1)) + $(word 2,$(subst $(comma), ,$1)))
endef

# Read flash memory into file
# $1 -> `Offset,Size` chunk
# $2 -> Output filename
define ReadFlash
$(info ReadFlash $1,$2)
$(Q) $(PICOTOOL) save -r $(call RangeStart,$1) $(call RangeEnd,$1) $2 -t bin
endef

# Read flash manufacturer ID and determine actual size
define ReadFlashID
$(info ReadFlashID)
$(Q) $(PICOTOOL) info -a $(TARGET_BIN)
# $(PICOTOOL) help info
endef
$(Q) $(PICOTOOL) info -a
endef

# Erase a region of Flash
# $1 -> Offset,Size
define EraseFlashRegion
$(info EraseFlashRegion $1)
$(Q) $(PICOTOOL) erase -r $(call RangeStart,$1) $(call RangeEnd,$1)
endef

# Erase flash memory contents
define EraseFlash
$(Q) $(PICOTOOL) erase -a
endef
2 changes: 1 addition & 1 deletion Sming/Arch/Rp2040/Components/picotool/picotool
Submodule picotool updated 98 files
+1 −0 .bazelignore
+1 −0 .bazelrc
+36 −0 .github/workflows/bazel_build.yml
+7 −0 .github/workflows/choco_packages.config
+73 −0 .github/workflows/test.yml
+5 −1 .gitignore
+123 −0 BUILD.bazel
+316 −23 CMakeLists.txt
+26 −0 MODULE.bazel
+968 −59 README.md
+0 −0 WORKSPACE
+21 −0 bazel/BUILD.bazel
+49 −0 bazel/README.md
+71 −0 bazel/binh.py
+5 −0 bazel/data_locs.cpp
+40 −0 bazel/defs.bzl
+60 −0 bazel/jsonh.py
+18 −0 bazel/mbedtls.BUILD
+35 −0 bintool/BUILD.bazel
+32 −0 bintool/CMakeLists.txt
+1,028 −0 bintool/bintool.cpp
+42 −0 bintool/bintool.h
+242 −0 bintool/mbedtls_wrapper.c
+60 −0 bintool/mbedtls_wrapper.h
+707 −0 bintool/metadata.h
+ bootrom.end.bin
+182 −51 cli.h
+48 −11 cmake/FindLIBUSB.cmake
+5 −0 cmake/bin.template.h
+28 −0 cmake/binh.cmake
+2 −0 cmake/jsonh.cmake
+3 −0 cmake/picotoolConfig.cmake
+6 −0 cmake/rp2350.json.template.h
+5 −0 data_locs.h
+7 −0 data_locs.template.cpp
+0 −60 elf.h
+20 −0 elf/BUILD.bazel
+6 −0 elf/CMakeLists.txt
+94 −0 elf/addresses.h
+126 −0 elf/elf.h
+548 −0 elf/elf_file.cpp
+74 −0 elf/elf_file.h
+167 −0 elf/portable_endian.h
+20 −0 elf2uf2/BUILD.bazel
+6 −0 elf2uf2/CMakeLists.txt
+344 −0 elf2uf2/elf2uf2.cpp
+28 −0 elf2uf2/elf2uf2.h
+8 −0 errors/BUILD.bazel
+3 −0 errors/CMakeLists.txt
+16 −0 errors/errors.cpp
+41 −0 errors/errors.h
+37 −0 json/default-pt.json
+27 −0 json/sample-permissions.json
+26 −0 json/sample-wl.json
+77 −0 json/schemas/otp-contents-schema.json
+50 −0 json/schemas/otp-schema.json
+158 −0 json/schemas/partition-table-schema.json
+52 −0 json/schemas/permissions-schema.json
+124 −0 json/schemas/whitelabel-schema.json
+6 −0 lib/BUILD.bazel
+27 −0 lib/CMakeLists.txt
+4,217 −0 lib/include/mbedtls_config.h
+7 −0 lib/nlohmann_json/BUILD.bazel
+126 −0 lib/nlohmann_json/CMakeLists.txt
+21 −0 lib/nlohmann_json/LICENSE.MIT
+24,766 −0 lib/nlohmann_json/single_include/nlohmann/json.hpp
+14 −0 lib/whereami/BUILD.bazel
+7 −0 lib/whereami/CMakeLists.txt
+101 −0 lib/whereami/whereami++.cpp
+66 −0 lib/whereami/whereami++.h
+801 −0 lib/whereami/whereami.c
+64 −0 lib/whereami/whereami.h
+6,556 −783 main.cpp
+23 −0 no_otp.cpp
+84 −0 otp.cpp
+97 −0 otp.h
+19 −0 otp_header_parser/BUILD.bazel
+18 −0 otp_header_parser/CMakeLists.txt
+389 −0 otp_header_parser/otp_header_parse.cpp
+31,174 −0 otp_header_parser/rp2350.json.h
+24 −0 picoboot_connection/BUILD.bazel
+5 −2 picoboot_connection/CMakeLists.txt
+731 −0 picoboot_connection/picoboot_connection.c
+0 −428 picoboot_connection/picoboot_connection.cpp
+65 −25 picoboot_connection/picoboot_connection.h
+35 −0 picoboot_connection/picoboot_connection_cxx.cpp
+17 −2 picoboot_connection/picoboot_connection_cxx.h
+8 −0 picoboot_flash_id/BUILD.bazel
+36 −0 picoboot_flash_id/CMakeLists.txt
+ picoboot_flash_id/flash_id.bin
+70 −0 picoboot_flash_id/flash_id.c
+24 −0 udev/99-picotool.rules
+39 −0 xip_ram_perms.cpp
+12 −0 xip_ram_perms.h
+17 −0 xip_ram_perms/BUILD.bazel
+53 −0 xip_ram_perms/CMakeLists.txt
+192 −0 xip_ram_perms/set_perms.c
+ xip_ram_perms/xip_ram_perms.elf
28 changes: 28 additions & 0 deletions Sming/Arch/Rp2040/Components/picotool/picotool.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
diff --git a/lib/whereami/whereami.c b/lib/whereami/whereami.c
index d052e14..940736e 100644
--- a/lib/whereami/whereami.c
+++ b/lib/whereami/whereami.c
@@ -60,8 +60,9 @@ extern "C" {
#if defined(_MSC_VER)
#pragma warning(push, 3)
#endif
+#undef _WIN32_WINNT
+#define _WIN32_WINNT _WIN32_WINNT_WINXP
#include <windows.h>
-#include <intrin.h>
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
diff --git a/picoboot_connection/picoboot_connection.c b/picoboot_connection/picoboot_connection.c
index 265608c..e487714 100644
--- a/picoboot_connection/picoboot_connection.c
+++ b/picoboot_connection/picoboot_connection.c
@@ -9,6 +9,8 @@
#include <stdbool.h>
#include <inttypes.h>

+#define static_assert _Static_assert
+
#include "picoboot_connection.h"
#include "boot/bootrom_constants.h"
#include "pico/stdio_usb/reset_interface.h"
Loading
Loading