Skip to content

Commit f6ca86c

Browse files
committed
tested cdc_msc_hid_freertos with samd51
add -Wno-error=format for espressif wrap up cdc_msc_hid_freertos
1 parent a7c136c commit f6ca86c

File tree

16 files changed

+703
-87
lines changed

16 files changed

+703
-87
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
include ../../make.mk
2+
3+
FREERTOS_SRC = lib/FreeRTOS-Kernel
4+
FREERTOS_PORTABLE_PATH= $(FREERTOS_SRC)/portable/$(if $(USE_IAR),IAR,GCC)
5+
6+
INC += \
7+
src \
8+
$(TOP)/hw \
9+
$(TOP)/$(FREERTOS_SRC)/include \
10+
$(TOP)/$(FREERTOS_PORTABLE_SRC) \
11+
12+
# Example source
13+
EXAMPLE_SOURCE = \
14+
src/cdc_app.c \
15+
src/freertos_hook.c \
16+
src/hid_app.c \
17+
src/main.c \
18+
src/msc_app.c \
19+
20+
SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
21+
22+
# TinyUSB Host Stack source
23+
SRC_C += \
24+
src/class/cdc/cdc_host.c \
25+
src/class/hid/hid_host.c \
26+
src/class/msc/msc_host.c \
27+
src/host/hub.c \
28+
src/host/usbh.c \
29+
src/portable/ohci/ohci.c \
30+
src/portable/nxp/lpc17_40/hcd_lpc17_40.c
31+
32+
include ../../rules.mk
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
mcu:LPC175X_6X
2+
mcu:LPC177X_8X
3+
mcu:LPC18XX
4+
mcu:LPC40XX
5+
mcu:LPC43XX
6+
mcu:MIMXRT1XXX
7+
mcu:MIMXRT10XX
8+
mcu:MIMXRT11XX
9+
mcu:RP2040
10+
mcu:MSP432E4
11+
mcu:RX65X
12+
mcu:RAXXX
13+
mcu:MAX3421
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# This file is for ESP-IDF only
2-
idf_component_register(SRCS "hid_app.c" "main.c"
2+
idf_component_register(SRCS "cdc_app.c" "hid_app.c" "main.c" "msc_app.c"
33
INCLUDE_DIRS "."
44
REQUIRES boards tinyusb_src)
5+
6+
target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-error=format)
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2022, Ha Thach (tinyusb.org)
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*
24+
* This file is part of the TinyUSB stack.
25+
*/
26+
27+
#include "tusb.h"
28+
#include "bsp/board_api.h"
29+
30+
//--------------------------------------------------------------------+
31+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
32+
//--------------------------------------------------------------------+
33+
34+
35+
//------------- IMPLEMENTATION -------------//
36+
37+
size_t get_console_inputs(uint8_t *buf, size_t bufsize) {
38+
size_t count = 0;
39+
while (count < bufsize) {
40+
int ch = board_getchar();
41+
if (ch <= 0) break;
42+
43+
buf[count] = (uint8_t) ch;
44+
count++;
45+
}
46+
47+
return count;
48+
}
49+
50+
void cdc_app_task(void* param) {
51+
(void) param;
52+
53+
uint8_t buf[64 + 1]; // +1 for extra null character
54+
uint32_t const bufsize = sizeof(buf) - 1;
55+
56+
while (1) {
57+
uint32_t count = get_console_inputs(buf, bufsize);
58+
buf[count] = 0;
59+
60+
if (count) {
61+
// loop over all mounted interfaces
62+
for (uint8_t idx = 0; idx < CFG_TUH_CDC; idx++) {
63+
if (tuh_cdc_mounted(idx)) {
64+
// console --> cdc interfaces
65+
tuh_cdc_write(idx, buf, count);
66+
tuh_cdc_write_flush(idx);
67+
}
68+
}
69+
}
70+
71+
taskYIELD();
72+
}
73+
}
74+
75+
// Invoked when received new data
76+
void tuh_cdc_rx_cb(uint8_t idx) {
77+
uint8_t buf[64 + 1]; // +1 for extra null character
78+
uint32_t const bufsize = sizeof(buf) - 1;
79+
80+
// forward cdc interfaces -> console
81+
uint32_t count = tuh_cdc_read(idx, buf, bufsize);
82+
buf[count] = 0;
83+
84+
printf((char *) buf);
85+
}
86+
87+
void tuh_cdc_mount_cb(uint8_t idx) {
88+
tuh_itf_info_t itf_info = { 0 };
89+
tuh_cdc_itf_get_info(idx, &itf_info);
90+
91+
printf("CDC Interface is mounted: address = %u, itf_num = %u\r\n", itf_info.daddr, itf_info.desc.bInterfaceNumber);
92+
93+
#ifdef CFG_TUH_CDC_LINE_CODING_ON_ENUM
94+
// CFG_TUH_CDC_LINE_CODING_ON_ENUM must be defined for line coding is set by tinyusb in enumeration
95+
// otherwise you need to call tuh_cdc_set_line_coding() first
96+
cdc_line_coding_t line_coding = { 0 };
97+
if (tuh_cdc_get_local_line_coding(idx, &line_coding)) {
98+
printf(" Baudrate: %lu, Stop Bits : %u\r\n", line_coding.bit_rate, line_coding.stop_bits);
99+
printf(" Parity : %u, Data Width: %u\r\n", line_coding.parity, line_coding.data_bits);
100+
}
101+
#endif
102+
}
103+
104+
void tuh_cdc_umount_cb(uint8_t idx) {
105+
tuh_itf_info_t itf_info = { 0 };
106+
tuh_cdc_itf_get_info(idx, &itf_info);
107+
108+
printf("CDC Interface is unmounted: address = %u, itf_num = %u\r\n", itf_info.daddr, itf_info.desc.bInterfaceNumber);
109+
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2019 Ha Thach (tinyusb.org)
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*
24+
*/
25+
26+
//--------------------------------------------------------------------+
27+
// INCLUDE
28+
//--------------------------------------------------------------------+
29+
#include "FreeRTOS.h"
30+
#include "task.h"
31+
#include "common/tusb_common.h"
32+
33+
void vApplicationMallocFailedHook(void) {
34+
taskDISABLE_INTERRUPTS();
35+
TU_ASSERT(false,);
36+
}
37+
38+
void vApplicationStackOverflowHook(xTaskHandle pxTask, char *pcTaskName) {
39+
(void) pxTask;
40+
(void) pcTaskName;
41+
42+
taskDISABLE_INTERRUPTS();
43+
TU_ASSERT(false,);
44+
}
45+
46+
/* configSUPPORT_STATIC_ALLOCATION is set to 1, so the application must provide an
47+
* implementation of vApplicationGetIdleTaskMemory() to provide the memory that is
48+
* used by the Idle task. */
49+
void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer,
50+
uint32_t *pulIdleTaskStackSize) {
51+
/* If the buffers to be provided to the Idle task are declared inside this
52+
* function then they must be declared static - otherwise they will be allocated on
53+
* the stack and so not exists after this function exits. */
54+
static StaticTask_t xIdleTaskTCB;
55+
static StackType_t uxIdleTaskStack[configMINIMAL_STACK_SIZE];
56+
57+
/* Pass out a pointer to the StaticTask_t structure in which the Idle task's
58+
state will be stored. */
59+
*ppxIdleTaskTCBBuffer = &xIdleTaskTCB;
60+
61+
/* Pass out the array that will be used as the Idle task's stack. */
62+
*ppxIdleTaskStackBuffer = uxIdleTaskStack;
63+
64+
/* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer.
65+
Note that, as the array is necessarily of type StackType_t,
66+
configMINIMAL_STACK_SIZE is specified in words, not bytes. */
67+
*pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
68+
}
69+
70+
/* configSUPPORT_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the
71+
* application must provide an implementation of vApplicationGetTimerTaskMemory()
72+
* to provide the memory that is used by the Timer service task. */
73+
void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer,
74+
uint32_t *pulTimerTaskStackSize) {
75+
/* If the buffers to be provided to the Timer task are declared inside this
76+
* function then they must be declared static - otherwise they will be allocated on
77+
* the stack and so not exists after this function exits. */
78+
static StaticTask_t xTimerTaskTCB;
79+
static StackType_t uxTimerTaskStack[configTIMER_TASK_STACK_DEPTH];
80+
81+
/* Pass out a pointer to the StaticTask_t structure in which the Timer
82+
task's state will be stored. */
83+
*ppxTimerTaskTCBBuffer = &xTimerTaskTCB;
84+
85+
/* Pass out the array that will be used as the Timer task's stack. */
86+
*ppxTimerTaskStackBuffer = uxTimerTaskStack;
87+
88+
/* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer.
89+
Note that, as the array is necessarily of type StackType_t,
90+
configTIMER_TASK_STACK_DEPTH is specified in words, not bytes. */
91+
*pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
92+
}
93+
94+
#if CFG_TUSB_MCU == OPT_MCU_RX63X | CFG_TUSB_MCU == OPT_MCU_RX65X
95+
#include "iodefine.h"
96+
void vApplicationSetupTimerInterrupt(void)
97+
{
98+
/* Enable CMT0 */
99+
SYSTEM.PRCR.WORD = (0xA5u<<8) | TU_BIT(1);
100+
MSTP(CMT0) = 0;
101+
SYSTEM.PRCR.WORD = (0xA5u<<8);
102+
103+
CMT0.CMCNT = 0;
104+
CMT0.CMCOR = (unsigned short)(((configPERIPHERAL_CLOCK_HZ/configTICK_RATE_HZ)-1)/128);
105+
CMT0.CMCR.WORD = TU_BIT(6) | 2;
106+
IR(CMT0, CMI0) = 0;
107+
IPR(CMT0, CMI0) = configKERNEL_INTERRUPT_PRIORITY;
108+
IEN(CMT0, CMI0) = 1;
109+
CMT.CMSTR0.BIT.STR0 = 1;
110+
}
111+
#endif

0 commit comments

Comments
 (0)