Skip to content

Commit

Permalink
Merge pull request #464 from sneakywumpus/dev
Browse files Browse the repository at this point in the history
sync with SDK 2.1.0 pico_stdio_usb, move USB manu/prod to CMakeLists.txt
  • Loading branch information
udo-munk authored Dec 3, 2024
2 parents b340927 + 06cea2b commit 9ea683d
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 22 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
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 9ea683d

Please sign in to comment.