Only sleep mode can be used for USB suspend on STM32F103.

This commit is contained in:
NIIBE Yutaka
2017-11-16 12:19:25 +09:00
parent 3552fc5615
commit d745c9fdb9
2 changed files with 33 additions and 23 deletions

View File

@@ -709,6 +709,7 @@ svc (void)
}
#endif
#ifdef MCU_STM32F0
struct SCB
{
volatile uint32_t CPUID;
@@ -748,27 +749,27 @@ static struct PWR *const PWR = ((struct PWR *)0x40007000);
void
chx_sleep_mode (int how)
{
if (how == 0)
;
else
{
if (how == 1)
/* sleep only */
PWR->CR |= PWR_CR_CWUF;
PWR->CR &= ~(PWR_CR_PDDS|PWR_CR_LPDS);
if (how == 0 || how == 1 /* Sleep only (not deepsleep) */)
SCB->SCR &= ~SCB_SCR_SLEEPDEEP;
else
{
PWR->CR |= PWR_CR_CWUF;
if (how == 2 || how == 3)
{
PWR->CR &= ~PWR_CR_PDDS;
{ /* Deepsleep */
/* how == 2: deepsleep but regulator ON */
if (how == 3)
PWR->CR |= PWR_CR_LPDS;
}
else /* how == 4 */
PWR->CR |= PWR_CR_PDDS;
PWR->CR |= PWR_CR_LPDS; /* regulator low-power mode */
else if (how == 4)
PWR->CR |= PWR_CR_PDDS; /* Power down: All OFF */
SCB->SCR |= SCB_SCR_SLEEPDEEP;
}
}
#else
/* Deepsleep is only useful with RTC, Watch Dog, or WKUP pin. */
void
chx_sleep_mode (int how)
{
(void)how;
}
#endif

View File

@@ -29,7 +29,6 @@
#include <stdint.h>
#include <stdlib.h>
#include "mcu/stm32f103.h"
#include "sys-stm32f103.h"
#include "usb_lld.h"
#include "usb_lld_driver.h"
@@ -343,9 +342,19 @@ void usb_lld_init (struct usb_dev *dev, uint8_t feature)
st103_set_cntr (CNTR_CTRM | CNTR_OVRM | CNTR_ERRM
| CNTR_WKUPM | CNTR_SUSPM | CNTR_RESETM);
/* Setting of EXTI wakeup event to break sleep on WFE. */
EXTI->RTSR |= (1 << 18); /* Rising trigger selection */
#if 0
/*
* Since stop mode makes PLL, HSI & HES oscillators stop, USB clock is
* not supplied in stop mode. Thus, USB wakeup can't occur.
*
* So, only sleep mode can be supported with USB, which doesn't
* require use of EXTI.
*/
#include "mcu/stm32f103.h"
/* Setting of EXTI wakeup event to break stop mode. */
EXTI->EMR |= (1 << 18); /* Event mask cleared */
EXTI->RTSR |= (1 << 18); /* Rising trigger selection */
#endif
}
void usb_lld_prepare_shutdown (void)