PageRenderTime 39ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/configs/nucleo-l476rg/src/nucleo-l476rg.h

https://bitbucket.org/benchmark-electronics/nuttx
C Header | 424 lines | 134 code | 68 blank | 222 comment | 6 complexity | f647a0086a6cb1ee17556621ea90acff MD5 | raw file
Possible License(s): 0BSD
  1. /************************************************************************************
  2. * configs/nucleo-l476rg/src/nucleo-l476rg.h
  3. *
  4. * Copyright (C) 2014, 2016, 2018 Gregory Nutt. All rights reserved.
  5. * Authors: Frank Bennett
  6. * Gregory Nutt <gnutt@nuttx.org>
  7. * Sebastien Lorquet <sebastien@lorquet.fr>
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. *
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. * 3. Neither the name NuttX nor the names of its contributors may be
  20. * used to endorse or promote products derived from this software
  21. * without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  24. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  25. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  26. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  27. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  28. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  29. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  30. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  31. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  32. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  33. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  34. * POSSIBILITY OF SUCH DAMAGE.
  35. *
  36. ************************************************************************************/
  37. #ifndef __CONFIGS_NUCLEO_L476RG_SRC_NUCLEO_L476RG_H
  38. #define __CONFIGS_NUCLEO_L476RG_SRC_NUCLEO_L476RG_H
  39. /************************************************************************************
  40. * Included Files
  41. ************************************************************************************/
  42. #include <nuttx/config.h>
  43. #include <nuttx/compiler.h>
  44. #include <stdint.h>
  45. /************************************************************************************
  46. * Pre-processor Definitions
  47. ************************************************************************************/
  48. /* Configuration ********************************************************************/
  49. #define HAVE_PROC 1
  50. #define HAVE_RTC_DRIVER 1
  51. #define HAVE_MMCSD_SPI 1
  52. #define HAVE_MMCSD_SDIO 1
  53. #if !defined(CONFIG_FS_PROCFS)
  54. # undef HAVE_PROC
  55. #endif
  56. #if defined(HAVE_PROC) && defined(CONFIG_DISABLE_MOUNTPOINT)
  57. # warning Mountpoints disabled. No procfs support
  58. # undef HAVE_PROC
  59. #endif
  60. /* Check if we can support the RTC driver */
  61. #if !defined(CONFIG_RTC) || !defined(CONFIG_RTC_DRIVER)
  62. # undef HAVE_RTC_DRIVER
  63. #endif
  64. #if !defined(CONFIG_STM32L4_SPI1) || !defined(CONFIG_MMCSD) || \
  65. !defined(CONFIG_MMCSD_SPI)
  66. # undef HAVE_MMCSD_SPI
  67. #endif
  68. #if !defined(CONFIG_STM32L4_SDIO) || !defined(CONFIG_MMCSD) || \
  69. !defined(CONFIG_MMCSD_SDIO)
  70. # undef HAVE_MMCSD_SDIO
  71. #endif
  72. /* LED. User LD2: the green LED is a user LED connected to Arduino signal D13
  73. * corresponding to MCU I/O PA5 (pin 21) or PB13 (pin 34) depending on the STM32
  74. * target.
  75. *
  76. * - When the I/O is HIGH value, the LED is on.
  77. * - When the I/O is LOW, the LED is off.
  78. */
  79. #define GPIO_LD2 \
  80. (GPIO_PORTA | GPIO_PIN5 | GPIO_OUTPUT_CLEAR | GPIO_OUTPUT | GPIO_PULLUP | \
  81. GPIO_SPEED_50MHz)
  82. /* Buttons
  83. *
  84. * B1 USER: the user button is connected to the I/O PC13 (pin 2) of the STM32
  85. * microcontroller.
  86. */
  87. #define MIN_IRQBUTTON BUTTON_USER
  88. #define MAX_IRQBUTTON BUTTON_USER
  89. #define NUM_IRQBUTTONS 1
  90. #define GPIO_BTN_USER \
  91. (GPIO_INPUT |GPIO_FLOAT |GPIO_EXTI | GPIO_PORTC | GPIO_PIN13)
  92. /* The shield uses the following pins:
  93. *
  94. * +5V
  95. * GND
  96. * SERIAL_TX=PA_2 USER_BUTTON=PC_13
  97. * SERIAL_RX=PA_3 LD2=PA_5
  98. *
  99. * Analog Digital
  100. * A0=PA_0 USART2RX D0=PA_3 D8 =PA_9
  101. * A1=PA_1 USART2TX D1=PA_2 D9 =PC_7
  102. * A2=PA_4 D2=PA_10 WIFI_CS=D10=PB_6 SPI_CS
  103. * A3=PB_0 WIFI_INT=D3=PB_3 D11=PA_7 SPI_MOSI
  104. * A4=PC_1 SD_CS=D4=PB_5 D12=PA_6 SPI_MISO
  105. * A5=PC_0 WIFI_EN=D5=PB_4 LD2=D13=PA_5 SPI_SCK
  106. * LED2=D6=PB_10 I2C1_SDA=D14=PB_9 WIFI Probe
  107. * D7=PA_8 I2C1_SCL=D15=PB_8 WIFI Probe
  108. *
  109. * mostly from: https://mbed.org/platforms/ST-Nucleo-F401RE/
  110. */
  111. #ifdef CONFIG_WL_CC1101
  112. # define GPIO_CC1101_PWR (GPIO_PORTC | GPIO_PIN6 | GPIO_OUTPUT_SET | \
  113. GPIO_OUTPUT | GPIO_PULLUP | GPIO_SPEED_50MHz)
  114. # define GPIO_CC1101_CS (GPIO_PORTB | GPIO_PIN12 | GPIO_OUTPUT_SET | \
  115. GPIO_OUTPUT | GPIO_PULLUP | GPIO_SPEED_50MHz)
  116. # define GPIO_CC1101_MISO (GPIO_PORTB | GPIO_PIN14)
  117. # define GPIO_CC1101_GDO2 (GPIO_PORTC | GPIO_PIN10 | \
  118. GPIO_EXTI | GPIO_SPEED_50MHz)
  119. #endif
  120. /* SPI chip selects */
  121. #ifdef CONFIG_MMCSD_SPI
  122. # define GPIO_SPI_CS_SD_CARD \
  123. (GPIO_OUTPUT | GPIO_PUSHPULL | GPIO_SPEED_50MHz | \
  124. GPIO_OUTPUT_SET | GPIO_PORTB | GPIO_PIN10)
  125. #endif
  126. #ifdef CONFIG_LCD_PCD8544
  127. #define STM32_LCD_CS (GPIO_OUTPUT|GPIO_PULLUP|GPIO_SPEED_2MHz|\
  128. GPIO_OUTPUT_SET|GPIO_PORTC|GPIO_PIN4)
  129. #define STM32_LCD_CD (GPIO_OUTPUT|GPIO_PULLUP|GPIO_SPEED_2MHz|\
  130. GPIO_OUTPUT_SET|GPIO_PORTA|GPIO_PIN10)
  131. #define STM32_LCD_RST (GPIO_OUTPUT|GPIO_PULLUP|GPIO_SPEED_2MHz|\
  132. GPIO_OUTPUT_SET|GPIO_PORTB|GPIO_PIN13)
  133. #endif
  134. /* Devices on the onboard bus.
  135. *
  136. * Note that these are unshifted addresses.
  137. */
  138. #define NUCLEO_I2C_OBDEV_LED 0x55
  139. #define NUCLEO_I2C_OBDEV_HMC5883 0x1e
  140. /* User GPIOs
  141. *
  142. * GPIO0-1 are for probing WIFI status
  143. */
  144. /* Itead Joystick Shield
  145. *
  146. * See http://imall.iteadstudio.com/im120417014.html for more information
  147. * about this joystick.
  148. *
  149. * --------- ----------------- ---------------------------------
  150. * ARDUINO ITEAD NUCLEO-F4x1
  151. * PIN NAME SIGNAL SIGNAL
  152. * --------- ----------------- ---------------------------------
  153. * D3 Button E Output PB3
  154. * D4 Button D Output PB5
  155. * D5 Button C Output PB4
  156. * D6 Button B Output PB10
  157. * D7 Button A Output PA8
  158. * D8 Button F Output PA9
  159. * D9 Button G Output PC7
  160. * A0 Joystick Y Output PA0 ADC1_0
  161. * A1 Joystick X Output PA1 ADC1_1
  162. * --------- ----------------- ---------------------------------
  163. *
  164. * All buttons are pulled on the shield. A sensed low value indicates
  165. * when the button is pressed.
  166. *
  167. * NOTE: Button F cannot be used with the default USART1 configuration
  168. * because PA9 is configured for USART1_RX by default. Use select
  169. * different USART1 pins in the board.h file or select a different
  170. * USART or select CONFIG_NUCLEO_L476RG_AJOY_MINBUTTONS which will
  171. * eliminate all but buttons A, B, and C.
  172. */
  173. #define ADC_XOUPUT 1 /* X output is on ADC channel 1 */
  174. #define ADC_YOUPUT 0 /* Y output is on ADC channel 0 */
  175. #define GPIO_BUTTON_A \
  176. (GPIO_INPUT | GPIO_PULLUP |GPIO_EXTI | GPIO_PORTA | GPIO_PIN8)
  177. #define GPIO_BUTTON_B \
  178. (GPIO_INPUT | GPIO_PULLUP |GPIO_EXTI | GPIO_PORTB | GPIO_PIN10)
  179. #define GPIO_BUTTON_C \
  180. (GPIO_INPUT | GPIO_PULLUP |GPIO_EXTI | GPIO_PORTB | GPIO_PIN4)
  181. #define GPIO_BUTTON_D \
  182. (GPIO_INPUT | GPIO_PULLUP |GPIO_EXTI | GPIO_PORTB | GPIO_PIN5)
  183. #define GPIO_BUTTON_E \
  184. (GPIO_INPUT | GPIO_PULLUP |GPIO_EXTI | GPIO_PORTB | GPIO_PIN3)
  185. #define GPIO_BUTTON_F \
  186. (GPIO_INPUT | GPIO_PULLUP |GPIO_EXTI | GPIO_PORTA | GPIO_PIN9)
  187. #define GPIO_BUTTON_G \
  188. (GPIO_INPUT | GPIO_PULLUP |GPIO_EXTI | GPIO_PORTC | GPIO_PIN7)
  189. /* Itead Joystick Signal interpretation:
  190. *
  191. * --------- ----------------------- ---------------------------
  192. * BUTTON TYPE NUTTX ALIAS
  193. * --------- ----------------------- ---------------------------
  194. * Button A Large button A JUMP/BUTTON 3
  195. * Button B Large button B FIRE/BUTTON 2
  196. * Button C Joystick select button SELECT/BUTTON 1
  197. * Button D Tiny Button D BUTTON 6
  198. * Button E Tiny Button E BUTTON 7
  199. * Button F Large Button F BUTTON 4
  200. * Button G Large Button G BUTTON 5
  201. * --------- ----------------------- ---------------------------
  202. */
  203. #define GPIO_BUTTON_1 GPIO_BUTTON_C
  204. #define GPIO_BUTTON_2 GPIO_BUTTON_B
  205. #define GPIO_BUTTON_3 GPIO_BUTTON_A
  206. #define GPIO_BUTTON_4 GPIO_BUTTON_F
  207. #define GPIO_BUTTON_5 GPIO_BUTTON_G
  208. #define GPIO_BUTTON_6 GPIO_BUTTON_D
  209. #define GPIO_BUTTON_7 GPIO_BUTTON_E
  210. #define GPIO_SELECT GPIO_BUTTON_1
  211. #define GPIO_FIRE GPIO_BUTTON_2
  212. #define GPIO_JUMP GPIO_BUTTON_3
  213. /* GPIO pins used by the GPIO Subsystem
  214. * Added by: Ben vd Veen (DisruptiveNL) -- www.nuttx.nl
  215. */
  216. #define BOARD_NGPIOIN 1 /* Amount of GPIO Input pins */
  217. #define BOARD_NGPIOOUT 1 /* Amount of GPIO Output pins */
  218. #define BOARD_NGPIOINT 1 /* Amount of GPIO Input w/ Interruption pins */
  219. /* This was really something to find out! But the GPIOA Port was causing
  220. * conflicts with the nsh console. So thats why I have chosen GPIOB
  221. *
  222. * Author: Ben vd Veen (DisruptiveNL) -- www.nuttx.nl
  223. * https://www.youtube.com/watch?v=VXsTLzI6idA -- Original video GPIO
  224. */
  225. #define GPIO_IN1 (GPIO_INPUT | GPIO_FLOAT | GPIO_PORTB | GPIO_PIN0)
  226. #define GPIO_OUT1 (GPIO_OUTPUT | GPIO_OUTPUT | GPIO_SPEED_50MHz | \
  227. GPIO_OUTPUT_SET | GPIO_PORTB | GPIO_PIN1)
  228. #define GPIO_INT1 (GPIO_INPUT | GPIO_FLOAT | GPIO_PORTB | GPIO_PIN2)
  229. #define GPIO_HTS221_INT (GPIO_INPUT | GPIO_FLOAT | GPIO_PORTA | GPIO_PIN10)
  230. #define GPIO_LSM6DSL_INT1 (GPIO_INPUT | GPIO_FLOAT | GPIO_PORTB | GPIO_PIN4)
  231. #define GPIO_LSM6DSL_INT2 (GPIO_INPUT | GPIO_FLOAT | GPIO_PORTB | GPIO_PIN5)
  232. /************************************************************************************
  233. * Public Data
  234. ************************************************************************************/
  235. /* Global driver instances */
  236. #ifdef CONFIG_STM32L4_SPI1
  237. extern struct spi_dev_s *g_spi1;
  238. #endif
  239. #ifdef CONFIG_STM32L4_SPI2
  240. extern struct spi_dev_s *g_spi2;
  241. #endif
  242. #ifdef HAVE_MMCSD_SDIO
  243. extern struct sdio_dev_s *g_sdio;
  244. #endif
  245. /************************************************************************************
  246. * Public Functions
  247. ************************************************************************************/
  248. /************************************************************************************
  249. * Name: stm32l4_spiinitialize
  250. *
  251. * Description:
  252. * Called to configure SPI chip select GPIO pins.
  253. *
  254. ************************************************************************************/
  255. void stm32l4_spiinitialize(void);
  256. /************************************************************************************
  257. * Name: stm32l4_usbinitialize
  258. *
  259. * Description:
  260. * Called to setup USB-related GPIO pins.
  261. *
  262. ************************************************************************************/
  263. void stm32l4_usbinitialize(void);
  264. /****************************************************************************
  265. * Name: stm32_gpio_initialize
  266. *
  267. * Description:
  268. * Initialize GPIO drivers for use with /apps/examples/gpio
  269. * Added by: Ben vd Veen (DisruptiveNL) -- www.nuttx.nl
  270. *
  271. ****************************************************************************/
  272. #ifdef CONFIG_DEV_GPIO
  273. int stm32l4_gpio_initialize(void);
  274. #endif
  275. /************************************************************************************
  276. * Name: stm32l4_can_setup -- DisruptiveNL
  277. *
  278. * Description:
  279. * Initialize CAN and register the CAN device.
  280. * Added by: Ben vd Veen (DisruptiveNL) -- www.nuttx.nl
  281. *
  282. ************************************************************************************/
  283. #ifdef CONFIG_CAN
  284. int stm32l4_can_setup(void);
  285. #endif
  286. /************************************************************************************
  287. * Name: stm32l4_pwm_setup
  288. *
  289. * Description:
  290. * Initialize PWM and register the PWM device.
  291. *
  292. ************************************************************************************/
  293. #ifdef CONFIG_PWM
  294. int stm32l4_pwm_setup(void);
  295. #endif
  296. /************************************************************************************
  297. * Name: stm32l4_adc_setup
  298. *
  299. * Description:
  300. * Initialize ADC and register the ADC driver.
  301. *
  302. ************************************************************************************/
  303. #ifdef CONFIG_ADC
  304. int stm32l4_adc_setup(void);
  305. #endif
  306. /****************************************************************************
  307. * Name: board_ajoy_initialize
  308. *
  309. * Description:
  310. * Initialize and register the button joystick driver
  311. *
  312. ****************************************************************************/
  313. #ifdef CONFIG_AJOYSTICK
  314. int board_ajoy_initialize(void);
  315. #endif
  316. /****************************************************************************
  317. * Name: stm32l4_mmcsd_initialize
  318. *
  319. * Description:
  320. * Initializes SPI-based SD card
  321. *
  322. ****************************************************************************/
  323. #ifdef CONFIG_MMCSD_SPI
  324. int stm32l4_mmcsd_initialize(int minor);
  325. #endif
  326. /****************************************************************************
  327. * Name: board_timer_driver_initialize
  328. *
  329. * Description:
  330. * Initialize and register a timer
  331. *
  332. ****************************************************************************/
  333. #ifdef CONFIG_TIMER
  334. int board_timer_driver_initialize(FAR const char *devpath, int timer);
  335. #endif
  336. /****************************************************************************
  337. * Name: stm32l4_qencoder_initialize
  338. *
  339. * Description:
  340. * Initialize and register a qencoder
  341. *
  342. ****************************************************************************/
  343. #ifdef CONFIG_SENSORS_QENCODER
  344. int stm32l4_qencoder_initialize(FAR const char *devpath, int timer);
  345. #endif
  346. /****************************************************************************
  347. * Name: stm32_cc1101_initialize
  348. *
  349. * Description:
  350. * Initialize and register the cc1101 radio driver
  351. *
  352. ****************************************************************************/
  353. #ifdef CONFIG_WL_CC1101
  354. int stm32_cc1101_initialize(void);
  355. #endif
  356. #endif /* __CONFIGS_NUCLEO_L476RG_SRC_NUCLEO_L476RG_H */