added CDC UART to RP2040 (Pico)
This commit is contained in:
parent
687b3fea3e
commit
270c127bca
|
@ -26,6 +26,7 @@ if(FAMILY STREQUAL "rp2040")
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/CMSIS_5/CMSIS/DAP/Firmware/Source/DAP_vendor.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMSIS_5/CMSIS/DAP/Firmware/Source/SWO.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMSIS_5/CMSIS/DAP/Firmware/Source/SW_DP.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/bsp/${FAMILY}/cdc_uart.c
|
||||
)
|
||||
|
||||
# Example include
|
||||
|
|
3
Makefile
3
Makefile
|
@ -17,6 +17,7 @@ SRC_C += \
|
|||
./CMSIS_5/CMSIS/DAP/Firmware/Source/JTAG_DP.c \
|
||||
./CMSIS_5/CMSIS/DAP/Firmware/Source/DAP_vendor.c \
|
||||
./CMSIS_5/CMSIS/DAP/Firmware/Source/SWO.c \
|
||||
./CMSIS_5/CMSIS/DAP/Firmware/Source/SW_DP.c
|
||||
./CMSIS_5/CMSIS/DAP/Firmware/Source/SW_DP.c \
|
||||
./bsp/$(BOARD)/cdc_uart.c
|
||||
|
||||
include ./tinyusb/examples/rules.mk
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2021 Raspberry Pi (Trading) Ltd.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <pico/stdlib.h>
|
||||
|
||||
#include "tusb.h"
|
||||
|
||||
#include "picoprobe_config.h"
|
||||
|
||||
void cdc_uart_init(void) {
|
||||
gpio_set_function(PICOPROBE_UART_TX, GPIO_FUNC_UART);
|
||||
gpio_set_function(PICOPROBE_UART_RX, GPIO_FUNC_UART);
|
||||
uart_init(PICOPROBE_UART_INTERFACE, PICOPROBE_UART_BAUDRATE);
|
||||
}
|
||||
|
||||
void cdc_task(void) {
|
||||
uint8_t rx_buf[CFG_TUD_CDC_RX_BUFSIZE];
|
||||
uint8_t tx_buf[CFG_TUD_CDC_TX_BUFSIZE];
|
||||
|
||||
// Consume uart fifo regardless even if not connected
|
||||
uint rx_len = 0;
|
||||
while(uart_is_readable(PICOPROBE_UART_INTERFACE) && (rx_len < sizeof(rx_buf))) {
|
||||
rx_buf[rx_len++] = uart_getc(PICOPROBE_UART_INTERFACE);
|
||||
}
|
||||
|
||||
if (tud_cdc_connected()) {
|
||||
// Do we have anything to display on the host's terminal?
|
||||
if (rx_len) {
|
||||
for (uint i = 0; i < rx_len; i++) {
|
||||
tud_cdc_write_char(rx_buf[i]);
|
||||
}
|
||||
tud_cdc_write_flush();
|
||||
}
|
||||
|
||||
if (tud_cdc_available()) {
|
||||
// Is there any data from the host for us to tx
|
||||
uint tx_len = tud_cdc_read(tx_buf, sizeof(tx_buf));
|
||||
uart_write_blocking(PICOPROBE_UART_INTERFACE, tx_buf, tx_len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void tud_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const* line_coding) {
|
||||
picoprobe_info("New baud rate %d\n", line_coding->bit_rate);
|
||||
uart_init(PICOPROBE_UART_INTERFACE, line_coding->bit_rate);
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
void cdc_uart_init(void)
|
||||
{
|
||||
}
|
||||
|
||||
void cdc_task(void)
|
||||
{
|
||||
}
|
5
main.c
5
main.c
|
@ -33,9 +33,13 @@
|
|||
#include "DAP_config.h" /* ARM code *assumes* this is included prior to DAP.h */
|
||||
#include "DAP.h"
|
||||
|
||||
void cdc_uart_init(void);
|
||||
void cdc_task(void);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
board_init();
|
||||
cdc_uart_init();
|
||||
DAP_Setup();
|
||||
|
||||
tusb_init();
|
||||
|
@ -43,6 +47,7 @@ int main(void)
|
|||
while (1)
|
||||
{
|
||||
tud_task(); // tinyusb device task
|
||||
cdc_task();
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -94,7 +94,7 @@
|
|||
#endif
|
||||
|
||||
//------------- CLASS -------------//
|
||||
#define CFG_TUD_CDC 0
|
||||
#define CFG_TUD_CDC 1
|
||||
#define CFG_TUD_MSC 0
|
||||
#define CFG_TUD_HID 1
|
||||
#define CFG_TUD_MIDI 0
|
||||
|
@ -103,6 +103,10 @@
|
|||
|
||||
#define CFG_TUD_HID_EP_BUFSIZE 64
|
||||
|
||||
// CDC FIFO size of TX and RX
|
||||
#define CFG_TUD_CDC_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -100,12 +100,17 @@ uint8_t const * tud_hid_descriptor_report_cb(void)
|
|||
enum
|
||||
{
|
||||
ITF_NUM_HID,
|
||||
ITF_NUM_CDC_COM,
|
||||
ITF_NUM_CDC_DATA,
|
||||
ITF_NUM_TOTAL
|
||||
};
|
||||
|
||||
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_HID_INOUT_DESC_LEN)
|
||||
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN + TUD_HID_INOUT_DESC_LEN)
|
||||
|
||||
#define EPNUM_HID 0x01
|
||||
#define EPNUM_HID 0x01
|
||||
#define EPNUM_CDC_NOTIF 0x83
|
||||
#define EPNUM_CDC_OUT 0x02
|
||||
#define EPNUM_CDC_IN 0x82
|
||||
|
||||
uint8_t const desc_configuration[] =
|
||||
{
|
||||
|
@ -113,7 +118,10 @@ uint8_t const desc_configuration[] =
|
|||
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100),
|
||||
|
||||
// Interface number, string index, protocol, report descriptor len, EP In & Out address, size & polling interval
|
||||
TUD_HID_INOUT_DESCRIPTOR(ITF_NUM_HID, 0, HID_PROTOCOL_NONE, sizeof(desc_hid_report), EPNUM_HID, 0x80 | EPNUM_HID, CFG_TUD_HID_EP_BUFSIZE, 1)
|
||||
TUD_HID_INOUT_DESCRIPTOR(ITF_NUM_HID, 0, HID_PROTOCOL_NONE, sizeof(desc_hid_report), EPNUM_HID, 0x80 | EPNUM_HID, CFG_TUD_HID_EP_BUFSIZE, 1),
|
||||
|
||||
// Interface number, string index, EP notification address and size, EP data address (out, in) and size.
|
||||
TUD_CDC_DESCRIPTOR(ITF_NUM_CDC_COM, 0, EPNUM_CDC_NOTIF, 64, EPNUM_CDC_OUT, EPNUM_CDC_IN, 64),
|
||||
};
|
||||
|
||||
// Invoked when received GET CONFIGURATION DESCRIPTOR
|
||||
|
|
Loading…
Reference in New Issue