Skip to content

Commit 6ecd480

Browse files
authored
Merge pull request hathach#2061 from hathach/imx-usbhost
iMX.RT EHCI add dcache support and other fixes + refactor
2 parents e2d3c0b + 7211dd1 commit 6ecd480

File tree

22 files changed

+626
-435
lines changed

22 files changed

+626
-435
lines changed

.idea/cmake.xml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/rt1010.xml

Lines changed: 0 additions & 10 deletions
This file was deleted.

.idea/runConfigurations/rt1010_nxplink.xml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/rt1060_jlink.xml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/dual/host_hid_to_device_cdc/src/tusb_config.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@
8484
#define CFG_TUH_RPI_PIO_USB 1
8585
#endif
8686

87-
88-
// CFG_TUSB_DEBUG is defined by compiler in DEBUG build
89-
// #define CFG_TUSB_DEBUG 0
90-
9187
/* USB DMA on some MCUs can only access a specific SRAM region with restriction on alignment.
9288
* Tinyusb use follows macros to declare transferring memory so that they can be put
9389
* into those specific section.
@@ -133,7 +129,7 @@
133129
#endif
134130

135131
#ifndef CFG_TUH_MEM_ALIGN
136-
#define CFG_TUH_MEM_ALIGN __attribute__ ((aligned(4)))
132+
#define CFG_TUH_MEM_ALIGN __attribute__ ((aligned(4)))
137133
#endif
138134

139135
#define CFG_TUH_HUB 1

examples/host/cdc_msc_hid/src/hid_app.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ static void process_generic_report(uint8_t dev_addr, uint8_t instance, uint8_t c
263263

264264
if (!rpt_info)
265265
{
266-
printf("Couldn't find the report info for this report !\r\n");
266+
printf("Couldn't find report info !\r\n");
267267
return;
268268
}
269269

hw/bsp/imxrt/family.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,10 @@ void board_init(void)
131131
freq = CLOCK_GetOscFreq() / (CLOCK_GetDiv(kCLOCK_UartDiv) + 1U);
132132
}
133133

134-
LPUART_Init(UART_PORT, &uart_config, freq);
134+
if ( kStatus_Success != LPUART_Init(UART_PORT, &uart_config, freq) ) {
135+
// failed to init uart, probably baudrate is not supported
136+
// TU_BREAKPOINT();
137+
}
135138

136139
//------------- USB -------------//
137140
// Note: RT105x RT106x and later have dual USB controllers.

hw/bsp/imxrt/family.cmake

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,16 @@ if (NOT TARGET ${BOARD_TARGET})
5757
)
5858
update_board(${BOARD_TARGET})
5959

60+
if (NOT DEFINED LD_FILE_${TOOLCHAIN})
61+
set(LD_FILE_gcc ${SDK_DIR}/devices/${MCU_VARIANT}/gcc/${MCU_VARIANT}xxxxx_flexspi_nor.ld)
62+
endif ()
63+
6064
if (TOOLCHAIN STREQUAL "gcc")
6165
target_sources(${BOARD_TARGET} PUBLIC
6266
${SDK_DIR}/devices/${MCU_VARIANT}/gcc/startup_${MCU_VARIANT}.S
6367
)
6468
target_link_options(${BOARD_TARGET} PUBLIC
65-
"LINKER:--script=${SDK_DIR}/devices/${MCU_VARIANT}/gcc/${MCU_VARIANT}xxxxx_flexspi_nor.ld"
69+
"LINKER:--script=${LD_FILE_gcc}"
6670
"LINKER:-Map=$<IF:$<BOOL:$<TARGET_PROPERTY:OUTPUT_NAME>>,$<TARGET_PROPERTY:OUTPUT_NAME>,$<TARGET_PROPERTY:NAME>>${CMAKE_EXECUTABLE_SUFFIX}.map"
6771
# nanolib
6872
--specs=nosys.specs
@@ -144,6 +148,21 @@ function(family_configure_target TARGET)
144148
COMMAND ${LINKSERVER_PATH} flash ${NXPLINK_DEVICE} load $<TARGET_FILE:${TARGET}>
145149
)
146150

151+
# Flash using jlink
152+
set(JLINKEXE JLinkExe)
153+
file(GENERATE
154+
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.jlink
155+
CONTENT "halt
156+
loadfile $<TARGET_FILE:${TARGET}>
157+
r
158+
go
159+
exit"
160+
)
161+
add_custom_target(${TARGET}-jlink
162+
DEPENDS ${TARGET}
163+
COMMAND ${JLINKEXE} -device ${JLINK_DEVICE} -if swd -JTAGConf -1,-1 -speed auto -CommandFile ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.jlink
164+
)
165+
147166
endfunction()
148167

149168

src/class/cdc/cdc_host.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@
3535

3636
// Debug level, TUSB_CFG_DEBUG must be at least this level for debug message
3737
#define CDCH_DEBUG 2
38-
39-
#define TU_LOG_CDCH(...) TU_LOG(CDCH_DEBUG, __VA_ARGS__)
38+
#define TU_LOG_DRV(...) TU_LOG(CDCH_DEBUG, __VA_ARGS__)
4039

4140
//--------------------------------------------------------------------+
4241
// Host CDC Interface
@@ -537,6 +536,8 @@ void cdch_close(uint8_t daddr)
537536
cdch_interface_t* p_cdc = &cdch_data[idx];
538537
if (p_cdc->daddr == daddr)
539538
{
539+
TU_LOG_DRV(" CDCh close addr = %u index = %u\r\n", daddr, idx);
540+
540541
// Invoke application callback
541542
if (tuh_cdc_umount_cb) tuh_cdc_umount_cb(idx);
542543

@@ -804,7 +805,7 @@ static void acm_process_config(tuh_xfer_t* xfer)
804805

805806
static bool acm_set_control_line_state(cdch_interface_t* p_cdc, uint16_t line_state, tuh_xfer_cb_t complete_cb, uintptr_t user_data) {
806807
TU_VERIFY(p_cdc->acm_capability.support_line_request);
807-
TU_LOG_CDCH("CDC ACM Set Control Line State\r\n");
808+
TU_LOG_DRV("CDC ACM Set Control Line State\r\n");
808809

809810
tusb_control_request_t const request = {
810811
.bmRequestType_bit = {
@@ -834,7 +835,7 @@ static bool acm_set_control_line_state(cdch_interface_t* p_cdc, uint16_t line_st
834835
}
835836

836837
static bool acm_set_line_coding(cdch_interface_t* p_cdc, cdc_line_coding_t const* line_coding, tuh_xfer_cb_t complete_cb, uintptr_t user_data) {
837-
TU_LOG_CDCH("CDC ACM Set Line Conding\r\n");
838+
TU_LOG_DRV("CDC ACM Set Line Conding\r\n");
838839

839840
tusb_control_request_t const request = {
840841
.bmRequestType_bit = {
@@ -894,7 +895,7 @@ static bool ftdi_open(uint8_t daddr, const tusb_desc_interface_t *itf_desc, uint
894895
cdch_interface_t * p_cdc = make_new_itf(daddr, itf_desc);
895896
TU_VERIFY(p_cdc);
896897

897-
TU_LOG_CDCH("FTDI opened\r\n");
898+
TU_LOG_DRV("FTDI opened\r\n");
898899

899900
p_cdc->serial_drid = SERIAL_DRIVER_FTDI;
900901

@@ -938,7 +939,7 @@ static bool ftdi_sio_reset(cdch_interface_t* p_cdc, tuh_xfer_cb_t complete_cb, u
938939

939940
static bool ftdi_sio_set_modem_ctrl(cdch_interface_t* p_cdc, uint16_t line_state, tuh_xfer_cb_t complete_cb, uintptr_t user_data)
940941
{
941-
TU_LOG_CDCH("CDC FTDI Set Control Line State\r\n");
942+
TU_LOG_DRV("CDC FTDI Set Control Line State\r\n");
942943
p_cdc->user_control_cb = complete_cb;
943944
TU_ASSERT(ftdi_sio_set_request(p_cdc, FTDI_SIO_MODEM_CTRL, 0x0300 | line_state,
944945
complete_cb ? cdch_internal_control_complete : NULL, user_data));
@@ -974,7 +975,7 @@ static uint32_t ftdi_232bm_baud_to_divisor(uint32_t baud)
974975
static bool ftdi_sio_set_baudrate(cdch_interface_t* p_cdc, uint32_t baudrate, tuh_xfer_cb_t complete_cb, uintptr_t user_data)
975976
{
976977
uint16_t const divisor = (uint16_t) ftdi_232bm_baud_to_divisor(baudrate);
977-
TU_LOG_CDCH("CDC FTDI Set BaudRate = %lu, divisor = 0x%04x\n", baudrate, divisor);
978+
TU_LOG_DRV("CDC FTDI Set BaudRate = %lu, divisor = 0x%04x\n", baudrate, divisor);
978979

979980
p_cdc->user_control_cb = complete_cb;
980981
_ftdi_requested_baud = baudrate;
@@ -1061,7 +1062,7 @@ static bool cp210x_open(uint8_t daddr, tusb_desc_interface_t const *itf_desc, ui
10611062
cdch_interface_t * p_cdc = make_new_itf(daddr, itf_desc);
10621063
TU_VERIFY(p_cdc);
10631064

1064-
TU_LOG_CDCH("CP210x opened\r\n");
1065+
TU_LOG_DRV("CP210x opened\r\n");
10651066
p_cdc->serial_drid = SERIAL_DRIVER_CP210X;
10661067

10671068
// endpoint pair
@@ -1109,7 +1110,7 @@ static bool cp210x_ifc_enable(cdch_interface_t* p_cdc, uint16_t enabled, tuh_xfe
11091110
}
11101111

11111112
static bool cp210x_set_baudrate(cdch_interface_t* p_cdc, uint32_t baudrate, tuh_xfer_cb_t complete_cb, uintptr_t user_data) {
1112-
TU_LOG_CDCH("CDC CP210x Set BaudRate = %lu\n", baudrate);
1113+
TU_LOG_DRV("CDC CP210x Set BaudRate = %lu\n", baudrate);
11131114
uint32_t baud_le = tu_htole32(baudrate);
11141115
p_cdc->user_control_cb = complete_cb;
11151116
return cp210x_set_request(p_cdc, CP210X_SET_BAUDRATE, 0, (uint8_t *) &baud_le, 4,
@@ -1118,7 +1119,7 @@ static bool cp210x_set_baudrate(cdch_interface_t* p_cdc, uint32_t baudrate, tuh_
11181119

11191120
static bool cp210x_set_modem_ctrl(cdch_interface_t* p_cdc, uint16_t line_state, tuh_xfer_cb_t complete_cb, uintptr_t user_data)
11201121
{
1121-
TU_LOG_CDCH("CDC CP210x Set Control Line State\r\n");
1122+
TU_LOG_DRV("CDC CP210x Set Control Line State\r\n");
11221123
p_cdc->user_control_cb = complete_cb;
11231124
return cp210x_set_request(p_cdc, CP210X_SET_MHS, 0x0300 | line_state, NULL, 0,
11241125
complete_cb ? cdch_internal_control_complete : NULL, user_data);

src/class/hid/hid_host.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333

3434
#include "hid_host.h"
3535

36+
// Debug level, TUSB_CFG_DEBUG must be at least this level for debug message
37+
#define HIDH_DEBUG 2
38+
#define TU_LOG_DRV(...) TU_LOG(HIDH_DEBUG, __VA_ARGS__)
39+
3640
//--------------------------------------------------------------------+
3741
// MACRO CONSTANT TYPEDEF
3842
//--------------------------------------------------------------------+
@@ -68,7 +72,7 @@ tu_static hidh_interface_t _hidh_itf[CFG_TUH_HID];
6872
TU_ATTR_ALWAYS_INLINE static inline
6973
hidh_interface_t* get_hid_itf(uint8_t daddr, uint8_t idx)
7074
{
71-
TU_ASSERT(daddr && idx < CFG_TUH_HID, NULL);
75+
TU_ASSERT(daddr > 0 && idx < CFG_TUH_HID, NULL);
7276
hidh_interface_t* p_hid = &_hidh_itf[idx];
7377
return (p_hid->daddr == daddr) ? p_hid : NULL;
7478
}
@@ -207,7 +211,7 @@ static void set_protocol_complete(tuh_xfer_t* xfer)
207211

208212
static bool _hidh_set_protocol(uint8_t daddr, uint8_t itf_num, uint8_t protocol, tuh_xfer_cb_t complete_cb, uintptr_t user_data)
209213
{
210-
TU_LOG2("HID Set Protocol = %d\r\n", protocol);
214+
TU_LOG_DRV("HID Set Protocol = %d\r\n", protocol);
211215

212216
tusb_control_request_t const request =
213217
{
@@ -246,7 +250,7 @@ bool tuh_hid_set_protocol(uint8_t daddr, uint8_t idx, uint8_t protocol)
246250

247251
static void set_report_complete(tuh_xfer_t* xfer)
248252
{
249-
TU_LOG2("HID Set Report complete\r\n");
253+
TU_LOG_DRV("HID Set Report complete\r\n");
250254

251255
if (tuh_hid_set_report_complete_cb)
252256
{
@@ -266,7 +270,7 @@ bool tuh_hid_set_report(uint8_t daddr, uint8_t idx, uint8_t report_id, uint8_t r
266270
hidh_interface_t* p_hid = get_hid_itf(daddr, idx);
267271
TU_VERIFY(p_hid);
268272

269-
TU_LOG2("HID Set Report: id = %u, type = %u, len = %u\r\n", report_id, report_type, len);
273+
TU_LOG_DRV("HID Set Report: id = %u, type = %u, len = %u\r\n", report_id, report_type, len);
270274

271275
tusb_control_request_t const request =
272276
{
@@ -298,7 +302,7 @@ bool tuh_hid_set_report(uint8_t daddr, uint8_t idx, uint8_t report_id, uint8_t r
298302
static bool _hidh_set_idle(uint8_t daddr, uint8_t itf_num, uint16_t idle_rate, tuh_xfer_cb_t complete_cb, uintptr_t user_data)
299303
{
300304
// SET IDLE request, device can stall if not support this request
301-
TU_LOG2("HID Set Idle \r\n");
305+
TU_LOG_DRV("HID Set Idle \r\n");
302306

303307
tusb_control_request_t const request =
304308
{
@@ -367,7 +371,7 @@ bool tuh_hid_send_ready(uint8_t dev_addr, uint8_t idx)
367371

368372
bool tuh_hid_send_report(uint8_t daddr, uint8_t idx, uint8_t report_id, const void* report, uint16_t len)
369373
{
370-
TU_LOG2("HID Send Report %d\r\n", report_id);
374+
TU_LOG_DRV("HID Send Report %d\r\n", report_id);
371375

372376
hidh_interface_t* p_hid = get_hid_itf(daddr, idx);
373377
TU_VERIFY(p_hid);
@@ -430,7 +434,7 @@ bool hidh_xfer_cb(uint8_t daddr, uint8_t ep_addr, xfer_result_t result, uint32_t
430434

431435
if ( dir == TUSB_DIR_IN )
432436
{
433-
TU_LOG2(" Get Report callback (%u, %u)\r\n", daddr, idx);
437+
TU_LOG_DRV(" Get Report callback (%u, %u)\r\n", daddr, idx);
434438
TU_LOG3_MEM(p_hid->epin_buf, xferred_bytes, 2);
435439
tuh_hid_report_received_cb(daddr, idx, p_hid->epin_buf, (uint16_t) xferred_bytes);
436440
}else
@@ -448,8 +452,9 @@ void hidh_close(uint8_t daddr)
448452
hidh_interface_t* p_hid = &_hidh_itf[i];
449453
if (p_hid->daddr == daddr)
450454
{
451-
if(tuh_hid_umount_cb) tuh_hid_umount_cb(daddr, i);
452-
p_hid->daddr = 0;
455+
TU_LOG_DRV(" HIDh close addr = %u index = %u\r\n", daddr, i);
456+
if(tuh_hid_umount_cb) tuh_hid_umount_cb(daddr, i);
457+
p_hid->daddr = 0;
453458
}
454459
}
455460
}
@@ -465,7 +470,7 @@ bool hidh_open(uint8_t rhport, uint8_t daddr, tusb_desc_interface_t const *desc_
465470

466471
TU_VERIFY(TUSB_CLASS_HID == desc_itf->bInterfaceClass);
467472

468-
TU_LOG2("[%u] HID opening Interface %u\r\n", daddr, desc_itf->bInterfaceNumber);
473+
TU_LOG_DRV("[%u] HID opening Interface %u\r\n", daddr, desc_itf->bInterfaceNumber);
469474

470475
// len = interface + hid + n*endpoints
471476
uint16_t const drv_len = (uint16_t) (sizeof(tusb_desc_interface_t) + sizeof(tusb_hid_descriptor_hid_t) +
@@ -592,7 +597,7 @@ static void process_set_config(tuh_xfer_t* xfer)
592597
// using usbh enumeration buffer since report descriptor can be very long
593598
if( p_hid->report_desc_len > CFG_TUH_ENUMERATION_BUFSIZE )
594599
{
595-
TU_LOG2("HID Skip Report Descriptor since it is too large %u bytes\r\n", p_hid->report_desc_len);
600+
TU_LOG_DRV("HID Skip Report Descriptor since it is too large %u bytes\r\n", p_hid->report_desc_len);
596601

597602
// Driver is mounted without report descriptor
598603
config_driver_mount_complete(daddr, idx, NULL, 0);
@@ -763,7 +768,7 @@ uint8_t tuh_hid_parse_report_descriptor(tuh_hid_report_info_t* report_info_arr,
763768
for ( uint8_t i = 0; i < report_num; i++ )
764769
{
765770
info = report_info_arr+i;
766-
TU_LOG2("%u: id = %u, usage_page = %u, usage = %u\r\n", i, info->report_id, info->usage_page, info->usage);
771+
TU_LOG_DRV("%u: id = %u, usage_page = %u, usage = %u\r\n", i, info->report_id, info->usage_page, info->usage);
767772
}
768773

769774
return report_num;

0 commit comments

Comments
 (0)