From 36da9a8af56545146f586233b0bfb78615af0b5f Mon Sep 17 00:00:00 2001 From: Mathias Brossard Date: Sat, 1 Apr 2023 21:29:37 -0500 Subject: [PATCH 1/5] usb_config: Add macro options to disable USB endpoints from interface projects --- source/daplink/cmsis-dap/DAP_vendor.c | 2 ++ source/daplink/drag-n-drop/vfs_manager.c | 2 +- source/daplink/interface/main_interface.c | 4 +++- source/daplink/usb2uart/usbd_user_cdc_acm.c | 3 +++ source/usb/bulk/usbd_bulk.c | 4 ++++ source/usb/cdc/usbd_cdc_acm.c | 4 +++- source/usb/cdc/usbd_core_cdc.c | 4 ++++ source/usb/hid/usbd_core_hid.c | 4 ++++ source/usb/hid/usbd_hid.c | 4 ++++ source/usb/hid/usbd_user_hid.c | 4 +++- source/usb/msc/usbd_core_msc.c | 5 ++++- source/usb/msc/usbd_msc.c | 4 ++++ 12 files changed, 39 insertions(+), 5 deletions(-) diff --git a/source/daplink/cmsis-dap/DAP_vendor.c b/source/daplink/cmsis-dap/DAP_vendor.c index 8e31dd743b..e15471a06e 100644 --- a/source/daplink/cmsis-dap/DAP_vendor.c +++ b/source/daplink/cmsis-dap/DAP_vendor.c @@ -76,6 +76,7 @@ uint32_t DAP_ProcessVendorCommand(const uint8_t *request, uint8_t *response) { num += (len + 1); // increment response count by ID length + length byte break; } +#if defined(CDC_ENDPOINT) && !defined(CDC_ENDPOINT_DISABLE) case ID_DAP_UART_GetLineCoding: { // get line coding int32_t read_len = sizeof(CDC_LINE_CODING); @@ -121,6 +122,7 @@ uint32_t DAP_ProcessVendorCommand(const uint8_t *request, uint8_t *response) { num += ((write_len + 1) << 16) | 1; break; } +#endif case ID_DAP_Vendor5: break; case ID_DAP_Vendor6: break; case ID_DAP_Vendor7: break; diff --git a/source/daplink/drag-n-drop/vfs_manager.c b/source/daplink/drag-n-drop/vfs_manager.c index 3dce714fd5..99a5705223 100644 --- a/source/daplink/drag-n-drop/vfs_manager.c +++ b/source/daplink/drag-n-drop/vfs_manager.c @@ -116,7 +116,7 @@ static const file_transfer_state_t default_transfer_state = { }; //Compile option not to include MSC at all, these will be dummy variables -#ifndef MSC_ENDPOINT +#if !defined(MSC_ENDPOINT) || defined(MSC_ENDPOINT_DISABLE) BOOL USBD_MSC_MediaReady = __FALSE; BOOL USBD_MSC_ReadOnly = __FALSE; U32 USBD_MSC_MemorySize; diff --git a/source/daplink/interface/main_interface.c b/source/daplink/interface/main_interface.c index 76bd7240f3..0b1472b767 100644 --- a/source/daplink/interface/main_interface.c +++ b/source/daplink/interface/main_interface.c @@ -384,10 +384,12 @@ void main_task(void * arg) target_set_state(NO_DEBUG); } +#if defined(CDC_ENDPOINT) && !defined(CDC_ENDPOINT_DISABLE) if (flags & FLAGS_MAIN_CDC_EVENT) { cdc_process_event(); } - +#endif + if (flags & FLAGS_BOARD_EVENT) { board_custom_event(); } diff --git a/source/daplink/usb2uart/usbd_user_cdc_acm.c b/source/daplink/usb2uart/usbd_user_cdc_acm.c index 9229708193..9c2c5e8516 100644 --- a/source/daplink/usb2uart/usbd_user_cdc_acm.c +++ b/source/daplink/usb2uart/usbd_user_cdc_acm.c @@ -19,6 +19,8 @@ * limitations under the License. */ +#if defined(CDC_ENDPOINT) && !defined(CDC_ENDPOINT_DISABLE) + #include "cmsis_os2.h" #include "rl_usb.h" #include "daplink.h" @@ -203,3 +205,4 @@ void cdc_process_event(void) } #endif +#endif diff --git a/source/usb/bulk/usbd_bulk.c b/source/usb/bulk/usbd_bulk.c index 9786892718..76cfd4c123 100644 --- a/source/usb/bulk/usbd_bulk.c +++ b/source/usb/bulk/usbd_bulk.c @@ -19,6 +19,8 @@ * limitations under the License. */ +#if defined(BULK_ENDPOINT) && !defined(BULK_ENDPOINT_DISABLE) + #include #include "rl_usb.h" @@ -108,3 +110,5 @@ void USBD_BULK_EP_BULK_Event(U32 event) USBD_BULK_EP_BULKIN_Event(0); } } + +#endif diff --git a/source/usb/cdc/usbd_cdc_acm.c b/source/usb/cdc/usbd_cdc_acm.c index 6d254ede45..a74ee583b3 100644 --- a/source/usb/cdc/usbd_cdc_acm.c +++ b/source/usb/cdc/usbd_cdc_acm.c @@ -19,6 +19,8 @@ * limitations under the License. */ +#if defined(CDC_ENDPOINT) && !defined(CDC_ENDPOINT_DISABLE) + #include #include "rl_usb.h" @@ -1160,4 +1162,4 @@ void USBD_RTX_CDC_ACM_3_EP_BULK_Event(void) #endif #endif - +#endif diff --git a/source/usb/cdc/usbd_core_cdc.c b/source/usb/cdc/usbd_core_cdc.c index b96b88ac9b..1100abaec7 100644 --- a/source/usb/cdc/usbd_core_cdc.c +++ b/source/usb/cdc/usbd_core_cdc.c @@ -19,6 +19,8 @@ * limitations under the License. */ +#if defined(CDC_ENDPOINT) && !defined(CDC_ENDPOINT_DISABLE) + #include #include "rl_usb.h" @@ -150,3 +152,5 @@ __WEAK BOOL USBD_EndPoint0_Out_CDC_ReqToIF(void) return (__FALSE); } + +#endif diff --git a/source/usb/hid/usbd_core_hid.c b/source/usb/hid/usbd_core_hid.c index a77f8fff94..258e742ec1 100644 --- a/source/usb/hid/usbd_core_hid.c +++ b/source/usb/hid/usbd_core_hid.c @@ -19,6 +19,8 @@ * limitations under the License. */ +#if defined(HID_ENDPOINT) && !defined(HID_ENDPOINT_DISABLE) + #include #include "rl_usb.h" @@ -172,3 +174,5 @@ __WEAK BOOL USBD_EndPoint0_Out_HID_ReqToIF(void) return (__FALSE); } + +#endif diff --git a/source/usb/hid/usbd_hid.c b/source/usb/hid/usbd_hid.c index 980c910031..d9deb62974 100644 --- a/source/usb/hid/usbd_hid.c +++ b/source/usb/hid/usbd_hid.c @@ -19,6 +19,8 @@ * limitations under the License. */ +#if defined(HID_ENDPOINT) && !defined(HID_ENDPOINT_DISABLE) + #include #include "rl_usb.h" @@ -555,3 +557,5 @@ BOOL usbd_hid_get_report_trigger(U8 rid, U8 *buf, int len) return (__FALSE); } + +#endif diff --git a/source/usb/hid/usbd_user_hid.c b/source/usb/hid/usbd_user_hid.c index b2ccb05f7d..dc8d38a33f 100644 --- a/source/usb/hid/usbd_user_hid.c +++ b/source/usb/hid/usbd_user_hid.c @@ -19,6 +19,8 @@ * limitations under the License. */ +#if defined(HID_ENDPOINT) && !defined(HID_ENDPOINT_DISABLE) + #include #include "rl_usb.h" #include "usb.h" @@ -126,4 +128,4 @@ void usbd_hid_set_report(U8 rtype, U8 rid, U8 *buf, int len, U8 req) } } - +#endif diff --git a/source/usb/msc/usbd_core_msc.c b/source/usb/msc/usbd_core_msc.c index eec3311196..5241d71afc 100644 --- a/source/usb/msc/usbd_core_msc.c +++ b/source/usb/msc/usbd_core_msc.c @@ -19,12 +19,13 @@ * limitations under the License. */ +#if defined(MSC_ENDPOINT) && !defined(MSC_ENDPOINT_DISABLE) + #include #include "rl_usb.h" #include "usb_for_lib.h" - /* * Clear Feature USB Device Request - MSC specific handling * Parameters: EPNum: Endpoint number @@ -74,3 +75,5 @@ __WEAK BOOL USBD_EndPoint0_Setup_MSC_ReqToIF(void) return (__FALSE); } + +#endif diff --git a/source/usb/msc/usbd_msc.c b/source/usb/msc/usbd_msc.c index 9d54131d58..35038902d5 100644 --- a/source/usb/msc/usbd_msc.c +++ b/source/usb/msc/usbd_msc.c @@ -19,6 +19,8 @@ * limitations under the License. */ +#if defined(MSC_ENDPOINT) && !defined(MSC_ENDPOINT_DISABLE) + #include #include "rl_usb.h" @@ -1213,4 +1215,6 @@ __task void USBD_RTX_MSC_EP_BULK_Event(void) USBD_MSC_EP_BULK_Event(usbd_os_evt_get()); } } + +#endif #endif From a38febf04875f4d26b3a114bde25e41f09413776 Mon Sep 17 00:00:00 2001 From: Mathias Brossard Date: Sun, 2 Apr 2023 17:00:36 -0500 Subject: [PATCH 2/5] usb_config: Add option to disable drag-n-drop from interface projects --- source/board/microbitv2/microbitv2.c | 4 ++-- source/daplink/cmsis-dap/DAP_vendor.c | 8 ++++---- source/daplink/drag-n-drop/file_stream.c | 4 ++++ source/daplink/drag-n-drop/flash_decoder.c | 6 +++++- source/daplink/drag-n-drop/flash_intf.c | 4 ++++ source/daplink/drag-n-drop/flash_manager.c | 5 ++++- source/daplink/drag-n-drop/iap_flash_intf.c | 4 ++++ source/daplink/drag-n-drop/intelhex.c | 4 ++++ source/daplink/drag-n-drop/vfs_manager.c | 4 ++++ source/daplink/drag-n-drop/vfs_user.c | 4 ++++ source/daplink/drag-n-drop/virtual_fs.c | 4 ++++ source/daplink/info.c | 4 ++-- source/daplink/interface/bootloader_update.c | 3 ++- source/daplink/interface/daplink.c | 2 +- source/daplink/interface/main_interface.c | 10 +++++----- source/daplink/interface/target_flash.c | 6 ++++-- source/daplink/usb2uart/usbd_user_cdc_acm.c | 4 ++-- source/target/target_board.h | 2 +- source/usb/usb_lib.c | 2 +- 19 files changed, 61 insertions(+), 23 deletions(-) diff --git a/source/board/microbitv2/microbitv2.c b/source/board/microbitv2/microbitv2.c index 427e4e3268..4aeed8d8e3 100644 --- a/source/board/microbitv2/microbitv2.c +++ b/source/board/microbitv2/microbitv2.c @@ -44,7 +44,7 @@ #include "gpio_extra.h" #include "board_id.h" -#ifdef DRAG_N_DROP_SUPPORT +#if defined(DRAG_N_DROP_SUPPORT) && !defined(DRAG_N_DROP_DISABLE) #include "flash_intf.h" #endif @@ -155,7 +155,7 @@ static void reset_power_led_state() // Handle the reset button behavior, this function is called in the main task every 30ms void handle_reset_button() { -#ifdef DRAG_N_DROP_SUPPORT +#if defined(DRAG_N_DROP_SUPPORT) && !defined(DRAG_N_DROP_DISABLE) if (!flash_intf_target->flash_busy()) //added checking if flashing on target is in progress #endif { diff --git a/source/daplink/cmsis-dap/DAP_vendor.c b/source/daplink/cmsis-dap/DAP_vendor.c index e15471a06e..6c71e0bb16 100644 --- a/source/daplink/cmsis-dap/DAP_vendor.c +++ b/source/daplink/cmsis-dap/DAP_vendor.c @@ -37,12 +37,12 @@ #include "uart.h" #include "settings.h" #include "target_family.h" -#include "flash_manager.h" #include #include "daplink_vendor_commands.h" -#ifdef DRAG_N_DROP_SUPPORT +#if defined(DRAG_N_DROP_SUPPORT) && !defined(DRAG_N_DROP_DISABLE) #include "file_stream.h" +#include "flash_manager.h" #endif //************************************************************************************************** @@ -147,7 +147,7 @@ uint32_t DAP_ProcessVendorCommand(const uint8_t *request, uint8_t *response) { num += 1; break; } -#ifdef DRAG_N_DROP_SUPPORT +#if defined(DRAG_N_DROP_SUPPORT) && !defined(DRAG_N_DROP_DISABLE) case ID_DAP_MSD_Open: { // open mass storage device stream *response = stream_open((stream_type_t)(*request)); @@ -169,7 +169,6 @@ uint32_t DAP_ProcessVendorCommand(const uint8_t *request, uint8_t *response) { num += ((write_len + 1) << 16) | 1; break; } -#endif case ID_DAP_SelectEraseMode: { // switching between chip erase and page erase // COMMAND(OUT Packet) @@ -189,6 +188,7 @@ uint32_t DAP_ProcessVendorCommand(const uint8_t *request, uint8_t *response) { num += (1U << 16) | 1U; // increment request and response count each by 1 break; } +#endif case ID_DAP_Vendor14: break; case ID_DAP_Vendor15: break; case ID_DAP_Vendor16: break; diff --git a/source/daplink/drag-n-drop/file_stream.c b/source/daplink/drag-n-drop/file_stream.c index 284ccc9f82..53b51c61b4 100644 --- a/source/daplink/drag-n-drop/file_stream.c +++ b/source/daplink/drag-n-drop/file_stream.c @@ -19,6 +19,8 @@ * limitations under the License. */ +#if defined(DRAG_N_DROP_SUPPORT) && !defined(DRAG_N_DROP_DISABLE) + #include #include "file_stream.h" @@ -364,3 +366,5 @@ static error_t close_hex(void *state) status = flash_decoder_close(); return status; } + +#endif diff --git a/source/daplink/drag-n-drop/flash_decoder.c b/source/daplink/drag-n-drop/flash_decoder.c index 46b4bc7ae3..a60452cc52 100644 --- a/source/daplink/drag-n-drop/flash_decoder.c +++ b/source/daplink/drag-n-drop/flash_decoder.c @@ -19,6 +19,8 @@ * limitations under the License. */ +#if defined(DRAG_N_DROP_SUPPORT) && !defined(DRAG_N_DROP_DISABLE) + #include #include "flash_decoder.h" @@ -292,7 +294,7 @@ error_t flash_decoder_write(uint32_t addr, const uint8_t *data, uint32_t size) state = DECODER_STATE_ERROR; return status; } - + // Validate incompatible target image file if (config_get_detect_incompatible_target()){ status = flash_decoder_validate_target_image(flash_type, flash_buf, flash_buf_pos); @@ -423,3 +425,5 @@ static bool flash_decoder_is_at_end(uint32_t addr, const uint8_t *data, uint32_t return false; } } + +#endif diff --git a/source/daplink/drag-n-drop/flash_intf.c b/source/daplink/drag-n-drop/flash_intf.c index 807dc3c5f8..34c684b4a8 100644 --- a/source/daplink/drag-n-drop/flash_intf.c +++ b/source/daplink/drag-n-drop/flash_intf.c @@ -19,9 +19,13 @@ * limitations under the License. */ +#if defined(DRAG_N_DROP_SUPPORT) && !defined(DRAG_N_DROP_DISABLE) + #include "flash_intf.h" #include "compiler.h" __WEAK const flash_intf_t *const flash_intf_iap_protected = 0; __WEAK const flash_intf_t *const flash_intf_target = 0; __WEAK const flash_intf_t *const flash_intf_target_custom = 0; + +#endif diff --git a/source/daplink/drag-n-drop/flash_manager.c b/source/daplink/drag-n-drop/flash_manager.c index 64b2a77773..3a0120d65c 100755 --- a/source/daplink/drag-n-drop/flash_manager.c +++ b/source/daplink/drag-n-drop/flash_manager.c @@ -4,7 +4,7 @@ * * DAPLink Interface Firmware * Copyright (c) 2009-2019, ARM Limited, All Rights Reserved - * Copyright 2019, Cypress Semiconductor Corporation + * Copyright 2019, Cypress Semiconductor Corporation * or a subsidiary of Cypress Semiconductor Corporation. * SPDX-License-Identifier: Apache-2.0 * @@ -21,6 +21,8 @@ * limitations under the License. */ +#if defined(DRAG_N_DROP_SUPPORT) && !defined(DRAG_N_DROP_DISABLE) + #include "flash_manager.h" #include "util.h" #include "error.h" @@ -348,3 +350,4 @@ static error_t setup_next_sector(uint32_t addr) current_write_block_size, current_sector_size, min_prog_size); return ERROR_SUCCESS; } +#endif diff --git a/source/daplink/drag-n-drop/iap_flash_intf.c b/source/daplink/drag-n-drop/iap_flash_intf.c index ca7b274cef..c922229f1b 100644 --- a/source/daplink/drag-n-drop/iap_flash_intf.c +++ b/source/daplink/drag-n-drop/iap_flash_intf.c @@ -19,6 +19,8 @@ * limitations under the License. */ +#if defined(DRAG_N_DROP_SUPPORT) && !defined(DRAG_N_DROP_DISABLE) + #include #include "daplink.h" @@ -505,3 +507,5 @@ static error_t critical_erase_and_program(uint32_t addr, const uint8_t *data, ui static uint8_t target_flash_busy(void){ return (state == STATE_OPEN); } + +#endif diff --git a/source/daplink/drag-n-drop/intelhex.c b/source/daplink/drag-n-drop/intelhex.c index 6233371862..aff9221399 100644 --- a/source/daplink/drag-n-drop/intelhex.c +++ b/source/daplink/drag-n-drop/intelhex.c @@ -19,6 +19,8 @@ * limitations under the License. */ +#if defined(DRAG_N_DROP_SUPPORT) && !defined(DRAG_N_DROP_DISABLE) + #include #include "intelhex.h" @@ -276,3 +278,5 @@ hexfile_parse_status_t parse_hex_blob(const uint8_t *hex_blob, const uint32_t he #elif defined(__GNUC__) && !defined(__ARMCC_VERSION) #pragma GCC pop_options #endif + +#endif diff --git a/source/daplink/drag-n-drop/vfs_manager.c b/source/daplink/drag-n-drop/vfs_manager.c index 99a5705223..d592bb7e8e 100644 --- a/source/daplink/drag-n-drop/vfs_manager.c +++ b/source/daplink/drag-n-drop/vfs_manager.c @@ -19,6 +19,8 @@ * limitations under the License. */ +#if defined(DRAG_N_DROP_SUPPORT) && !defined(DRAG_N_DROP_DISABLE) + #include #include "daplink.h" @@ -845,3 +847,5 @@ static void transfer_update_state(error_t status) vfs_mngr_fs_remount(); } } + +#endif diff --git a/source/daplink/drag-n-drop/vfs_user.c b/source/daplink/drag-n-drop/vfs_user.c index 2a0278cead..4264073a53 100644 --- a/source/daplink/drag-n-drop/vfs_user.c +++ b/source/daplink/drag-n-drop/vfs_user.c @@ -21,6 +21,8 @@ * limitations under the License. */ +#if defined(DRAG_N_DROP_SUPPORT) && !defined(DRAG_N_DROP_DISABLE) + #include #include #include @@ -700,3 +702,5 @@ static void erase_target(void) flash_intf_target->erase_chip(); flash_intf_target->uninit(); } + +#endif diff --git a/source/daplink/drag-n-drop/virtual_fs.c b/source/daplink/drag-n-drop/virtual_fs.c index c8b903e3bc..62d73b7769 100644 --- a/source/daplink/drag-n-drop/virtual_fs.c +++ b/source/daplink/drag-n-drop/virtual_fs.c @@ -19,6 +19,8 @@ * limitations under the License. */ +#if defined(DRAG_N_DROP_SUPPORT) && !defined(DRAG_N_DROP_DISABLE) + #include #include "virtual_fs.h" @@ -741,3 +743,5 @@ static bool filename_character_valid(char character) // All of the checks have passed so this is a valid file name character return true; } + +#endif diff --git a/source/daplink/info.c b/source/daplink/info.c index 05efa202c9..23e65128fb 100644 --- a/source/daplink/info.c +++ b/source/daplink/info.c @@ -136,7 +136,8 @@ static void setup_basics(void) //Family ID string_family_id[idx++] = hex_to_ascii(((family_id >> 12) & 0xF)); string_family_id[idx++] = hex_to_ascii(((family_id >> 8) & 0xF)); -#if !(defined(DAPLINK_BL)) && defined(DRAG_N_DROP_SUPPORT) //need to change the unique id when the msd is disabled +#if !(defined(DAPLINK_BL)) && defined(DRAG_N_DROP_SUPPORT) && !defined(DRAG_N_DROP_DISABLE) + // Need to change the unique id when the msd is disabled #if defined(MSC_ENDPOINT) if (config_ram_get_disable_msd() == 1 || flash_algo_valid()==0){ string_family_id[idx++] = hex_to_ascii((((family_id >> 4) | 0x08) & 0xF)); @@ -321,4 +322,3 @@ uint32_t info_get_interface_version(void) return info_if->version; } - diff --git a/source/daplink/interface/bootloader_update.c b/source/daplink/interface/bootloader_update.c index c86bc6f2b0..684f723fa8 100644 --- a/source/daplink/interface/bootloader_update.c +++ b/source/daplink/interface/bootloader_update.c @@ -19,7 +19,8 @@ * limitations under the License. */ -#ifdef DRAG_N_DROP_SUPPORT +#if defined(DRAG_N_DROP_SUPPORT) && !defined(DRAG_N_DROP_DISABLE) + #include #include #include "flash_manager.h" diff --git a/source/daplink/interface/daplink.c b/source/daplink/interface/daplink.c index 4952a8bc0d..067818f26e 100644 --- a/source/daplink/interface/daplink.c +++ b/source/daplink/interface/daplink.c @@ -21,7 +21,7 @@ #include "daplink.h" -#ifdef DRAG_N_DROP_SUPPORT +#if defined(DRAG_N_DROP_SUPPORT) && !defined(DRAG_N_DROP_DISABLE) #include "virtual_fs.h" #include "compiler.h" diff --git a/source/daplink/interface/main_interface.c b/source/daplink/interface/main_interface.c index 0b1472b767..badef13070 100644 --- a/source/daplink/interface/main_interface.c +++ b/source/daplink/interface/main_interface.c @@ -40,7 +40,7 @@ #include "target_family.h" #include "target_board.h" -#ifdef DRAG_N_DROP_SUPPORT +#if defined(DRAG_N_DROP_SUPPORT) && !defined(DRAG_N_DROP_DISABLE) #include "vfs_manager.h" #include "flash_intf.h" #include "flash_manager.h" @@ -156,7 +156,7 @@ __WEAK void handle_reset_button(void) // handle reset button without eventing if (!reset_pressed && gpio_get_reset_btn_fwrd()) { -#ifdef DRAG_N_DROP_SUPPORT +#if defined(DRAG_N_DROP_SUPPORT) && !defined(DRAG_N_DROP_DISABLE) if (!flash_intf_target->flash_busy()) //added checking if flashing on target is in progress #endif { @@ -314,7 +314,7 @@ void main_task(void * arg) swd_set_reset_connect(CONNECT_UNDER_RESET); } if (g_board_info.flags & kEnablePageErase) { -#ifdef DRAG_N_DROP_SUPPORT +#if defined(DRAG_N_DROP_SUPPORT) && !defined(DRAG_N_DROP_DISABLE) flash_manager_set_page_erase(true); #endif } @@ -325,7 +325,7 @@ void main_task(void * arg) bootloader_check_and_update(); // USB usbd_init(); -#ifdef DRAG_N_DROP_SUPPORT +#if defined(DRAG_N_DROP_SUPPORT) && !defined(DRAG_N_DROP_DISABLE) vfs_mngr_fs_enable((config_ram_get_disable_msd()==0)); #endif usbd_connect(0); @@ -396,7 +396,7 @@ void main_task(void * arg) if (flags & FLAGS_MAIN_90MS) { // Update USB busy status -#ifdef DRAG_N_DROP_SUPPORT +#if defined(DRAG_N_DROP_SUPPORT) && !defined(DRAG_N_DROP_DISABLE) vfs_mngr_periodic(90); // FLAGS_MAIN_90MS #endif // Update USB connect status diff --git a/source/daplink/interface/target_flash.c b/source/daplink/interface/target_flash.c index 77489dac7c..a0494c429f 100644 --- a/source/daplink/interface/target_flash.c +++ b/source/daplink/interface/target_flash.c @@ -4,7 +4,7 @@ * * DAPLink Interface Firmware * Copyright (c) 2009-2019, ARM Limited, All Rights Reserved - * Copyright 2019, Cypress Semiconductor Corporation + * Copyright 2019, Cypress Semiconductor Corporation * or a subsidiary of Cypress Semiconductor Corporation. * SPDX-License-Identifier: Apache-2.0 * @@ -20,7 +20,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifdef DRAG_N_DROP_SUPPORT + +#if defined(DRAG_N_DROP_SUPPORT) && !defined(DRAG_N_DROP_DISABLE) + #include #include "target_config.h" diff --git a/source/daplink/usb2uart/usbd_user_cdc_acm.c b/source/daplink/usb2uart/usbd_user_cdc_acm.c index 9c2c5e8516..4ccafa4c8b 100644 --- a/source/daplink/usb2uart/usbd_user_cdc_acm.c +++ b/source/daplink/usb2uart/usbd_user_cdc_acm.c @@ -26,7 +26,7 @@ #include "daplink.h" #include DAPLINK_MAIN_HEADER #include "uart.h" -#ifdef DRAG_N_DROP_SUPPORT +#if defined(DRAG_N_DROP_SUPPORT) && !defined(DRAG_N_DROP_DISABLE) #include "flash_intf.h" #endif #include "target_family.h" @@ -124,7 +124,7 @@ static U32 start_break_time = 0; int32_t USBD_CDC_ACM_SendBreak(usbd_cdc_num_t cdc_num, uint16_t dur) { uint32_t end_break_time; -#ifdef DRAG_N_DROP_SUPPORT +#if defined(DRAG_N_DROP_SUPPORT) && !defined(DRAG_N_DROP_DISABLE) if (!flash_intf_target->flash_busy()) #endif { //added checking if flashing on target is in progress diff --git a/source/target/target_board.h b/source/target/target_board.h index 6b4476aa4b..e87ff4d387 100644 --- a/source/target/target_board.h +++ b/source/target/target_board.h @@ -25,7 +25,7 @@ #include #include "target_config.h" #include "target_family.h" -#include "virtual_fs.h" +#include "../drag-n-drop/virtual_fs.h" //! @brief Current board info version. //! diff --git a/source/usb/usb_lib.c b/source/usb/usb_lib.c index 8fbf85e801..2eb17bc310 100644 --- a/source/usb/usb_lib.c +++ b/source/usb/usb_lib.c @@ -3616,7 +3616,7 @@ void usbd_class_init(void) #if (USBD_MSC_ENABLE) -#if !(defined(DAPLINK_BL)) && defined(DRAG_N_DROP_SUPPORT) +#if !(defined(DAPLINK_BL)) && defined(DRAG_N_DROP_SUPPORT) && !defined(DRAG_N_DROP_DISABLE) //change descriptors here if (config_ram_get_disable_msd() == 1 || flash_algo_valid()==0 ){ usbd_if_num -= USBD_MSC_ENABLE; From debd0ac0fdc2a09ee9ac92b1646c908fc2c16d7a Mon Sep 17 00:00:00 2001 From: Mathias Brossard Date: Sun, 2 Apr 2023 17:26:29 -0500 Subject: [PATCH 3/5] sam3u2c: Add support for interface project configuration of endpoints --- source/hic_hal/atmel/sam3u2c/usb_config.c | 101 +++++++++++++++------- 1 file changed, 68 insertions(+), 33 deletions(-) diff --git a/source/hic_hal/atmel/sam3u2c/usb_config.c b/source/hic_hal/atmel/sam3u2c/usb_config.c index e78132cd41..40ec8cf05d 100644 --- a/source/hic_hal/atmel/sam3u2c/usb_config.c +++ b/source/hic_hal/atmel/sam3u2c/usb_config.c @@ -21,6 +21,72 @@ #include "util.h" +#ifdef HID_ENDPOINT_DISABLE +#undef HID_ENDPOINT +#define HID_ENDPOINT 0 +#else +#ifndef HID_ENDPOINT +#define HID_ENDPOINT 0 +#else +#define HID_ENDPOINT 1 +#endif +#endif + +#ifdef MSC_ENDPOINT_DISABLE +#undef MSC_ENDPOINT +#define MSC_ENDPOINT 0 +#else +#ifndef MSC_ENDPOINT +#define MSC_ENDPOINT 0 +#else +#define MSC_ENDPOINT 1 +#endif +#endif + +#ifdef CDC_ENDPOINT_DISABLE +#undef CDC_ENDPOINT +#define CDC_ENDPOINT 0 +#else +#ifndef CDC_ENDPOINT +#define CDC_ENDPOINT 0 +#else +#define CDC_ENDPOINT 1 +#endif +#endif + +#ifdef BULK_ENDPOINT_DISABLE +#undef BULK_ENDPOINT +#define BULK_ENDPOINT 0 +#else +#ifndef BULK_ENDPOINT +#define BULK_ENDPOINT 0 +#else +#define BULK_ENDPOINT 1 +#endif +#endif + +#ifdef WEBUSB_INTERFACE_DISABLE +#undef WEBUSB_INTERFACE +#define WEBUSB_INTERFACE 0 +#else +#ifndef WEBUSB_INTERFACE +#define WEBUSB_INTERFACE 0 +#else +#define WEBUSB_INTERFACE 1 +#endif +#endif + +#ifdef WINUSB_INTERFACE_DISABLE +#undef WINUSB_INTERFACE +#define WINUSB_INTERFACE 0 +#else +#ifndef WINUSB_INTERFACE +#define WINUSB_INTERFACE 0 +#else +#define WINUSB_INTERFACE 1 +#endif +#endif + // USB Device // Enable the USB Device functionality #define USBD_ENABLE 1 @@ -141,23 +207,6 @@ // Maximum Feature Report Size (in bytes) <1-65535> // // -#ifndef HID_ENDPOINT -#define HID_ENDPOINT 0 -#else -#define HID_ENDPOINT 1 -#endif - -#ifndef WEBUSB_INTERFACE -#define WEBUSB_INTERFACE 0 -#else -#define WEBUSB_INTERFACE 1 -#endif - -#ifndef WINUSB_INTERFACE -#define WINUSB_INTERFACE 0 -#else -#define WINUSB_INTERFACE 1 -#endif #define USBD_HID_ENABLE HID_ENDPOINT #define USBD_HID_EP_INTIN 3 @@ -207,11 +256,7 @@ // // // -#ifndef MSC_ENDPOINT -#define MSC_ENDPOINT 0 -#else -#define MSC_ENDPOINT 1 -#endif + #define USBD_MSC_ENABLE MSC_ENDPOINT #define USBD_MSC_EP_BULKIN 1 #define USBD_MSC_EP_BULKIN_STACK 0 @@ -328,11 +373,6 @@ // // -#ifndef CDC_ENDPOINT -#define CDC_ENDPOINT 0 -#else -#define CDC_ENDPOINT 1 -#endif #define USBD_CDC_ACM_ENABLE CDC_ENDPOINT #define USBD_CDC_ACM_EP_INTIN 4 #define USBD_CDC_ACM_EP_INTIN_STACK 0 @@ -390,11 +430,6 @@ // // -#ifndef BULK_ENDPOINT -#define BULK_ENDPOINT 0 -#else -#define BULK_ENDPOINT 1 -#endif #define USBD_BULK_ENABLE BULK_ENDPOINT //no endpts left #define USBD_BULK_EP_BULKIN 7 #define USBD_BULK_EP_BULKOUT 8 @@ -418,7 +453,7 @@ #define USBD_EP_NUM_CALC6 MAX(USBD_EP_NUM_CALC4, USBD_EP_NUM_CALC5) #define USBD_EP_NUM_CALC7 MAX((USBD_BULK_ENABLE*(USBD_BULK_EP_BULKIN)), (USBD_BULK_ENABLE*(USBD_BULK_EP_BULKOUT))) #define USBD_EP_NUM MAX(USBD_EP_NUM_CALC6, USBD_EP_NUM_CALC7) - + #if (USBD_EP_NUM > 6) #error "SAM3U only have 7 endpoints including EP0!" #endif From 08a439291a01ce3c9ca8fc6c2be694aa114ba856 Mon Sep 17 00:00:00 2001 From: 9names <60134748+9names@users.noreply.github.com> Date: Sat, 1 Apr 2023 14:43:50 +1100 Subject: [PATCH 4/5] sam3u2c: use MSC/CDC EPs for BULK if disabled --- source/hic_hal/atmel/sam3u2c/usb_config.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/source/hic_hal/atmel/sam3u2c/usb_config.c b/source/hic_hal/atmel/sam3u2c/usb_config.c index 40ec8cf05d..2dc7e1d361 100644 --- a/source/hic_hal/atmel/sam3u2c/usb_config.c +++ b/source/hic_hal/atmel/sam3u2c/usb_config.c @@ -430,9 +430,21 @@ // // -#define USBD_BULK_ENABLE BULK_ENDPOINT //no endpts left -#define USBD_BULK_EP_BULKIN 7 -#define USBD_BULK_EP_BULKOUT 8 +#define USBD_BULK_ENABLE BULK_ENDPOINT +// We don't have enough endpoints for BULK unless MSC or CDC are disabled. +// MSC is the best choice, since this is only useful in the fixed target IF config and we can still upload firmware via DAP. +// We'll still want MSC for the BL though, but in that case BULK isn't useful anyway. +#if USBD_MSC_ENABLE == 0 +#define USBD_BULK_EP_BULKIN 1 // Use the MSC endpoints for BULK +#define USBD_BULK_EP_BULKOUT 2 +#elif USBD_CDC_ACM_ENABLE == 0 +#define USBD_BULK_EP_BULKIN 5 // Use the CDC endpoints for BULK +#define USBD_BULK_EP_BULKOUT 6 +#else +#define USBD_BULK_EP_BULKIN 7 // Use non-existent endpoints to force an error +#define USBD_BULK_EP_BULKOUT 8 // if BULK is enabled but MSC + CDC are still enabled +#endif + #define USBD_BULK_WMAXPACKETSIZE 64 #define USBD_BULK_HS_ENABLE 1 #define USBD_BULK_HS_WMAXPACKETSIZE 512 From f0ef2eabfef466f73a4f4a0a509fa4ae9671c1e5 Mon Sep 17 00:00:00 2001 From: Mathias Brossard Date: Sun, 2 Apr 2023 17:16:04 -0500 Subject: [PATCH 5/5] sam3u2c: Use CMSIS-DAP v2 interface for sam3u2c_if project Disabling CMSIS-DAP v1 interface for improved performance --- docs/hic/sam3u2c.md | 2 +- projects.yaml | 2 + records/board/sam3u2c_if.yaml | 5 ++ source/hic_hal/atmel/sam3u2c/DAP_config.h | 6 +-- source/hic_hal/atmel/sam3u2c/usb_config.c | 61 +++++++++++++++-------- 5 files changed, 51 insertions(+), 25 deletions(-) create mode 100644 records/board/sam3u2c_if.yaml diff --git a/docs/hic/sam3u2c.md b/docs/hic/sam3u2c.md index 3ae591ca45..ad98a8afec 100644 --- a/docs/hic/sam3u2c.md +++ b/docs/hic/sam3u2c.md @@ -4,7 +4,7 @@ Based on ATSAM3U2C chip ([Datasheet](https://ww1.microchip.com/downloads/en/Devi - Cortex-M3 96 Mhz - 128 KB Flash - 36 KB RAM -- High-speed USB 2.0 device controller: up to 7 bi-directional endpoints including EP0 (*) +- High-speed USB 2.0 device controller: up to 7 endpoints including EP0 (*) - LQFP100 packaging (*) "up to 7 bidirectional Endpoints" (source: Datasheet](https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-6430-32-bit-Cortex-M3-Microcontroller-SAM3U4-SAM3U2-SAM3U1_Datasheet.pdf)) diff --git a/projects.yaml b/projects.yaml index 710aa6ff43..67cc342527 100644 --- a/projects.yaml +++ b/projects.yaml @@ -215,6 +215,8 @@ projects: sam3u2c_if: - *module_if - *module_hic_sam3u2c + - records/usb/usb-bulk.yaml + - records/board/sam3u2c_if.yaml - records/family/all_family.yaml stm32f072x8_if: - *module_if diff --git a/records/board/sam3u2c_if.yaml b/records/board/sam3u2c_if.yaml new file mode 100644 index 0000000000..5d3201adba --- /dev/null +++ b/records/board/sam3u2c_if.yaml @@ -0,0 +1,5 @@ +common: + macros: + - HID_ENDPOINT_DISABLE + - MSC_ENDPOINT_DISABLE + - DRAG_N_DROP_DISABLE diff --git a/source/hic_hal/atmel/sam3u2c/DAP_config.h b/source/hic_hal/atmel/sam3u2c/DAP_config.h index 22b5c04780..4cf8fc1a59 100644 --- a/source/hic_hal/atmel/sam3u2c/DAP_config.h +++ b/source/hic_hal/atmel/sam3u2c/DAP_config.h @@ -83,10 +83,10 @@ This information includes: /// This configuration settings is used to optimize the communication performance with the /// debugger and depends on the USB peripheral. Typical vales are 64 for Full-speed USB HID or WinUSB, /// 1024 for High-speed USB HID and 512 for High-speed USB WinUSB. -#ifndef HID_ENDPOINT //HID end points currently set limits to 64 -#define DAP_PACKET_SIZE 512 ///< Specifies Packet Size in bytes. -#else +#if defined(HID_ENDPOINT) && !defined(HID_ENDPOINT_DISABLE) // HID end points currently set limits to 64 #define DAP_PACKET_SIZE 64 ///< Specifies Packet Size in bytes. +#else +#define DAP_PACKET_SIZE 512 ///< Specifies Packet Size in bytes. #endif /// Maximum Package Buffers for Command and Response data. diff --git a/source/hic_hal/atmel/sam3u2c/usb_config.c b/source/hic_hal/atmel/sam3u2c/usb_config.c index 2dc7e1d361..5e6b3e19f2 100644 --- a/source/hic_hal/atmel/sam3u2c/usb_config.c +++ b/source/hic_hal/atmel/sam3u2c/usb_config.c @@ -87,6 +87,46 @@ #endif #endif +#if (BULK_ENDPOINT) +/* SAM3UC only has 7 endpoints, and as a consequence BULK_ENDPOINT cannot + * be enabled at the same time as CDC_ENDPOINT and MSC_ENDPOINT. + */ +#if (CDC_ENDPOINT && MSC_ENDPOINT) +#error "SAM3U2C does not have enough endpoints to support this configuration" +#endif +#if (CDC_ENDPOINT) +#define USBD_HID_EP_INTOUT 0 +#define USBD_BULK_EP_BULKIN 1 +#define USBD_BULK_EP_BULKOUT 2 +#define USBD_HID_EP_INTIN 3 +#define USBD_CDC_ACM_EP_INTIN 4 +#define USBD_CDC_ACM_EP_BULKOUT 5 +#define USBD_CDC_ACM_EP_BULKIN 6 +#define USBD_MSC_EP_BULKIN 7 /* Unused */ +#define USBD_MSC_EP_BULKOUT 7 /* Unused */ +#else // !(CDC_ENDPOINT) +#define USBD_MSC_EP_BULKIN 1 +#define USBD_MSC_EP_BULKOUT 2 +#define USBD_HID_EP_INTIN 3 +#define USBD_HID_EP_INTOUT 4 +#define USBD_BULK_EP_BULKOUT 5 +#define USBD_BULK_EP_BULKIN 6 +#define USBD_CDC_ACM_EP_INTIN 7 /* Unused */ +#define USBD_CDC_ACM_EP_BULKIN 7 /* Unused */ +#define USBD_CDC_ACM_EP_BULKOUT 7 /* Unused */ +#endif +#else // !(BULK_ENDPOINT) +#define USBD_HID_EP_INTOUT 0 +#define USBD_MSC_EP_BULKIN 1 +#define USBD_MSC_EP_BULKOUT 2 +#define USBD_HID_EP_INTIN 3 +#define USBD_CDC_ACM_EP_INTIN 4 +#define USBD_CDC_ACM_EP_BULKOUT 5 +#define USBD_CDC_ACM_EP_BULKIN 6 +#define USBD_BULK_EP_BULKIN 7 /* Unused */ +#define USBD_BULK_EP_BULKOUT 7 /* Unused */ +#endif + // USB Device // Enable the USB Device functionality #define USBD_ENABLE 1 @@ -209,9 +249,7 @@ // #define USBD_HID_ENABLE HID_ENDPOINT -#define USBD_HID_EP_INTIN 3 #define USBD_HID_EP_INTIN_STACK 0 -#define USBD_HID_EP_INTOUT 0 #define USBD_HID_EP_INTOUT_STACK 0 #define USBD_HID_WMAXPACKETSIZE 64 #define USBD_HID_BINTERVAL 1 @@ -258,9 +296,7 @@ // #define USBD_MSC_ENABLE MSC_ENDPOINT -#define USBD_MSC_EP_BULKIN 1 #define USBD_MSC_EP_BULKIN_STACK 0 -#define USBD_MSC_EP_BULKOUT 2 #define USBD_MSC_EP_BULKOUT_STACK 0 #define USBD_MSC_WMAXPACKETSIZE 64 #define USBD_MSC_HS_ENABLE 1 @@ -374,16 +410,13 @@ // #define USBD_CDC_ACM_ENABLE CDC_ENDPOINT -#define USBD_CDC_ACM_EP_INTIN 4 #define USBD_CDC_ACM_EP_INTIN_STACK 0 #define USBD_CDC_ACM_WMAXPACKETSIZE 16 #define USBD_CDC_ACM_BINTERVAL 32 #define USBD_CDC_ACM_HS_ENABLE 1 #define USBD_CDC_ACM_HS_WMAXPACKETSIZE 64 #define USBD_CDC_ACM_HS_BINTERVAL 2 -#define USBD_CDC_ACM_EP_BULKIN 6 #define USBD_CDC_ACM_EP_BULKIN_STACK 0 -#define USBD_CDC_ACM_EP_BULKOUT 5 #define USBD_CDC_ACM_EP_BULKOUT_STACK 0 #define USBD_CDC_ACM_WMAXPACKETSIZE1 64 #define USBD_CDC_ACM_HS_ENABLE1 1 @@ -431,20 +464,6 @@ // #define USBD_BULK_ENABLE BULK_ENDPOINT -// We don't have enough endpoints for BULK unless MSC or CDC are disabled. -// MSC is the best choice, since this is only useful in the fixed target IF config and we can still upload firmware via DAP. -// We'll still want MSC for the BL though, but in that case BULK isn't useful anyway. -#if USBD_MSC_ENABLE == 0 -#define USBD_BULK_EP_BULKIN 1 // Use the MSC endpoints for BULK -#define USBD_BULK_EP_BULKOUT 2 -#elif USBD_CDC_ACM_ENABLE == 0 -#define USBD_BULK_EP_BULKIN 5 // Use the CDC endpoints for BULK -#define USBD_BULK_EP_BULKOUT 6 -#else -#define USBD_BULK_EP_BULKIN 7 // Use non-existent endpoints to force an error -#define USBD_BULK_EP_BULKOUT 8 // if BULK is enabled but MSC + CDC are still enabled -#endif - #define USBD_BULK_WMAXPACKETSIZE 64 #define USBD_BULK_HS_ENABLE 1 #define USBD_BULK_HS_WMAXPACKETSIZE 512