diff options
Diffstat (limited to '02-usart/src/arch')
-rw-r--r-- | 02-usart/src/arch/stm32l4xxx/peripherals/clock.c | 11 | ||||
-rw-r--r-- | 02-usart/src/arch/stm32l4xxx/peripherals/init.c | 49 | ||||
-rw-r--r-- | 02-usart/src/arch/stm32l4xxx/peripherals/usart.c | 13 |
3 files changed, 20 insertions, 53 deletions
diff --git a/02-usart/src/arch/stm32l4xxx/peripherals/clock.c b/02-usart/src/arch/stm32l4xxx/peripherals/clock.c index 1029d39..9051572 100644 --- a/02-usart/src/arch/stm32l4xxx/peripherals/clock.c +++ b/02-usart/src/arch/stm32l4xxx/peripherals/clock.c @@ -5,10 +5,13 @@ #include "arch/stm32l4xxx/peripherals/clock.h" #include "arch/stm32l4xxx/peripherals/flash.h" +#include "kern/init.h" + #include <stdint.h> #define TIMEOUT 10000 + int pll_off() { uint32_t c; @@ -66,8 +69,16 @@ int configure_pll( return 0; } +static _no_init uint8_t clock_mHz; +uint8_t get_clock_mhz() +{ + return clock_mHz; +} + int set_system_clock_MHz(uint8_t mhz) { + clock_mHz = mhz; + /* Set the source of the system colck to MSI temporarily. */ set_system_clock_src(SYSTEM_CLOCK_SRC_MSI); diff --git a/02-usart/src/arch/stm32l4xxx/peripherals/init.c b/02-usart/src/arch/stm32l4xxx/peripherals/init.c deleted file mode 100644 index 47bfaa5..0000000 --- a/02-usart/src/arch/stm32l4xxx/peripherals/init.c +++ /dev/null @@ -1,49 +0,0 @@ -#include "arch.h" -#include "arch/stm32l4xxx/peripherals/system.h" - -/* Forward-declare the main function. This is implemented in main.c. */ -void main(); - -/* These are defined in the linker script. */ - -#ifdef ARCH_STM32L4 -extern uint32_t INIT_DATA_VALUES; -extern uint32_t DATA_SEGMENT_START; -extern uint32_t DATA_SEGMENT_STOP; -extern uint32_t BSS_START; -extern uint32_t BSS_END; - -/* - * Runs before main. Initializes the data and bss segments by loading them - * into memory. - */ -_Noreturn void on_reset() -{ - uint32_t* src; - uint32_t* dest; - - src = &INIT_DATA_VALUES; - dest = &DATA_SEGMENT_START; - - /* Copy the values from flash into the data segment. */ - while (dest != &DATA_SEGMENT_STOP) { - *(dest++) = *(src++); - } - - /* Everything in the BSS segment is set to zero. */ - dest = &BSS_START; - while (dest != &BSS_END) { - *(dest++) = 0; - } - - /* Set the vector offset table to be at the start - * of FLASH memory. */ - SCB.vto_r = 0x08000000; - - /* Jump to main. */ - main(); - - for(;;); -} - -#endif /* ARCH_STM32L4 */ diff --git a/02-usart/src/arch/stm32l4xxx/peripherals/usart.c b/02-usart/src/arch/stm32l4xxx/peripherals/usart.c index d37eee2..7309b48 100644 --- a/02-usart/src/arch/stm32l4xxx/peripherals/usart.c +++ b/02-usart/src/arch/stm32l4xxx/peripherals/usart.c @@ -97,9 +97,8 @@ void usart_enable_dma(__IO usart_t* usart, usart_enable_t enabled) }; } -void usart_printf(__IO usart_t* usart, const char* fmt, ...) +void usart_vprintf(__IO usart_t* usart, const char* fmt, va_list l) { - va_list l; union { void* ptr; char* str; @@ -107,8 +106,6 @@ void usart_printf(__IO usart_t* usart, const char* fmt, ...) } b; char buf[128]; - va_start(l, fmt); - while (*fmt != 0) { if (*fmt == '%') { switch (*(++fmt)) { @@ -145,3 +142,11 @@ void usart_printf(__IO usart_t* usart, const char* fmt, ...) end: va_end(l); } + +void usart_printf(__IO usart_t* usart, const char* fmt, ...) +{ + va_list l; + va_start(l, fmt); + + usart_vprintf(usart, fmt, l); +} |