aboutsummaryrefslogtreecommitdiffstats
path: root/firmware
diff options
context:
space:
mode:
authorKévin Redon <kredon@sysmocom.de>2018-08-06 17:57:20 +0200
committerKévin Redon <kredon@sysmocom.de>2018-08-07 12:09:49 +0200
commitff3d84922df22dc4cfaa373c48b3b00ad9f672b0 (patch)
treeee471aefd5be3cf396cadba0aebc1ab117871ace /firmware
parent9547e419eb1df6e75db4af7b9f3ea4061f4d3e1e (diff)
USB: increase USB reset time
USB reset can be signaled by pulling low USB D+ for at least 10 ms, according to the USB specification. This force a re-enumeration. This time is increased to 20 ms to work with more USB HUBs. Some SAM3S based board have external D+ pull-up mechanism (such as SIMtrace) which needs to be used to pull D+ low. This is a legacy mechanism from SAM7S history. This mechanism is not required anymore on the SAM3S, and the qmod does not use it. When the USB HAL is suspended, the transceiver is disabled, causing D+ and D- to be pulled low. Then the HAL is activated again. This is particularly required when DFU is started (and enumerated), and after flashing the SAM3S switched to the main application (without reset), so it can properly re-enumerate. This board difference is now defined on the board header. Change-Id: I9b58d8101c2fcf5595026b675728826af26127a3
Diffstat (limited to 'firmware')
-rw-r--r--firmware/apps/dfu/main.c10
-rw-r--r--firmware/libboard/common/include/board_common.h7
-rw-r--r--firmware/libboard/simtrace/include/board.h5
-rw-r--r--firmware/libcommon/source/usb.c10
4 files changed, 23 insertions, 9 deletions
diff --git a/firmware/apps/dfu/main.c b/firmware/apps/dfu/main.c
index 74268ad..7f8fbfc 100644
--- a/firmware/apps/dfu/main.c
+++ b/firmware/apps/dfu/main.c
@@ -22,6 +22,7 @@
#include "usb/device/dfu/dfu.h"
#include "usb/common/dfu/usb_dfu.h"
#include "manifest.h"
+#include "USBD_HAL.h"
#include <osmocom/core/timer.h>
@@ -294,11 +295,18 @@ extern int main(void)
TRACE_INFO("USB init...\n\r");
/* Signal USB reset by disabling the pull-up on USB D+ for at least 10 ms */
+#ifdef PIN_USB_PULLUP
const Pin usb_dp_pullup = PIN_USB_PULLUP;
PIO_Configure(&usb_dp_pullup, 1);
PIO_Set(&usb_dp_pullup);
- mdelay(15);
+#endif
+ USBD_HAL_Suspend();
+ mdelay(20);
+#ifdef PIN_USB_PULLUP
PIO_Clear(&usb_dp_pullup);
+#endif
+ USBD_HAL_Activate();
+
USBDFU_Initialize(&dfu_descriptors);
while (USBD_GetState() < USBD_STATE_CONFIGURED) {
diff --git a/firmware/libboard/common/include/board_common.h b/firmware/libboard/common/include/board_common.h
index 06d3d6a..1b29680 100644
--- a/firmware/libboard/common/include/board_common.h
+++ b/firmware/libboard/common/include/board_common.h
@@ -114,15 +114,8 @@
#define SIM_PWEN PIO_PA5
#define VCC_FWD PIO_PA26
-/** Pin configuration to control USB pull-up on D+
- * @details the USB pull-up on D+ is enable by default on the board but can be disabled by setting PA16 high
- */
-#define PIN_USB_PULLUP {PIO_PA16, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}
-
// Board has UDP controller
#define BOARD_USB_UDP
-// D+ has external pull-up
-#define BOARD_USB_PULLUP_EXTERNAL
#define BOARD_USB_DFU
#define BOARD_DFU_BOOT_SIZE (16 * 1024)
diff --git a/firmware/libboard/simtrace/include/board.h b/firmware/libboard/simtrace/include/board.h
index db3a925..6751863 100644
--- a/firmware/libboard/simtrace/include/board.h
+++ b/firmware/libboard/simtrace/include/board.h
@@ -117,6 +117,11 @@
/* SPI flash write protect pin (active low, pulled low) */
#define PIN_SPI_WP {PA15, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}
+/** Pin configuration to control USB pull-up on D+
+ * @details the USB pull-up on D+ is enable by default on the board but can be disabled by setting PA16 high
+ */
+#define PIN_USB_PULLUP {PIO_PA16, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}
+
/** USB definitions */
/* OpenMoko SIMtrace 2 USB vendor ID */
#define BOARD_USB_VENDOR_ID USB_VENDOR_OPENMOKO
diff --git a/firmware/libcommon/source/usb.c b/firmware/libcommon/source/usb.c
index e929a05..43c7bb2 100644
--- a/firmware/libcommon/source/usb.c
+++ b/firmware/libcommon/source/usb.c
@@ -2,6 +2,7 @@
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2009, Atmel Corporation
+ * Copyright (c) 2018, sysmocom -s.f.m.c. GmbH, Author: Kevin Redon <kredon@sysmocom.de>
*
* All rights reserved.
*
@@ -35,6 +36,7 @@
#include "simtrace.h"
#include "simtrace_usb.h"
#include "utils.h"
+#include "USBD_HAL.h"
#include <cciddriverdescriptors.h>
#include <usb/common/dfu/usb_dfu.h>
@@ -576,11 +578,17 @@ void SIMtrace_USB_Initialize(void)
{
/* Signal USB reset by disabling the pull-up on USB D+ for at least 10 ms */
+#ifdef PIN_USB_PULLUP
const Pin usb_dp_pullup = PIN_USB_PULLUP;
PIO_Configure(&usb_dp_pullup, 1);
PIO_Set(&usb_dp_pullup);
- mdelay(15);
+#endif
+ USBD_HAL_Suspend();
+ mdelay(20);
+#ifdef PIN_USB_PULLUP
PIO_Clear(&usb_dp_pullup);
+#endif
+ USBD_HAL_Activate();
// Get std USB driver
USBDDriver *pUsbd = USBD_GetDriver();