STM32F3xx-Nucleo BSP User Manual: stm32f3xx_nucleo.h Source File

STM32F3xx-Nucleo BSP Drivers

stm32f3xx_nucleo.h
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f3xx_nucleo.h
00004   * @author  MCD Application Team
00005   * @brief   This file contains definitions for:
00006   *          - LEDs and push-button available on STM32F3XX-Nucleo Kit 
00007   *            from STMicroelectronics
00008   *          - LCD, joystick and microSD available on Adafruit 1.8" TFT LCD 
00009   *            shield (reference ID 802)
00010   ******************************************************************************
00011   * @attention
00012   *
00013   * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
00014   *
00015   * Redistribution and use in source and binary forms, with or without modification,
00016   * are permitted provided that the following conditions are met:
00017   *   1. Redistributions of source code must retain the above copyright notice,
00018   *      this list of conditions and the following disclaimer.
00019   *   2. Redistributions in binary form must reproduce the above copyright notice,
00020   *      this list of conditions and the following disclaimer in the documentation
00021   *      and/or other materials provided with the distribution.
00022   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00023   *      may be used to endorse or promote products derived from this software
00024   *      without specific prior written permission.
00025   *
00026   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00027   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00029   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00030   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00031   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00032   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00033   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00034   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00035   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036   *
00037   ******************************************************************************
00038   */
00039   
00040 /* Define to prevent recursive inclusion -------------------------------------*/
00041 #ifndef __STM32F3XX_NUCLEO_H
00042 #define __STM32F3XX_NUCLEO_H
00043 
00044 #ifdef __cplusplus
00045  extern "C" {
00046 #endif
00047 
00048 
00049 /** @addtogroup BSP
00050   * @{
00051   */
00052 
00053 /** @defgroup STM32F3XX_NUCLEO STM32F3XX-NUCLEO
00054   * @{
00055   */
00056   
00057 /* Includes ------------------------------------------------------------------*/
00058 #include "stm32f3xx_hal.h"
00059 
00060 
00061 /** @defgroup STM32F3XX_NUCLEO_Common STM32F3XX-NUCLEO Common
00062   * @{
00063   */
00064 
00065 /** @defgroup STM32F3XX_NUCLEO_Private_Constants Private Constants
00066   * @{
00067   */
00068 /**
00069 * @}
00070 */        
00071 
00072 /** @defgroup STM32F3XX_NUCLEO_Private_Variables Private Variables
00073   * @{
00074   */ 
00075 /**
00076 * @}
00077 */
00078 
00079 /** @defgroup STM32F3XX_NUCLEO_Exported_Types Exported Types
00080   * @{
00081   */
00082 
00083 /**
00084  * @brief LED Types Definition
00085  */
00086 typedef enum 
00087 {
00088   LED2 = 0,
00089   LED_GREEN = LED2
00090 } Led_TypeDef;
00091 
00092 /**
00093  * @brief BUTTON Types Definition
00094  */
00095 typedef enum 
00096 {  
00097   BUTTON_USER = 0,
00098   /* Alias */
00099   BUTTON_KEY  = BUTTON_USER
00100 } Button_TypeDef;
00101 
00102 typedef enum 
00103 {  
00104   BUTTON_MODE_GPIO = 0,
00105   BUTTON_MODE_EXTI = 1
00106 } ButtonMode_TypeDef; 
00107 
00108 /**
00109  * @brief JOYSTICK Types Definition
00110  */
00111 typedef enum 
00112 { 
00113   JOY_NONE  = 0,
00114   JOY_SEL   = 1,
00115   JOY_DOWN  = 2,
00116   JOY_LEFT  = 3,
00117   JOY_RIGHT = 4,
00118   JOY_UP    = 5
00119 } JOYState_TypeDef;
00120 
00121 /**
00122   * @}
00123   */ 
00124 
00125 /** @defgroup STM32F3XX_NUCLEO_Exported_Constants Exported Constants
00126   * @{
00127   */ 
00128 
00129 /** 
00130 * @brief        Define for STM32F3XX_NUCLEO board  
00131 */ 
00132 
00133 #if !defined (USE_STM32F3XX_NUCLEO)
00134  #define USE_STM32F3XX_NUCLEO
00135 #endif
00136 
00137 /** @defgroup STM32F3XX_NUCLEO_LED STM32F3XX-NUCLEO LED
00138   * @{
00139   */
00140 #define LEDn                              1
00141 
00142 #if defined(STM32F302x8)
00143 #define LED2_PIN                          GPIO_PIN_13
00144 #define LED2_GPIO_PORT                    GPIOB
00145 #define LED2_GPIO_CLK_ENABLE()            __HAL_RCC_GPIOB_CLK_ENABLE()  
00146 #define LED2_GPIO_CLK_DISABLE()           __HAL_RCC_GPIOB_CLK_DISABLE()
00147 
00148 #elif defined(STM32F301x8) || defined(STM32F334x8) || defined(STM32F303xE)
00149 #define LED2_PIN                          GPIO_PIN_5
00150 #define LED2_GPIO_PORT                    GPIOA
00151 #define LED2_GPIO_CLK_ENABLE()            __HAL_RCC_GPIOA_CLK_ENABLE()
00152 #define LED2_GPIO_CLK_DISABLE()           __HAL_RCC_GPIOA_CLK_DISABLE()
00153 
00154 #else
00155 #error "MCU device not yet supported on STM32 F3 Nucleo kit"
00156 #endif /* STM32F302x8 */
00157 
00158 
00159 #define LEDx_GPIO_CLK_ENABLE(__INDEX__)   do { if ((__INDEX__) == 0) LED2_GPIO_CLK_ENABLE();} while(0)
00160 #define LEDx_GPIO_CLK_DISABLE(__INDEX__)  (((__INDEX__) == 0) ? LED2_GPIO_CLK_DISABLE() : 0)
00161 
00162 /**
00163   * @}
00164   */ 
00165   
00166 /** @defgroup STM32F3XX_NUCLEO_BUTTON STM32F3XX-NUCLEO BUTTON
00167   * @{
00168   */  
00169 #define BUTTONn                           1
00170 
00171 /**
00172  * @brief User button
00173  */
00174 #define USER_BUTTON_PIN                       GPIO_PIN_13
00175 #define USER_BUTTON_GPIO_PORT                 GPIOC
00176 #define USER_BUTTON_GPIO_CLK_ENABLE()         __HAL_RCC_GPIOC_CLK_ENABLE()
00177 #define USER_BUTTON_GPIO_CLK_DISABLE()        __HAL_RCC_GPIOC_CLK_DISABLE()
00178 #define USER_BUTTON_EXTI_IRQn                 EXTI15_10_IRQn
00179 /* Aliases */
00180 #define KEY_BUTTON_PIN                        USER_BUTTON_PIN
00181 #define KEY_BUTTON_GPIO_PORT                  USER_BUTTON_GPIO_PORT
00182 #define KEY_BUTTON_GPIO_CLK_ENABLE()          USER_BUTTON_GPIO_CLK_ENABLE()
00183 #define KEY_BUTTON_GPIO_CLK_DISABLE()         USER_BUTTON_GPIO_CLK_DISABLE()
00184 #define KEY_BUTTON_EXTI_LINE                  USER_BUTTON_EXTI_LINE
00185 #define KEY_BUTTON_EXTI_IRQn                  USER_BUTTON_EXTI_IRQn
00186 
00187 #define BUTTONx_GPIO_CLK_ENABLE(__INDEX__)    do { if ((__INDEX__) == 0) USER_BUTTON_GPIO_CLK_ENABLE();} while(0)
00188 #define BUTTONx_GPIO_CLK_DISABLE(__INDEX__)   (((__INDEX__) == 0) ? USER_BUTTON_GPIO_CLK_DISABLE() : 0)
00189 /**
00190   * @}
00191   */
00192 
00193 /** @defgroup STM32F3XX_NUCLEO_COM STM32F3XX-NUCLEO COM
00194   * @{
00195   */ 
00196 #if defined(HAL_SPI_MODULE_ENABLED)
00197 #if defined(STM32F301x8) || defined(STM32F302x8)
00198 /*###################### SPI2 ###################################*/
00199 #define NUCLEO_SPIx                               SPI2
00200 #define NUCLEO_SPIx_CLK_ENABLE()                  __HAL_RCC_SPI2_CLK_ENABLE()
00201 
00202 #define NUCLEO_SPIx_SCK_AF                        GPIO_AF5_SPI2
00203 #define NUCLEO_SPIx_SCK_GPIO_PORT                 GPIOB
00204 #define NUCLEO_SPIx_SCK_PIN                       GPIO_PIN_13
00205 #define NUCLEO_SPIx_SCK_GPIO_CLK_ENABLE()         __HAL_RCC_GPIOB_CLK_ENABLE()
00206 #define NUCLEO_SPIx_SCK_GPIO_CLK_DISABLE()        __HAL_RCC_GPIOB_CLK_DISABLE()
00207 
00208 #define NUCLEO_SPIx_MISO_MOSI_AF                  GPIO_AF5_SPI2
00209 #define NUCLEO_SPIx_MISO_MOSI_GPIO_PORT           GPIOB
00210 #define NUCLEO_SPIx_MISO_MOSI_GPIO_CLK_ENABLE()   __HAL_RCC_GPIOB_CLK_ENABLE()
00211 #define NUCLEO_SPIx_MISO_MOSI_GPIO_CLK_DISABLE()  __HAL_RCC_GPIOB_CLK_DISABLE()
00212 #define NUCLEO_SPIx_MISO_PIN                      GPIO_PIN_14
00213 #define NUCLEO_SPIx_MOSI_PIN                      GPIO_PIN_15
00214 
00215 #elif defined(STM32F334x8) || defined(STM32F303xE)
00216 /*###################### SPI1 ###################################*/
00217 #define NUCLEO_SPIx                               SPI1
00218 #define NUCLEO_SPIx_CLK_ENABLE()                  __HAL_RCC_SPI1_CLK_ENABLE()
00219 
00220 #define NUCLEO_SPIx_SCK_AF                        GPIO_AF5_SPI1
00221 #define NUCLEO_SPIx_SCK_GPIO_PORT                 GPIOA
00222 #define NUCLEO_SPIx_SCK_PIN                       GPIO_PIN_5
00223 #define NUCLEO_SPIx_SCK_GPIO_CLK_ENABLE()         __HAL_RCC_GPIOA_CLK_ENABLE()
00224 #define NUCLEO_SPIx_SCK_GPIO_CLK_DISABLE()        __HAL_RCC_GPIOA_CLK_DISABLE()
00225 
00226 #define NUCLEO_SPIx_MISO_MOSI_AF                  GPIO_AF5_SPI1
00227 #define NUCLEO_SPIx_MISO_MOSI_GPIO_PORT           GPIOA
00228 #define NUCLEO_SPIx_MISO_MOSI_GPIO_CLK_ENABLE()   __HAL_RCC_GPIOA_CLK_ENABLE()
00229 #define NUCLEO_SPIx_MISO_MOSI_GPIO_CLK_DISABLE()  __HAL_RCC_GPIOA_CLK_DISABLE()
00230 #define NUCLEO_SPIx_MISO_PIN                      GPIO_PIN_6
00231 #define NUCLEO_SPIx_MOSI_PIN                      GPIO_PIN_7
00232 
00233 #else
00234 #error "MCU device not yet supported on STM32 F3 Nucleo kit"
00235 #endif /* STM32F302x8 */
00236 
00237 /* Maximum Timeout values for flags waiting loops. These timeouts are not based
00238    on accurate values, they just guarantee that the application will not remain
00239    stuck if the SPI communication is corrupted.
00240    You may modify these timeout values depending on CPU frequency and application
00241    conditions (interrupts routines ...). */   
00242 #define NUCLEO_SPIx_TIMEOUT_MAX                   1000
00243 #endif /* HAL_SPI_MODULE_ENABLED */
00244 /**
00245   * @}
00246   */
00247 
00248 
00249 /** @defgroup STM32F3XX_NUCLEO_COMPONENT STM32F3XX-NUCLEO COMPONENT
00250   * @{
00251   */
00252 
00253 /**
00254   * @brief  SD Control Lines management
00255   */
00256 #define SD_CS_LOW()       HAL_GPIO_WritePin(SD_CS_GPIO_PORT, SD_CS_PIN, GPIO_PIN_RESET)
00257 #define SD_CS_HIGH()      HAL_GPIO_WritePin(SD_CS_GPIO_PORT, SD_CS_PIN, GPIO_PIN_SET)
00258 
00259 /**
00260   * @brief  LCD Control Lines management
00261   */
00262 #define LCD_CS_LOW()      HAL_GPIO_WritePin(LCD_CS_GPIO_PORT, LCD_CS_PIN, GPIO_PIN_RESET)
00263 #define LCD_CS_HIGH()     HAL_GPIO_WritePin(LCD_CS_GPIO_PORT, LCD_CS_PIN, GPIO_PIN_SET)
00264 #define LCD_DC_LOW()      HAL_GPIO_WritePin(LCD_DC_GPIO_PORT, LCD_DC_PIN, GPIO_PIN_RESET)
00265 #define LCD_DC_HIGH()     HAL_GPIO_WritePin(LCD_DC_GPIO_PORT, LCD_DC_PIN, GPIO_PIN_SET)
00266      
00267 /**
00268   * @brief  SD Control Interface pins (shield D4)
00269   */
00270 #define SD_CS_PIN                                 GPIO_PIN_5
00271 #define SD_CS_GPIO_PORT                           GPIOB
00272 #define SD_CS_GPIO_CLK_ENABLE()                 __HAL_RCC_GPIOB_CLK_ENABLE()
00273 #define SD_CS_GPIO_CLK_DISABLE()                __HAL_RCC_GPIOB_CLK_DISABLE()
00274 
00275 /**
00276   * @brief  LCD Control Interface pins (shield D10)
00277   */
00278 #define LCD_CS_PIN                                 GPIO_PIN_6
00279 #define LCD_CS_GPIO_PORT                           GPIOB
00280 #define LCD_CS_GPIO_CLK_ENABLE()                 __HAL_RCC_GPIOB_CLK_ENABLE()
00281 #define LCD_CS_GPIO_CLK_DISABLE()                __HAL_RCC_GPIOB_CLK_DISABLE()
00282     
00283 /**
00284   * @brief  LCD Data/Command Interface pins
00285   */
00286 #define LCD_DC_PIN                                 GPIO_PIN_9
00287 #define LCD_DC_GPIO_PORT                           GPIOA
00288 #define LCD_DC_GPIO_CLK_ENABLE()                 __HAL_RCC_GPIOA_CLK_ENABLE()
00289 #define LCD_DC_GPIO_CLK_DISABLE()                __HAL_RCC_GPIOA_CLK_DISABLE()
00290 
00291 #if defined(HAL_ADC_MODULE_ENABLED)
00292 #if defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F334x8)
00293 /*##################### ADC1 ###################################*/
00294 /**
00295   * @brief  ADC Interface pins
00296   *         used to detect motion of Joystick available on Adafruit 1.8" TFT shield
00297   */
00298 #define NUCLEO_ADCx                                 ADC1
00299 #define NUCLEO_ADCx_CLK_ENABLE()                  __HAL_RCC_ADC1_CLK_ENABLE()
00300 #define NUCLEO_ADCx_CLK_DISABLE()                 __HAL_RCC_ADC1_CLK_DISABLE()
00301 #elif defined(STM32F303xE)
00302 /*##################### ADC3 ###################################*/
00303 /**
00304   * @brief  ADC Interface pins
00305   *         used to detect motion of Joystick available on Adafruit 1.8" TFT shield
00306   */
00307 #define NUCLEO_ADCx                                 ADC3
00308 #define NUCLEO_ADCx_CLK_ENABLE()                  __HAL_RCC_ADC34_CLK_ENABLE()
00309 #define NUCLEO_ADCx_CLK_DISABLE()                 __HAL_RCC_ADC34_CLK_DISABLE()
00310 #else
00311 #error "MCU device not yet supported on STM32 F3 Nucleo kit"
00312 #endif /* STM32F302x8 || STM32F334x8 */
00313 
00314 #define NUCLEO_ADCx_GPIO_PORT                       GPIOB
00315 #define NUCLEO_ADCx_GPIO_PIN                        GPIO_PIN_0
00316 #define NUCLEO_ADCx_GPIO_CLK_ENABLE()             __HAL_RCC_GPIOB_CLK_ENABLE()
00317 #define NUCLEO_ADCx_GPIO_CLK_DISABLE()            __HAL_RCC_GPIOB_CLK_DISABLE()
00318 
00319 #endif /* HAL_ADC_MODULE_ENABLED */
00320 
00321 /**
00322   * @}
00323   */
00324 
00325 /**
00326   * @}
00327   */ 
00328 
00329 /** @defgroup STM32F3XX_NUCLEO_Exported_Functions Exported Functions
00330   * @{
00331   */
00332 uint32_t  BSP_GetVersion(void);  
00333 void      BSP_LED_Init(Led_TypeDef Led);
00334 void      BSP_LED_DeInit(Led_TypeDef Led);
00335 void      BSP_LED_On(Led_TypeDef Led);
00336 void      BSP_LED_Off(Led_TypeDef Led);
00337 void      BSP_LED_Toggle(Led_TypeDef Led);
00338 void      BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode);
00339 void      BSP_PB_DeInit(Button_TypeDef Button);
00340 uint32_t  BSP_PB_GetState(Button_TypeDef Button);
00341 #if defined(HAL_ADC_MODULE_ENABLED)
00342 uint8_t          BSP_JOY_Init(void);
00343 JOYState_TypeDef BSP_JOY_GetState(void);
00344 void             BSP_JOY_DeInit(void);
00345 #endif /* HAL_ADC_MODULE_ENABLED */
00346 
00347   
00348 /**
00349   * @}
00350   */
00351 
00352 /**
00353   * @}
00354   */ 
00355 
00356 /**
00357   * @}
00358   */
00359 
00360 /**
00361   * @}
00362   */
00363 
00364 #ifdef __cplusplus
00365 }
00366 #endif
00367 
00368 #endif /* __STM32F3XX_NUCLEO_H */
00369 
00370 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
00371 
Generated on Wed May 31 2017 10:59:20 for STM32F3xx-Nucleo BSP User Manual by   doxygen 1.7.6.1