mirror of
https://github.com/micropython/micropython.git
synced 2026-01-06 12:10:13 +01:00
stm32: Add USB support for STM32L1 MCUs.
Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
This commit is contained in:
@@ -348,6 +348,8 @@ void SystemClock_Config(void) {
|
||||
#elif defined(STM32L1)
|
||||
|
||||
void SystemClock_Config(void) {
|
||||
// Enable SYSCFG clock
|
||||
__HAL_RCC_SYSCFG_CLK_ENABLE();
|
||||
// Enable power control peripheral
|
||||
__HAL_RCC_PWR_CLK_ENABLE();
|
||||
|
||||
@@ -388,25 +390,6 @@ void SystemClock_Config(void) {
|
||||
SystemCoreClockUpdate();
|
||||
powerctrl_config_systick();
|
||||
|
||||
#if MICROPY_HW_ENABLE_USB
|
||||
// Enable the 48MHz internal oscillator
|
||||
RCC->CRRCR |= RCC_CRRCR_HSI48ON;
|
||||
RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN;
|
||||
SYSCFG->CFGR3 |= SYSCFG_CFGR3_ENREF_HSI48;
|
||||
while (!(RCC->CRRCR & RCC_CRRCR_HSI48RDY)) {
|
||||
// Wait for HSI48 to be ready
|
||||
}
|
||||
|
||||
// Select RC48 as HSI48 for USB and RNG
|
||||
RCC->CCIPR |= RCC_CCIPR_HSI48SEL;
|
||||
|
||||
// Synchronise HSI48 with 1kHz USB SoF
|
||||
__HAL_RCC_CRS_CLK_ENABLE();
|
||||
CRS->CR = 0x20 << CRS_CR_TRIM_Pos;
|
||||
CRS->CFGR = 2 << CRS_CFGR_SYNCSRC_Pos | 0x22 << CRS_CFGR_FELIM_Pos
|
||||
| __HAL_RCC_CRS_RELOADVALUE_CALCULATE(48000000, 1000) << CRS_CFGR_RELOAD_Pos;
|
||||
#endif
|
||||
|
||||
// Disable the Debug Module in low-power mode due to prevent
|
||||
// unexpected HardFault after __WFI().
|
||||
#if !defined(NDEBUG)
|
||||
|
||||
Reference in New Issue
Block a user