PageRenderTime 58ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/nuttx/configs/stm3220g-eval/src/up_nsh.c

https://gitlab.com/BlueCabbage/NuttX
C | 232 lines | 113 code | 45 blank | 74 comment | 11 complexity | 1f4f19b6b74da96e3f9e78c364434b85 MD5 | raw file
  1. /****************************************************************************
  2. * config/stm3220g_eval/src/up_nsh.c
  3. * arch/arm/src/board/up_nsh.c
  4. *
  5. * Copyright (C) 2012 Gregory Nutt. All rights reserved.
  6. * Author: Gregory Nutt <gnutt@nuttx.org>
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in
  16. * the documentation and/or other materials provided with the
  17. * distribution.
  18. * 3. Neither the name NuttX nor the names of its contributors may be
  19. * used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  25. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  26. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  27. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  28. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  29. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  30. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  31. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  32. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  33. * POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ****************************************************************************/
  36. /****************************************************************************
  37. * Included Files
  38. ****************************************************************************/
  39. #include <nuttx/config.h>
  40. #include <stdbool.h>
  41. #include <stdio.h>
  42. #include <debug.h>
  43. #include <errno.h>
  44. #ifdef CONFIG_STM32_SPI1
  45. # include <nuttx/spi.h>
  46. # include <nuttx/mtd.h>
  47. #endif
  48. #ifdef CONFIG_STM32_SDIO
  49. # include <nuttx/sdio.h>
  50. # include <nuttx/mmcsd.h>
  51. #endif
  52. #ifdef CONFIG_STM32_OTGFS
  53. # include "stm32_usbhost.h"
  54. #endif
  55. #include "stm32.h"
  56. #include "stm3220g-internal.h"
  57. /****************************************************************************
  58. * Pre-Processor Definitions
  59. ****************************************************************************/
  60. /* Configuration ************************************************************/
  61. /* For now, don't build in any SPI1 support -- NSH is not using it */
  62. #undef CONFIG_STM32_SPI1
  63. /* MMCSD PORT and SLOT number probably depend on the board configuration */
  64. #define HAVE_USBDEV 1
  65. #define HAVE_MMCSD 1
  66. #define HAVE_USBHOST 1
  67. #if defined(CONFIG_NSH_MMCSDSLOTNO) && CONFIG_NSH_MMCSDSLOTNO != 0
  68. # error "Only one MMC/SD slot"
  69. # undef CONFIG_NSH_MMCSDSLOTNO
  70. #endif
  71. #ifndef CONFIG_NSH_MMCSDSLOTNO
  72. # define CONFIG_NSH_MMCSDSLOTNO 0
  73. #endif
  74. /* Can't support MMC/SD features if mountpoints are disabled or if SDIO support
  75. * is not enabled.
  76. */
  77. #if defined(CONFIG_DISABLE_MOUNTPOINT) || !defined(CONFIG_STM32_SDIO)
  78. # undef HAVE_MMCSD
  79. #endif
  80. #ifndef CONFIG_NSH_MMCSDMINOR
  81. # define CONFIG_NSH_MMCSDMINOR 0
  82. #endif
  83. /* Can't support USB host or device features if USB OTG FS is not enabled */
  84. #ifndef CONFIG_STM32_OTGFS
  85. # undef HAVE_USBDEV
  86. # undef HAVE_USBHOST
  87. #endif
  88. /* Can't support USB device is USB device is not enabled */
  89. #ifndef CONFIG_USBDEV
  90. # undef HAVE_USBDEV
  91. #endif
  92. /* Can't support USB host is USB host is not enabled */
  93. #ifndef CONFIG_USBHOST
  94. # undef HAVE_USBHOST
  95. #endif
  96. /* Debug ********************************************************************/
  97. #ifdef CONFIG_CPP_HAVE_VARARGS
  98. # ifdef CONFIG_DEBUG
  99. # define message(...) lowsyslog(__VA_ARGS__)
  100. # else
  101. # define message(...) printf(__VA_ARGS__)
  102. # endif
  103. #else
  104. # ifdef CONFIG_DEBUG
  105. # define message lowsyslog
  106. # else
  107. # define message printf
  108. # endif
  109. #endif
  110. /****************************************************************************
  111. * Public Functions
  112. ****************************************************************************/
  113. /****************************************************************************
  114. * Name: nsh_archinitialize
  115. *
  116. * Description:
  117. * Perform architecture specific initialization
  118. *
  119. ****************************************************************************/
  120. int nsh_archinitialize(void)
  121. {
  122. #ifdef CONFIG_STM32_SPI1
  123. FAR struct spi_dev_s *spi;
  124. FAR struct mtd_dev_s *mtd;
  125. #endif
  126. #ifdef HAVE_MMCSD
  127. FAR struct sdio_dev_s *sdio;
  128. #endif
  129. #if defined(HAVE_MMCSD) || defined (HAVE_USBHOST)
  130. int ret;
  131. #endif
  132. /* Configure SPI-based devices */
  133. #ifdef CONFIG_STM32_SPI1
  134. /* Get the SPI port */
  135. spi = up_spiinitialize(1);
  136. if (!spi)
  137. {
  138. message("nsh_archinitialize: Failed to initialize SPI port 0\n");
  139. return -ENODEV;
  140. }
  141. /* Now bind the SPI interface to the M25P64/128 SPI FLASH driver */
  142. mtd = m25p_initialize(spi);
  143. if (!mtd)
  144. {
  145. message("nsh_archinitialize: Failed to bind SPI port 0 to the SPI FLASH driver\n");
  146. return -ENODEV;
  147. }
  148. #warning "Now what are we going to do with this SPI FLASH driver?"
  149. #endif
  150. /* Mount the SDIO-based MMC/SD block driver */
  151. #ifdef HAVE_MMCSD
  152. /* First, get an instance of the SDIO interface */
  153. message("nsh_archinitialize: Initializing SDIO slot %d\n",
  154. CONFIG_NSH_MMCSDSLOTNO);
  155. sdio = sdio_initialize(CONFIG_NSH_MMCSDSLOTNO);
  156. if (!sdio)
  157. {
  158. message("nsh_archinitialize: Failed to initialize SDIO slot %d\n",
  159. CONFIG_NSH_MMCSDSLOTNO);
  160. return -ENODEV;
  161. }
  162. /* Now bind the SDIO interface to the MMC/SD driver */
  163. ret = mmcsd_slotinitialize(CONFIG_NSH_MMCSDMINOR, sdio);
  164. if (ret != OK)
  165. {
  166. message("nsh_archinitialize: Failed to bind SDIO to the MMC/SD driver: %d\n", ret);
  167. return ret;
  168. }
  169. /* Then let's guess and say that there is a card in the slot. I need to check to
  170. * see if the STM3220G-EVAL board supports a GPIO to detect if there is a card in
  171. * the slot.
  172. */
  173. sdio_mediachange(sdio, true);
  174. #endif
  175. /* Initialize USB host operation. stm32_usbhost_initialize() starts a thread
  176. * will monitor for USB connection and disconnection events.
  177. */
  178. #ifdef HAVE_USBHOST
  179. ret = stm32_usbhost_initialize();
  180. if (ret != OK)
  181. {
  182. message("nsh_archinitialize: Failed to initialize USB host: %d\n", ret);
  183. return ret;
  184. }
  185. #endif
  186. return OK;
  187. }