Skip to content

Commit

Permalink
Merge pull request #466 from udo-munk/dev
Browse files Browse the repository at this point in the history
merge dev, on RP2350 devices it now runs on ARM and on RISC-V cores
  • Loading branch information
udo-munk authored Dec 3, 2024
2 parents ac73c36 + 77d8450 commit 1863325
Show file tree
Hide file tree
Showing 15 changed files with 94 additions and 55 deletions.
2 changes: 2 additions & 0 deletions picosim/rp2040/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions picosim/rp2040/stdio_msc_usb/include/stdio_msc_usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
19 changes: 12 additions & 7 deletions picosim/rp2040/stdio_msc_usb/reset_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
12 changes: 10 additions & 2 deletions picosim/rp2040/stdio_msc_usb/stdio_msc_usb_descriptors.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions picosim/rp2350/CMakeLists.txt.arm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions picosim/rp2350/CMakeLists.txt.corev
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Original file line number Diff line number Diff line change
Expand Up @@ -51,30 +51,25 @@ call to millis() returns 0xFFFFFFFF:
#include <stdint.h>
//
#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) {
sleep_ms(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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ specific language governing permissions and limitations under the License.
#include <stdint.h>
#include <string.h>
//
#if PICO_RP2040
#include "RP2040.h"
#else
#include "RP2350.h"
#endif
//
#include "my_debug.h"

#ifdef __cplusplus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
{
Expand Down
19 changes: 14 additions & 5 deletions picosim/rp2350/no-OS-FatFS-SD-SDIO-SPI-RPi-Pico/src/src/crash.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ specific language governing permissions and limitations under the License.
#include <time.h>
//
#include "pico/stdlib.h"
#include "hardware/sync.h"
#include "hardware/watchdog.h"
//
#include "crc.h"
#include "my_debug.h"
Expand All @@ -40,7 +42,10 @@ static inline void reset() {
// if (debugger_connected()) {
__breakpoint();
// } else {
NVIC_SystemReset();
watchdog_reboot(0, 0, 0);
for (;;) {
__wfi();
}
// }
__builtin_unreachable();
}
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
Expand All @@ -202,6 +209,8 @@ __attribute__((naked)) void isr_hardfault(void) {
" b Hardfault_HandlerC \n");
}

#endif // !__riscv

enum {
crash_info_magic,
crash_info_hf_lr,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@ specific language governing permissions and limitations under the License.
#include <stdint.h>
#include <string.h>
//
#if PICO_RP2040
#include "RP2040.h"
#else
#include "RP2350.h"
#endif
#include "pico/stdlib.h"
#include "hardware/sync.h"
//
#include "crash.h"
//
Expand Down Expand Up @@ -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);
}

Expand Down
9 changes: 7 additions & 2 deletions picosim/rp2350/stdio_msc_usb/include/stdio_msc_usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
19 changes: 12 additions & 7 deletions picosim/rp2350/stdio_msc_usb/reset_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
12 changes: 10 additions & 2 deletions picosim/rp2350/stdio_msc_usb/stdio_msc_usb_descriptors.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 1863325

Please sign in to comment.