stm32: flash: pull up prefetch to _all

Turns out, there's lots of common code for flash.  Pull up prefetch
on/off to start with, as there's only a single bit name different.

Pull up the definitions of common API functions too, starting with
flash_set_ws.  Even if the implementations are different, things that
meant to be the same, should be defined centrally.
This commit is contained in:
Karl Palsson 2018-07-10 22:21:18 +00:00
parent 9dd901ba27
commit b23dccc7ae
30 changed files with 117 additions and 185 deletions

View File

@ -0,0 +1,48 @@
/** @addtogroup flash_defines
*
*/
/*
* This file is part of the libopencm3 project.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This library 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <libopencm3/cm3/common.h>
BEGIN_DECLS
/**
* This buffer is used for instruction fetches and is enabled by default after
* reset.
*
* Note carefully the clock restrictions under which the prefetch buffer may be
* enabled or disabled. Changes are normally made while the clock is running in
* the power-on low frequency mode before being set to a higher speed mode.
*
* See the reference manual for details.
*/
void flash_prefetch_enable(void);
/**
* Note carefully the clock restrictions under which the prefetch buffer may be
* set to disabled. See the reference manual for details.
*/
void flash_prefetch_disable(void);
void flash_set_ws(uint32_t ws);
END_DECLS

View File

@ -62,6 +62,8 @@
#define FLASH_ACR_PRFTBS (1 << 5)
#define FLASH_ACR_PRFTBE (1 << 4)
/** Compatibility define */
#define FLASH_ACR_PRFTEN FLASH_ACR_PRFTBE
/* --- FLASH_SR values ----------------------------------------------------- */
@ -97,9 +99,6 @@
BEGIN_DECLS
void flash_set_ws(uint32_t ws);
void flash_prefetch_enable(void);
void flash_prefetch_disable(void);
void flash_unlock(void);
void flash_lock(void);
void flash_clear_pgerr_flag(void);

View File

@ -74,7 +74,6 @@
BEGIN_DECLS
void flash_set_ws(uint32_t ws);
void flash_unlock(void);
void flash_lock(void);
void flash_clear_pgperr_flag(void);

View File

@ -124,8 +124,6 @@ void flash_dcache_enable(void);
void flash_dcache_disable(void);
void flash_icache_enable(void);
void flash_icache_disable(void);
void flash_prefetch_enable(void);
void flash_prefetch_disable(void);
void flash_dcache_reset(void);
void flash_icache_reset(void);
void flash_erase_all_sectors(uint32_t program_size);

View File

@ -29,6 +29,8 @@
#define LIBOPENCM3_FLASH_COMMON_L01_H
/**@{*/
#include <libopencm3/stm32/common/flash_common_all.h>
/* --- FLASH registers ----------------------------------------------------- */
#define FLASH_ACR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x00)
@ -110,9 +112,6 @@
BEGIN_DECLS
void flash_prefetch_enable(void);
void flash_prefetch_disable(void);
void flash_set_ws(uint32_t ws);
void flash_unlock_pecr(void);
void flash_lock_pecr(void);
void flash_unlock_progmem(void);

View File

@ -36,6 +36,7 @@
#define LIBOPENCM3_FLASH_H
/**@{*/
#include <libopencm3/stm32/common/flash_common_all.h>
#include <libopencm3/stm32/common/flash_common_f01.h>
/* --- FLASH_OPTION values ------------------------------------------------- */

View File

@ -43,6 +43,7 @@
/**@{*/
#include <libopencm3/stm32/common/flash_common_all.h>
#include <libopencm3/stm32/common/flash_common_f01.h>
/* --- FLASH_OPTION bytes ------------------------------------------------- */

View File

@ -31,6 +31,7 @@
#ifndef LIBOPENCM3_FLASH_H
#define LIBOPENCM3_FLASH_H
#include <libopencm3/stm32/common/flash_common_all.h>
#include <libopencm3/stm32/common/flash_common_f24.h>
#endif

View File

@ -32,6 +32,7 @@
#define LIBOPENCM3_FLASH_H
/**@{*/
#include <libopencm3/stm32/common/flash_common_all.h>
#include <libopencm3/stm32/common/flash_common_f234.h>
/* --- FLASH registers ----------------------------------------------------- */
@ -44,6 +45,8 @@
#define FLASH_ACR_PRFTBS (1 << 5)
#define FLASH_ACR_PRFTBE (1 << 4)
/** Compatibility alias */
#define FLASH_ACR_PRFTEN FLASH_ACR_PRFTBE
#define FLASH_ACR_HLFCYA (1 << 3)
/* --- FLASH_SR values ----------------------------------------------------- */
@ -70,8 +73,6 @@
BEGIN_DECLS
void flash_prefetch_enable(void);
void flash_prefetch_disable(void);
END_DECLS

View File

@ -31,6 +31,7 @@
#ifndef LIBOPENCM3_FLASH_H
#define LIBOPENCM3_FLASH_H
#include <libopencm3/stm32/common/flash_common_all.h>
#include <libopencm3/stm32/common/flash_common_f24.h>
#endif

View File

@ -32,6 +32,7 @@
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <libopencm3/stm32/common/flash_common_all.h>
/*
* For details see:
* PM0081 Programming manual: STM32F40xxx and STM32F41xxx Flash programming
@ -151,7 +152,6 @@
BEGIN_DECLS
void flash_set_ws(uint32_t ws);
void flash_unlock(void);
void flash_lock(void);
void flash_clear_pgperr_flag(void);
@ -165,8 +165,6 @@ void flash_clear_wrperr_flag(void);
void flash_clear_pgaerr_flag(void);
void flash_art_enable(void);
void flash_art_disable(void);
void flash_prefetch_enable(void);
void flash_prefetch_disable(void);
void flash_art_reset(void);
void flash_clear_status_flags(void);
void flash_erase_all_sectors(uint32_t program_size);

View File

@ -31,6 +31,7 @@
#define LIBOPENCM3_FLASH_H
/**@{*/
#include <libopencm3/stm32/common/flash_common_all.h>
#include <libopencm3/stm32/common/flash_common_l01.h>
/* --- FLASH registers ----------------------------------------------------- */

View File

@ -44,6 +44,7 @@
#define LIBOPENCM3_FLASH_H
/**@{*/
#include <libopencm3/stm32/common/flash_common_all.h>
#include <libopencm3/stm32/common/flash_common_l01.h>
/* --- FLASH registers ----------------------------------------------------- */

View File

@ -41,6 +41,8 @@
#ifndef LIBOPENCM3_FLASH_H
#define LIBOPENCM3_FLASH_H
#include <libopencm3/stm32/common/flash_common_all.h>
/* --- FLASH registers ----------------------------------------------------- */
#define FLASH_ACR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x00)
@ -222,7 +224,6 @@
BEGIN_DECLS
void flash_set_ws(uint32_t ws);
void flash_unlock(void);
void flash_lock(void);
void flash_clear_pgperr_flag(void);
@ -232,8 +233,6 @@ void flash_dcache_enable(void);
void flash_dcache_disable(void);
void flash_icache_enable(void);
void flash_icache_disable(void);
void flash_prefetch_enable(void);
void flash_prefetch_disable(void);
void flash_dcache_reset(void);
void flash_icache_reset(void);
void flash_clear_pgserr_flag(void);

View File

@ -0,0 +1,37 @@
/** @addtogroup flash_file
*
*/
/*
* This file is part of the libopencm3 project.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This library 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
/**@{*/
#include <libopencm3/stm32/flash.h>
void flash_prefetch_enable(void)
{
FLASH_ACR |= FLASH_ACR_PRFTEN;
}
void flash_prefetch_disable(void)
{
FLASH_ACR &= ~FLASH_ACR_PRFTEN;
}
/*@}*/

View File

@ -25,34 +25,6 @@
#include <libopencm3/stm32/flash.h>
/*---------------------------------------------------------------------------*/
/** @brief Enable the FLASH Prefetch Buffer
This buffer is used for instruction fetches and is enabled by default after
reset.
Note carefully the clock restrictions under which the prefetch buffer may be
enabled or disabled. Changes are normally made while the clock is running in
the power-on low frequency mode before being set to a higher speed mode.
See the reference manual for details.
*/
void flash_prefetch_enable(void)
{
FLASH_ACR |= FLASH_ACR_PRFTBE;
}
/*---------------------------------------------------------------------------*/
/** @brief Disable the FLASH Prefetch Buffer
Note carefully the clock restrictions under which the prefetch buffer may be
set to disabled. See the reference manual for details.
*/
void flash_prefetch_disable(void)
{
FLASH_ACR &= ~FLASH_ACR_PRFTBE;
}
/*---------------------------------------------------------------------------*/
/** @brief Set the Number of Wait States

View File

@ -81,34 +81,6 @@ void flash_icache_disable(void)
FLASH_ACR &= ~FLASH_ACR_ICEN;
}
/*---------------------------------------------------------------------------*/
/** @brief Enable the FLASH Prefetch Buffer
This buffer is used for instruction fetches and is enabled by default after
reset.
Note carefully the clock restrictions under which the prefetch buffer may be
enabled or disabled. Changes are normally made while the clock is running in
the power-on low frequency mode before being set to a higher speed mode.
See the reference manual for details.
*/
void flash_prefetch_enable(void)
{
FLASH_ACR |= FLASH_ACR_PRFTEN;
}
/*---------------------------------------------------------------------------*/
/** @brief Disable the FLASH Prefetch Buffer
Note carefully the clock restrictions under which the prefetch buffer may be
set to disabled. See the reference manual for details.
*/
void flash_prefetch_disable(void)
{
FLASH_ACR &= ~FLASH_ACR_PRFTEN;
}
/*---------------------------------------------------------------------------*/
/** @brief Reset the Data Cache

View File

@ -29,34 +29,6 @@
#include <libopencm3/stm32/flash.h>
/*---------------------------------------------------------------------------*/
/** @brief Enable the FLASH Prefetch Buffer
This buffer is used for instruction fetches and is enabled by default after
reset.
Note carefully the restrictions under which the prefetch buffer may be
enabled or disabled. Prefetch is only available when 64-bit
access is enabled.
*/
void flash_prefetch_enable(void)
{
FLASH_ACR |= FLASH_ACR_PRFTEN;
}
/*---------------------------------------------------------------------------*/
/** @brief Disable the FLASH Prefetch Buffer
Note carefully the restrictions under which the prefetch buffer may be
set to disabled. See the reference and programming manuals for details.
*/
void flash_prefetch_disable(void)
{
FLASH_ACR &= ~FLASH_ACR_PRFTEN;
}
/*---------------------------------------------------------------------------*/
/** @brief Set the Number of Wait States

View File

@ -42,11 +42,12 @@ OBJS = can.o flash.o rcc.o dma.o rtc.o comparator.o \
OBJS += gpio_common_all.o gpio_common_f0234.o crc_common_all.o crc_v2.o \
pwr_common_v1.o iwdg_common_all.o rtc_common_l1f024.o \
dma_common_l1f013.o exti_common_all.o \
flash_common_f01.o dac_common_all.o \
dac_common_all.o \
timer_common_all.o timer_common_f0234.o rcc_common_all.o
OBJS += adc_common_v2.o
OBJS += crs_common_all.o
OBJS += flash_common_all.o flash_common_f01.o
OBJS += usart_common_all.o usart_common_v2.o
OBJS += i2c_common_v2.o
OBJS += spi_common_all.o spi_common_v2.o

View File

@ -44,8 +44,9 @@ OBJS += crc_common_all.o dac_common_all.o dma_common_l1f013.o \
gpio_common_all.o i2c_common_v1.o iwdg_common_all.o \
pwr_common_v1.o \
timer_common_all.o usart_common_all.o usart_common_f124.o \
rcc_common_all.o exti_common_all.o \
flash_common_f01.o
rcc_common_all.o exti_common_all.o
OBJS += flash_common_all.o flash_common_f01.o
OBJS += spi_common_all.o spi_common_v1.o
OBJS += usb.o usb_control.o usb_standard.o usb_msc.o

View File

@ -43,8 +43,9 @@ OBJS += crc_common_all.o dac_common_all.o dma_common_f24.o \
iwdg_common_all.o rtc_common_l1f024.o \
timer_common_all.o timer_common_f0234.o \
timer_common_f24.o usart_common_all.o usart_common_f124.o \
flash_common_f234.o flash_common_f24.o hash_common_f24.o \
hash_common_f24.o \
crypto_common_f24.o exti_common_all.o rcc_common_all.o
OBJS += flash_common_all.o flash_common_f234.o flash_common_f24.o
OBJS += rng_common_v1.o
OBJS += spi_common_all.o spi_common_v1.o spi_common_v1_frf.o

View File

@ -42,9 +42,10 @@ OBJS = rcc.o adc.o can.o pwr.o dma.o flash.o desig.o
OBJS += gpio_common_all.o gpio_common_f0234.o \
dac_common_all.o crc_common_all.o crc_v2.o \
iwdg_common_all.o pwr_common_v1.o dma_common_l1f013.o\
timer_common_all.o timer_common_f0234.o flash_common_f234.o \
flash.o exti_common_all.o rcc_common_all.o
timer_common_all.o timer_common_f0234.o \
exti_common_all.o rcc_common_all.o
OBJS += adc_common_v2.o adc_common_v2_multi.o
OBJS += flash_common_all.o flash_common_f234.o
OBJS += usart_common_v2.o usart_common_all.o
OBJS += i2c_common_v2.o
OBJS += spi_common_all.o spi_common_v2.o

View File

@ -58,25 +58,5 @@ void flash_clear_status_flags(void)
flash_clear_eop_flag();
}
/**
* Enable the FLASH Prefetch Buffer
* This buffer is used for instruction fetches and is enabled by default after
* reset.
*/
void flash_prefetch_enable(void)
{
FLASH_ACR |= FLASH_ACR_PRFTBE;
}
/**
* Disable the FLASH Prefetch Buffer
* This buffer is used for instruction fetches and is enabled by default after
* reset.
*/
void flash_prefetch_disable(void)
{
FLASH_ACR &= ~FLASH_ACR_PRFTBE;
}
/**@}*/

View File

@ -47,9 +47,10 @@ OBJS += crc_common_all.o dac_common_all.o dma_common_f24.o \
iwdg_common_all.o pwr_common_v1.o rtc_common_l1f024.o \
timer_common_all.o \
timer_common_f0234.o timer_common_f24.o usart_common_all.o \
usart_common_f124.o flash_common_f234.o flash_common_f24.o \
usart_common_f124.o \
hash_common_f24.o crypto_common_f24.o exti_common_all.o \
rcc_common_all.o
OBJS += flash_common_all.o flash_common_f234.o flash_common_f24.o
OBJS += rng_common_v1.o
OBJS += spi_common_all.o spi_common_v1.o spi_common_v1_frf.o

View File

@ -42,7 +42,7 @@ TGT_CFLAGS += $(STANDARD_FLAGS)
ARFLAGS = rcs
OBJS = flash.o pwr.o rcc.o
OBJS = flash_common_all.o flash.o pwr.o rcc.o
OBJS += gpio.o gpio_common_all.o gpio_common_f0234.o
OBJS += rcc_common_all.o

View File

@ -217,35 +217,6 @@ void flash_art_enable(void)
FLASH_ACR |= FLASH_ACR_ARTEN;
}
/*---------------------------------------------------------------------------*/
/** @brief Enable the FLASH Prefetch Buffer
This buffer is used for instruction fetches and is enabled by default after
reset.
Note carefully the clock restrictions under which the prefetch buffer may be
enabled or disabled. Changes are normally made while the clock is running in
the power-on low frequency mode before being set to a higher speed mode.
See the reference manual for details.
*/
void flash_prefetch_enable(void)
{
FLASH_ACR |= FLASH_ACR_PRFTEN;
}
/*---------------------------------------------------------------------------*/
/** @brief Disable the FLASH Prefetch Buffer
Note carefully the clock restrictions under which the prefetch buffer may be
set to disabled. See the reference manual for details.
*/
void flash_prefetch_disable(void)
{
FLASH_ACR &= ~FLASH_ACR_PRFTEN;
}
/*---------------------------------------------------------------------------*/
/** @brief Reset the ART Cache

View File

@ -46,7 +46,7 @@ OBJS += adc_common_v2.o
OBJS += crs_common_all.o
OBJS += dma_common_l1f013.o
OBJS += exti_common_all.o
OBJS += flash.o flash_common_l01.o
OBJS += flash.o flash_common_all.o flash_common_l01.o
OBJS += i2c_common_v2.o
OBJS += rng_common_v1.o
OBJS += usart_common_all.o usart_common_v2.o

View File

@ -38,7 +38,7 @@ ARFLAGS = rcs
OBJS = desig.o flash.o rcc.o dma.o lcd.o
OBJS += crc_common_all.o dac_common_all.o
OBJS += dma_common_l1f013.o
OBJS += flash_common_l01.o
OBJS += flash_common_all.o flash_common_l01.o
OBJS += gpio_common_all.o gpio_common_f0234.o
OBJS += i2c_common_v1.o iwdg_common_all.o
OBJS += pwr_common_v1.o pwr_common_v2.o rtc_common_l1f024.o

View File

@ -47,6 +47,7 @@ OBJS += exti_common_all.o
OBJS += adc_common_v2.o adc_common_v2_multi.o
OBJS += crc_common_all.o crc_v2.o
OBJS += crs_common_all.o
OBJS += flash_common_all.o
OBJS += rng_common_v1.o
OBJS += timer_common_all.o
OBJS += i2c_common_v2.o

View File

@ -42,31 +42,6 @@
#include <libopencm3/stm32/flash.h>
/** @brief Enable the FLASH Prefetch Buffer
This buffer is used for instruction fetches and is enabled by default after
reset.
Note carefully the clock restrictions under which the prefetch buffer may be
enabled or disabled. Changes are normally made while the clock is running in
the power-on low frequency mode before being set to a higher speed mode.
See the reference manual for details.
*/
void flash_prefetch_enable(void)
{
FLASH_ACR |= FLASH_ACR_PRFTEN;
}
/** @brief Disable the FLASH Prefetch Buffer
Note carefully the clock restrictions under which the prefetch buffer may be
set to disabled. See the reference manual for details.
*/
void flash_prefetch_disable(void)
{
FLASH_ACR &= ~FLASH_ACR_PRFTEN;
}
/** @brief Set the Number of Wait States
Used to match the system clock to the FLASH memory access time. See the