From a9a85f080bb8fc729125d3ad162058f063496e60 Mon Sep 17 00:00:00 2001 From: Ken Sarkies Date: Thu, 7 Mar 2013 18:35:04 +1030 Subject: [PATCH] Add test in common headers for improper inclusion of such files in application. (prevents inclusion and also issues warning) Changes to some source files to remove references to common headers. Changes to rng.h to make guard symbols the same in f2 and f4. --- include/libopencm3/stm32/common/crc_common_all.h | 9 ++++++++- include/libopencm3/stm32/common/dac_common_all.h | 9 +++++++++ include/libopencm3/stm32/common/dma_common_f13.h | 9 +++++++++ include/libopencm3/stm32/common/dma_common_f24.h | 8 +++++++- include/libopencm3/stm32/common/gpio_common_all.h | 8 +++++++- include/libopencm3/stm32/common/gpio_common_f24.h | 8 +++++++- include/libopencm3/stm32/common/i2c_common_all.h | 8 +++++++- include/libopencm3/stm32/common/i2c_common_f24.h | 8 +++++++- include/libopencm3/stm32/common/iwdg_common_all.h | 8 +++++++- include/libopencm3/stm32/common/pwr_common_all.h | 9 ++++++++- include/libopencm3/stm32/common/rng_common_f24.h | 9 +++++++++ include/libopencm3/stm32/common/rtc_common_bcd.h | 11 +++++++++-- include/libopencm3/stm32/common/spi_common_all.h | 9 ++++++++- include/libopencm3/stm32/common/spi_common_f24.h | 8 +++++++- include/libopencm3/stm32/common/usart_common_all.h | 8 +++++++- include/libopencm3/stm32/common/usart_common_f24.h | 9 ++++++++- include/libopencm3/stm32/f2/rng.h | 4 ++-- include/libopencm3/stm32/f4/rng.h | 4 ++-- lib/stm32/common/gpio_common_f24.c | 1 - lib/stm32/f1/gpio.c | 1 - lib/stm32/f2/gpio.c | 2 -- lib/stm32/f4/gpio.c | 2 -- lib/stm32/l1/gpio.c | 2 -- 23 files changed, 128 insertions(+), 26 deletions(-) diff --git a/include/libopencm3/stm32/common/crc_common_all.h b/include/libopencm3/stm32/common/crc_common_all.h index 209f19bf..ad87c667 100644 --- a/include/libopencm3/stm32/common/crc_common_all.h +++ b/include/libopencm3/stm32/common/crc_common_all.h @@ -23,8 +23,11 @@ * along with this library. If not, see . */ -/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY, BUT ONLY VIA CRC.H */ +/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY, BUT ONLY VIA CRC.H +The order of header inclusion is important. crc.h includes the device +specific memorymap.h header before including this header file.*/ +#ifdef LIBOPENCM3_CRC_H #ifndef LIBOPENCM3_CRC_COMMON_ALL_H #define LIBOPENCM3_CRC_COMMON_ALL_H @@ -87,3 +90,7 @@ u32 crc_calculate_block(u32 *datap, int size); END_DECLS #endif +#else +#warning "crc_common_all.h should not be included explicitly, only via crc.h" +#endif + diff --git a/include/libopencm3/stm32/common/dac_common_all.h b/include/libopencm3/stm32/common/dac_common_all.h index 94bf01bb..b3f75682 100644 --- a/include/libopencm3/stm32/common/dac_common_all.h +++ b/include/libopencm3/stm32/common/dac_common_all.h @@ -25,6 +25,11 @@ /**@{*/ +/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY, BUT ONLY VIA DAC.H +The order of header inclusion is important. dac.h includes the device +specific memorymap.h header before including this header file.*/ + +#ifdef LIBOPENCM3_DAC_H #ifndef LIBOPENCM3_DAC_COMMON_ALL_H #define LIBOPENCM3_DAC_COMMON_ALL_H @@ -403,5 +408,9 @@ void dac_software_trigger(data_channel dac_channel); END_DECLS #endif +#else +#warning "dac_common_all.h should not be included explicitly, only via dac.h" +#endif + /**@}*/ diff --git a/include/libopencm3/stm32/common/dma_common_f13.h b/include/libopencm3/stm32/common/dma_common_f13.h index 68ade004..642ed730 100644 --- a/include/libopencm3/stm32/common/dma_common_f13.h +++ b/include/libopencm3/stm32/common/dma_common_f13.h @@ -27,6 +27,11 @@ /**@{*/ +/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY, BUT ONLY VIA DMA.H +The order of header inclusion is important. dma.h includes the device +specific memorymap.h header before including this header file.*/ + +#ifdef LIBOPENCM3_DMA_H #ifndef LIBOPENCM3_DMA_COMMON_F13_H #define LIBOPENCM3_DMA_COMMON_F13_H @@ -390,5 +395,9 @@ void dma_set_number_of_data(u32 dma, u8 channel, u16 number); END_DECLS #endif +#else +#warning "dma_common_f13.h should not be included explicitly, only via dma.h" +#endif + /**@}*/ diff --git a/include/libopencm3/stm32/common/dma_common_f24.h b/include/libopencm3/stm32/common/dma_common_f24.h index ecf9fcfc..c8aab3ea 100644 --- a/include/libopencm3/stm32/common/dma_common_f24.h +++ b/include/libopencm3/stm32/common/dma_common_f24.h @@ -24,8 +24,11 @@ * along with this library. If not, see . */ -/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY, BUT ONLY VIA DMA.H */ +/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY, BUT ONLY VIA DMA.H +The order of header inclusion is important. dma.h includes the device +specific memorymap.h header before including this header file.*/ +#ifdef LIBOPENCM3_DMA_H #ifndef LIBOPENCM3_DMA_COMMON_F24_H #define LIBOPENCM3_DMA_COMMON_F24_H @@ -605,4 +608,7 @@ void dma_set_number_of_data(u32 dma, u8 stream, u16 number); END_DECLS /**@}*/ #endif +#else +#warning "dma_common_f24.h should not be included explicitly, only via dma.h" +#endif diff --git a/include/libopencm3/stm32/common/gpio_common_all.h b/include/libopencm3/stm32/common/gpio_common_all.h index 4d03db09..beac325e 100644 --- a/include/libopencm3/stm32/common/gpio_common_all.h +++ b/include/libopencm3/stm32/common/gpio_common_all.h @@ -25,8 +25,11 @@ * along with this library. If not, see . */ -/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY, BUT ONLY VIA GPIO.H */ +/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY, BUT ONLY VIA GPIO.H +The order of header inclusion is important. gpio.h includes the device +specific memorymap.h header before including this header file.*/ +#if defined (LIBOPENCM3_GPIO_H) || defined (LIBOPENCM3_GPIO_COMMON_F24_H) #ifndef LIBOPENCM3_GPIO_COMMON_ALL_H #define LIBOPENCM3_GPIO_COMMON_ALL_H @@ -79,4 +82,7 @@ END_DECLS /**@}*/ #endif +#else +#warning "gpio_common_all.h should not be included explicitly, only via gpio.h" +#endif diff --git a/include/libopencm3/stm32/common/gpio_common_f24.h b/include/libopencm3/stm32/common/gpio_common_f24.h index 2ce0167e..6263d516 100644 --- a/include/libopencm3/stm32/common/gpio_common_f24.h +++ b/include/libopencm3/stm32/common/gpio_common_f24.h @@ -24,8 +24,11 @@ * along with this library. If not, see . */ -/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY, BUT ONLY VIA GPIO.H */ +/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY, BUT ONLY VIA GPIO.H +The order of header inclusion is important. gpio.h includes the device +specific memorymap.h header before including this header file.*/ +#ifdef LIBOPENCM3_GPIO_H #ifndef LIBOPENCM3_GPIO_COMMON_F24_H #define LIBOPENCM3_GPIO_COMMON_F24_H @@ -287,4 +290,7 @@ void gpio_set_af(u32 gpioport, u8 alt_func_num, u16 gpios); END_DECLS /**@}*/ #endif +#else +#warning "gpio_common_f24.h should not be included explicitly, only via gpio.h" +#endif diff --git a/include/libopencm3/stm32/common/i2c_common_all.h b/include/libopencm3/stm32/common/i2c_common_all.h index 7f6d447e..cd954cb8 100644 --- a/include/libopencm3/stm32/common/i2c_common_all.h +++ b/include/libopencm3/stm32/common/i2c_common_all.h @@ -23,8 +23,11 @@ * along with this library. If not, see . */ -/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY, BUT ONLY VIA I2C.H */ +/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY, BUT ONLY VIA I2C.H +The order of header inclusion is important. i2c.h includes the device +specific memorymap.h header before including this header file.*/ +#if defined (LIBOPENCM3_I2C_H) || defined (LIBOPENCM3_I2C_COMMON_F24_H) #ifndef LIBOPENCM3_I2C_COMMON_ALL_H #define LIBOPENCM3_I2C_COMMON_ALL_H @@ -382,6 +385,9 @@ void i2c_clear_dma_last_transfer(u32 i2c); END_DECLS +#endif +#else +#warning "i2c_common_all.h should not be included explicitly, only via i2c.h" #endif /**@}*/ diff --git a/include/libopencm3/stm32/common/i2c_common_f24.h b/include/libopencm3/stm32/common/i2c_common_f24.h index c267bd85..8cb4ae7f 100644 --- a/include/libopencm3/stm32/common/i2c_common_f24.h +++ b/include/libopencm3/stm32/common/i2c_common_f24.h @@ -23,8 +23,11 @@ * along with this library. If not, see . */ -/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY, BUT ONLY VIA I2C.H */ +/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY, BUT ONLY VIA I2C.H +The order of header inclusion is important. i2c.h includes the device +specific memorymap.h header before including this header file.*/ +#ifdef LIBOPENCM3_I2C_H #ifndef LIBOPENCM3_I2C_COMMON_F24_H #define LIBOPENCM3_I2C_COMMON_F24_H @@ -37,3 +40,6 @@ /**@}*/ #endif +#else +#warning "i2c_common_f24.h should not be included explicitly, only via i2c.h" +#endif diff --git a/include/libopencm3/stm32/common/iwdg_common_all.h b/include/libopencm3/stm32/common/iwdg_common_all.h index b75e4d14..eed4cdb9 100644 --- a/include/libopencm3/stm32/common/iwdg_common_all.h +++ b/include/libopencm3/stm32/common/iwdg_common_all.h @@ -22,8 +22,11 @@ * along with this library. If not, see . */ -/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY, BUT ONLY VIA IWDG.H */ +/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY, BUT ONLY VIA IWDG.H +The order of header inclusion is important. iwdg.h includes the device +specific memorymap.h header before including this header file.*/ +#ifdef LIBOPENCM3_IWDG_H #ifndef LIBOPENCM3_IWDG_COMMON_ALL_H #define LIBOPENCM3_IWDG_COMMON_ALL_H @@ -108,6 +111,9 @@ void iwdg_reset(void); END_DECLS +#endif +#else +#warning "iwdg_common_all.h should not be included explicitly, only via iwdg.h" #endif /**@}*/ diff --git a/include/libopencm3/stm32/common/pwr_common_all.h b/include/libopencm3/stm32/common/pwr_common_all.h index a6b38d88..fd9b4224 100644 --- a/include/libopencm3/stm32/common/pwr_common_all.h +++ b/include/libopencm3/stm32/common/pwr_common_all.h @@ -23,8 +23,11 @@ * along with this library. If not, see . */ -/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY, BUT ONLY VIA PWR.H */ +/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY, BUT ONLY VIA PWR.H +The order of header inclusion is important. pwr.h includes the device +specific memorymap.h header before including this header file.*/ +#ifdef LIBOPENCM3_PWR_H #ifndef LIBOPENCM3_PWR_COMMON_ALL_H #define LIBOPENCM3_PWR_COMMON_ALL_H @@ -121,3 +124,7 @@ END_DECLS /**@}*/ #endif +#else +#warning "pwr_common_all.h should not be included explicitly, only via pwr.h" +#endif + diff --git a/include/libopencm3/stm32/common/rng_common_f24.h b/include/libopencm3/stm32/common/rng_common_f24.h index 7d98bfab..4fb3745c 100644 --- a/include/libopencm3/stm32/common/rng_common_f24.h +++ b/include/libopencm3/stm32/common/rng_common_f24.h @@ -16,6 +16,11 @@ * along with this library. If not, see . */ +/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY, BUT ONLY VIA RNG.H +The order of header inclusion is important. rng.h includes the device +specific memorymap.h header before including this header file.*/ + +#ifdef LIBOPENCM3_RNG_H #ifndef LIBOPENCM3_RNG_COMMON_F24_H #define LIBOPENCM3_RNG_COMMON_F24_H @@ -59,3 +64,7 @@ #define RNG_SR_SEIS (1 << 6) #endif +#else +#warning "rng_common_f24.h should not be included explicitly, only via rng.h" +#endif + diff --git a/include/libopencm3/stm32/common/rtc_common_bcd.h b/include/libopencm3/stm32/common/rtc_common_bcd.h index 41afe3f5..791af8db 100644 --- a/include/libopencm3/stm32/common/rtc_common_bcd.h +++ b/include/libopencm3/stm32/common/rtc_common_bcd.h @@ -22,8 +22,6 @@ * along with this library. If not, see . */ -/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY, BUT ONLY VIA RTC.H */ - /* * This covers the "version 2" RTC peripheral. This is completely different * to the v1 RTC periph on the F1 series devices. It has BCD counters, with @@ -32,6 +30,11 @@ * only support a subset. */ +/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY, BUT ONLY VIA RTC.H +The order of header inclusion is important. rtc.h includes the device +specific memorymap.h header before including this header file.*/ + +#ifdef LIBOPENCM3_RTC_H #ifndef LIBOPENCM3_RTC2_H #define LIBOPENCM3_RTC2_H @@ -316,4 +319,8 @@ END_DECLS /**@}*/ #endif /* RTC2_H */ +#else +#warning "rtc_common_bcd.h should not be included explicitly, only via rtc.h" +#endif + diff --git a/include/libopencm3/stm32/common/spi_common_all.h b/include/libopencm3/stm32/common/spi_common_all.h index a337c371..26086f7c 100644 --- a/include/libopencm3/stm32/common/spi_common_all.h +++ b/include/libopencm3/stm32/common/spi_common_all.h @@ -23,8 +23,11 @@ * along with this library. If not, see . */ -/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY, BUT ONLY VIA SPI.H */ +/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY, BUT ONLY VIA SPI.H +The order of header inclusion is important. spi.h includes the device +specific memorymap.h header before including this header file.*/ +#if defined (LIBOPENCM3_SPI_H) || defined (LIBOPENCM3_SPI_COMMON_F24_H) #ifndef LIBOPENCM3_SPI_COMMON_ALL_H #define LIBOPENCM3_SPI_COMMON_ALL_H @@ -402,3 +405,7 @@ END_DECLS /**@}*/ #endif +#else +#warning "spi_common_all.h should not be included explicitly, only via spi.h" +#endif + diff --git a/include/libopencm3/stm32/common/spi_common_f24.h b/include/libopencm3/stm32/common/spi_common_f24.h index 0a5873dd..ad901429 100644 --- a/include/libopencm3/stm32/common/spi_common_f24.h +++ b/include/libopencm3/stm32/common/spi_common_f24.h @@ -22,8 +22,11 @@ * along with this library. If not, see . */ -/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY, BUT ONLY VIA SPI.H */ +/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY, BUT ONLY VIA SPI.H +The order of header inclusion is important. spi.h includes the device +specific memorymap.h header before including this header file.*/ +#ifdef LIBOPENCM3_SPI_H #ifndef LIBOPENCM3_SPI_COMMON_F24_H #define LIBOPENCM3_SPI_COMMON_F24_H @@ -49,6 +52,9 @@ /* TIFRFE: TI frame format error */ #define SPI_SR_TIFRFE (1 << 8) +#endif +#else +#warning "spi_common_f24.h should not be included explicitly, only via spi.h" #endif /**@}*/ diff --git a/include/libopencm3/stm32/common/usart_common_all.h b/include/libopencm3/stm32/common/usart_common_all.h index b7ab394a..2f33942b 100644 --- a/include/libopencm3/stm32/common/usart_common_all.h +++ b/include/libopencm3/stm32/common/usart_common_all.h @@ -25,8 +25,11 @@ /**@{*/ -/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY, BUT ONLY VIA SPI.H */ +/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY, BUT ONLY VIA USART.H +The order of header inclusion is important. usart.h includes the device +specific memorymap.h header before including this header file.*/ +#if defined (LIBOPENCM3_USART_H) || defined (LIBOPENCM3_USART_COMMON_F24_H) #ifndef LIBOPENCM3_USART_COMMON_ALL_H #define LIBOPENCM3_USART_COMMON_ALL_H @@ -370,6 +373,9 @@ bool usart_get_interrupt_source(u32 usart, u32 flag); END_DECLS +#endif +#else +#warning "usart_common_all.h should not be included explicitly, only via usart.h" #endif /**@}*/ diff --git a/include/libopencm3/stm32/common/usart_common_f24.h b/include/libopencm3/stm32/common/usart_common_f24.h index 301eceb7..22bb194e 100644 --- a/include/libopencm3/stm32/common/usart_common_f24.h +++ b/include/libopencm3/stm32/common/usart_common_f24.h @@ -24,8 +24,11 @@ * along with this library. If not, see . */ -/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY, BUT ONLY VIA SPI.H */ +/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY, BUT ONLY VIA USART.H +The order of header inclusion is important. usart.h includes the device +specific memorymap.h header before including this header file.*/ +#ifdef LIBOPENCM3_USART_H #ifndef LIBOPENCM3_USART_COMMON_F24_H #define LIBOPENCM3_USART_COMMON_F24_H @@ -69,3 +72,7 @@ #define USART_CR3_ONEBIT (1 << 11) #endif +#else +#warning "usart_common_f24.h should not be included explicitly, only via usart.h" +#endif + diff --git a/include/libopencm3/stm32/f2/rng.h b/include/libopencm3/stm32/f2/rng.h index 403c7c77..2dbd5f17 100644 --- a/include/libopencm3/stm32/f2/rng.h +++ b/include/libopencm3/stm32/f2/rng.h @@ -15,8 +15,8 @@ * along with this library. If not, see . */ -#ifndef LIBOPENCM3_RNG_F2_H -#define LIBOPENCM3_RNG_F2_H +#ifndef LIBOPENCM3_RNG_H +#define LIBOPENCM3_RNG_H #include #include diff --git a/include/libopencm3/stm32/f4/rng.h b/include/libopencm3/stm32/f4/rng.h index e8e6cc43..2dbd5f17 100644 --- a/include/libopencm3/stm32/f4/rng.h +++ b/include/libopencm3/stm32/f4/rng.h @@ -15,8 +15,8 @@ * along with this library. If not, see . */ -#ifndef LIBOPENCM3_RNG_F4_H -#define LIBOPENCM3_RNG_F4_H +#ifndef LIBOPENCM3_RNG_H +#define LIBOPENCM3_RNG_H #include #include diff --git a/lib/stm32/common/gpio_common_f24.c b/lib/stm32/common/gpio_common_f24.c index 63c18c3f..dfa2bacd 100644 --- a/lib/stm32/common/gpio_common_f24.c +++ b/lib/stm32/common/gpio_common_f24.c @@ -68,7 +68,6 @@ Example 2: Digital input on port C12 with pullup /**@{*/ -#include #include /*-----------------------------------------------------------------------------*/ diff --git a/lib/stm32/f1/gpio.c b/lib/stm32/f1/gpio.c index cbb6b9d3..0cc4f5e0 100644 --- a/lib/stm32/f1/gpio.c +++ b/lib/stm32/f1/gpio.c @@ -73,7 +73,6 @@ LGPL License Terms @ref lgpl_license */ #include -#include /**@{*/ diff --git a/lib/stm32/f2/gpio.c b/lib/stm32/f2/gpio.c index 370f59ba..052e306f 100644 --- a/lib/stm32/f2/gpio.c +++ b/lib/stm32/f2/gpio.c @@ -29,5 +29,3 @@ LGPL License Terms @ref lgpl_license */ #include -#include - diff --git a/lib/stm32/f4/gpio.c b/lib/stm32/f4/gpio.c index db42e8da..ea59ae79 100644 --- a/lib/stm32/f4/gpio.c +++ b/lib/stm32/f4/gpio.c @@ -29,5 +29,3 @@ LGPL License Terms @ref lgpl_license */ #include -#include - diff --git a/lib/stm32/l1/gpio.c b/lib/stm32/l1/gpio.c index fd42ba87..46ea658a 100644 --- a/lib/stm32/l1/gpio.c +++ b/lib/stm32/l1/gpio.c @@ -29,5 +29,3 @@ LGPL License Terms @ref lgpl_license */ #include -#include -