STM32F3xx_Nucleo BSP User Manual: stm32f3xx_nucleo.h Source File

STM32F3xx_Nucleo BSP Driver

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