/boards/arm/stm32/nucleo-f4x1re/src/stm32_bringup.c

https://github.com/apache/incubator-nuttx · C · 182 lines · 85 code · 33 blank · 64 comment · 10 complexity · 943c020bc767576e5a107baa2dcc8adf MD5 · raw file

  1. /****************************************************************************
  2. * boards/arm/stm32/nucleo-f4x1re/src/stm32_bringup.c
  3. *
  4. * Copyright (C) 2014, 2016, 2019 Gregory Nutt. All rights reserved.
  5. * Author: Gregory Nutt <gnutt@nuttx.org>
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in
  15. * the documentation and/or other materials provided with the
  16. * distribution.
  17. * 3. Neither the name NuttX nor the names of its contributors may be
  18. * used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. * POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. ****************************************************************************/
  35. /****************************************************************************
  36. * Included Files
  37. ****************************************************************************/
  38. #include <nuttx/config.h>
  39. #include <stdio.h>
  40. #include <syslog.h>
  41. #include <errno.h>
  42. #include <nuttx/arch.h>
  43. #include <nuttx/sdio.h>
  44. #include <nuttx/mmcsd.h>
  45. #include <stm32.h>
  46. #include <stm32_uart.h>
  47. #include <arch/board/board.h>
  48. #include "nucleo-f4x1re.h"
  49. #include <nuttx/board.h>
  50. #ifdef CONFIG_SENSORS_QENCODER
  51. #include "board_qencoder.h"
  52. #endif
  53. /****************************************************************************
  54. * Public Functions
  55. ****************************************************************************/
  56. /****************************************************************************
  57. * Name: stm32_bringup
  58. *
  59. * Description:
  60. * Perform architecture-specific initialization
  61. *
  62. * CONFIG_BOARD_LATE_INITIALIZE=y :
  63. * Called from board_late_initialize().
  64. *
  65. * CONFIG_BOARD_LATE_INITIALIZE=n && CONFIG_LIB_BOARDCTL=y :
  66. * Called from the NSH library
  67. *
  68. ****************************************************************************/
  69. int stm32_bringup(void)
  70. {
  71. int ret = OK;
  72. /* Configure SPI-based devices */
  73. #ifdef CONFIG_STM32_SPI1
  74. /* Get the SPI port */
  75. struct spi_dev_s *spi;
  76. spi = stm32_spibus_initialize(1);
  77. if (!spi)
  78. {
  79. syslog(LOG_ERR, "ERROR: Failed to initialize SPI port 1\n");
  80. return -ENODEV;
  81. }
  82. #ifdef CONFIG_CAN_MCP2515
  83. #ifdef CONFIG_STM32_SPI1
  84. stm32_configgpio(GPIO_MCP2515_CS); /* MEMS chip select */
  85. #endif
  86. /* Configure and initialize the MCP2515 CAN device */
  87. ret = stm32_mcp2515initialize("/dev/can0");
  88. if (ret < 0)
  89. {
  90. syslog(LOG_ERR, "ERROR: stm32_mcp2515initialize() failed: %d\n", ret);
  91. }
  92. #endif
  93. #endif
  94. #ifdef HAVE_MMCSD
  95. /* First, get an instance of the SDIO interface */
  96. g_sdio = sdio_initialize(CONFIG_NSH_MMCSDSLOTNO);
  97. if (!g_sdio)
  98. {
  99. syslog(LOG_ERR, "ERROR: Failed to initialize SDIO slot %d\n",
  100. CONFIG_NSH_MMCSDSLOTNO);
  101. return -ENODEV;
  102. }
  103. /* Now bind the SDIO interface to the MMC/SD driver */
  104. ret = mmcsd_slotinitialize(CONFIG_NSH_MMCSDMINOR, g_sdio);
  105. if (ret != OK)
  106. {
  107. syslog(LOG_ERR,
  108. "ERROR: Failed to bind SDIO to the MMC/SD driver: %d\n",
  109. ret);
  110. return ret;
  111. }
  112. /* Then let's guess and say that there is a card in the slot. There is no
  113. * card detect GPIO.
  114. */
  115. sdio_mediachange(g_sdio, true);
  116. syslog(LOG_INFO, "[boot] Initialized SDIO\n");
  117. #endif
  118. #ifdef CONFIG_ADC
  119. /* Initialize ADC and register the ADC driver. */
  120. ret = stm32_adc_setup();
  121. if (ret < 0)
  122. {
  123. syslog(LOG_ERR, "ERROR: stm32_adc_setup failed: %d\n", ret);
  124. }
  125. #endif
  126. #ifdef CONFIG_SENSORS_QENCODER
  127. /* Initialize and register the qencoder driver */
  128. ret = board_qencoder_initialize(0, CONFIG_NUCLEO_F401RE_QETIMER);
  129. if (ret != OK)
  130. {
  131. syslog(LOG_ERR,
  132. "ERROR: Failed to register the qencoder: %d\n",
  133. ret);
  134. return ret;
  135. }
  136. #endif
  137. #ifdef CONFIG_AJOYSTICK
  138. /* Initialize and register the joystick driver */
  139. ret = board_ajoy_initialize();
  140. if (ret != OK)
  141. {
  142. syslog(LOG_ERR,
  143. "ERROR: Failed to register the joystick driver: %d\n",
  144. ret);
  145. return ret;
  146. }
  147. #endif
  148. return ret;
  149. }