Skip to content

Commit 4ab4ca1

Browse files
committed
zephyr: fix the assert() mess
1 parent 5d08c67 commit 4ab4ca1

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

c2usb/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ if(ZEPHYR_BASE)
6161
# until https://github.com/zephyrproject-rtos/zephyr/pull/69490 is merged
6262
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive" PARENT_SCOPE)
6363
endif()
64+
target_compile_definitions(zephyr_interface INTERFACE
65+
# set the standard compiler flag based on zephyr Kconfig, so e.g. assert() works as intended
66+
$<IF:$<BOOL:${CONFIG_DEBUG}>,DEBUG,NDEBUG>
67+
)
6468
elseif(MCUX_SDK_PROJECT_NAME)
6569
add_subdirectory(port/nxp)
6670
endif()

c2usb/port/zephyr/udc_mac.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ extern "C"
2020
#include <zephyr/drivers/usb/udc.h>
2121
}
2222

23+
#if defined(CONFIG_DEBUG) == defined(NDEBUG)
24+
// for assert() to be active in debug configuration only, this is necessary
25+
#error "Either CONFIG_DEBUG or NDEBUG must be defined"
26+
#endif
27+
2328
using namespace usb::zephyr;
2429
using namespace usb::df;
2530

@@ -425,7 +430,7 @@ void udc_mac::process_ctrl_ep_event(net_buf* buf, const udc_buf_info& info)
425430
if (addr_before_status(udc_caps(dev_)) and (request() == standard::device::SET_ADDRESS))
426431
[[unlikely]]
427432
{
428-
auto ret = udc_set_address(dev_, request().wValue.low_byte());
433+
[[maybe_unused]] auto ret = udc_set_address(dev_, request().wValue.low_byte());
429434
assert(ret == 0);
430435
}
431436
}
@@ -441,7 +446,7 @@ void udc_mac::process_ctrl_ep_event(net_buf* buf, const udc_buf_info& info)
441446
if (!addr_before_status(udc_caps(dev_)) and (request() == standard::device::SET_ADDRESS))
442447
[[unlikely]]
443448
{
444-
auto ret = udc_set_address(dev_, request().wValue.low_byte());
449+
[[maybe_unused]] auto ret = udc_set_address(dev_, request().wValue.low_byte());
445450
assert(ret == 0);
446451
}
447452
}
@@ -476,8 +481,7 @@ int udc_mac::event_callback(const udc_event& event)
476481

477482
int udc_mac::process_event(const udc_event& event)
478483
{
479-
if ((power_state() == power::state::L3_OFF) and (event.type != UDC_EVT_VBUS_READY))
480-
[[unlikely]]
484+
if ((power_state() == power::state::L3_OFF) and (event.type != UDC_EVT_VBUS_READY)) [[unlikely]]
481485
{
482486
// flush late events after Vbus removal
483487
return 0;
@@ -505,7 +509,6 @@ int udc_mac::process_event(const udc_event& event)
505509
set_power_state(power::state::L0_ON);
506510
break;
507511
case UDC_EVT_VBUS_READY:
508-
assert(power_state() == power::state::L3_OFF);
509512
set_power_state(power::state::L2_SUSPEND);
510513
set_attached(active());
511514
break;
@@ -558,7 +561,7 @@ void udc_mac::allocate_endpoints(config::view config)
558561
// first clean up the previous allocation
559562
for (auto* buf : ep_bufs_)
560563
{
561-
auto ret = udc_ep_buf_free(dev_, buf);
564+
[[maybe_unused]] auto ret = udc_ep_buf_free(dev_, buf);
562565
assert(ret == 0);
563566
}
564567
ep_bufs_ = {};
@@ -569,7 +572,7 @@ void udc_mac::allocate_endpoints(config::view config)
569572
{
570573
return;
571574
}
572-
constexpr size_t ctrl_ep_buf_demand = 4; // 2 * (setup + data)
575+
[[maybe_unused]] constexpr size_t ctrl_ep_buf_demand = 4; // 2 * (setup + data)
573576
assert(CONFIG_UDC_BUF_COUNT >= (ctrl_ep_buf_demand + ep_bufs_count));
574577

575578
// abuse the buffer pool to allocate the pointer array storage

0 commit comments

Comments
 (0)