Minor cleanups. Add the required Cube HAL to app Makefile.

pull/143/head
David Garske 2021-08-24 09:31:43 -07:00 committed by Daniele Lacamera
parent 17a3d5c476
commit ff28cec38a
6 changed files with 104 additions and 46 deletions

12
arch.mk
View File

@ -78,11 +78,6 @@ ifeq ($(ARCH),ARM)
endif
endif
ifeq ($(TARGET),stm32l4)
ARCH_FLASH_OFFSET=0x08000000
SPI_TARGET=stm32
endif
## Cortex-M CPU
ifeq ($(CORTEX_M33),1)
CFLAGS+=-mcpu=cortex-m33
@ -274,10 +269,13 @@ endif
ifeq ($(TARGET),stm32l4)
SPI_TARGET=stm32
ARCH_FLASH_OFFSET=0x08000000
OBJS+=$(STM32CUBE)/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash.o
OBJS+=$(STM32CUBE)/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash_ex.o
CFLAGS+=-DSTM32L4A6xx -DUSE_HAL_DRIVER -I$(STM32CUBE)/Drivers/STM32L4xx_HAL_Driver/Inc/ \
-Isrc -I$(STM32CUBE)/Drivers/BSP/STM32L4xx_Nucleo_144/ -I$(STM32CUBE)/Drivers/CMSIS/Device/ST/STM32L4xx/Include/ \
CFLAGS+=-DSTM32L4A6xx -DUSE_HAL_DRIVER -Isrc -Ihal \
-I$(STM32CUBE)/Drivers/STM32L4xx_HAL_Driver/Inc/ \
-I$(STM32CUBE)/Drivers/BSP/STM32L4xx_Nucleo_144/ \
-I$(STM32CUBE)/Drivers/CMSIS/Device/ST/STM32L4xx/Include/ \
-I$(STM32CUBE)/Drivers/CMSIS/Include/
endif

View File

@ -27,14 +27,9 @@
#define DMB() asm volatile ("dmb")
/*** RCC ***/
#define RCC_PRESCALER_DIV_NONE 0
static uint32_t Address = 0, PAGEError = 0;
static FLASH_EraseInitTypeDef EraseInitStruct;
@ -127,7 +122,7 @@ int RAMFUNCTION hal_flash_erase(uint32_t address,int len)
static void RAMFUNCTION flash_set_waitstates(int waitstates)
{
FLASH->ACR |= waitstates | FLASH_ACR_DCEN | FLASH_ACR_ICEN;
FLASH->ACR |= (waitstates | FLASH_ACR_DCEN | FLASH_ACR_ICEN);
}
static RAMFUNCTION void flash_wait_complete(void)
@ -141,7 +136,7 @@ int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
int i = 0;
uint32_t *dst;
uint32_t reg;
int ret=-1;
int ret = -1;
hal_flash_clear_errors();
reg = FLASH->CR & (~FLASH_CR_FSTPG);
@ -178,10 +173,12 @@ int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
static void clock_pll_off(void)
{
uint32_t reg32;
/* Enable internal multi-speed oscillator. */
RCC->CR |= RCC_CR_HSION;
DMB();
while ((RCC->CR & RCC_CR_HSIRDY) == 0) {};
/* Select HSI as SYSCLK source. */
reg32 = RCC->CFGR;
reg32 &= ~((1 << 1) | (1 << 0));
@ -201,6 +198,7 @@ static void clockconfig(int powersave)
/* Enable Power controller */
RCC->APB1ENR1 |= RCC_APB1ENR1_PWREN;
/* Select clock parameters */
/*cpu_freq=16000000;*/
hpre= RCC_PRESCALER_DIV_NONE;
@ -208,17 +206,19 @@ static void clockconfig(int powersave)
ppre2=RCC_PRESCALER_DIV_NONE;
flash_waitstates = 3;
flash_set_waitstates(flash_waitstates);
/* Enable internal high-speed oscillator. */
RCC->CR |=RCC_CR_HSION;
DMB();
while ((RCC->CR & RCC_CR_HSIRDY)==0);
/* select HSI as SYSCLK source*/
reg32 = RCC->CFGR;
reg32 &= ~((1 << 1) | (1 << 0));
RCC->CFGR = (reg32 | RCC_CFGR_SW_HSI);
DMB();
/* Set prescalers for AHB, ADC, ABP1, ABP2.
*/
/* Set prescalers for AHB, ADC, ABP1, ABP2 */
reg32 = RCC->CFGR;
reg32 &= ~(0xF0);
RCC->CFGR = (reg32 | (hpre << 4));

View File

@ -1,9 +1,33 @@
/* stm32-4xx_hal_conf.h
*
* Copyright (C) 2021 wolfSSL Inc.
*
* This file is part of wolfBoot.
*
* wolfBoot is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* wolfBoot is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/
#ifndef __STM32L4xx_HAL_CONF_H
#define __STM32L4xx_HAL_CONF_H
#define HAL_MODULE_ENABLED
#define HAL_FLASH_MODULE_ENABLED
#define HAL_RCC_MODULE_ENABLED
#include "stm32l4xx_hal_flash.h"
#include "stm32l4xx_hal_rcc.h"
#define assert_param(expr) ((void)0U)
#endif /* __STM32L4xx_HAL_CONF_H */

View File

@ -79,6 +79,16 @@ ifeq ($(TARGET),stm32h7)
LSCRIPT_TEMPLATE=ARM-stm32h7.ld
endif
ifeq ($(TARGET),stm32l4)
APP_OBJS+=$(STM32CUBE)/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash.o
APP_OBJS+=$(STM32CUBE)/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash_ex.o
CFLAGS+=-DSTM32L4A6xx -DUSE_HAL_DRIVER -Isrc -Ihal \
-I$(STM32CUBE)/Drivers/STM32L4xx_HAL_Driver/Inc/ \
-I$(STM32CUBE)/Drivers/BSP/STM32L4xx_Nucleo_144/ \
-I$(STM32CUBE)/Drivers/CMSIS/Device/ST/STM32L4xx/Include/ \
-I$(STM32CUBE)/Drivers/CMSIS/Include/
endif
ifeq ($(TARGET),stm32l5)
ifeq ($(TZEN),1)
LSCRIPT_TEMPLATE=ARM-stm32l5-ns.ld

View File

@ -1,3 +1,27 @@
/* app_stm32l4.c
*
* Test bare-metal boot-led-on application
*
* Copyright (C) 2020 wolfSSL Inc.
*
* This file is part of wolfBoot.
*
* wolfBoot is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* wolfBoot is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/
#include "led.h"
#include "hal.h"
#include "wolfboot/wolfboot.h"
@ -10,17 +34,19 @@ void main(void)
hal_init();
boot_led_on();
boot_version = wolfBoot_current_firmware_version();
if(boot_version == 1) {
if (boot_version == 1) {
/* Turn on Blue LED */
boot_led_on();
wolfBoot_update_trigger();
} else if(boot_version >= 2) {
} else if (boot_version >= 2) {
/* Turn on Red LED */
led_on();
wolfBoot_success();
}
/* Wait for reboot */
while(1) {
}
}
#endif /* PLATFORM_stm32l4 */

View File

@ -180,7 +180,7 @@ void boot_led_off(void)
#endif /* PLATFORM_stm32wb */
#ifdef PLATFORM_stm32l4
#define AHB2_CLOCK_ER (*(volatile uint32_t *)(0x4002104C)) // RCC_AHB2ENR
#define AHB2_CLOCK_ER (*(volatile uint32_t *)(0x4002104C)) /* RCC_AHB2ENR */
#define GPIOB_AHB2_CLOCK_ER (1 << 1)
#define GPIOB_BASE 0x48000400