mirror of
https://github.com/hathach/tinyusb.git
synced 2025-03-19 01:21:01 +00:00
host msc example work well with rp2040 pio-usb
This commit is contained in:
parent
ba9f88f18c
commit
460bef9dbb
@ -69,7 +69,7 @@ int main(void)
|
||||
|
||||
// echo
|
||||
uint8_t ch;
|
||||
if ( board_uart_read(&ch, 1) )
|
||||
if ( board_uart_read(&ch, 1) > 0 )
|
||||
{
|
||||
board_uart_write(&ch, 1);
|
||||
}
|
||||
|
@ -29,4 +29,16 @@ target_include_directories(${PROJECT} PUBLIC
|
||||
family_configure_host_example(${PROJECT})
|
||||
|
||||
# For rp2040, un-comment to enable pico-pio-usb
|
||||
# family_add_pico_pio_usb(${PROJECT})
|
||||
family_add_pico_pio_usb(${PROJECT})
|
||||
|
||||
# due to warnings from Pico-PIO-USB
|
||||
target_compile_options(${PROJECT} PUBLIC
|
||||
-Wno-error=shadow
|
||||
-Wno-error=cast-align
|
||||
-Wno-error=cast-qual
|
||||
-Wno-error=redundant-decls
|
||||
-Wno-error=sign-conversion
|
||||
-Wno-error=conversion
|
||||
-Wno-error=sign-compare
|
||||
-Wno-error=unused-function
|
||||
)
|
||||
|
@ -54,13 +54,8 @@ int main(void)
|
||||
tuh_task();
|
||||
led_blinking_task();
|
||||
|
||||
#if CFG_TUH_CDC
|
||||
cdc_task();
|
||||
#endif
|
||||
|
||||
#if CFG_TUH_HID
|
||||
hid_app_task();
|
||||
#endif
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -69,7 +64,6 @@ int main(void)
|
||||
//--------------------------------------------------------------------+
|
||||
// USB CDC
|
||||
//--------------------------------------------------------------------+
|
||||
#if CFG_TUH_CDC
|
||||
CFG_TUSB_MEM_SECTION static char serial_in_buffer[64] = { 0 };
|
||||
|
||||
// invoked ISR context
|
||||
@ -90,8 +84,6 @@ void cdc_task(void)
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// TinyUSB Callbacks
|
||||
//--------------------------------------------------------------------+
|
||||
|
@ -25,8 +25,6 @@
|
||||
|
||||
#include "tusb.h"
|
||||
|
||||
#if CFG_TUH_MSC
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
|
||||
//--------------------------------------------------------------------+
|
||||
@ -103,4 +101,3 @@ void tuh_msc_umount_cb(uint8_t dev_addr)
|
||||
// }
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -34,6 +34,12 @@
|
||||
// Board Specific Configuration
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
#if CFG_TUSB_MCU == OPT_MCU_RP2040
|
||||
// change to 1 if using pico-pio-usb as host controller for raspberry rp2040
|
||||
#define CFG_TUH_RPI_PIO_USB 0
|
||||
#define BOARD_TUH_RHPORT CFG_TUH_RPI_PIO_USB
|
||||
#endif
|
||||
|
||||
// RHPort number used for host can be defined by board.mk, default to port 0
|
||||
#ifndef BOARD_TUH_RHPORT
|
||||
#define BOARD_TUH_RHPORT 0
|
||||
|
@ -162,7 +162,6 @@ void tuh_hid_mount_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* desc_re
|
||||
void tuh_hid_umount_cb(uint8_t dev_addr, uint8_t instance)
|
||||
{
|
||||
printf("HID device address = %d, instance = %d is unmounted\r\n", dev_addr, instance);
|
||||
|
||||
}
|
||||
|
||||
// check if different than 2
|
||||
|
@ -35,6 +35,7 @@
|
||||
//--------------------------------------------------------------------+
|
||||
void led_blinking_task(void);
|
||||
|
||||
// from msc_app.c
|
||||
extern bool msc_app_init(void);
|
||||
extern void msc_app_task(void);
|
||||
|
||||
@ -75,7 +76,6 @@ void tuh_umount_cb(uint8_t dev_addr)
|
||||
(void) dev_addr;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Blinking Task
|
||||
//--------------------------------------------------------------------+
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
#include <ctype.h>
|
||||
#include "tusb.h"
|
||||
#include "bsp/board.h"
|
||||
|
||||
#include "ff.h"
|
||||
#include "diskio.h"
|
||||
@ -75,13 +76,13 @@ void msc_app_task(void)
|
||||
{
|
||||
if (!_cli) return;
|
||||
|
||||
int ch = getchar();
|
||||
int ch = board_uart_getchar();
|
||||
if ( ch > 0 )
|
||||
{
|
||||
while( ch > 0 )
|
||||
{
|
||||
embeddedCliReceiveChar(_cli, (char) ch);
|
||||
ch = getchar();
|
||||
ch = board_uart_getchar();
|
||||
}
|
||||
embeddedCliProcess(_cli);
|
||||
}
|
||||
|
@ -132,15 +132,11 @@ static inline void board_delay(uint32_t ms)
|
||||
}
|
||||
}
|
||||
|
||||
// stdio getchar() is blocking, this is non-blocking version for uart
|
||||
static inline int board_uart_getchar(void)
|
||||
{
|
||||
uint8_t c;
|
||||
return board_uart_read(&c, 1) ? (int) c : (-1);
|
||||
}
|
||||
|
||||
static inline int board_uart_putchar(uint8_t c)
|
||||
{
|
||||
return board_uart_write(&c, 1);
|
||||
return ( board_uart_read(&c, 1) > 0 ) ? (int) c : (-1);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -121,16 +121,6 @@ static uart_inst_t *uart_inst;
|
||||
|
||||
void board_init(void)
|
||||
{
|
||||
#ifdef LED_PIN
|
||||
bi_decl(bi_1pin_with_name(LED_PIN, "LED"));
|
||||
gpio_init(LED_PIN);
|
||||
gpio_set_dir(LED_PIN, GPIO_OUT);
|
||||
#endif
|
||||
|
||||
// Button
|
||||
#ifndef BUTTON_BOOTSEL
|
||||
#endif
|
||||
|
||||
#if CFG_TUH_RPI_PIO_USB || CFG_TUD_RPI_PIO_USB
|
||||
// Set the system clock to a multiple of 120mhz for bitbanging USB with pico-usb
|
||||
set_sys_clock_khz(120000, true);
|
||||
@ -148,6 +138,16 @@ void board_init(void)
|
||||
tuh_configure(BOARD_TUH_RHPORT, TUH_CFGID_RPI_PIO_USB_CONFIGURATION, &pio_cfg);
|
||||
#endif
|
||||
|
||||
#ifdef LED_PIN
|
||||
bi_decl(bi_1pin_with_name(LED_PIN, "LED"));
|
||||
gpio_init(LED_PIN);
|
||||
gpio_set_dir(LED_PIN, GPIO_OUT);
|
||||
#endif
|
||||
|
||||
// Button
|
||||
#ifndef BUTTON_BOOTSEL
|
||||
#endif
|
||||
|
||||
#if defined(UART_DEV) && defined(LIB_PICO_STDIO_UART)
|
||||
bi_decl(bi_2pins_with_func(UART_TX_PIN, UART_TX_PIN, GPIO_FUNC_UART));
|
||||
uart_inst = uart_get_instance(UART_DEV);
|
||||
@ -192,10 +192,13 @@ uint32_t board_button_read(void)
|
||||
int board_uart_read(uint8_t* buf, int len)
|
||||
{
|
||||
#ifdef UART_DEV
|
||||
for(int i=0;i<len;i++) {
|
||||
buf[i] = uart_getc(uart_inst);
|
||||
int count = 0;
|
||||
while ( (count < len) && uart_is_readable(uart_inst) )
|
||||
{
|
||||
buf[count] = uart_getc(uart_inst);
|
||||
count++;
|
||||
}
|
||||
return len;
|
||||
return count;
|
||||
#else
|
||||
(void) buf; (void) len;
|
||||
return 0;
|
||||
|
@ -71,7 +71,7 @@ struct tuh_xfer_s
|
||||
// ConfigID for tuh_config()
|
||||
enum
|
||||
{
|
||||
TUH_CFGID_RPI_PIO_USB_CONFIGURATION = OPT_MCU_RP2040 // cfg_param: pio_usb_configuration_t
|
||||
TUH_CFGID_RPI_PIO_USB_CONFIGURATION = OPT_MCU_RP2040 << 8 // cfg_param: pio_usb_configuration_t
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
|
Loading…
x
Reference in New Issue
Block a user