xref: /btstack/port/stm32-f4discovery-cc256x/bsp/stm32f4_discovery.h (revision 225f4ba4fe806afeda1ee8519bb5f4a8ce540af2)
1 /**
2   ******************************************************************************
3   * @file    stm32f4_discovery.h
4   * @author  MCD Application Team
5   * @version V2.1.2
6   * @date    27-January-2017
7   * @brief   This file contains definitions for STM32F4-Discovery Kit's Leds and
8   *          push-button hardware resources.
9   ******************************************************************************
10   * @attention
11   *
12   * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
13   *
14   * Redistribution and use in source and binary forms, with or without modification,
15   * are permitted provided that the following conditions are met:
16   *   1. Redistributions of source code must retain the above copyright notice,
17   *      this list of conditions and the following disclaimer.
18   *   2. Redistributions in binary form must reproduce the above copyright notice,
19   *      this list of conditions and the following disclaimer in the documentation
20   *      and/or other materials provided with the distribution.
21   *   3. Neither the name of STMicroelectronics nor the names of its contributors
22   *      may be used to endorse or promote products derived from this software
23   *      without specific prior written permission.
24   *
25   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
29   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
33   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35   *
36   ******************************************************************************
37   */
38 
39 /* Define to prevent recursive inclusion -------------------------------------*/
40 #ifndef __STM32F4_DISCOVERY_H
41 #define __STM32F4_DISCOVERY_H
42 
43 #ifdef __cplusplus
44  extern "C" {
45 #endif
46 
47 /* Includes ------------------------------------------------------------------*/
48 #include "stm32f4xx_hal.h"
49 
50 /** @addtogroup BSP
51   * @{
52   */
53 
54 /** @addtogroup STM32F4_DISCOVERY
55   * @{
56   */
57 
58 /** @addtogroup STM32F4_DISCOVERY_LOW_LEVEL
59   * @{
60   */
61 
62 /** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_Exported_Types STM32F4 DISCOVERY LOW LEVEL_Exported_Types
63   * @{
64   */
65 typedef enum
66 {
67   LED4 = 0,
68   LED3 = 1,
69   LED5 = 2,
70   LED6 = 3
71 } Led_TypeDef;
72 
73 typedef enum
74 {
75   BUTTON_KEY = 0,
76 } Button_TypeDef;
77 
78 typedef enum
79 {
80   BUTTON_MODE_GPIO = 0,
81   BUTTON_MODE_EXTI = 1
82 } ButtonMode_TypeDef;
83 /**
84   * @}
85   */
86 
87 /** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_Exported_Constants STM32F4 DISCOVERY LOW LEVEL Exported Constants
88   * @{
89   */
90 
91 /**
92 * @brief  Define for STM32F4_DISCOVERY board
93 */
94 #if !defined (USE_STM32F4_DISCO)
95  #define USE_STM32F4_DISCO
96 #endif
97 
98 /** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_LED STM32F4 DISCOVERY LOW LEVEL LED
99   * @{
100   */
101 #define LEDn                             4
102 
103 #define LED4_PIN                         GPIO_PIN_12
104 #define LED4_GPIO_PORT                   GPIOD
105 #define LED4_GPIO_CLK_ENABLE()           __HAL_RCC_GPIOD_CLK_ENABLE()
106 #define LED4_GPIO_CLK_DISABLE()          __HAL_RCC_GPIOD_CLK_DISABLE()
107 
108 #define LED3_PIN                         GPIO_PIN_13
109 #define LED3_GPIO_PORT                   GPIOD
110 #define LED3_GPIO_CLK_ENABLE()           __HAL_RCC_GPIOD_CLK_ENABLE()
111 #define LED3_GPIO_CLK_DISABLE()          __HAL_RCC_GPIOD_CLK_DISABLE()
112 
113 #define LED5_PIN                         GPIO_PIN_14
114 #define LED5_GPIO_PORT                   GPIOD
115 #define LED5_GPIO_CLK_ENABLE()           __HAL_RCC_GPIOD_CLK_ENABLE()
116 #define LED5_GPIO_CLK_DISABLE()          __HAL_RCC_GPIOD_CLK_DISABLE()
117 
118 #define LED6_PIN                         GPIO_PIN_15
119 #define LED6_GPIO_PORT                   GPIOD
120 #define LED6_GPIO_CLK_ENABLE()           __HAL_RCC_GPIOD_CLK_ENABLE()
121 #define LED6_GPIO_CLK_DISABLE()          __HAL_RCC_GPIOD_CLK_DISABLE()
122 
123 #define LEDx_GPIO_CLK_ENABLE(__INDEX__) do{if((__INDEX__) == 0) LED4_GPIO_CLK_ENABLE(); else \
124                                            if((__INDEX__) == 1) LED3_GPIO_CLK_ENABLE(); else \
125                                            if((__INDEX__) == 2) LED5_GPIO_CLK_ENABLE(); else \
126                                            if((__INDEX__) == 3) LED6_GPIO_CLK_ENABLE(); \
127                                            }while(0)
128 
129 #define LEDx_GPIO_CLK_DISABLE(__INDEX__) do{if((__INDEX__) == 0) LED4_GPIO_CLK_DISABLE(); else \
130                                             if((__INDEX__) == 1) LED3_GPIO_CLK_DISABLE(); else \
131                                             if((__INDEX__) == 2) LED5_GPIO_CLK_DISABLE(); else \
132                                             if((__INDEX__) == 3) LED6_GPIO_CLK_DISABLE(); \
133                                             }while(0)
134 /**
135   * @}
136   */
137 
138 /** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_BUTTON STM32F4 DISCOVERY LOW LEVEL BUTTON
139   * @{
140   */
141 #define BUTTONn                          1
142 
143 /**
144  * @brief Wakeup push-button
145  */
146 #define KEY_BUTTON_PIN                GPIO_PIN_0
147 #define KEY_BUTTON_GPIO_PORT          GPIOA
148 #define KEY_BUTTON_GPIO_CLK_ENABLE()  __HAL_RCC_GPIOA_CLK_ENABLE()
149 #define KEY_BUTTON_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
150 #define KEY_BUTTON_EXTI_IRQn          EXTI0_IRQn
151 
152 #define BUTTONx_GPIO_CLK_ENABLE(__INDEX__)    do{if((__INDEX__) == 0) KEY_BUTTON_GPIO_CLK_ENABLE(); \
153                                                 }while(0)
154 
155 #define BUTTONx_GPIO_CLK_DISABLE(__INDEX__)    do{if((__INDEX__) == 0) KEY_BUTTON_GPIO_CLK_DISABLE(); \
156                                                  }while(0)
157 /**
158   * @}
159   */
160 
161 /** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_BUS STM32F4 DISCOVERY LOW LEVEL BUS
162   * @{
163   */
164 
165 /*############################### SPI1 #######################################*/
166 #define DISCOVERY_SPIx                              SPI1
167 #define DISCOVERY_SPIx_CLK_ENABLE()                 __HAL_RCC_SPI1_CLK_ENABLE()
168 #define DISCOVERY_SPIx_GPIO_PORT                    GPIOA                      /* GPIOA */
169 #define DISCOVERY_SPIx_AF                           GPIO_AF5_SPI1
170 #define DISCOVERY_SPIx_GPIO_CLK_ENABLE()            __HAL_RCC_GPIOA_CLK_ENABLE()
171 #define DISCOVERY_SPIx_GPIO_CLK_DISABLE()           __HAL_RCC_GPIOA_CLK_DISABLE()
172 #define DISCOVERY_SPIx_SCK_PIN                      GPIO_PIN_5                 /* PA.05 */
173 #define DISCOVERY_SPIx_MISO_PIN                     GPIO_PIN_6                 /* PA.06 */
174 #define DISCOVERY_SPIx_MOSI_PIN                     GPIO_PIN_7                 /* PA.07 */
175 
176 /* Maximum Timeout values for flags waiting loops. These timeouts are not based
177    on accurate values, they just guarantee that the application will not remain
178    stuck if the SPI communication is corrupted.
179    You may modify these timeout values depending on CPU frequency and application
180    conditions (interrupts routines ...). */
181 #define SPIx_TIMEOUT_MAX                            0x1000 /*<! The value of the maximal timeout for BUS waiting loops */
182 
183 
184 /*############################# I2C1 #########################################*/
185 /* I2C clock speed configuration (in Hz) */
186 #ifndef BSP_I2C_SPEED
187  #define BSP_I2C_SPEED                            100000
188 #endif /* BSP_I2C_SPEED */
189 
190 /* I2C peripheral configuration defines (control interface of the audio codec) */
191 #define DISCOVERY_I2Cx                            I2C1
192 #define DISCOVERY_I2Cx_CLK_ENABLE()               __HAL_RCC_I2C1_CLK_ENABLE()
193 #define DISCOVERY_I2Cx_SCL_SDA_GPIO_CLK_ENABLE()  __HAL_RCC_GPIOB_CLK_ENABLE()
194 #define DISCOVERY_I2Cx_SCL_SDA_AF                 GPIO_AF4_I2C1
195 #define DISCOVERY_I2Cx_SCL_SDA_GPIO_PORT          GPIOB
196 #define DISCOVERY_I2Cx_SCL_PIN                    GPIO_PIN_6
197 #define DISCOVERY_I2Cx_SDA_PIN                    GPIO_PIN_9
198 
199 #define DISCOVERY_I2Cx_FORCE_RESET()              __HAL_RCC_I2C1_FORCE_RESET()
200 #define DISCOVERY_I2Cx_RELEASE_RESET()            __HAL_RCC_I2C1_RELEASE_RESET()
201 
202 /* I2C interrupt requests */
203 #define DISCOVERY_I2Cx_EV_IRQn                    I2C1_EV_IRQn
204 #define DISCOVERY_I2Cx_ER_IRQn                    I2C1_ER_IRQn
205 
206 /* Maximum Timeout values for flags waiting loops. These timeouts are not based
207    on accurate values, they just guarantee that the application will not remain
208    stuck if the SPI communication is corrupted.
209    You may modify these timeout values depending on CPU frequency and application
210    conditions (interrupts routines ...). */
211 #define I2Cx_TIMEOUT_MAX    0x1000 /*<! The value of the maximal timeout for BUS waiting loops */
212 
213 
214 /*############################# ACCELEROMETER ################################*/
215 /* Read/Write command */
216 #define READWRITE_CMD                     ((uint8_t)0x80)
217 /* Multiple byte read/write command */
218 #define MULTIPLEBYTE_CMD                  ((uint8_t)0x40)
219 /* Dummy Byte Send by the SPI Master device in order to generate the Clock to the Slave device */
220 #define DUMMY_BYTE                        ((uint8_t)0x00)
221 
222 /* Chip Select macro definition */
223 #define ACCELERO_CS_LOW()       HAL_GPIO_WritePin(ACCELERO_CS_GPIO_PORT, ACCELERO_CS_PIN, GPIO_PIN_RESET)
224 #define ACCELERO_CS_HIGH()      HAL_GPIO_WritePin(ACCELERO_CS_GPIO_PORT, ACCELERO_CS_PIN, GPIO_PIN_SET)
225 
226 /**
227   * @brief  ACCELEROMETER Interface pins
228   */
229 #define ACCELERO_CS_PIN                        GPIO_PIN_3                 /* PE.03 */
230 #define ACCELERO_CS_GPIO_PORT                  GPIOE                      /* GPIOE */
231 #define ACCELERO_CS_GPIO_CLK_ENABLE()          __HAL_RCC_GPIOE_CLK_ENABLE()
232 #define ACCELERO_CS_GPIO_CLK_DISABLE()         __HAL_RCC_GPIOE_CLK_DISABLE()
233 #define ACCELERO_INT_GPIO_PORT                 GPIOE                      /* GPIOE */
234 #define ACCELERO_INT_GPIO_CLK_ENABLE()         __HAL_RCC_GPIOE_CLK_ENABLE()
235 #define ACCELERO_INT_GPIO_CLK_DISABLE()        __HAL_RCC_GPIOE_CLK_DISABLE()
236 #define ACCELERO_INT1_PIN                      GPIO_PIN_0                 /* PE.00 */
237 #define ACCELERO_INT1_EXTI_IRQn                EXTI0_IRQn
238 #define ACCELERO_INT2_PIN                      GPIO_PIN_1                 /* PE.01 */
239 #define ACCELERO_INT2_EXTI_IRQn                EXTI1_IRQn
240 /**
241   * @}
242   */
243 
244 
245 /*############################### AUDIO ######################################*/
246 /**
247   * @brief  AUDIO I2C Interface pins
248   */
249 #define AUDIO_I2C_ADDRESS                     0x94
250 
251   /* Audio Reset Pin definition */
252 #define AUDIO_RESET_GPIO_CLK_ENABLE()         __HAL_RCC_GPIOD_CLK_ENABLE()
253 #define AUDIO_RESET_PIN                       GPIO_PIN_4
254 #define AUDIO_RESET_GPIO                      GPIOD
255 /**
256   * @}
257   */
258 
259 /** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_Exported_Macros STM32F4 DISCOVERY LOW LEVEL Exported Macros
260   * @{
261   */
262 /**
263   * @}
264   */
265 
266 /** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_Exported_Functions STM32F4 DISCOVERY LOW LEVEL Exported Functions
267   * @{
268   */
269 uint32_t BSP_GetVersion(void);
270 void     BSP_LED_Init(Led_TypeDef Led);
271 void     BSP_LED_On(Led_TypeDef Led);
272 void     BSP_LED_Off(Led_TypeDef Led);
273 void     BSP_LED_Toggle(Led_TypeDef Led);
274 void     BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef Mode);
275 uint32_t BSP_PB_GetState(Button_TypeDef Button);
276 
277 /**
278   * @}
279   */
280 
281 /**
282   * @}
283   */
284 
285 /**
286   * @}
287   */
288 
289 /**
290   * @}
291   */
292 
293 /**
294   * @}
295   */
296 
297 #ifdef __cplusplus
298 }
299 #endif
300 
301 #endif /* __STM32F4_DISCOVERY_H */
302 
303 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
304