AVR8: Add option to keep 3.3V regulator enabled
authorMichael Hanselmann <public@hansmi.ch>
Thu, 19 Dec 2013 22:44:23 +0000 (23:44 +0100)
committerMichael Hanselmann <public@hansmi.ch>
Thu, 19 Dec 2013 23:04:51 +0000 (00:04 +0100)
The documentation contains example code[1] on how to restart into the
bootloader. In the process of preparing for the reset, USB is disabled
using “USB_Disable()”. For hardware making use of the AVR8's internal
3.3V regulator that call would also disable the regulator, resetting the
processor immediately rather than setting the boot key and letting the
watchdog reset the processor.

This patch adds a new flag to be given to “USB_Init()” or to be defined
in “USE_STATIC_OPTIONS” telling “USB_Disable()” to keep the regulator
enabled.

On November 1st, 2013 this issue was already mentioned on the mailing
list[2], but no fix came from that discussion.

[1]
<http://www.fourwalledcubicle.com/files/LUFA/Doc/130901/
html/_page__software_bootloader_start.html>

[2]
<https://groups.google.com/d/msg/lufa-support/uwrFpRQpJzU/e9I6UK5jMJQJ>

Signed-off-by: Michael Hanselmann <public@hansmi.ch>
LUFA/DoxygenPages/ChangeLog.txt
LUFA/Drivers/USB/Core/AVR8/USBController_AVR8.c
LUFA/Drivers/USB/Core/AVR8/USBController_AVR8.h

index 55150f4..75a1c6c 100644 (file)
@@ -11,6 +11,7 @@
   *  - Library Applications:
   *   - Added new Bulk Vendor low level device demo
   *   - Added new libUSB host Python and NodeJS application examples for the class driver GenericHID demo (thanks to Laszlo Monda)
   *  - Library Applications:
   *   - Added new Bulk Vendor low level device demo
   *   - Added new libUSB host Python and NodeJS application examples for the class driver GenericHID demo (thanks to Laszlo Monda)
+  *   - Added new AVR8 USB option to keep 3.3V regulator enabled
   *
   *  <b>Changed:</b>
   *  - Library Applications:
   *
   *  <b>Changed:</b>
   *  - Library Applications:
index 8faec1d..dc96c0f 100644 (file)
@@ -112,7 +112,8 @@ void USB_Disable(void)
        if (!(USB_Options & USB_OPT_MANUAL_PLL))
          USB_PLL_Off();
 
        if (!(USB_Options & USB_OPT_MANUAL_PLL))
          USB_PLL_Off();
 
-       USB_REG_Off();
+       if (!(USB_Options & USB_OPT_REG_KEEP_ENABLED))
+         USB_REG_Off();
 
        #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)
        USB_OTGPAD_Off();
 
        #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)
        USB_OTGPAD_Off();
index 1b72bf1..fedc04e 100644 (file)
                         */
                        #define USB_OPT_REG_ENABLED                (0 << 1)
 
                         */
                        #define USB_OPT_REG_ENABLED                (0 << 1)
 
+                       /** Option mask for \ref USB_Init() to keep regulator enabled at all times. Indicates that \ref USB_Disable()
+                        *  should not disable the regulator as it would otherwise. Has no effect if regulator is disabled using
+                        *  \ref USB_OPT_REG_DISABLED.
+                        *
+                        *  \note See USB AVR data sheet for more information on the internal pad regulator.
+                        */
+                       #define USB_OPT_REG_KEEP_ENABLED           (1 << 3)
+
                        /** Manual PLL control option mask for \ref USB_Init(). This indicates to the library that the user application
                         *  will take full responsibility for controlling the AVR's PLL (used to generate the high frequency clock
                         *  that the USB controller requires) and ensuring that it is locked at the correct frequency for USB operations.
                        /** Manual PLL control option mask for \ref USB_Init(). This indicates to the library that the user application
                         *  will take full responsibility for controlling the AVR's PLL (used to generate the high frequency clock
                         *  that the USB controller requires) and ensuring that it is locked at the correct frequency for USB operations.