Skip to content

Commit 177b388

Browse files
authored
Merge pull request #2571 from hathach/fix-max3421-rp2040-build
fix build with rp2040 + max3421
2 parents 66cdf6d + ebe6923 commit 177b388

File tree

6 files changed

+40
-45
lines changed

6 files changed

+40
-45
lines changed

examples/build_system/make/make.mk

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ CFLAGS += -DBOARD_$(BOARD_UPPER)
113113
ifeq (${MAX3421_HOST},1)
114114
SRC_C += src/portable/analog/max3421/hcd_max3421.c
115115
CFLAGS += -DCFG_TUH_MAX3421=1
116+
CMAKE_DEFSYM += -DMAX3421_HOST=1
116117
endif
117118

118119
# Log level is mapped to TUSB DEBUG option
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mcu:RP2040

hw/bsp/family_support.cmake

+16-27
Original file line numberDiff line numberDiff line change
@@ -79,48 +79,37 @@ set(WARNING_FLAGS_IAR "")
7979
function(family_filter RESULT DIR)
8080
get_filename_component(DIR ${DIR} ABSOLUTE BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
8181

82-
if (EXISTS "${DIR}/only.txt")
83-
file(READ "${DIR}/only.txt" ONLYS)
84-
# Replace newlines with semicolon so that it is treated as a list by CMake
85-
string(REPLACE "\n" ";" ONLYS_LINES ${ONLYS})
86-
87-
# For each mcu
82+
if (EXISTS "${DIR}/skip.txt")
83+
file(STRINGS "${DIR}/skip.txt" SKIPS_LINES)
8884
foreach(MCU IN LISTS FAMILY_MCUS)
8985
# For each line in only.txt
90-
foreach(_line ${ONLYS_LINES})
91-
# If mcu:xxx exists for this mcu or board:xxx then include
92-
if (${_line} STREQUAL "mcu:${MCU}" OR ${_line} STREQUAL "board:${BOARD}")
93-
set(${RESULT} 1 PARENT_SCOPE)
86+
foreach(_line ${SKIPS_LINES})
87+
# If mcu:xxx exists for this mcu then skip
88+
if (${_line} STREQUAL "mcu:${MCU}" OR ${_line} STREQUAL "board:${BOARD}" OR ${_line} STREQUAL "family:${FAMILY}")
89+
set(${RESULT} 0 PARENT_SCOPE)
9490
return()
9591
endif()
9692
endforeach()
9793
endforeach()
94+
endif ()
9895

99-
# Didn't find it in only file so don't build
100-
set(${RESULT} 0 PARENT_SCOPE)
101-
102-
elseif (EXISTS "${DIR}/skip.txt")
103-
file(READ "${DIR}/skip.txt" SKIPS)
104-
# Replace newlines with semicolon so that it is treated as a list by CMake
105-
string(REPLACE "\n" ";" SKIPS_LINES ${SKIPS})
106-
107-
# For each mcu
96+
if (EXISTS "${DIR}/only.txt")
97+
file(STRINGS "${DIR}/only.txt" ONLYS_LINES)
10898
foreach(MCU IN LISTS FAMILY_MCUS)
10999
# For each line in only.txt
110-
foreach(_line ${SKIPS_LINES})
111-
# If mcu:xxx exists for this mcu then skip
112-
if (${_line} STREQUAL "mcu:${MCU}")
113-
set(${RESULT} 0 PARENT_SCOPE)
100+
foreach(_line ${ONLYS_LINES})
101+
# If mcu:xxx exists for this mcu or board:xxx then include
102+
if (${_line} STREQUAL "mcu:${MCU}" OR ${_line} STREQUAL "board:${BOARD}" OR ${_line} STREQUAL "family:${FAMILY}")
103+
set(${RESULT} 1 PARENT_SCOPE)
114104
return()
115105
endif()
116106
endforeach()
117107
endforeach()
118108

119-
# Didn't find in skip file so build
120-
set(${RESULT} 1 PARENT_SCOPE)
109+
# Didn't find it in only file so don't build
110+
set(${RESULT} 0 PARENT_SCOPE)
121111
else()
122-
123-
# Didn't find skip or only file so build
112+
# only.txt not exist so build
124113
set(${RESULT} 1 PARENT_SCOPE)
125114
endif()
126115
endfunction()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
set(PICO_BOARD adafruit_feather_rp2040)
2+
3+
# Enable MAX3421E USB Host
4+
set(MAX3421_HOST 1)

src/portable/analog/max3421/hcd_max3421.c

+7-8
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ static void xact_generic(uint8_t rhport, max3421_ep_t *ep, bool switch_ep, bool
654654

655655
// status
656656
if (ep->buf == NULL || ep->total_len == 0) {
657-
uint8_t const hxfr = HXFR_HS | (ep->hxfr_bm.is_out ? HXFR_OUT_NIN : 0);
657+
uint8_t const hxfr = (uint8_t) (HXFR_HS | (ep->hxfr & HXFR_OUT_NIN));
658658
peraddr_write(rhport, ep->daddr, in_isr);
659659
hxfr_write(rhport, hxfr, in_isr);
660660
return;
@@ -676,19 +676,18 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t daddr, uint8_t ep_addr, uint8_t * buf
676676
max3421_ep_t* ep = find_opened_ep(daddr, ep_num, ep_dir);
677677
TU_VERIFY(ep);
678678

679-
// control transfer can switch direction
680-
ep->hxfr_bm.is_out = ep_dir ? 0u : 1u;
679+
if (ep_num == 0) {
680+
// control transfer can switch direction
681+
ep->hxfr_bm.is_out = ep_dir ? 0 : 1;
682+
ep->hxfr_bm.is_setup = 0;
683+
ep->data_toggle = 1;
684+
}
681685

682686
ep->buf = buffer;
683687
ep->total_len = buflen;
684688
ep->xferred_len = 0;
685689
ep->state = EP_STATE_ATTEMPT_1;
686690

687-
if (ep_num == 0) {
688-
ep->hxfr_bm.is_setup = 0;
689-
ep->data_toggle = 1;
690-
}
691-
692691
// carry out transfer if not busy
693692
if (!atomic_flag_test_and_set(&_hcd_data.busy)) {
694693
xact_generic(rhport, ep, true, false);

tools/build_utils.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,19 @@ def skip_example(example, board):
6464
skip_file = ex_dir / "skip.txt"
6565
only_file = ex_dir / "only.txt"
6666

67-
if skip_file.exists() and only_file.exists():
68-
raise RuntimeError("Only have a skip or only file. Not both.")
69-
elif skip_file.exists():
67+
if skip_file.exists():
7068
skips = skip_file.read_text().split()
71-
return ("mcu:" + mcu in skips or
72-
"board:" + board in skips or
73-
"family:" + family in skips)
74-
elif only_file.exists():
69+
if ("mcu:" + mcu in skips or
70+
"board:" + board in skips or
71+
"family:" + family in skips):
72+
return True
73+
74+
if only_file.exists():
7575
onlys = only_file.read_text().split()
76-
return not ("mcu:" + mcu in onlys or
77-
"board:" + board in onlys or
78-
"family:" + family in onlys)
76+
if not ("mcu:" + mcu in onlys or
77+
"board:" + board in onlys or
78+
"family:" + family in onlys):
79+
return True
7980

8081
return False
8182

0 commit comments

Comments
 (0)