//go:build stm32l0 // +build stm32l0 package runtime import ( "device/stm32" "machine" ) const ( RCC_SYSCLK_DIV1 = 0 // Needs SVD update (should be stm32.RCC_SYSCLK_DIV1) ) func putchar(c byte) { machine.Serial.WriteByte(c) } func getchar() byte { for machine.Serial.Buffered() == 0 { Gosched() } v, _ := machine.Serial.ReadByte() return v } func buffered() int { return machine.Serial.Buffered() } func initCLK() { // Set Power Regulator to enable max performance (1.8V) stm32.PWR.CR.ReplaceBits(1< getFlashLatency() { setFlashLatency(FlashLatency) for getFlashLatency() != FlashLatency { } } // HCLK stm32.RCC.CFGR.ReplaceBits(RCC_SYSCLK_DIV1, stm32.RCC_CFGR_HPRE_Msk, 0) // Use PLL As System clock stm32.RCC.CFGR.ReplaceBits(stm32.RCC_CFGR_SWS_PLL, stm32.RCC_CFGR_SW_Msk, 0) for stm32.RCC.CFGR.Get()&stm32.RCC_CFGR_SW_Msk != stm32.RCC_CFGR_SWS_PLL { } // Set prescalers so half system clock (PCLKx = HCLK/2) stm32.RCC.CFGR.SetBits(stm32.RCC_CFGR_PPRE1_Div2 << stm32.RCC_CFGR_PPRE1_Pos) stm32.RCC.CFGR.SetBits(stm32.RCC_CFGR_PPRE2_Div2 << stm32.RCC_CFGR_PPRE2_Pos) } func getFlashLatency() uint32 { return stm32.FLASH.ACR.Get() & stm32.Flash_ACR_LATENCY_Msk } func setFlashLatency(l uint32) { stm32.FLASH.ACR.ReplaceBits(l, stm32.Flash_ACR_LATENCY_Msk, 0) }