blob: f8c0c536b92be666be2735ba1864a36509394bc3 [file] [log] [blame]
Kévin Redon9a12d682018-07-08 13:21:16 +02001/* SIMtrace 2 firmware USB DFU bootloader
2 *
3 * (C) 2015-2017 by Harald Welte <hwelte@hmw-consulting.de>
Kévin Redon9b367872019-02-07 17:52:08 +01004 * (C) 2018-2019 by sysmocom -s.f.m.c. GmbH, Author: Kevin Redon <kredon@sysmocom.de>
Kévin Redon9a12d682018-07-08 13:21:16 +02005 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
Harald Welted8a003d2017-02-27 20:31:09 +010020#include "board.h"
21#include "utils.h"
22#include "usb/device/dfu/dfu.h"
23#include "usb/common/dfu/usb_dfu.h"
24#include "manifest.h"
Kévin Redonff3d8492018-08-06 17:57:20 +020025#include "USBD_HAL.h"
Harald Welted8a003d2017-02-27 20:31:09 +010026
Harald Welte3bbaba02017-03-06 22:47:06 +010027#include <osmocom/core/timer.h>
28
Kévin Redonb6e2f0f2019-12-11 17:04:21 +010029/* USB alternate interface index used to identify which partition to flash */
30/** USB alternate interface index indicating RAM partition */
Harald Welte32852bc2017-02-28 00:21:45 +010031#define ALTIF_RAM 0
Kévin Redonb6e2f0f2019-12-11 17:04:21 +010032/** USB alternate interface index indicating flash partition */
33#if defined(ENVIRONMENT_flash)
Harald Welte32852bc2017-02-28 00:21:45 +010034#define ALTIF_FLASH 1
Kévin Redonb6e2f0f2019-12-11 17:04:21 +010035#elif defined(ENVIRONMENT_dfu)
36#define ALTIF_FLASH 2
37#endif
Harald Welte32852bc2017-02-28 00:21:45 +010038
Harald Welted8a003d2017-02-27 20:31:09 +010039unsigned int g_unique_id[4];
Kévin Redon869dbfa2018-06-17 22:36:44 +020040/* remember if the watchdog has been configured in the main loop so we can kick it in the ISR */
41static bool watchdog_configured = false;
Harald Welted8a003d2017-02-27 20:31:09 +010042
Kévin Redon9def7632018-06-27 16:27:41 +020043/* There is not enough space in the 16 KiB DFU bootloader to include led.h functions */
44#ifdef PINS_LEDS
45/** LED pin configurations */
46static const Pin pinsLeds[] = { PINS_LEDS } ;
47#endif
48
Harald Welted8a003d2017-02-27 20:31:09 +010049/*----------------------------------------------------------------------------
50 * Callbacks
51 *----------------------------------------------------------------------------*/
52
Harald Welte32852bc2017-02-28 00:21:45 +010053#define RAM_ADDR(offset) (IRAM_ADDR + BOARD_DFU_RAM_SIZE + offset)
Kévin Redonb6e2f0f2019-12-11 17:04:21 +010054#if defined(ENVIRONMENT_flash)
Harald Welte32852bc2017-02-28 00:21:45 +010055#define FLASH_ADDR(offset) (IFLASH_ADDR + BOARD_DFU_BOOT_SIZE + offset)
Kévin Redonb6e2f0f2019-12-11 17:04:21 +010056#elif defined(ENVIRONMENT_dfu)
57#define FLASH_ADDR(offset) (IFLASH_ADDR + offset)
58#endif
Harald Welte32852bc2017-02-28 00:21:45 +010059
Kévin Redonb6e2f0f2019-12-11 17:04:21 +010060#define IRAM_END ((uint8_t *)IRAM_ADDR + IRAM_SIZE)
61#if defined(ENVIRONMENT_flash)
62#define IFLASH_END ((uint8_t *)IFLASH_ADDR + IFLASH_SIZE)
63#elif defined(ENVIRONMENT_dfu)
64#define IFLASH_END ((uint8_t *)IFLASH_ADDR + BOARD_DFU_BOOT_SIZE)
65#endif
Harald Welte32852bc2017-02-28 00:21:45 +010066
Kévin Redon318309f2018-06-01 11:02:49 +020067/* incoming call-back: Host has transferred 'len' bytes (stored at
Harald Welte32852bc2017-02-28 00:21:45 +010068 * 'data'), which we shall write to 'offset' into the partition
Kévin Redon318309f2018-06-01 11:02:49 +020069 * associated with 'altif'. Guaranted to be less than
Harald Welte32852bc2017-02-28 00:21:45 +010070 * BOARD_DFU_PAGE_SIZE */
71int USBDFU_handle_dnload(uint8_t altif, unsigned int offset,
72 uint8_t *data, unsigned int len)
Harald Welted8a003d2017-02-27 20:31:09 +010073{
Harald Welte32852bc2017-02-28 00:21:45 +010074 uint32_t addr;
Harald Welte1cfc2612018-06-29 21:07:41 +020075 unsigned int i;
Harald Welte32852bc2017-02-28 00:21:45 +010076 int rc;
Kévin Redon318309f2018-06-01 11:02:49 +020077 /* address of the last allocated variable on the stack */
78 uint32_t stack_addr = (uint32_t)&rc;
Kévin Redon869dbfa2018-06-17 22:36:44 +020079 /* kick the dog to have enough time to flash */
80 if (watchdog_configured) {
81 WDT_Restart(WDT);
82 }
Harald Welte32852bc2017-02-28 00:21:45 +010083
Kévin Redon98fbf232019-02-07 17:55:24 +010084#if TRACE_LEVEL >= TRACE_LEVEL_INFO
85 TRACE_INFO("dnload(altif=%u, offset=%u, len=%u)\n\r", altif, offset, len);
86#else
87 printf("DL off=%u\n\r", offset);
88#endif
Harald Welte32852bc2017-02-28 00:21:45 +010089
Kévin Redon9def7632018-06-27 16:27:41 +020090#ifdef PINS_LEDS
91 PIO_Clear(&pinsLeds[LED_NUM_RED]);
92#endif
93
Harald Welte32852bc2017-02-28 00:21:45 +010094 switch (altif) {
95 case ALTIF_RAM:
96 addr = RAM_ADDR(offset);
Kévin Redonb73f0a02018-06-17 22:33:29 +020097 if (addr < IRAM_ADDR || addr + len >= IRAM_ADDR + IRAM_SIZE || addr + len >= stack_addr) {
Harald Welteadba0ce2017-02-28 01:02:24 +010098 g_dfu->state = DFU_STATE_dfuERROR;
99 g_dfu->status = DFU_STATUS_errADDRESS;
Kévin Redon9def7632018-06-27 16:27:41 +0200100 rc = DFU_RET_STALL;
101 break;
Harald Welte32852bc2017-02-28 00:21:45 +0100102 }
103 memcpy((void *)addr, data, len);
Kévin Redon9def7632018-06-27 16:27:41 +0200104 rc = DFU_RET_ZLP;
105 break;
Harald Welte32852bc2017-02-28 00:21:45 +0100106 case ALTIF_FLASH:
107 addr = FLASH_ADDR(offset);
Kévin Redonb6e2f0f2019-12-11 17:04:21 +0100108#if defined(ENVIRONMENT_flash)
Kévin Redonb73f0a02018-06-17 22:33:29 +0200109 if (addr < IFLASH_ADDR || addr + len >= IFLASH_ADDR + IFLASH_SIZE) {
Kévin Redonb6e2f0f2019-12-11 17:04:21 +0100110#elif defined(ENVIRONMENT_dfu)
111 if (addr < IFLASH_ADDR || addr + len >= IFLASH_ADDR + BOARD_DFU_BOOT_SIZE) {
112#endif
Harald Welteadba0ce2017-02-28 01:02:24 +0100113 g_dfu->state = DFU_STATE_dfuERROR;
114 g_dfu->status = DFU_STATUS_errADDRESS;
Kévin Redon9def7632018-06-27 16:27:41 +0200115 rc = DFU_RET_STALL;
116 break;
Harald Welte32852bc2017-02-28 00:21:45 +0100117 }
Kévin Redonb73f0a02018-06-17 22:33:29 +0200118 rc = FLASHD_Unlock(addr, addr + len, 0, 0);
119 if (rc != 0) {
120 TRACE_ERROR("DFU download flash unlock failed\n\r");
Kévin Redon9def7632018-06-27 16:27:41 +0200121 rc = DFU_RET_STALL;
122 break;
Kévin Redonb73f0a02018-06-17 22:33:29 +0200123 }
Harald Welte32852bc2017-02-28 00:21:45 +0100124 rc = FLASHD_Write(addr, data, len);
125 if (rc != 0) {
Kévin Redonb73f0a02018-06-17 22:33:29 +0200126 TRACE_ERROR("DFU download flash erase failed\n\r");
Kévin Redon9def7632018-06-27 16:27:41 +0200127 rc = DFU_RET_STALL;
128 break;
Kévin Redonb73f0a02018-06-17 22:33:29 +0200129 }
Harald Welte1cfc2612018-06-29 21:07:41 +0200130 for (i = 0; i < len; i++) {
Kévin Redonb73f0a02018-06-17 22:33:29 +0200131 if (((uint8_t*)addr)[i]!=data[i]) {
132 TRACE_ERROR("DFU download flash data written not correct\n\r");
Kévin Redon9def7632018-06-27 16:27:41 +0200133 rc = DFU_RET_STALL;
134 break;
Kévin Redonb73f0a02018-06-17 22:33:29 +0200135 }
136 }
Kévin Redon9def7632018-06-27 16:27:41 +0200137 rc = DFU_RET_ZLP;
138 break;
Harald Welte32852bc2017-02-28 00:21:45 +0100139 default:
Harald Welte32852bc2017-02-28 00:21:45 +0100140 TRACE_ERROR("DFU download for unknown AltIf %d\n\r", altif);
Kévin Redon9def7632018-06-27 16:27:41 +0200141 rc = DFU_RET_STALL;
142 break;
Harald Welte32852bc2017-02-28 00:21:45 +0100143 }
Kévin Redon9def7632018-06-27 16:27:41 +0200144
145#ifdef PINS_LEDS
146 PIO_Set(&pinsLeds[LED_NUM_RED]);
147#endif
148
149 return rc;
Harald Welted8a003d2017-02-27 20:31:09 +0100150}
Harald Welte32852bc2017-02-28 00:21:45 +0100151
152/* incoming call-back: Host has requested to read back 'req_len' bytes
153 * starting from 'offset' of the firmware * associated with partition
154 * 'altif' */
155int USBDFU_handle_upload(uint8_t altif, unsigned int offset,
156 uint8_t *data, unsigned int req_len)
157{
158 uint32_t addr;
159
160 printf("upload(altif=%u, offset=%u, len=%u)", altif, offset, req_len);
161
162 switch (altif) {
163 case ALTIF_RAM:
164 addr = RAM_ADDR(offset);
165 if (addr > IRAM_ADDR + IRAM_SIZE) {
Harald Welteadba0ce2017-02-28 01:02:24 +0100166 g_dfu->state = DFU_STATE_dfuERROR;
167 g_dfu->status = DFU_STATUS_errADDRESS;
Harald Welte32852bc2017-02-28 00:21:45 +0100168 return -1;
169 }
170 if ((uint8_t *)addr + req_len > IRAM_END)
171 req_len = IRAM_END - (uint8_t *)addr;
172 memcpy(data, (void *)addr, req_len);
173 break;
174 case ALTIF_FLASH:
175 addr = FLASH_ADDR(offset);
176 if (addr > IFLASH_ADDR + IFLASH_SIZE) {
Harald Welteadba0ce2017-02-28 01:02:24 +0100177 g_dfu->state = DFU_STATE_dfuERROR;
178 g_dfu->status = DFU_STATUS_errADDRESS;
Harald Welte32852bc2017-02-28 00:21:45 +0100179 return -1;
180 }
181 if ((uint8_t *)addr + req_len > IFLASH_END)
182 req_len = IFLASH_END - (uint8_t *)addr;
183 memcpy(data, (void *)addr, req_len);
184 break;
185 default:
186 TRACE_ERROR("DFU upload for unknown AltIf %d\n\r", altif);
187 /* FIXME: set error codes */
188 return -1;
189 }
Harald Welteec0837c2017-03-03 01:33:24 +0100190 printf("=%u\n\r", req_len);
Harald Welte32852bc2017-02-28 00:21:45 +0100191 return req_len;
192}
193
Harald Welte27f5fc62017-11-28 22:15:56 +0100194/* can be overridden by board specific code, e.g. by pushbutton */
195WEAK int board_override_enter_dfu(void)
Harald Welte14051002017-03-04 19:17:27 +0100196{
Harald Welte27f5fc62017-11-28 22:15:56 +0100197 return 0;
Harald Welte14051002017-03-04 19:17:27 +0100198}
199
200/* using this function we can determine if we should enter DFU mode
201 * during boot, or if we should proceed towards the application/runtime */
202int USBDFU_OverrideEnterDFU(void)
203{
204 uint32_t *app_part = (uint32_t *)FLASH_ADDR(0);
Kévin Redon9918c282018-07-07 15:22:16 +0200205 /* at the first call we are before the text segment has been relocated,
206 * so g_dfu is not initialized yet */
207 g_dfu = &_g_dfu;
208 if (USB_DFU_MAGIC == g_dfu->magic) {
209 return 1;
210 }
Harald Welte14051002017-03-04 19:17:27 +0100211
212 /* If the loopback jumper is set, we enter DFU mode */
Kévin Redon9918c282018-07-07 15:22:16 +0200213 if (board_override_enter_dfu()) {
214 return 2;
215 }
Harald Welte14051002017-03-04 19:17:27 +0100216
217 /* if the first word of the application partition doesn't look
218 * like a stack pointer (i.e. point to RAM), enter DFU mode */
Kévin Redon9918c282018-07-07 15:22:16 +0200219 if ((app_part[0] < IRAM_ADDR) || ((uint8_t *)app_part[0] > IRAM_END)) {
220 return 3;
221 }
Harald Welte14051002017-03-04 19:17:27 +0100222
223 /* if the second word of the application partition doesn't look
224 * like a function from flash (reset vector), enter DFU mode */
225 if (((uint32_t *)app_part[1] < app_part) ||
Kévin Redon9918c282018-07-07 15:22:16 +0200226 ((uint8_t *)app_part[1] > IFLASH_END)) {
227 return 4;
228 }
Harald Welte14051002017-03-04 19:17:27 +0100229
230 return 0;
231}
Harald Welted8a003d2017-02-27 20:31:09 +0100232
233/* returns '1' in case we should break any endless loop */
234static void check_exec_dbg_cmd(void)
235{
236 int ch;
237
238 if (!UART_IsRxReady())
239 return;
240
241 ch = UART_GetChar();
242
243 //board_exec_dbg_cmd(ch);
244}
245
Harald Welte39070852020-08-16 15:51:14 +0200246/* print a horizontal line of '=' characters; Doing this in a loop vs. using a 'const'
247 * string saves us ~60 bytes of executable size (matters particularly for DFU loader) */
248static void print_line(void)
249{
250 int i;
251 for (i = 0; i < 78; i++)
252 fputc('=', stdout);
253 fputc('\n', stdout);
254 fputc('\r', stdout);
255}
256
Harald Welted8a003d2017-02-27 20:31:09 +0100257/*------------------------------------------------------------------------------
258 * Main
259 *------------------------------------------------------------------------------*/
260#define MAX_USB_ITER BOARD_MCK/72 // This should be around a second
261extern int main(void)
262{
263 uint8_t isUsbConnected = 0;
264 unsigned int i = 0;
Harald Welte5b108d82017-03-06 21:51:55 +0100265 uint32_t reset_cause = (RSTC->RSTC_SR & RSTC_SR_RSTTYP_Msk) >> RSTC_SR_RSTTYP_Pos;
Harald Welted8a003d2017-02-27 20:31:09 +0100266
Kévin Redon869dbfa2018-06-17 22:36:44 +0200267 /* Enable watchdog for 2000ms, with no window */
Harald Welte45ebe452017-03-03 19:01:53 +0100268 WDT_Enable(WDT, WDT_MR_WDRSTEN | WDT_MR_WDDBGHLT | WDT_MR_WDIDLEHLT |
Kévin Redon869dbfa2018-06-17 22:36:44 +0200269 (WDT_GetPeriod(2000) << 16) | WDT_GetPeriod(2000));
270 watchdog_configured = true;
Harald Welted8a003d2017-02-27 20:31:09 +0100271
Kévin Redon9def7632018-06-27 16:27:41 +0200272#ifdef PINS_LEDS
273 /* Configure LED */
274 PIO_Configure(pinsLeds, sizeof(pinsLeds));
275 PIO_Set(&pinsLeds[LED_NUM_RED]);
276 PIO_Clear(&pinsLeds[LED_NUM_GREEN]);
277#endif
278
Harald Welted8a003d2017-02-27 20:31:09 +0100279 EEFC_ReadUniqueID(g_unique_id);
280
Harald Welte39070852020-08-16 15:51:14 +0200281 printf("\n\r\n\r");
282 print_line();
283 printf("DFU bootloader %s for board %s\n\r"
284 "(C) 2010-2017 by Harald Welte, 2018-2019 by Kevin Redon\n\r",
Harald Welted8a003d2017-02-27 20:31:09 +0100285 manifest_revision, manifest_board);
Harald Welte39070852020-08-16 15:51:14 +0200286 print_line();
Harald Welted8a003d2017-02-27 20:31:09 +0100287
Kévin Redon75a5f222019-12-11 16:44:02 +0100288#if (TRACE_LEVEL >= TRACE_LEVEL_INFO)
289 TRACE_INFO("Chip ID: 0x%08lx (Ext 0x%08lx)\n\r", CHIPID->CHIPID_CIDR, CHIPID->CHIPID_EXID);
Harald Welteec0837c2017-03-03 01:33:24 +0100290 TRACE_INFO("Serial Nr. %08x-%08x-%08x-%08x\n\r",
Harald Welted8a003d2017-02-27 20:31:09 +0100291 g_unique_id[0], g_unique_id[1],
292 g_unique_id[2], g_unique_id[3]);
Kévin Redon75a5f222019-12-11 16:44:02 +0100293 static const char* reset_causes[] = {
294 "general reset (first power-up reset)",
295 "backup reset (return from backup mode)",
296 "watchdog reset (watchdog fault occurred)",
297 "software reset (processor reset required by the software)",
298 "user reset (NRST pin detected low)",
299 };
300 if (reset_cause < ARRAY_SIZE(reset_causes)) {
301 TRACE_INFO("Reset Cause: %s\n\r", reset_causes[reset_cause]);
302 } else {
303 TRACE_INFO("Reset Cause: 0x%lx\n\r", (RSTC->RSTC_SR & RSTC_SR_RSTTYP_Msk) >> RSTC_SR_RSTTYP_Pos);
304 }
305#endif
Harald Welte5b108d82017-03-06 21:51:55 +0100306
Kévin Redon9918c282018-07-07 15:22:16 +0200307#if (TRACE_LEVEL >= TRACE_LEVEL_INFO)
308 /* Find out why we are in the DFU bootloader, and not the main application */
309 TRACE_INFO("DFU bootloader start reason: ");
310 switch (USBDFU_OverrideEnterDFU()) {
311 case 0:
Kévin Redonb6e2f0f2019-12-11 17:04:21 +0100312 if (SCB->VTOR < IFLASH_ADDR + BOARD_DFU_BOOT_SIZE) {
313 TRACE_INFO_WP("unknown\n\r");
314 } else {
315 TRACE_INFO_WP("DFU is the main application\n\r");
316 }
317 break;
Kévin Redon9918c282018-07-07 15:22:16 +0200318 case 1:
319 TRACE_INFO_WP("DFU switch requested by main application\n\r");
320 break;
321 case 2:
322 TRACE_INFO_WP("bootloader forced (button pressed or jumper set)\n\r");
323 break;
324 case 3:
325 TRACE_INFO_WP("stack pointer (first application word) does no point in RAM\n\r");
326 break;
327 case 4: // the is no reason
328 TRACE_INFO_WP("reset vector (second application word) does no point in flash\n\r");
329 break;
330 default:
331 TRACE_INFO_WP("unknown\n\r");
332 break;
333 }
334#endif
335
Harald Welte5b108d82017-03-06 21:51:55 +0100336 /* clear g_dfu on power-up reset */
337 if (reset_cause == 0)
338 memset(g_dfu, 0, sizeof(*g_dfu));
Harald Welted8a003d2017-02-27 20:31:09 +0100339
Harald Welte8adf0ac2017-03-03 01:52:34 +0100340 board_main_top();
Harald Welted8a003d2017-02-27 20:31:09 +0100341
Harald Welteec0837c2017-03-03 01:33:24 +0100342 TRACE_INFO("USB init...\n\r");
Kévin Redonf5869d42018-06-17 22:31:21 +0200343 /* Signal USB reset by disabling the pull-up on USB D+ for at least 10 ms */
Kévin Redoned3ceec2019-12-03 15:29:33 +0100344 USBD_Disconnect();
Kévin Redonff3d8492018-08-06 17:57:20 +0200345#ifdef PIN_USB_PULLUP
Kévin Redonf5869d42018-06-17 22:31:21 +0200346 const Pin usb_dp_pullup = PIN_USB_PULLUP;
347 PIO_Configure(&usb_dp_pullup, 1);
348 PIO_Set(&usb_dp_pullup);
Kévin Redonff3d8492018-08-06 17:57:20 +0200349#endif
Kévin Redoned3ceec2019-12-03 15:29:33 +0100350 mdelay(50);
Kévin Redonff3d8492018-08-06 17:57:20 +0200351#ifdef PIN_USB_PULLUP
Kévin Redonf5869d42018-06-17 22:31:21 +0200352 PIO_Clear(&usb_dp_pullup);
Kévin Redonff3d8492018-08-06 17:57:20 +0200353#endif
Kévin Redonff3d8492018-08-06 17:57:20 +0200354
Harald Welted8a003d2017-02-27 20:31:09 +0100355 USBDFU_Initialize(&dfu_descriptors);
356
357 while (USBD_GetState() < USBD_STATE_CONFIGURED) {
Harald Welte45ebe452017-03-03 19:01:53 +0100358 WDT_Restart(WDT);
Harald Welted8a003d2017-02-27 20:31:09 +0100359 check_exec_dbg_cmd();
Harald Welte32852bc2017-02-28 00:21:45 +0100360#if 1
Harald Welted8a003d2017-02-27 20:31:09 +0100361 if (i >= MAX_USB_ITER * 3) {
Kévin Redond70836f2019-12-03 15:36:58 +0100362 TRACE_ERROR("Resetting board (USB could not be configured)\n\r");
363 g_dfu->magic = USB_DFU_MAGIC; // start the bootloader after reboot
Harald Weltef415d712017-03-03 01:51:43 +0100364 USBD_Disconnect();
Harald Welted8a003d2017-02-27 20:31:09 +0100365 NVIC_SystemReset();
366 }
367#endif
368 i++;
369 }
370
Kévin Redonb73f0a02018-06-17 22:33:29 +0200371 /* Initialize the flash to be able to write it, using the IAP ROM code */
Harald Welteec9b5ff2017-03-02 23:18:40 +0100372 FLASHD_Initialize(BOARD_MCK, 1);
Kévin Redonb73f0a02018-06-17 22:33:29 +0200373
Harald Welteec0837c2017-03-03 01:33:24 +0100374 TRACE_INFO("entering main loop...\n\r");
Harald Welted8a003d2017-02-27 20:31:09 +0100375 while (1) {
Harald Welte45ebe452017-03-03 19:01:53 +0100376 WDT_Restart(WDT);
Harald Welted8a003d2017-02-27 20:31:09 +0100377#if TRACE_LEVEL >= TRACE_LEVEL_DEBUG
378 const char rotor[] = { '-', '\\', '|', '/' };
379 putchar('\b');
380 putchar(rotor[i++ % ARRAY_SIZE(rotor)]);
381#endif
382 check_exec_dbg_cmd();
Harald Welte3bbaba02017-03-06 22:47:06 +0100383#if 0
384 osmo_timers_prepare();
385 osmo_timers_update();
386#endif
Harald Welted8a003d2017-02-27 20:31:09 +0100387
388 if (USBD_GetState() < USBD_STATE_CONFIGURED) {
389
390 if (isUsbConnected) {
391 isUsbConnected = 0;
392 }
393 } else if (isUsbConnected == 0) {
Harald Welteec0837c2017-03-03 01:33:24 +0100394 TRACE_INFO("USB is now configured\n\r");
Harald Welted8a003d2017-02-27 20:31:09 +0100395
396 isUsbConnected = 1;
397 }
398 }
399}