From 06cea2b05c9606632e4f0f1ae2445a12e625e0e3 Mon Sep 17 00:00:00 2001 From: Thomas Eberhardt Date: Tue, 3 Dec 2024 03:41:16 +0100 Subject: [PATCH 1/2] sync with SDK 2.1.0 pico_stdio_usb, move USB manu/prod to CMakeLists.txt --- picosim/rp2040/CMakeLists.txt | 2 ++ .../stdio_msc_usb/include/stdio_msc_usb.h | 9 +++++++-- .../rp2040/stdio_msc_usb/reset_interface.c | 19 ++++++++++++------- .../stdio_msc_usb/stdio_msc_usb_descriptors.c | 12 ++++++++++-- picosim/rp2350/CMakeLists.txt.arm | 2 ++ picosim/rp2350/CMakeLists.txt.corev | 2 ++ .../stdio_msc_usb/include/stdio_msc_usb.h | 9 +++++++-- .../rp2350/stdio_msc_usb/reset_interface.c | 19 ++++++++++++------- .../stdio_msc_usb/stdio_msc_usb_descriptors.c | 12 ++++++++++-- 9 files changed, 64 insertions(+), 22 deletions(-) diff --git a/picosim/rp2040/CMakeLists.txt b/picosim/rp2040/CMakeLists.txt index 250c2cdc..584201ed 100644 --- a/picosim/rp2040/CMakeLists.txt +++ b/picosim/rp2040/CMakeLists.txt @@ -65,6 +65,8 @@ target_compile_definitions(${PROJECT_NAME} PRIVATE PICO_STACK_SIZE=4096 PICO_CORE1_STACK_SIZE=4096 PICO_HEAP_SIZE=8192 + USBD_MANUFACTURER="Z80pack" + USBD_PRODUCT="Pi Pico RP2040" ) # compiler diagnostic options diff --git a/picosim/rp2040/stdio_msc_usb/include/stdio_msc_usb.h b/picosim/rp2040/stdio_msc_usb/include/stdio_msc_usb.h index dacb8541..367ae59c 100644 --- a/picosim/rp2040/stdio_msc_usb/include/stdio_msc_usb.h +++ b/picosim/rp2040/stdio_msc_usb/include/stdio_msc_usb.h @@ -47,7 +47,7 @@ #define STDIO_MSC_USB_ENABLE_RESET_VIA_BAUD_RATE 1 #endif -// PICO_CONFIG: STDIO_MSC_USB_RESET_MAGIC_BAUD_RATE, baud rate that if selected causes a reset into BOOTSEL mode (if STDIO_MSC_USB_ENABLE_RESET_VIA_BAUD_RATE is set), default=1200, group=stdio_msc_usb +// PICO_CONFIG: STDIO_MSC_USB_RESET_MAGIC_BAUD_RATE, Baud rate that if selected causes a reset into BOOTSEL mode (if STDIO_MSC_USB_ENABLE_RESET_VIA_BAUD_RATE is set), default=1200, group=stdio_msc_usb #ifndef STDIO_MSC_USB_RESET_MAGIC_BAUD_RATE #define STDIO_MSC_USB_RESET_MAGIC_BAUD_RATE 1200 #endif @@ -67,7 +67,12 @@ #define STDIO_MSC_USB_DEINIT_DELAY_MS 110 #endif -// PICO_CONFIG: STDIO_MSC_USB_RESET_BOOTSEL_ACTIVITY_LED, Optionally define a pin to use as bootloader activity LED when BOOTSEL mode is entered via USB (either VIA_BAUD_RATE or VIA_VENDOR_INTERFACE), type=int, min=0, max=29, group=stdio_msc_usb +// PICO_CONFIG: STDIO_MSC_USB_RESET_BOOTSEL_ACTIVITY_LED, Optionally define a pin to use as bootloader activity LED when BOOTSEL mode is entered via USB (either VIA_BAUD_RATE or VIA_VENDOR_INTERFACE), type=int, min=0, max=47 on RP2350B, 29 otherwise, group=stdio_msc_usb + +// PICO_CONFIG: STDIO_MSC_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW, Whether pin to use as bootloader activity LED when BOOTSEL mode is entered via USB (either VIA_BAUD_RATE or VIA_VENDOR_INTERFACE) is active low, type=bool, default=0, group=stdio_msc_usb +#ifndef STDIO_MSC_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED_ACTIVE_LOW +#define STDIO_MSC_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED_ACTIVE_LOW 0 +#endif // PICO_CONFIG: STDIO_MSC_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED, Whether the pin specified by STDIO_MSC_USB_RESET_BOOTSEL_ACTIVITY_LED is fixed or can be modified by picotool over the VENDOR USB interface, type=bool, default=0, group=stdio_msc_usb #ifndef STDIO_MSC_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED diff --git a/picosim/rp2040/stdio_msc_usb/reset_interface.c b/picosim/rp2040/stdio_msc_usb/reset_interface.c index 1ebf6d9c..5c2b84a5 100644 --- a/picosim/rp2040/stdio_msc_usb/reset_interface.c +++ b/picosim/rp2040/stdio_msc_usb/reset_interface.c @@ -122,16 +122,19 @@ static bool resetd_control_xfer_cb(uint8_t __unused rhport, uint8_t stage, tusb_ #if STDIO_MSC_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL if (request->bRequest == RESET_REQUEST_BOOTSEL) { #ifdef STDIO_MSC_USB_RESET_BOOTSEL_ACTIVITY_LED - uint gpio_mask = 1u << STDIO_MSC_USB_RESET_BOOTSEL_ACTIVITY_LED; + int gpio = STDIO_MSC_USB_RESET_BOOTSEL_ACTIVITY_LED; + bool active_low = STDIO_MSC_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW; #else - uint gpio_mask = 0u; + int gpio = -1; + bool active_low = false; #endif #if !STDIO_MSC_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED if (request->wValue & 0x100) { - gpio_mask = 1u << (request->wValue >> 9u); + gpio = request->wValue >> 9u; } + active_low = request->wValue & 0x200; #endif - reset_usb_boot(gpio_mask, (request->wValue & 0x7f) | STDIO_MSC_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK); + rom_reset_usb_boot_extra(gpio, (request->wValue & 0x7f) | STDIO_MSC_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK, active_low); // does not return, otherwise we'd return true } #endif @@ -176,11 +179,13 @@ usbd_class_driver_t const *usbd_app_driver_get_cb(uint8_t *driver_count) { void tud_cdc_line_coding_cb(__unused uint8_t itf, cdc_line_coding_t const* p_line_coding) { if (p_line_coding->bit_rate == STDIO_MSC_USB_RESET_MAGIC_BAUD_RATE) { #ifdef STDIO_MSC_USB_RESET_BOOTSEL_ACTIVITY_LED - const uint gpio_mask = 1u << STDIO_MSC_USB_RESET_BOOTSEL_ACTIVITY_LED; + int gpio = STDIO_MSC_USB_RESET_BOOTSEL_ACTIVITY_LED; + bool active_low = STDIO_MSC_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW; #else - const uint gpio_mask = 0u; + int gpio = -1; + bool active_low = false; #endif - reset_usb_boot(gpio_mask, STDIO_MSC_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK); + rom_reset_usb_boot_extra(gpio, STDIO_MSC_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK, active_low); } } #endif diff --git a/picosim/rp2040/stdio_msc_usb/stdio_msc_usb_descriptors.c b/picosim/rp2040/stdio_msc_usb/stdio_msc_usb_descriptors.c index 98badadf..89c8f4cb 100644 --- a/picosim/rp2040/stdio_msc_usb/stdio_msc_usb_descriptors.c +++ b/picosim/rp2040/stdio_msc_usb/stdio_msc_usb_descriptors.c @@ -44,11 +44,11 @@ #endif #ifndef USBD_MANUFACTURER -#define USBD_MANUFACTURER "Z80pack" +#define USBD_MANUFACTURER "Raspberry Pi" #endif #ifndef USBD_PRODUCT -#define USBD_PRODUCT "Pi Pico RP2040" +#define USBD_PRODUCT "Pico" #endif #define TUD_RPI_RESET_DESC_LEN 9 @@ -124,7 +124,15 @@ static const tusb_desc_device_t usbd_desc_device = { .bLength = sizeof(tusb_desc_device_t), .bDescriptorType = TUSB_DESC_DEVICE, +// On Windows, if bcdUSB = 0x210 then a Microsoft OS 2.0 descriptor is required, else the device won't be detected +// This is only needed for driverless access to the reset interface - the CDC interface doesn't require these descriptors +// for driverless access, but will still not work if bcdUSB = 0x210 and no descriptor is provided. Therefore always +// use bcdUSB = 0x200 if the Microsoft OS 2.0 descriptor isn't enabled +#if STDIO_MSC_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE && STDIO_MSC_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR .bcdUSB = 0x0210, +#else + .bcdUSB = 0x0200, +#endif .bDeviceClass = TUSB_CLASS_MISC, .bDeviceSubClass = MISC_SUBCLASS_COMMON, .bDeviceProtocol = MISC_PROTOCOL_IAD, diff --git a/picosim/rp2350/CMakeLists.txt.arm b/picosim/rp2350/CMakeLists.txt.arm index 86ea9843..850f1526 100644 --- a/picosim/rp2350/CMakeLists.txt.arm +++ b/picosim/rp2350/CMakeLists.txt.arm @@ -64,6 +64,8 @@ target_compile_definitions(${PROJECT_NAME} PRIVATE PICO_STACK_SIZE=4096 PICO_CORE1_STACK_SIZE=4096 PICO_HEAP_SIZE=8192 + USBD_MANUFACTURER="Z80pack" + USBD_PRODUCT="Pi Pico RP2350" ) # compiler diagnostic options diff --git a/picosim/rp2350/CMakeLists.txt.corev b/picosim/rp2350/CMakeLists.txt.corev index 2c0866a5..2ccfac5b 100644 --- a/picosim/rp2350/CMakeLists.txt.corev +++ b/picosim/rp2350/CMakeLists.txt.corev @@ -64,6 +64,8 @@ target_compile_definitions(${PROJECT_NAME} PRIVATE PICO_STACK_SIZE=4096 PICO_CORE1_STACK_SIZE=4096 PICO_HEAP_SIZE=8192 + USBD_MANUFACTURER="Z80pack" + USBD_PRODUCT="Pi Pico RP2350" ) # compiler diagnostic options diff --git a/picosim/rp2350/stdio_msc_usb/include/stdio_msc_usb.h b/picosim/rp2350/stdio_msc_usb/include/stdio_msc_usb.h index dacb8541..367ae59c 100644 --- a/picosim/rp2350/stdio_msc_usb/include/stdio_msc_usb.h +++ b/picosim/rp2350/stdio_msc_usb/include/stdio_msc_usb.h @@ -47,7 +47,7 @@ #define STDIO_MSC_USB_ENABLE_RESET_VIA_BAUD_RATE 1 #endif -// PICO_CONFIG: STDIO_MSC_USB_RESET_MAGIC_BAUD_RATE, baud rate that if selected causes a reset into BOOTSEL mode (if STDIO_MSC_USB_ENABLE_RESET_VIA_BAUD_RATE is set), default=1200, group=stdio_msc_usb +// PICO_CONFIG: STDIO_MSC_USB_RESET_MAGIC_BAUD_RATE, Baud rate that if selected causes a reset into BOOTSEL mode (if STDIO_MSC_USB_ENABLE_RESET_VIA_BAUD_RATE is set), default=1200, group=stdio_msc_usb #ifndef STDIO_MSC_USB_RESET_MAGIC_BAUD_RATE #define STDIO_MSC_USB_RESET_MAGIC_BAUD_RATE 1200 #endif @@ -67,7 +67,12 @@ #define STDIO_MSC_USB_DEINIT_DELAY_MS 110 #endif -// PICO_CONFIG: STDIO_MSC_USB_RESET_BOOTSEL_ACTIVITY_LED, Optionally define a pin to use as bootloader activity LED when BOOTSEL mode is entered via USB (either VIA_BAUD_RATE or VIA_VENDOR_INTERFACE), type=int, min=0, max=29, group=stdio_msc_usb +// PICO_CONFIG: STDIO_MSC_USB_RESET_BOOTSEL_ACTIVITY_LED, Optionally define a pin to use as bootloader activity LED when BOOTSEL mode is entered via USB (either VIA_BAUD_RATE or VIA_VENDOR_INTERFACE), type=int, min=0, max=47 on RP2350B, 29 otherwise, group=stdio_msc_usb + +// PICO_CONFIG: STDIO_MSC_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW, Whether pin to use as bootloader activity LED when BOOTSEL mode is entered via USB (either VIA_BAUD_RATE or VIA_VENDOR_INTERFACE) is active low, type=bool, default=0, group=stdio_msc_usb +#ifndef STDIO_MSC_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED_ACTIVE_LOW +#define STDIO_MSC_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED_ACTIVE_LOW 0 +#endif // PICO_CONFIG: STDIO_MSC_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED, Whether the pin specified by STDIO_MSC_USB_RESET_BOOTSEL_ACTIVITY_LED is fixed or can be modified by picotool over the VENDOR USB interface, type=bool, default=0, group=stdio_msc_usb #ifndef STDIO_MSC_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED diff --git a/picosim/rp2350/stdio_msc_usb/reset_interface.c b/picosim/rp2350/stdio_msc_usb/reset_interface.c index 1ebf6d9c..5c2b84a5 100644 --- a/picosim/rp2350/stdio_msc_usb/reset_interface.c +++ b/picosim/rp2350/stdio_msc_usb/reset_interface.c @@ -122,16 +122,19 @@ static bool resetd_control_xfer_cb(uint8_t __unused rhport, uint8_t stage, tusb_ #if STDIO_MSC_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL if (request->bRequest == RESET_REQUEST_BOOTSEL) { #ifdef STDIO_MSC_USB_RESET_BOOTSEL_ACTIVITY_LED - uint gpio_mask = 1u << STDIO_MSC_USB_RESET_BOOTSEL_ACTIVITY_LED; + int gpio = STDIO_MSC_USB_RESET_BOOTSEL_ACTIVITY_LED; + bool active_low = STDIO_MSC_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW; #else - uint gpio_mask = 0u; + int gpio = -1; + bool active_low = false; #endif #if !STDIO_MSC_USB_RESET_BOOTSEL_FIXED_ACTIVITY_LED if (request->wValue & 0x100) { - gpio_mask = 1u << (request->wValue >> 9u); + gpio = request->wValue >> 9u; } + active_low = request->wValue & 0x200; #endif - reset_usb_boot(gpio_mask, (request->wValue & 0x7f) | STDIO_MSC_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK); + rom_reset_usb_boot_extra(gpio, (request->wValue & 0x7f) | STDIO_MSC_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK, active_low); // does not return, otherwise we'd return true } #endif @@ -176,11 +179,13 @@ usbd_class_driver_t const *usbd_app_driver_get_cb(uint8_t *driver_count) { void tud_cdc_line_coding_cb(__unused uint8_t itf, cdc_line_coding_t const* p_line_coding) { if (p_line_coding->bit_rate == STDIO_MSC_USB_RESET_MAGIC_BAUD_RATE) { #ifdef STDIO_MSC_USB_RESET_BOOTSEL_ACTIVITY_LED - const uint gpio_mask = 1u << STDIO_MSC_USB_RESET_BOOTSEL_ACTIVITY_LED; + int gpio = STDIO_MSC_USB_RESET_BOOTSEL_ACTIVITY_LED; + bool active_low = STDIO_MSC_USB_RESET_BOOTSEL_ACTIVITY_LED_ACTIVE_LOW; #else - const uint gpio_mask = 0u; + int gpio = -1; + bool active_low = false; #endif - reset_usb_boot(gpio_mask, STDIO_MSC_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK); + rom_reset_usb_boot_extra(gpio, STDIO_MSC_USB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK, active_low); } } #endif diff --git a/picosim/rp2350/stdio_msc_usb/stdio_msc_usb_descriptors.c b/picosim/rp2350/stdio_msc_usb/stdio_msc_usb_descriptors.c index 15c8bab9..89c8f4cb 100644 --- a/picosim/rp2350/stdio_msc_usb/stdio_msc_usb_descriptors.c +++ b/picosim/rp2350/stdio_msc_usb/stdio_msc_usb_descriptors.c @@ -44,11 +44,11 @@ #endif #ifndef USBD_MANUFACTURER -#define USBD_MANUFACTURER "Z80pack" +#define USBD_MANUFACTURER "Raspberry Pi" #endif #ifndef USBD_PRODUCT -#define USBD_PRODUCT "Pi Pico RP2350" +#define USBD_PRODUCT "Pico" #endif #define TUD_RPI_RESET_DESC_LEN 9 @@ -124,7 +124,15 @@ static const tusb_desc_device_t usbd_desc_device = { .bLength = sizeof(tusb_desc_device_t), .bDescriptorType = TUSB_DESC_DEVICE, +// On Windows, if bcdUSB = 0x210 then a Microsoft OS 2.0 descriptor is required, else the device won't be detected +// This is only needed for driverless access to the reset interface - the CDC interface doesn't require these descriptors +// for driverless access, but will still not work if bcdUSB = 0x210 and no descriptor is provided. Therefore always +// use bcdUSB = 0x200 if the Microsoft OS 2.0 descriptor isn't enabled +#if STDIO_MSC_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE && STDIO_MSC_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR .bcdUSB = 0x0210, +#else + .bcdUSB = 0x0200, +#endif .bDeviceClass = TUSB_CLASS_MISC, .bDeviceSubClass = MISC_SUBCLASS_COMMON, .bDeviceProtocol = MISC_PROTOCOL_IAD, From 6f7224b92f4ad333e740cd91d7bf6f1fbbbbb4d1 Mon Sep 17 00:00:00 2001 From: Thomas Eberhardt Date: Tue, 3 Dec 2024 07:43:44 +0100 Subject: [PATCH 2/2] no-OS-FatFS-SD-SDIO-SPI-RPi-Pico: use Pico SDK API's instead of ARM CMSIS ones rp2040_sdio.c(rp2040_sdio_tx_poll): I think there is no way to determine if we are in an interrupt/exception-handler on RISC-V, therefore only do this on ARM. crash.c(reset): Use watchdog_reboot() instead of CMSIS NVIC_SystemReset(). crash.c: exclude ARM specific DebugMon_Handler()/isr_hardfault() on RISC-V. --- .../src/CMakeLists.txt | 1 - .../src/include/delays.h | 13 ++++--------- .../src/include/util.h | 6 ------ .../src/sd_driver/SDIO/rp2040_sdio.c | 16 ++++++++++------ .../src/src/crash.c | 19 ++++++++++++++----- .../src/src/my_debug.c | 8 ++------ 6 files changed, 30 insertions(+), 33 deletions(-) diff --git a/picosim/rp2350/no-OS-FatFS-SD-SDIO-SPI-RPi-Pico/src/CMakeLists.txt b/picosim/rp2350/no-OS-FatFS-SD-SDIO-SPI-RPi-Pico/src/CMakeLists.txt index b9b75b2b..ae2fe232 100755 --- a/picosim/rp2350/no-OS-FatFS-SD-SDIO-SPI-RPi-Pico/src/CMakeLists.txt +++ b/picosim/rp2350/no-OS-FatFS-SD-SDIO-SPI-RPi-Pico/src/CMakeLists.txt @@ -40,5 +40,4 @@ target_link_libraries(no-OS-FatFS-SD-SDIO-SPI-RPi-Pico INTERFACE hardware_spi pico_aon_timer pico_stdlib - cmsis_core ) diff --git a/picosim/rp2350/no-OS-FatFS-SD-SDIO-SPI-RPi-Pico/src/include/delays.h b/picosim/rp2350/no-OS-FatFS-SD-SDIO-SPI-RPi-Pico/src/include/delays.h index c3a974c0..dada4f37 100644 --- a/picosim/rp2350/no-OS-FatFS-SD-SDIO-SPI-RPi-Pico/src/include/delays.h +++ b/picosim/rp2350/no-OS-FatFS-SD-SDIO-SPI-RPi-Pico/src/include/delays.h @@ -51,20 +51,15 @@ call to millis() returns 0xFFFFFFFF: #include // #include "pico/stdlib.h" -#if PICO_RP2040 -#include "RP2040.h" -#else -#include "RP2350.h" -#endif #ifdef __cplusplus extern "C" { #endif static inline uint32_t millis() { - __COMPILER_BARRIER(); + __compiler_memory_barrier(); return time_us_64() / 1000; - __COMPILER_BARRIER(); + __compiler_memory_barrier(); } static inline void delay_ms(uint32_t ulTime_ms) { @@ -72,9 +67,9 @@ static inline void delay_ms(uint32_t ulTime_ms) { } static inline uint64_t micros() { - __COMPILER_BARRIER(); + __compiler_memory_barrier(); return to_us_since_boot(get_absolute_time()); - __COMPILER_BARRIER(); + __compiler_memory_barrier(); } #ifdef __cplusplus diff --git a/picosim/rp2350/no-OS-FatFS-SD-SDIO-SPI-RPi-Pico/src/include/util.h b/picosim/rp2350/no-OS-FatFS-SD-SDIO-SPI-RPi-Pico/src/include/util.h index 0263fc46..5562aa3e 100755 --- a/picosim/rp2350/no-OS-FatFS-SD-SDIO-SPI-RPi-Pico/src/include/util.h +++ b/picosim/rp2350/no-OS-FatFS-SD-SDIO-SPI-RPi-Pico/src/include/util.h @@ -18,12 +18,6 @@ specific language governing permissions and limitations under the License. #include #include // -#if PICO_RP2040 -#include "RP2040.h" -#else -#include "RP2350.h" -#endif -// #include "my_debug.h" #ifdef __cplusplus diff --git a/picosim/rp2350/no-OS-FatFS-SD-SDIO-SPI-RPi-Pico/src/sd_driver/SDIO/rp2040_sdio.c b/picosim/rp2350/no-OS-FatFS-SD-SDIO-SPI-RPi-Pico/src/sd_driver/SDIO/rp2040_sdio.c index ecbf217a..6b084335 100755 --- a/picosim/rp2350/no-OS-FatFS-SD-SDIO-SPI-RPi-Pico/src/sd_driver/SDIO/rp2040_sdio.c +++ b/picosim/rp2350/no-OS-FatFS-SD-SDIO-SPI-RPi-Pico/src/sd_driver/SDIO/rp2040_sdio.c @@ -15,11 +15,6 @@ #include "hardware/dma.h" #include "hardware/gpio.h" #include "hardware/pio.h" -#if PICO_RP2040 -#include "RP2040.h" -#else -#include "RP2350.h" -#endif // #include "dma_interrupts.h" #include "hw_config.h" @@ -686,11 +681,20 @@ void sdio_irq_handler(sd_card_t *sd_card_p) { // Check if transmission is complete sdio_status_t rp2040_sdio_tx_poll(sd_card_t *sd_card_p, uint32_t *bytes_complete) { - if (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) +#if !__riscv +# if PICO_RP2040 + const uint32_t icsr_vectactive_bits = M0PLUS_ICSR_VECTACTIVE_BITS; +# endif +# if PICO_RP2350 + const uint32_t icsr_vectactive_bits = M33_ICSR_VECTACTIVE_BITS; +# endif + + if (scb_hw->icsr & icsr_vectactive_bits) { // Verify that IRQ handler gets called even if we are in hardfault handler sdio_irq_handler(sd_card_p); } +#endif // !__riscv if (bytes_complete) { diff --git a/picosim/rp2350/no-OS-FatFS-SD-SDIO-SPI-RPi-Pico/src/src/crash.c b/picosim/rp2350/no-OS-FatFS-SD-SDIO-SPI-RPi-Pico/src/src/crash.c index 168617b2..51e6a32d 100644 --- a/picosim/rp2350/no-OS-FatFS-SD-SDIO-SPI-RPi-Pico/src/src/crash.c +++ b/picosim/rp2350/no-OS-FatFS-SD-SDIO-SPI-RPi-Pico/src/src/crash.c @@ -16,6 +16,8 @@ specific language governing permissions and limitations under the License. #include // #include "pico/stdlib.h" +#include "hardware/sync.h" +#include "hardware/watchdog.h" // #include "crc.h" #include "my_debug.h" @@ -40,7 +42,10 @@ static inline void reset() { // if (debugger_connected()) { __breakpoint(); // } else { - NVIC_SystemReset(); + watchdog_reboot(0, 0, 0); + for (;;) { + __wfi(); + } // } __builtin_unreachable(); } @@ -79,7 +84,7 @@ void system_reset_func(char const *const func) { func); crash_info_ram.xor_checksum = crc7((uint8_t *)&crash_info_ram, offsetof(crash_info_t, xor_checksum)); - __DSB(); + __dsb(); reset(); __builtin_unreachable(); @@ -104,11 +109,13 @@ void capture_assert(const char *file, int line, const char *func, const char *pr crash_info_ram.assert.line = line; crash_info_ram.xor_checksum = crc7((uint8_t *)&crash_info_ram, offsetof(crash_info_t, xor_checksum)); - __DSB(); + __dsb(); reset(); __builtin_unreachable(); } +#if !__riscv + __attribute__((used)) extern void DebugMon_HandlerC(uint32_t const *faultStackAddr) { memset((void *)crash_info_ram_p, 0, sizeof crash_info_ram); crash_info_ram.magic = crash_magic_debug_mon; @@ -144,7 +151,7 @@ __attribute__((used)) extern void DebugMon_HandlerC(uint32_t const *faultStackAd //} crash_info_ram.xor_checksum = crc7((uint8_t *)&crash_info_ram, offsetof(crash_info_t, xor_checksum)); - __DSB(); // make sure all data is really written into the memory before + __dsb(); // make sure all data is really written into the memory before // doing a reset reset(); } @@ -182,7 +189,7 @@ void Hardfault_HandlerC(uint32_t const *faultStackAddr) { crash_info_ram.xor_checksum = crc7((uint8_t *)&crash_info_ram, offsetof(crash_info_t, xor_checksum)); - __DSB(); // make sure all data is really written into the memory before + __dsb(); // make sure all data is really written into the memory before // doing a reset reset(); @@ -202,6 +209,8 @@ __attribute__((naked)) void isr_hardfault(void) { " b Hardfault_HandlerC \n"); } +#endif // !__riscv + enum { crash_info_magic, crash_info_hf_lr, diff --git a/picosim/rp2350/no-OS-FatFS-SD-SDIO-SPI-RPi-Pico/src/src/my_debug.c b/picosim/rp2350/no-OS-FatFS-SD-SDIO-SPI-RPi-Pico/src/src/my_debug.c index ab26702b..cf731d00 100644 --- a/picosim/rp2350/no-OS-FatFS-SD-SDIO-SPI-RPi-Pico/src/src/my_debug.c +++ b/picosim/rp2350/no-OS-FatFS-SD-SDIO-SPI-RPi-Pico/src/src/my_debug.c @@ -17,12 +17,8 @@ specific language governing permissions and limitations under the License. #include #include // -#if PICO_RP2040 -#include "RP2040.h" -#else -#include "RP2350.h" -#endif #include "pico/stdlib.h" +#include "hardware/sync.h" // #include "crash.h" // @@ -144,7 +140,7 @@ void __attribute__((weak)) my_assert_func(const char *file, int line, const char const char *pred) { error_message_printf_plain("assertion \"%s\" failed: file \"%s\", line %d, function: %s\n", pred, file, line, func); - __disable_irq(); /* Disable global interrupts. */ + (void)save_and_disable_interrupts(); /* Disable global interrupts. */ capture_assert(file, line, func, pred); }