/boards/arm/stm32/mikroe-stm32f4/src/stm32_extmem.c

https://github.com/apache/incubator-nuttx · C · 148 lines · 48 code · 25 blank · 75 comment · 1 complexity · 9dd61ff10cd62b9a1764f31a9513a9e5 MD5 · raw file

  1. /****************************************************************************
  2. * boards/arm/stm32/mikroe_stm32f4/src/stm32_extmem.c
  3. *
  4. * Copyright (C) 2012-2013 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 <stdint.h>
  40. #include <assert.h>
  41. #include <debug.h>
  42. #include <arch/board/board.h>
  43. #include "chip.h"
  44. #include "arm_arch.h"
  45. #include "stm32_gpio.h"
  46. #include "stm32.h"
  47. #include "mikroe-stm32f4.h"
  48. /****************************************************************************
  49. * Pre-processor Definitions
  50. ****************************************************************************/
  51. #ifndef CONFIG_STM32_FSMC
  52. # warning "FSMC is not enabled"
  53. #endif
  54. #if STM32_NGPIO_PORTS < 6
  55. # error "Required GPIO ports not enabled"
  56. #endif
  57. #define STM32_FSMC_NADDRCONFIGS 26
  58. #define STM32_FSMC_NDATACONFIGS 16
  59. /****************************************************************************
  60. * Public Data
  61. ****************************************************************************/
  62. /* GPIO configurations common to most external memories */
  63. static const uint32_t g_addressconfig[STM32_FSMC_NADDRCONFIGS] =
  64. {
  65. GPIO_FSMC_A0, GPIO_FSMC_A1 , GPIO_FSMC_A2, GPIO_FSMC_A3, GPIO_FSMC_A4 , GPIO_FSMC_A5,
  66. GPIO_FSMC_A6, GPIO_FSMC_A7, GPIO_FSMC_A8, GPIO_FSMC_A9, GPIO_FSMC_A10, GPIO_FSMC_A11,
  67. GPIO_FSMC_A12, GPIO_FSMC_A13, GPIO_FSMC_A14, GPIO_FSMC_A15, GPIO_FSMC_A16, GPIO_FSMC_A17,
  68. GPIO_FSMC_A18, GPIO_FSMC_A19, GPIO_FSMC_A20, GPIO_FSMC_A21, GPIO_FSMC_A22, GPIO_FSMC_A23,
  69. GPIO_FSMC_A24, GPIO_FSMC_A25
  70. };
  71. static const uint32_t g_dataconfig[STM32_FSMC_NDATACONFIGS] =
  72. {
  73. GPIO_FSMC_D0, GPIO_FSMC_D1 , GPIO_FSMC_D2, GPIO_FSMC_D3, GPIO_FSMC_D4 , GPIO_FSMC_D5,
  74. GPIO_FSMC_D6, GPIO_FSMC_D7, GPIO_FSMC_D8, GPIO_FSMC_D9, GPIO_FSMC_D10, GPIO_FSMC_D11,
  75. GPIO_FSMC_D12, GPIO_FSMC_D13, GPIO_FSMC_D14, GPIO_FSMC_D15
  76. };
  77. /****************************************************************************
  78. * Private Data
  79. ****************************************************************************/
  80. /****************************************************************************
  81. * Private Functions
  82. ****************************************************************************/
  83. /****************************************************************************
  84. * Public Functions
  85. ****************************************************************************/
  86. /****************************************************************************
  87. * Name: stm32_extmemgpios
  88. *
  89. * Description:
  90. * Initialize GPIOs for external memory usage
  91. *
  92. ****************************************************************************/
  93. void stm32_extmemgpios(const uint32_t *gpios, int ngpios)
  94. {
  95. int i;
  96. /* Configure GPIOs */
  97. for (i = 0; i < ngpios; i++)
  98. {
  99. stm32_configgpio(gpios[i]);
  100. }
  101. }
  102. /****************************************************************************
  103. * Name: stm32_extmemaddr
  104. *
  105. * Description:
  106. * Initialize address line GPIOs for external memory access
  107. *
  108. ****************************************************************************/
  109. void stm32_extmemaddr(int naddrs)
  110. {
  111. stm32_extmemgpios(g_addressconfig, naddrs);
  112. }
  113. /****************************************************************************
  114. * Name: stm32_extmemdata
  115. *
  116. * Description:
  117. * Initialize data line GPIOs for external memory access
  118. *
  119. ****************************************************************************/
  120. void stm32_extmemdata(int ndata)
  121. {
  122. stm32_extmemgpios(g_dataconfig, ndata);
  123. }