From 4a14fb6c4de25f18cbc4192ac34fcd20613e72e7 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Tue, 17 Oct 2017 11:44:53 +0200 Subject: [PATCH] boardloader: move periph_init to lowlevel.c --- embed/boardloader/lowlevel.c | 25 +++++++++++++++++++++++++ embed/boardloader/lowlevel.h | 1 + embed/boardloader/main.c | 28 ---------------------------- embed/bootloader/main.c | 1 - embed/firmware/main.c | 1 - 5 files changed, 26 insertions(+), 30 deletions(-) diff --git a/embed/boardloader/lowlevel.c b/embed/boardloader/lowlevel.c index 8621574a4d..785bfd7bf0 100644 --- a/embed/boardloader/lowlevel.c +++ b/embed/boardloader/lowlevel.c @@ -43,3 +43,28 @@ bool flash_check_option_bytes(void) ((FLASH->OPTCR & FLASH_OPTCR_RDP) == FLASH_OPTCR_RDP_2) && ((FLASH->OPTCR & FLASH_OPTCR_BOR_LEV) == (FLASH_OPTCR_BOR_LEV_0 | FLASH_OPTCR_BOR_LEV_1)); } + +void periph_init(void) +{ + // STM32F4xx HAL library initialization: + // - configure the Flash prefetch, instruction and data caches + // - configure the Systick to generate an interrupt each 1 msec + // - set NVIC Group Priority to 4 + // - global MSP (MCU Support Package) initialization + HAL_Init(); + + // Enable GPIO clocks + __HAL_RCC_GPIOA_CLK_ENABLE(); + __HAL_RCC_GPIOB_CLK_ENABLE(); + __HAL_RCC_GPIOC_CLK_ENABLE(); + __HAL_RCC_GPIOD_CLK_ENABLE(); + + // Clear the reset flags + PWR->CR |= PWR_CR_CSBF; + RCC->CSR |= RCC_CSR_RMVF; + + // Enable CPU ticks + CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; // Enable DWT + DWT->CYCCNT = 0; // Reset Cycle Count Register + DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk; // Enable Cycle Count Register +} diff --git a/embed/boardloader/lowlevel.h b/embed/boardloader/lowlevel.h index d0e37d4cf6..c50879f9a2 100644 --- a/embed/boardloader/lowlevel.h +++ b/embed/boardloader/lowlevel.h @@ -5,5 +5,6 @@ void flash_set_option_bytes(void); bool flash_check_option_bytes(void); +void periph_init(void); #endif diff --git a/embed/boardloader/main.c b/embed/boardloader/main.c index dd7ece766b..25cabe45a6 100644 --- a/embed/boardloader/main.c +++ b/embed/boardloader/main.c @@ -1,5 +1,3 @@ -#include STM32_HAL_H - #include #include "common.h" @@ -149,34 +147,8 @@ static const uint8_t * const BOARDLOADER_KEYS[] = { #endif }; -void periph_init(void) -{ - // STM32F4xx HAL library initialization: - // - configure the Flash prefetch, instruction and data caches - // - configure the Systick to generate an interrupt each 1 msec - // - set NVIC Group Priority to 4 - // - global MSP (MCU Support Package) initialization - HAL_Init(); - - // Enable GPIO clocks - __HAL_RCC_GPIOA_CLK_ENABLE(); - __HAL_RCC_GPIOB_CLK_ENABLE(); - __HAL_RCC_GPIOC_CLK_ENABLE(); - __HAL_RCC_GPIOD_CLK_ENABLE(); - - // Clear the reset flags - PWR->CR |= PWR_CR_CSBF; - RCC->CSR |= RCC_CSR_RMVF; - - // Enable CPU ticks - CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; // Enable DWT - DWT->CYCCNT = 0; // Reset Cycle Count Register - DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk; // Enable Cycle Count Register -} - int main(void) { - #if PRODUCTION flash_set_option_bytes(); if (!flash_check_option_bytes()) { diff --git a/embed/bootloader/main.c b/embed/bootloader/main.c index 7b96f8055b..ebdc986699 100644 --- a/embed/bootloader/main.c +++ b/embed/bootloader/main.c @@ -207,7 +207,6 @@ void check_bootloader_version(void) int main(void) { - #if PRODUCTION check_bootloader_version(); #endif diff --git a/embed/firmware/main.c b/embed/firmware/main.c index 1489165a64..76e3946a6d 100644 --- a/embed/firmware/main.c +++ b/embed/firmware/main.c @@ -23,7 +23,6 @@ int main(void) { - pendsv_init(); display_orientation(0);