Skip to content

Commit 1c2f927

Browse files
committed
feat(cherryusb): support pico_stdio_usb
Signed-off-by: sakumisu <[email protected]>
1 parent 50f3ab7 commit 1c2f927

File tree

7 files changed

+1136
-1
lines changed

7 files changed

+1136
-1
lines changed

lib/cherryusb

src/cmake/rp2_common.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ if (NOT PICO_BARE_METAL)
120120
endif()
121121
pico_add_subdirectory(rp2_common/tinyusb)
122122
pico_add_subdirectory(rp2_common/cherryusb)
123+
pico_add_subdirectory(rp2_common/pico_stdio_cherryusb)
123124
pico_add_subdirectory(rp2_common/pico_stdio_usb)
124125
pico_add_subdirectory(rp2_common/pico_i2c_slave)
125126

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
if (TARGET cherryusb_device)
2+
pico_add_library(pico_stdio_usb)
3+
4+
target_include_directories(pico_stdio_usb_headers SYSTEM INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
5+
6+
target_sources(pico_stdio_usb INTERFACE
7+
${CMAKE_CURRENT_LIST_DIR}/stdio_usb.c
8+
)
9+
10+
pico_mirrored_target_link_libraries(pico_stdio_usb INTERFACE
11+
pico_stdio
12+
pico_time
13+
pico_unique_id
14+
pico_usb_reset_interface
15+
)
16+
target_link_libraries(pico_stdio_usb INTERFACE
17+
cherryusb_device
18+
)
19+
# PICO_CMAKE_CONFIG: PICO_STDIO_CHERRYUSB_CONNECT_WAIT_TIMEOUT_MS, Maximum number of milliseconds to wait during initialization for a CDC connection from the host (negative means indefinite) during initialization, type=int, default=0, group=pico_stdio_usb
20+
if (PICO_STDIO_CHERRYUSB_CONNECT_WAIT_TIMEOUT_MS)
21+
target_compile_definitions(pico_stdio_usb INTERFACE
22+
PICO_STDIO_CHERRYUSB_CONNECT_WAIT_TIMEOUT_MS=${PICO_STDIO_CHERRYUSB_CONNECT_WAIT_TIMEOUT_MS}
23+
)
24+
endif()
25+
endif()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
/*
2+
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
#ifndef _PICO_STDIO_CHERRYUSB_H
8+
#define _PICO_STDIO_CHERRYUSB_H
9+
10+
#include "pico/stdio.h"
11+
12+
/** \brief Support for stdin/stdout over USB serial (CDC)
13+
* \defgroup pico_stdio_usb pico_stdio_usb
14+
* \ingroup pico_stdio
15+
*
16+
* Linking this library or calling `pico_enable_stdio_usb(TARGET ENABLED)` in the CMake (which
17+
* achieves the same thing) will add USB CDC to the drivers used for standard input/output
18+
*
19+
* Note this library is a developer convenience. It is not applicable in all cases; for one it takes full control of the USB device precluding your
20+
* use of the USB in device or host mode. For this reason, this library will automatically disengage if you try to using it alongside \ref tinyusb_device or
21+
* \ref tinyusb_host. It also takes control of a lower level IRQ and sets up a periodic background task.
22+
*
23+
* This library also includes (by default) functionality to enable the RP-series microcontroller to be reset over the USB interface.
24+
*/
25+
26+
// PICO_CONFIG: PICO_STDIO_CHERRYUSB_DEFAULT_CRLF, Default state of CR/LF translation for USB output, type=bool, default=PICO_STDIO_DEFAULT_CRLF, group=pico_stdio_usb
27+
#ifndef PICO_STDIO_CHERRYUSB_DEFAULT_CRLF
28+
#define PICO_STDIO_CHERRYUSB_DEFAULT_CRLF PICO_STDIO_DEFAULT_CRLF
29+
#endif
30+
31+
// PICO_CONFIG: PICO_STDIO_CHERRYUSB_STDOUT_TIMEOUT_US, Number of microseconds to be blocked trying to write USB output before assuming the host has disappeared and discarding data, default=500000, group=pico_stdio_usb
32+
#ifndef PICO_STDIO_CHERRYUSB_STDOUT_TIMEOUT_US
33+
#define PICO_STDIO_CHERRYUSB_STDOUT_TIMEOUT_US 500000
34+
#endif
35+
36+
// PICO_CONFIG: PICO_STDIO_CHERRYUSB_ENABLE_RESET_VIA_BAUD_RATE, Enable/disable resetting into BOOTSEL mode if the host sets the baud rate to a magic value (PICO_STDIO_CHERRYUSB_RESET_MAGIC_BAUD_RATE), type=bool, default=1 if application is not using TinyUSB directly, group=pico_stdio_usb
37+
#ifndef PICO_STDIO_CHERRYUSB_ENABLE_RESET_VIA_BAUD_RATE
38+
#define PICO_STDIO_CHERRYUSB_ENABLE_RESET_VIA_BAUD_RATE 1
39+
#endif
40+
41+
// PICO_CONFIG: PICO_STDIO_CHERRYUSB_RESET_MAGIC_BAUD_RATE, Baud rate that if selected causes a reset into BOOTSEL mode (if PICO_STDIO_CHERRYUSB_ENABLE_RESET_VIA_BAUD_RATE is set), default=1200, group=pico_stdio_usb
42+
#ifndef PICO_STDIO_CHERRYUSB_RESET_MAGIC_BAUD_RATE
43+
#define PICO_STDIO_CHERRYUSB_RESET_MAGIC_BAUD_RATE 1200
44+
#endif
45+
46+
// PICO_CONFIG: PICO_STDIO_CHERRYUSB_CONNECT_WAIT_TIMEOUT_MS, Maximum number of milliseconds to wait during initialization for a CDC connection from the host (negative means indefinite) during initialization, default=0, group=pico_stdio_usb
47+
#ifndef PICO_STDIO_CHERRYUSB_CONNECT_WAIT_TIMEOUT_MS
48+
#define PICO_STDIO_CHERRYUSB_CONNECT_WAIT_TIMEOUT_MS 0
49+
#endif
50+
51+
// PICO_CONFIG: PICO_STDIO_CHERRYUSB_CONNECT_WAIT_TIMEOUT_MS, Number of extra milliseconds to wait when using PICO_STDIO_CHERRYUSB_CONNECT_WAIT_TIMEOUT_MS after a host CDC connection is detected (some host terminals seem to sometimes lose transmissions sent right after connection), default=50, group=pico_stdio_usb
52+
#ifndef PICO_STDIO_CHERRYUSB_CONNECT_WAIT_TIMEOUT_MS
53+
#define PICO_STDIO_CHERRYUSB_CONNECT_WAIT_TIMEOUT_MS 50
54+
#endif
55+
56+
// PICO_CONFIG: PICO_STDIO_CHERRYUSB_DEINIT_DELAY_MS, Number of milliseconds to wait before deinitializing stdio_usb, default=110, group=pico_stdio_usb
57+
#ifndef PICO_STDIO_CHERRYUSB_DEINIT_DELAY_MS
58+
#define PICO_STDIO_CHERRYUSB_DEINIT_DELAY_MS 110
59+
#endif
60+
61+
// PICO_CONFIG: PICO_STDIO_CHERRYUSB_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=pico_stdio_usb
62+
63+
// PICO_CONFIG: PICO_STDIO_CHERRYUSB_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=pico_stdio_usb
64+
#ifndef PICO_STDIO_CHERRYUSB_RESET_BOOTSEL_FIXED_ACTIVITY_LED_ACTIVE_LOW
65+
#define PICO_STDIO_CHERRYUSB_RESET_BOOTSEL_FIXED_ACTIVITY_LED_ACTIVE_LOW 0
66+
#endif
67+
68+
// PICO_CONFIG: PICO_STDIO_CHERRYUSB_RESET_BOOTSEL_FIXED_ACTIVITY_LED, Whether the pin specified by PICO_STDIO_CHERRYUSB_RESET_BOOTSEL_ACTIVITY_LED is fixed or can be modified by picotool over the VENDOR USB interface, type=bool, default=0, group=pico_stdio_usb
69+
#ifndef PICO_STDIO_CHERRYUSB_RESET_BOOTSEL_FIXED_ACTIVITY_LED
70+
#define PICO_STDIO_CHERRYUSB_RESET_BOOTSEL_FIXED_ACTIVITY_LED 0
71+
#endif
72+
73+
// Any modes disabled here can't be re-enabled by picotool via VENDOR_INTERFACE.
74+
// PICO_CONFIG: PICO_STDIO_CHERRYUSB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK, Optionally disable either the mass storage interface (bit 0) or the PICOBOOT interface (bit 1) when entering BOOTSEL mode via USB (either VIA_BAUD_RATE or VIA_VENDOR_INTERFACE), type=int, min=0, max=3, default=0, group=pico_stdio_usb
75+
#ifndef PICO_STDIO_CHERRYUSB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK
76+
#define PICO_STDIO_CHERRYUSB_RESET_BOOTSEL_INTERFACE_DISABLE_MASK 0u
77+
#endif
78+
79+
// PICO_CONFIG: PICO_STDIO_CHERRYUSB_ENABLE_RESET_VIA_VENDOR_INTERFACE, Enable/disable resetting into BOOTSEL mode via an additional VENDOR USB interface - enables picotool based reset, type=bool, default=1 if application is not using TinyUSB directly, group=pico_stdio_usb
80+
#ifndef PICO_STDIO_CHERRYUSB_ENABLE_RESET_VIA_VENDOR_INTERFACE
81+
#define PICO_STDIO_CHERRYUSB_ENABLE_RESET_VIA_VENDOR_INTERFACE 1
82+
#endif
83+
84+
// PICO_CONFIG: PICO_STDIO_CHERRYUSB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL, If vendor reset interface is included allow rebooting to BOOTSEL mode, type=bool, default=1, group=pico_stdio_usb
85+
#ifndef PICO_STDIO_CHERRYUSB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL
86+
#define PICO_STDIO_CHERRYUSB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL 1
87+
#endif
88+
89+
// PICO_CONFIG: PICO_STDIO_CHERRYUSB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT, If vendor reset interface is included allow rebooting with regular flash boot, type=bool, default=1, group=pico_stdio_usb
90+
#ifndef PICO_STDIO_CHERRYUSB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT
91+
#define PICO_STDIO_CHERRYUSB_RESET_INTERFACE_SUPPORT_RESET_TO_FLASH_BOOT 1
92+
#endif
93+
94+
// PICO_CONFIG: PICO_STDIO_CHERRYUSB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR, If vendor reset interface is included add support for Microsoft OS 2.0 Descriptor, type=bool, default=1, group=pico_stdio_usb
95+
#ifndef PICO_STDIO_CHERRYUSB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR
96+
#define PICO_STDIO_CHERRYUSB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR 1
97+
#endif
98+
99+
// PICO_CONFIG: PICO_STDIO_CHERRYUSB_RESET_RESET_TO_FLASH_DELAY_MS, Delay in ms before rebooting via regular flash boot, default=100, group=pico_stdio_usb
100+
#ifndef PICO_STDIO_CHERRYUSB_RESET_RESET_TO_FLASH_DELAY_MS
101+
#define PICO_STDIO_CHERRYUSB_RESET_RESET_TO_FLASH_DELAY_MS 100
102+
#endif
103+
104+
// PICO_CONFIG: PICO_STDIO_CHERRYUSB_CONNECTION_WITHOUT_DTR, Disable use of DTR for connection checking meaning connection is assumed to be valid, type=bool, default=0, group=pico_stdio_usb
105+
#ifndef PICO_STDIO_CHERRYUSB_CONNECTION_WITHOUT_DTR
106+
#define PICO_STDIO_CHERRYUSB_CONNECTION_WITHOUT_DTR 0
107+
#endif
108+
109+
// PICO_CONFIG: PICO_STDIO_CHERRYUSB_DEVICE_SELF_POWERED, Set USB device as self powered device, type=bool, default=0, group=pico_stdio_usb
110+
#ifndef PICO_STDIO_CHERRYUSB_DEVICE_SELF_POWERED
111+
#define PICO_STDIO_CHERRYUSB_DEVICE_SELF_POWERED 0
112+
#endif
113+
114+
// PICO_CONFIG: PICO_STDIO_CHERRYUSB_SUPPORT_CHARS_AVAILABLE_CALLBACK, Enable USB STDIO support for stdio_set_chars_available_callback. Can be disabled to make use of USB CDC RX callback elsewhere, type=bool, default=1, group=pico_stdio_usb
115+
#ifndef PICO_STDIO_CHERRYUSB_SUPPORT_CHARS_AVAILABLE_CALLBACK
116+
#define PICO_STDIO_CHERRYUSB_SUPPORT_CHARS_AVAILABLE_CALLBACK 1
117+
#endif
118+
119+
#ifdef __cplusplus
120+
extern "C" {
121+
#endif
122+
123+
extern stdio_driver_t stdio_usb;
124+
125+
/*! \brief Explicitly initialize USB stdio and add it to the current set of stdin drivers
126+
* \ingroup pico_stdio_usb
127+
*
128+
* \ref PICO_STDIO_CHERRYUSB_CONNECT_WAIT_TIMEOUT_MS can be set to cause this method to wait for a CDC connection
129+
* from the host before returning, which is useful if you don't want any initial stdout output to be discarded
130+
* before the connection is established.
131+
*
132+
* \return true if the USB CDC was initialized, false if an error occurred
133+
*/
134+
bool stdio_usb_init(void);
135+
136+
/*! \brief Explicitly deinitialize USB stdio and remove it from the current set of stdin drivers
137+
* \ingroup pico_stdio_usb
138+
*
139+
* \return true if the USB CDC was deinitialized, false if an error occurred
140+
*/
141+
bool stdio_usb_deinit(void);
142+
143+
/*! \brief Check if there is an active stdio CDC connection to a host
144+
* \ingroup pico_stdio_usb
145+
*
146+
* \return true if stdio is connected over CDC
147+
*/
148+
bool stdio_usb_connected(void);
149+
#ifdef __cplusplus
150+
}
151+
#endif
152+
153+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Copyright (c) 2021 Raspberry Pi (Trading) Ltd.
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
#ifndef _PICO_STDIO_CHERRYUSB_RESET_INTERFACE_H
8+
#define _PICO_STDIO_CHERRYUSB_RESET_INTERFACE_H
9+
10+
// definitions have been moved here
11+
#include "pico/usb_reset_interface.h"
12+
13+
#endif

0 commit comments

Comments
 (0)