Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hw/bsp/same7x/boards/same70_qmtech/board.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set(JLINK_DEVICE SAME70N19B)
set(JLINK_DEVICE ATSAME70N19B)
set(LD_FILE_GNU ${TOP}/hw/mcu/microchip/same70/same70b/gcc/gcc/same70q21b_flash.ld)

function(update_board TARGET)
Expand Down
3 changes: 2 additions & 1 deletion hw/bsp/same7x/boards/same70_xplained/board.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
set(JLINK_DEVICE SAME70Q21B)
set(JLINK_DEVICE ATSAME70Q21B)
set(LD_FILE_GNU ${TOP}/hw/mcu/microchip/same70/same70b/gcc/gcc/same70q21b_flash.ld)
set(LD_FILE_IAR ${TOP}/hw/mcu/microchip/same70/same70b/iar/config/linker/Microchip/atsame70q21b/flash.icf)

function(update_board TARGET)
target_compile_definitions(${TARGET} PUBLIC
Expand Down
17 changes: 11 additions & 6 deletions hw/bsp/same7x/family.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ set(FAMILY_MCUS SAMX7X CACHE INTERNAL "")
#------------------------------------
set(STARTUP_FILE_GNU ${SDK_DIR}/same70b/gcc/gcc/startup_same70q21b.c)
set(STARTUP_FILE_Clang ${STARTUP_FILE_GNU})
set(STARTUP_FILE_IAR ${SDK_DIR}/same70b/iar/iar/startup_same70q21b.c)
set(LD_FILE_Clang ${LD_FILE_GNU})

#------------------------------------
Expand Down Expand Up @@ -47,12 +48,14 @@ function(family_add_board BOARD_TARGET)

update_board(${BOARD_TARGET})

target_compile_options(${BOARD_TARGET} PUBLIC
-Wno-error=unused-parameter
-Wno-error=cast-align
-Wno-error=redundant-decls
-Wno-error=cast-qual
)
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
target_compile_options(${BOARD_TARGET} PUBLIC
-Wno-error=unused-parameter
-Wno-error=cast-align
-Wno-error=redundant-decls
-Wno-error=cast-qual
)
endif()
endfunction()

#------------------------------------
Expand Down Expand Up @@ -89,9 +92,11 @@ function(family_configure_example TARGET RTOS)
"LINKER:--config=${LD_FILE_IAR}"
)
endif ()
if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
set_source_files_properties(${STARTUP_FILE_${CMAKE_C_COMPILER_ID}} PROPERTIES
SKIP_LINTING ON
COMPILE_OPTIONS -w)
endif()

family_add_bin_hex(${TARGET})
family_flash_jlink(${TARGET})
Expand Down
34 changes: 21 additions & 13 deletions src/class/audio/audio_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ tu_static CFG_TUD_MEM_SECTION struct {
#endif// CFG_TUD_AUDIO_ENABLE_EP_OUT && !CFG_TUD_EDPT_DEDICATED_HWFIFO

// Control buffer
CFG_TUD_MEM_ALIGN uint8_t ctrl_buf[CFG_TUD_AUDIO_CTRL_BUF_SZ];
#if CFG_TUD_AUDIO_CTRL_BUF_SZ > CFG_TUD_ENDPOINT0_BUFSIZE
tu_static CFG_TUD_MEM_ALIGN uint8_t ctrl_buf[CFG_TUD_AUDIO_CTRL_BUF_SZ];
#endif

// Aligned buffer for feedback EP
#if CFG_TUD_AUDIO_ENABLE_EP_OUT && CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP
Expand Down Expand Up @@ -423,6 +425,15 @@ bool tud_audio_n_mounted(uint8_t func_id) {
return audio->mounted;
}

static inline uint8_t* get_ctrl_buffer(void) {
// Use EP0 buffer if it is large enough, otherwise use dedicated buffer
#if CFG_TUD_AUDIO_CTRL_BUF_SZ > CFG_TUD_ENDPOINT0_BUFSIZE
return ctrl_buf;
#else
return _usbd_ctrl_epbuf.buf;
#endif
}

//--------------------------------------------------------------------+
// READ API
//--------------------------------------------------------------------+
Expand Down Expand Up @@ -1296,20 +1307,20 @@ static bool audiod_control_complete(uint8_t rhport, tusb_control_request_t const
if (tud_audio_n_version(func_id) == 2) {
uint8_t ctrlSel = TU_U16_HIGH(p_request->wValue);
if (_audiod_fct[func_id].bclock_id_tx == entityID && ctrlSel == AUDIO20_CS_CTRL_SAM_FREQ && p_request->bRequest == AUDIO20_CS_REQ_CUR) {
_audiod_fct[func_id].sample_rate_tx = tu_unaligned_read32(ctrl_buf);
_audiod_fct[func_id].sample_rate_tx = tu_unaligned_read32(get_ctrl_buffer());
audiod_calc_tx_packet_sz(&_audiod_fct[func_id]);
}
}
#endif

// Invoke callback
return tud_audio_set_req_entity_cb(rhport, p_request, ctrl_buf);
return tud_audio_set_req_entity_cb(rhport, p_request, get_ctrl_buffer());
} else {
// Find index of audio driver structure and verify interface really exists
TU_VERIFY(audiod_verify_itf_exists(itf, &func_id));

// Invoke callback
return tud_audio_set_req_itf_cb(rhport, p_request, ctrl_buf);
return tud_audio_set_req_itf_cb(rhport, p_request, get_ctrl_buffer());
}
} break;

Expand All @@ -1324,15 +1335,15 @@ static bool audiod_control_complete(uint8_t rhport, tusb_control_request_t const
if (_audiod_fct[func_id].ep_in == ep) {
uint8_t ctrlSel = TU_U16_HIGH(p_request->wValue);
if (ctrlSel == AUDIO10_EP_CTRL_SAMPLING_FREQ && p_request->bRequest == AUDIO10_CS_REQ_SET_CUR) {
_audiod_fct[func_id].sample_rate_tx = tu_unaligned_read32(ctrl_buf) & 0x00FFFFFF;
_audiod_fct[func_id].sample_rate_tx = tu_unaligned_read32(get_ctrl_buffer()) & 0x00FFFFFF;
audiod_calc_tx_packet_sz(&_audiod_fct[func_id]);
}
}
}
#endif

// Invoke callback
bool ret = tud_audio_set_req_ep_cb(rhport, p_request, ctrl_buf);
bool ret = tud_audio_set_req_ep_cb(rhport, p_request, get_ctrl_buffer());

#if CFG_TUD_AUDIO_ENABLE_EP_OUT && CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP
if (ret && tud_audio_n_version(func_id) == 1) {
Expand Down Expand Up @@ -1429,7 +1440,7 @@ static bool audiod_control_request(uint8_t rhport, tusb_control_request_t const
}

// If we end here, the received request is a set request - we schedule a receive for the data stage and return true here. We handle the rest later in audiod_control_complete() once the data stage was finished
TU_VERIFY(tud_control_xfer(rhport, p_request, ctrl_buf, sizeof(ctrl_buf)));
TU_VERIFY(tud_control_xfer(rhport, p_request, get_ctrl_buffer(), CFG_TUD_AUDIO_CTRL_BUF_SZ));
return true;
}

Expand Down Expand Up @@ -1695,11 +1706,8 @@ bool tud_audio_buffer_and_schedule_control_xfer(uint8_t rhport, tusb_control_req
return false;
}

// Crop length
if (len > sizeof(ctrl_buf)) len = sizeof(ctrl_buf);

// Copy into buffer
TU_VERIFY(0 == tu_memcpy_s(ctrl_buf, sizeof(ctrl_buf), data, (size_t) len));
TU_VERIFY(0 == tu_memcpy_s(get_ctrl_buffer(), CFG_TUD_AUDIO_CTRL_BUF_SZ, data, (size_t) len));

#if CFG_TUD_AUDIO_ENABLE_EP_IN && CFG_TUD_AUDIO_EP_IN_FLOW_CONTROL
if (tud_audio_n_version(func_id) == 2) {
Expand All @@ -1708,15 +1716,15 @@ bool tud_audio_buffer_and_schedule_control_xfer(uint8_t rhport, tusb_control_req
uint8_t entityID = TU_U16_HIGH(p_request->wIndex);
uint8_t ctrlSel = TU_U16_HIGH(p_request->wValue);
if (_audiod_fct[func_id].bclock_id_tx == entityID && ctrlSel == AUDIO20_CS_CTRL_SAM_FREQ && p_request->bRequest == AUDIO20_CS_REQ_CUR) {
_audiod_fct[func_id].sample_rate_tx = tu_unaligned_read32(ctrl_buf);
_audiod_fct[func_id].sample_rate_tx = tu_unaligned_read32(get_ctrl_buffer());
audiod_calc_tx_packet_sz(&_audiod_fct[func_id]);
}
}
}
#endif

// Schedule transmit
return tud_control_xfer(rhport, p_request, ctrl_buf, len);
return tud_control_xfer(rhport, p_request, get_ctrl_buffer(), len);
}

// Verify an entity with the given ID exists and returns also the corresponding driver index
Expand Down
19 changes: 15 additions & 4 deletions src/class/dfu/dfu_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,25 @@ typedef struct {

static dfu_state_ctx_t _dfu_ctx;

#if CFG_TUD_DFU_XFER_BUFSIZE > CFG_TUD_ENDPOINT0_BUFSIZE
TU_ATTR_ALIGNED(4) uint8_t _transfer_buf[CFG_TUD_DFU_XFER_BUFSIZE];
#endif

static void reset_state(void) {
_dfu_ctx.state = DFU_IDLE;
_dfu_ctx.status = DFU_STATUS_OK;
_dfu_ctx.flashing_in_progress = false;
}

static inline uint8_t* get_xfer_buffer(void) {
// Use EP0 buffer if it is large enough, otherwise use dedicated buffer
#if CFG_TUD_DFU_XFER_BUFSIZE > CFG_TUD_ENDPOINT0_BUFSIZE
return _transfer_buf;
#else
return _usbd_ctrl_epbuf.buf;
#endif
}

static bool reply_getstatus(uint8_t rhport, const tusb_control_request_t* request, dfu_state_t state, dfu_status_t status, uint32_t timeout);
static bool process_download_get_status(uint8_t rhport, uint8_t stage, const tusb_control_request_t* request);
static bool process_manifest_get_status(uint8_t rhport, uint8_t stage, const tusb_control_request_t* request);
Expand Down Expand Up @@ -283,10 +294,10 @@ bool dfu_moded_control_xfer_cb(uint8_t rhport, uint8_t stage, const tusb_control
TU_VERIFY(_dfu_ctx.attrs & DFU_ATTR_CAN_UPLOAD);
TU_VERIFY(request->wLength <= CFG_TUD_DFU_XFER_BUFSIZE);

const uint16_t xfer_len = tud_dfu_upload_cb(_dfu_ctx.alt, request->wValue, _transfer_buf,
const uint16_t xfer_len = tud_dfu_upload_cb(_dfu_ctx.alt, request->wValue, get_xfer_buffer(),
request->wLength);

return tud_control_xfer(rhport, request, _transfer_buf, xfer_len);
return tud_control_xfer(rhport, request, get_xfer_buffer(), xfer_len);
}
break;

Expand All @@ -306,7 +317,7 @@ bool dfu_moded_control_xfer_cb(uint8_t rhport, uint8_t stage, const tusb_control
if (request->wLength > 0) {
// Download with payload -> transition to DOWNLOAD SYNC
_dfu_ctx.state = DFU_DNLOAD_SYNC;
return tud_control_xfer(rhport, request, _transfer_buf, request->wLength);
return tud_control_xfer(rhport, request, get_xfer_buffer(), request->wLength);
} else {
// Download is complete -> transition to MANIFEST SYNC
_dfu_ctx.state = DFU_MANIFEST_SYNC;
Expand Down Expand Up @@ -380,7 +391,7 @@ static bool process_download_get_status(uint8_t rhport, uint8_t stage, const tus
} else if (stage == CONTROL_STAGE_ACK) {
if (_dfu_ctx.flashing_in_progress) {
_dfu_ctx.state = DFU_DNBUSY;
tud_dfu_download_cb(_dfu_ctx.alt, _dfu_ctx.block, _transfer_buf, _dfu_ctx.length);
tud_dfu_download_cb(_dfu_ctx.alt, _dfu_ctx.block, get_xfer_buffer(), _dfu_ctx.length);
} else {
_dfu_ctx.state = DFU_DNLOAD_IDLE;
}
Expand Down
14 changes: 7 additions & 7 deletions src/device/usbd_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ typedef struct {

static usbd_control_xfer_t _ctrl_xfer;

CFG_TUD_MEM_SECTION static struct {
TUD_EPBUF_DEF(buf, CFG_TUD_ENDPOINT0_BUFSIZE);
} _ctrl_epbuf;
CFG_TUD_MEM_SECTION usbd_ctrl_epbuf_t _usbd_ctrl_epbuf;

//--------------------------------------------------------------------+
// Application API
Expand Down Expand Up @@ -93,12 +91,12 @@ static bool data_stage_xact(uint8_t rhport) {

if (_ctrl_xfer.request.bmRequestType_bit.direction == TUSB_DIR_IN) {
ep_addr = EDPT_CTRL_IN;
if (0u != xact_len) {
TU_VERIFY(0 == tu_memcpy_s(_ctrl_epbuf.buf, CFG_TUD_ENDPOINT0_BUFSIZE, _ctrl_xfer.buffer, xact_len));
if (0u != xact_len && _ctrl_xfer.buffer != _usbd_ctrl_epbuf.buf) {
TU_VERIFY(0 == tu_memcpy_s(_usbd_ctrl_epbuf.buf, CFG_TUD_ENDPOINT0_BUFSIZE, _ctrl_xfer.buffer, xact_len));
}
}

return usbd_edpt_xfer(rhport, ep_addr, xact_len ? _ctrl_epbuf.buf : NULL, xact_len, false);
return usbd_edpt_xfer(rhport, ep_addr, xact_len ? _usbd_ctrl_epbuf.buf : NULL, xact_len, false);
}

// Transmit data to/from the control endpoint.
Expand Down Expand Up @@ -169,7 +167,9 @@ bool usbd_control_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result,

if (_ctrl_xfer.request.bmRequestType_bit.direction == TUSB_DIR_OUT) {
TU_VERIFY(_ctrl_xfer.buffer);
memcpy(_ctrl_xfer.buffer, _ctrl_epbuf.buf, xferred_bytes);
if (_ctrl_xfer.buffer != _usbd_ctrl_epbuf.buf) {
memcpy(_ctrl_xfer.buffer, _usbd_ctrl_epbuf.buf, xferred_bytes);
}
TU_LOG_MEM(CFG_TUD_LOG_LEVEL, _ctrl_xfer.buffer, xferred_bytes, 2);
}

Expand Down
6 changes: 6 additions & 0 deletions src/device/usbd_pvt.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ void usbd_int_set(bool enabled);
void usbd_spin_lock(bool in_isr);
void usbd_spin_unlock(bool in_isr);

typedef struct {
TUD_EPBUF_DEF(buf, CFG_TUD_ENDPOINT0_BUFSIZE);
} usbd_ctrl_epbuf_t;

extern usbd_ctrl_epbuf_t _usbd_ctrl_epbuf;

//--------------------------------------------------------------------+
// USBD Endpoint API
// Note: rhport should be 0 since device stack only support 1 rhport for now
Expand Down