diff --git a/include/libopenstm32/rcc.h b/include/libopenstm32/rcc.h index 6422f463..43751469 100644 --- a/include/libopenstm32/rcc.h +++ b/include/libopenstm32/rcc.h @@ -386,5 +386,10 @@ void rcc_set_sysclk_source(u32 clk); void rcc_set_pll_multiplication_factor(u32 mul); void rcc_set_pll_source(u32 pllsrc); void rcc_set_pllxtpre(u32 pllxtpre); +void rcc_set_adcpre(u32 adcpre); +void rcc_set_ppre2(u32 ppre2); +void rcc_set_ppre1(u32 ppre1); +void rcc_set_hpre(u32 hpre); +u32 rcc_get_system_clock_source(int i); #endif diff --git a/lib/rcc.c b/lib/rcc.c index 58ab8b55..23920846 100644 --- a/lib/rcc.c +++ b/lib/rcc.c @@ -3,6 +3,8 @@ * * Copyright (C) 2009 Federico Ruiz-Ugalde * Copyright (C) 2009 Uwe Hermann + * Copyright (C) 2010 Thomas Otto + * * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -279,3 +281,45 @@ void rcc_set_pllxtpre(u32 pllxtpre) reg32 &= ~(1 << 17); RCC_CFGR = (reg32 | (pllxtpre << 17)); } + +void rcc_set_adcpre(u32 adcpre) +{ + u32 reg32; + + reg32 = RCC_CFGR; + reg32 &= ((1 << 14) | (1 << 15)); + RCC_CFGR = (reg32 | (adcpre << 14)); +} + +void rcc_set_ppre2(u32 ppre2) +{ + u32 reg32; + + reg32 = RCC_CFGR; + reg32 &= ((1 << 11) | (1 << 12) | (1 << 13)); + RCC_CFGR = (reg32 | (ppre2 << 11)); +} + +void rcc_set_ppre1(u32 ppre1) +{ + u32 reg32; + + reg32 = RCC_CFGR; + reg32 &= ((1 << 8) | (1 << 9) | (1 << 10)); + RCC_CFGR = (reg32 | (ppre1 << 8)); +} + +void rcc_set_hpre(u32 hpre) +{ + u32 reg32; + + reg32 = RCC_CFGR; + reg32 &= ((1 << 4) | (1 << 5) | (1 << 6) | (1 << 7)); + RCC_CFGR = (reg32 | (hpre << 4)); +} + +u32 rcc_system_clock_source(void) +{ + /* Return the clock source which is used as system clock. */ + return ((RCC_CFGR & 0x000c) >> 2); +}