Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
usbd_user_cdc_acm.c
00001 /** 00002 * @file usbd_user_cdc_acm.c 00003 * @brief implementation of USB CDC ACM middleware 00004 * 00005 * DAPLink Interface Firmware 00006 * Copyright (c) 2009-2019, ARM Limited, All Rights Reserved 00007 * SPDX-License-Identifier: Apache-2.0 00008 * 00009 * Licensed under the Apache License, Version 2.0 (the "License"); you may 00010 * not use this file except in compliance with the License. 00011 * You may obtain a copy of the License at 00012 * 00013 * http://www.apache.org/licenses/LICENSE-2.0 00014 * 00015 * Unless required by applicable law or agreed to in writing, software 00016 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 00017 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00018 * See the License for the specific language governing permissions and 00019 * limitations under the License. 00020 */ 00021 00022 #include "cmsis_os2.h" 00023 #include "rl_usb.h" 00024 #include "main.h" 00025 #include "uart.h" 00026 #ifdef DRAG_N_DROP_SUPPORT 00027 #include "flash_intf.h" 00028 #endif 00029 #include "target_family.h" 00030 00031 UART_Configuration UART_Config; 00032 00033 /** @brief Vitual COM Port initialization 00034 * 00035 * The function inititalizes the hardware resources of the port used as 00036 * the Virtual COM Port. 00037 * 00038 * @return 0 Function failed. 00039 * @return 1 Function succeeded. 00040 */ 00041 int32_t USBD_CDC_ACM_PortInitialize(void) 00042 { 00043 uart_initialize(); 00044 main_cdc_send_event(); 00045 return 1; 00046 } 00047 00048 /** @brief Vitual COM Port uninitialization 00049 * 00050 * The function uninititalizes/releases the hardware resources of the port used 00051 * as the Virtual COM Port. 00052 * 00053 * @return 0 Function failed. 00054 * @return 1 Function succeeded. 00055 */ 00056 int32_t USBD_CDC_ACM_PortUninitialize(void) 00057 { 00058 uart_uninitialize(); 00059 return 1; 00060 } 00061 00062 /** @brief Vitual COM Port reset 00063 * 00064 * The function resets the internal states of the port used 00065 * as the Virtual COM Port. 00066 * 00067 * @return 0 Function failed. 00068 * @return 1 Function succeeded. 00069 */ 00070 int32_t USBD_CDC_ACM_PortReset(void) 00071 { 00072 uart_reset(); 00073 return 1; 00074 } 00075 00076 /** @brief Virtual COM Port change communication settings 00077 * 00078 * The function changes communication settings of the port used as the 00079 * Virtual COM Port. 00080 * 00081 * @param [in] line_coding Pointer to the loaded CDC_LINE_CODING structure. 00082 * @return 0 Function failed. 00083 * @return 1 Function succeeded. 00084 */ 00085 int32_t USBD_CDC_ACM_PortSetLineCoding(CDC_LINE_CODING *line_coding ) 00086 { 00087 UART_Config.Baudrate = line_coding->dwDTERate; 00088 UART_Config.DataBits = (UART_DataBits) line_coding->bDataBits; 00089 UART_Config.Parity = (UART_Parity) line_coding->bParityType; 00090 UART_Config.StopBits = (UART_StopBits) line_coding->bCharFormat; 00091 UART_Config.FlowControl = UART_FLOW_CONTROL_NONE; 00092 return uart_set_configuration(&UART_Config); 00093 } 00094 00095 /** @brief Vitual COM Port retrieve communication settings 00096 * 00097 * The function retrieves communication settings of the port used as the 00098 * Virtual COM Port. 00099 * 00100 * @param [in] line_coding Pointer to the CDC_LINE_CODING structure. 00101 * @return 0 Function failed. 00102 * @return 1 Function succeeded. 00103 */ 00104 int32_t USBD_CDC_ACM_PortGetLineCoding(CDC_LINE_CODING *line_coding ) 00105 { 00106 line_coding->dwDTERate = UART_Config.Baudrate; 00107 line_coding->bDataBits = UART_Config.DataBits; 00108 line_coding->bParityType = UART_Config.Parity; 00109 line_coding->bCharFormat = UART_Config.StopBits; 00110 return (1); 00111 } 00112 00113 static U32 start_break_time = 0; 00114 int32_t USBD_CDC_ACM_SendBreak(uint16_t dur) 00115 { 00116 uint32_t end_break_time; 00117 #ifdef DRAG_N_DROP_SUPPORT 00118 if (!flash_intf_target->flash_busy()) 00119 #endif 00120 { //added checking if flashing on target is in progress 00121 // reset and send the unique id over CDC 00122 if (dur != 0) { 00123 start_break_time = osKernelGetSysTimerCount(); 00124 target_set_state(RESET_HOLD); 00125 } else { 00126 end_break_time = osKernelGetSysTimerCount(); 00127 00128 // long reset -> send uID over serial (300 -> break > 3s) 00129 if ((end_break_time - start_break_time) >= (300)) { 00130 main_reset_target(1); 00131 } else { 00132 main_reset_target(0); 00133 } 00134 } 00135 } 00136 return (1); 00137 } 00138 00139 /** @brief Virtual COM Port set control line state 00140 * 00141 * The function sets control line state on the port used as the 00142 * Virtual COM Port. 00143 * 00144 * @param [in] ctrl_bmp Control line settings 00145 * bitmap (0. bit - DTR state, 1. bit - RTS state). 00146 * @return 0 Function failed. 00147 * @return 1 Function succeeded. 00148 */ 00149 int32_t USBD_CDC_ACM_PortSetControlLineState(uint16_t ctrl_bmp) 00150 { 00151 return (1); 00152 } 00153 00154 void cdc_process_event() 00155 { 00156 int32_t len_data = 0; 00157 uint8_t data[64]; 00158 00159 len_data = USBD_CDC_ACM_DataFree(); 00160 00161 if (len_data > sizeof(data)) { 00162 len_data = sizeof(data); 00163 } 00164 00165 if (len_data) { 00166 len_data = uart_read_data(data, len_data); 00167 } 00168 00169 if (len_data) { 00170 if (USBD_CDC_ACM_DataSend(data , len_data)) { 00171 main_blink_cdc_led(MAIN_LED_FLASH); 00172 } 00173 } 00174 00175 len_data = uart_write_free(); 00176 00177 if (len_data > sizeof(data)) { 00178 len_data = sizeof(data); 00179 } 00180 00181 if (len_data) { 00182 len_data = USBD_CDC_ACM_DataRead(data, len_data); 00183 } 00184 00185 if (len_data) { 00186 if (uart_write_data(data, len_data)) { 00187 main_blink_cdc_led(MAIN_LED_FLASH); 00188 } 00189 } 00190 00191 // Always process events 00192 main_cdc_send_event(); 00193 }
Generated on Tue Jul 12 2022 15:37:27 by
1.7.2