Commit Graph

37 Commits

Author SHA1 Message Date
Eric Wild f83d42ce51 firmware: remove usb pullup that dates back to simtrace1
All the parts are DNP and never existed on the simtrace2 with sam3; the
sam3 has internal pullups that are part of the usb peripheral.

Change-Id: I04a703a2eba6ff1dc64692c089213389d0c1066d
2021-11-01 14:35:14 +01:00
Eric Wild 17bfa5273f fix bootloader led config crash
This led to occasional crashes for targets with leds since it was
introduced 3 years ago
The interesting thing is that most of the time it didn't crash...

Change-Id: Ia6a1b1fc0e44a301b4fb1d9c9fdbc27d61dcab97
2021-10-20 20:03:06 +02:00
Harald Welte 3907085239 dfu: Save another 60 bytes by changing the way we print horizontal lines
Change-Id: I1660a04fb3e42200bc2fdd23aa114119620125a1
2020-08-16 15:51:14 +02:00
Harald Welte 9866c7373c dfu: Shrink code by 144 bytes (by not calling PIO_InitializeInterrupts)
We are not using any PIO interrupts from DFU mode.  It's only used in
the main application firmware (verified by "git grep PIO_ConfigureIt")

Change-Id: Id1447af519df3183061f3d3f156a8dd84789af16
2020-08-16 15:47:00 +02:00
Kevin Redon b6e2f0f8e7 DFU: add DFU application
this adds the DFU as application, allowing to flash the bootloader.
a USB DFU alternative is added to flash the bootloader partition.

when the DFU is started as bootloader, the partition/alternative
to flash the bootloader is marked as "not available", and
ineffective.
the same happens for the application partition when DFU is started
as application.

this distinction is make at compile time, not at runtime, because
of size restrictions (the bootloader was already close to the
16 kB limit).
*_dfu_flash.bin should not be mixed with *_dfu_dfu.bin.
*_dfu_dfu.bin should be flashed as application using the already
existing DFU bootloader.
once this images is started (as application), the *_dfu_flash.bin
should be flashed as bootloader using the DFU application.

once the DFU bootloader has been flashed, soft resetting
(not re-powering) will cause the bootloader to start, allowing to
flash the application with a normal image (e.g. not DFU),
replacing the DFU application.
this switch to DFU only happens after downloading (e.g. flashing).

it is planned to have the DFU application erase itself after
flashing, but this is currently not implemented.

Change-Id: Ic273bb593a7669111b0219fe301d7897419167c8
2020-01-16 20:35:04 +00:00
Kevin Redon 75a5f224c0 minor: improve trace output
the USB trace now respects the global setting.
the verbosity is also decreased, not showing USB activity unless
debugging.
this also saves some space.

the reset cause is now printed.
the strings increase the bootloader size, but it already exceeded
the 16 kB limit when trace level is set to info.

Change-Id: I9ba08d4bb4f188f6e7a202ea86acb7a42a2054f3
2019-12-11 16:58:07 +01:00
Kevin Redon d70836f965 DFU: restart bootloader when USB conf failed
when starting the DFU bootloader, but USB configuration (e.g.
enumeration) failed, the MCU restarted in the main application.
this occured after a DFU detach and were the USB host missed the
USB reset.
now after MCU reset, the bootloader is started again, since this
is what was requested to begin with.
the bootloader will always restart in the bootloader until USB
enumeration succeeded.
this boot loop can be stopped by unplugging/removing power from
the device.

Change-Id: I4062a7d8a7934af2119c169759b614dc45990651
2019-12-03 15:51:52 +00:00
Kevin Redon ed3ceec56f DFU: increase USB reset duration to 50 ms
the specification requires a reset duration of at least 10 ms.
reset is indicated by the device to the host by removing the
pull-up on D+ (host to device reset is a USB packet).
we used 20 ms, but on some setups (USB host, stack, hub, and load
dependent), this does not seem to be enough (no USB enumeration
was performed afterward, at least for the DFU bootloader).
increasing to 50 ms solved the issue on the affected setups.

instead of USB suspend, the more proper USB disconnect is used.
this mainly disables the pull-up provided by the USB peripheral.
USB activate is not required since the follow up initialisation
takes care of it.

Change-Id: If5ceb3b8f7a8f134d4439fdd138dd12b46589f97
2019-12-03 15:51:52 +00:00
Kevin Redon 98fbf23897 dfu: minor: make debug output only verbose in info level
the longer output is to fast and often incomplete.
the shorter version is enough to view the progress when not
debugging.

Change-Id: I97bb84da68d1f3bc14fb7c05400edf1748f55460
2019-12-02 19:26:56 +01:00
Kevin Redon 9b367872c8 minor: updated copyright years
Change-Id: I9254b1ddf6436b5a4964b9124a36ae17bfc22886
2019-12-02 19:26:11 +01:00
Kevin Redon ba15387b09 DFU: fix Wformat compile warning
Change-Id: I8c422d8a709f8311c40d37e1f1f01dcd3a199b6f
2018-09-03 21:11:44 +02:00
Kevin Redon ff3d84922d 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
2018-08-07 12:09:49 +02:00
Kevin Redon 9a12d68c74 firmware: set license to GPLv2+
Change-Id: Id4c00159f984976b6d8641900fb64e36a3a30407
2018-07-11 22:01:58 +02:00
Kevin Redon 9918c2840e DFU: use central DFU override check
TRACE_INFO will also provide the DFU start reason, but TRACE_INFO
(TRACE_LEVEL >= 4) should only be used for debugging.
WARNING: With TRACE_LEVEL >= 4 the DFU binary is over the maximum of
16 kiB allocated for the DFU bootloader.
Thus make combined will not boot the main application because its
start if after the expecte 16 kiB address; and flashing using DFU
will overwrite the DFU bootloader itself.

Change-Id: I82323e0f76c03f67df7dc8f2b6783166cc25f3aa
2018-07-11 20:48:24 +02:00
Kevin Redon 9def7631ba DFU: switch green LED on to indicate DFU mode, and red LED to indicate flashing activity
Change-Id: I8e34fd869ed94ad122d6a17f5a432f5a09b820bb
2018-07-04 14:29:28 +02:00
Harald Welte 1cfc2614dd apps/dfu/main.c: Avoid variable declaration in for loop initial
This fixes the following compile error:

apps/dfu/main.c:73:3: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
   for (unsigned int i=0; i<len; i++) {
   ^
apps/dfu/main.c:73:3: note: use option -std=c99, -std=gnu99, -std=c11 or -std=gnu11 to compile your code

which was recently introduced in b73f0a00bc
2018-06-29 21:07:41 +02:00
Kevin Redon 869dbfafe4 DFU: incread watchdog timeout and restart watchdog before writing in flash to prevent the watchdog to trigger while flashing 2018-06-29 20:07:31 +02:00
Kevin Redon b73f0a00bc DFU: unlock the flash before writing, verify written data, and relock it 2018-06-29 20:07:31 +02:00
Kevin Redon f5869d4a59 USB: implement USB reset by setting the on-board pull-up on D+ low 2018-06-29 20:07:31 +02:00
Kevin Redon 318309f30f dfu: fix address destination check and add stack overwrite check in USBDFU_handle_dnload
During DFU download the destination start address is checked to not exceed the
RAM or flash end address, but it is also necessary to check if the end of the
data to be downloaded is also within the allowed range.
When downloading to RAM it is also necessary to check if the data to be
downloaded does not overwrite (i.e. corrupt) the stack.
2018-06-29 20:07:31 +02:00
Harald Welte 27f5fc681c DFU: Move "Override DFU" (force DFU) code to board-specific section
Each board can define its own conditions on which the controller should
boot into DFU mode rather than normal application mode.  Let's move the
"UART loopback jumper" to QMOD specific part.  For SIMtrace we have an
actual button and can use that in a future patch.
2017-11-28 22:15:56 +01:00
Harald Welte 8e7fca3255 migrate from req_ctx to msgb
We now generalize the USB communiction and abandon the 'req_ctx'
structure inherited from openpcd.  Instead we use the libosmocore 'msgb'
structure to handle incoming and outgoing USB tranfers.  We also use
linuxlist-based msgb-queues for each endpoint.
2017-05-07 23:09:56 +02:00
Harald Welte 3bbaba0090 DFU: Disable LED blinking code
Something odd is happening that breaks DFU mode if we blink.  Let's
remove this feature for now.
2017-03-06 22:47:06 +01:00
Harald Welte 5b108d8cf0 DFU: initialize g_dfu during real power up
At power-up we need to initialize g_dfu once, to ensure a consistent
state.  Afterwards we want to keep it across (software) reset, but on
power-up the memory would otherwise be filled with random data, causing
issues with detection of DFU/Runtime switching.
2017-03-06 21:51:55 +01:00
Harald Welte abba8a8d85 LED: Introduce LED blinking pattern code
It might be useful to display some different blinking patterns to
indicate specific system state (such as DFU mode vs. regular firmware)
2017-03-06 16:58:00 +01:00
Harald Welte 1405100dff DFU: Introduce board/app-specific override for booting in DFU mode
Using the USBDFU_OverrideEnterDFU() function, a board/application can
define extra conditions when the system should boot in DFU mode, even if
it was not explicitly switched to DFU mode from the application.

The app/dfu/main.c uses this mechanism to boot into DFU mode if the
stack + reset vector addresses are not plausible (i.e. some random junk
appears to be flashed in the application partition) or if the user
places a jumper accross the RxD+TxD lines of the debug UART.  The idea
is that the system can be recovered by placing this jumper and then
re-installing the application from DFU.
2017-03-04 19:17:27 +01:00
Harald Welte 7214b4747f Make sure to print CPU Reset Cause when starting the software 2017-03-03 19:02:09 +01:00
Harald Welte 45ebe4591a Enable Watchdog (500ms) 2017-03-03 19:01:53 +01:00
Harald Welte 8adf0ac2ce DFU app: call into board_main_top() for qmod related initialization 2017-03-03 01:52:34 +01:00
Harald Welte f415d7163b Call USBD_Disconnect before software-triggered CPU reset
This makes sure that we'll re-enumerate on the USB, as a CPU reset
apparently doesn't automatically release the pull-up and notify the hub
that we were gone?
2017-03-03 01:51:43 +01:00
Harald Welte ec0837c463 change from \r\n (CRLF) to \n\r (LFCR)
For some strange reason my output is garbled in both the 'screen' and
'cu' teerminal programs and 'raw' terminal (stty) mode.  I fail to
understand why, but let's simply adjust the code as needed for now.
2017-03-03 01:33:24 +01:00
Harald Welte e8eea29cf6 dfu: fix cosmetic issue in debug message 2017-03-03 00:35:51 +01:00
Harald Welte ec9b5fff3f dfu/main.c: Initialize FLASHD driver before using it 2017-03-02 23:18:40 +01:00
Harald Welte e36970cac7 dfu: print Chip ID during boot 2017-03-02 19:24:14 +01:00
Harald Welte adba0ce80b fix g_dfu access from both DFU and runtime access
We need to refer to g_dfu as a pointer from all code.  In DFU mode, it
gets assigned to the address of _g_dfu, which is placed by the linker
script at the start of RAM.  In runtime mode, the pointer is statically
defined to point at the start of RAM.  The linker script for the runtime
(dfu environment) is adjusted to save the first 32 bytes for the _g_dfu
structure.
2017-02-28 01:10:32 +01:00
Harald Welte 32852bc1d9 DFU: towards a more complete implementation
* we now actually route the EP0 control requests in DFU mode to the
  correct handler (weak linker symbols are tricky)
* we now actually call code to read/write data from/to RAM/FLASH
2017-02-28 01:10:23 +01:00
Harald Welte d8a003dfd7 Structure build system to build for multiple boards/apps/environments 2017-02-27 22:18:45 +01:00