Fix sd_mmc_spi_mem capacity; clean up USB code (#12134)
- Fix an error in the return value of `sd_mmc_spi_read_capacity` which was causing the host OS to read beyond the last sector in the card.
- Clean up the USB flashdrive code and add better debugging.
Use macros that explicitly avoid double-evaluation and can be used for any datatype, replacing `min`, `max`, `abs`, `fabs`, `labs`, and `FABS`.
Co-Authored-By: ejtagle <ejtagle@hotmail.com>
As Bob-The-Khun suggested, resetting the USB peripheral solves the huge startup delays that happen when a WDT reset happens and we are connected through the native port
- Watchdog reset during SD Card initialization.
- Move `DebugMonitor` to `DebugMonitor_Due.cpp`.
- Since the watchdog is enabled on boot do extra resets during init.
- Have `thermalManager` do watchdog reset before its ISR starts to prevent reset.
- Ensure that timers are stopped before reprogramming them to address tone issues.
- Improve SAM3XE reset when reflashed through the native port.
DUE USB CDC: Do not send any character if no program on the PC is listening to them. This avoids Marlin waiting until the user actually opens a program that is able to consume the output of Marlin
Added Arduino-compatible kludge to the (ATMEL supplied) SAM3X USB stack we are now using so the Native port is also usable as a programming port on Arduino DUE and derived designs