ksk_lpc4088.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. * Copyright (C) 2013 by Ole Reinhardt (ole.reinhardt@embedded-it.de)
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the copyright holders nor the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  23. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. * For additional information see http://www.ethernut.de/
  33. */
  34. /*
  35. * \file arch/cm3/board/ksk_lpc4088.c
  36. * \brief IAR KSK LPC4088 eval board initialization.
  37. *
  38. *
  39. * \verbatim
  40. * $Id: $
  41. * \endverbatim
  42. */
  43. #include <cfg/arch.h>
  44. #include <arch/cm3.h>
  45. #include <inttypes.h>
  46. #include <sys/timer.h>
  47. #include <arch/cm3/nxp/lpc407x_8x_clk.h>
  48. #include <arch/cm3/nxp/lpc177x_8x_emc.h>
  49. #include <dev/gpio.h>
  50. #include <dev/sdram.h>
  51. #include <sys/heap.h>
  52. /* SDRAM configuration for IAR KSK LPC1788 evaluation board */
  53. /* configuration for K4S561632J sdram. */
  54. #define SDRAM_BASE_ADDR 0xA0000000
  55. #define SDRAM_SIZE 0x04000000
  56. /* Samsung K4S561632J SDRAMs */
  57. static SDRAM sdram_k4s561632j = {
  58. .base_addr = SDRAM_BASE_ADDR,
  59. .size = SDRAM_SIZE,
  60. .bus_width = 32,
  61. .rows = 13,
  62. .cols = 9,
  63. .ras_latency = 3,
  64. .cas_latency = 3,
  65. .tRP = 20,
  66. .tRAS = 45,
  67. .tSREX = 67, /* same as .tXSR */
  68. .tAPR = 1,
  69. .tDAL = 3,
  70. .tWR = 3,
  71. .tRC = 65,
  72. .tRFC = 66,
  73. .tXSR = 67,
  74. .tRRD = 15,
  75. .tMRD = 3,
  76. .refresh = 7813,
  77. };
  78. /*!
  79. * \brief Early KSK LPC1788 SK hardware initialization. Especialy SD-RAM
  80. *
  81. * This routine is called during system initalization.
  82. */
  83. void NutBoardInit(void)
  84. {
  85. int i;
  86. /* Configure SDRAM interface GPIO Pins */
  87. /* Pin configuration:
  88. * P2.14 - /EMC_CS2 - not used
  89. * P2.15 - /EMC_CS3 - not used
  90. *
  91. * P2.16 - /EMC_CAS
  92. * P2.17 - /EMC_RAS
  93. * P2.18 - EMC_CLK[0]
  94. * P2.19 - EMC_CLK[1]
  95. *
  96. * P2.20 - EMC_DYCS0
  97. * P2.21 - EMC_DYCS1 - not used
  98. * P2.22 - EMC_DYCS2 - not used
  99. * P2.23 - EMC_DYCS3 - not used
  100. *
  101. * P2.24 - EMC_CKE0
  102. * P2.25 - EMC_CKE1 - not used
  103. * P2.26 - EMC_CKE2 - not used
  104. * P2.27 - EMC_CKE3 - not used
  105. *
  106. * P2.28 - EMC_DQM0
  107. * P2.29 - EMC_DQM1
  108. * P2.30 - EMC_DQM2
  109. * P2.31 - EMC_DQM3
  110. *
  111. * P3.0-P3.31 - EMC_D[0-31]
  112. * P4.0-P4.23 - EMC_A[0-23] - only A0 .. A14 used
  113. *
  114. * P4.24 - /EMC_OE - not used
  115. * P4.25 - /EMC_WE
  116. *
  117. * P4.30 - /EMC_CS0 - not used
  118. * P4.31 - /EMC_CS1 - not used
  119. */
  120. GpioPinConfigSet(NUTGPIO_PORT2, 16, GPIO_CFG_PERIPHERAL1 | GPIO_CFG_SLEWCTRL);
  121. GpioPinConfigSet(NUTGPIO_PORT2, 17, GPIO_CFG_PERIPHERAL1 | GPIO_CFG_SLEWCTRL);
  122. GpioPinConfigSet(NUTGPIO_PORT2, 18, GPIO_CFG_PERIPHERAL1 | GPIO_CFG_SLEWCTRL);
  123. GpioPinConfigSet(NUTGPIO_PORT2, 20, GPIO_CFG_PERIPHERAL1 | GPIO_CFG_SLEWCTRL);
  124. GpioPinConfigSet(NUTGPIO_PORT2, 24, GPIO_CFG_PERIPHERAL1 | GPIO_CFG_SLEWCTRL);
  125. GpioPinConfigSet(NUTGPIO_PORT2, 28, GPIO_CFG_PERIPHERAL1 | GPIO_CFG_SLEWCTRL);
  126. GpioPinConfigSet(NUTGPIO_PORT2, 29, GPIO_CFG_PERIPHERAL1 | GPIO_CFG_SLEWCTRL);
  127. GpioPinConfigSet(NUTGPIO_PORT2, 30, GPIO_CFG_PERIPHERAL1 | GPIO_CFG_SLEWCTRL);
  128. GpioPinConfigSet(NUTGPIO_PORT2, 31, GPIO_CFG_PERIPHERAL1 | GPIO_CFG_SLEWCTRL);
  129. /* Configure D0 .. D31 */
  130. for(i = 0; i < 32; i++) {
  131. GpioPinConfigSet(NUTGPIO_PORT3, i, GPIO_CFG_PERIPHERAL1 | GPIO_CFG_SLEWCTRL | GPIO_CFG_REPEATER);
  132. }
  133. /* Configure A0 .. A12, A13 and A14 used as bank select */
  134. for(i = 0; i < 15; i++) {
  135. GpioPinConfigSet(NUTGPIO_PORT4, i, GPIO_CFG_PERIPHERAL1 | GPIO_CFG_SLEWCTRL);
  136. }
  137. GpioPinConfigSet(NUTGPIO_PORT4, 25, GPIO_CFG_PERIPHERAL1 | GPIO_CFG_SLEWCTRL);
  138. /* Initialize the external memory controller */
  139. Lpc177x_8x_EmcInit();
  140. Lpc177x_8x_EmcSDRAMInit(sdram_k4s561632j, 0x00004680 /* 13 rows, 9 cols, 16Mx32, 64MB */);
  141. }
  142. /*!
  143. * \brief Adjust the sdram timings to compensate temperature drifts
  144. *
  145. * This function is called as timer callback which was initialised at NutIdleInit()
  146. */
  147. static void adjust_sdram_timing(HANDLE this, void* arg)
  148. {
  149. Lpc177x_8x_EmcSDRAMAdjustTiming();
  150. }
  151. /*!
  152. * \brief Extended system initialisation. Add sdram memory to the available memory
  153. *
  154. * This routine is called during system initialisation right before the idle
  155. * thread is created. We will use it to add the SDRAM memory space to out heap.
  156. */
  157. void NutIdleInit(void)
  158. {
  159. /* Sanity check if the sdram is working. If all is fine add the sdram to
  160. heap space.
  161. */
  162. if (Lpc177x_8x_EmcSDRAMCheck(sdram_k4s561632j, 0xaa55) == 0) {
  163. NutHeapAdd((void*)sdram_k4s561632j.base_addr, sdram_k4s561632j.size);
  164. }
  165. /* Initialise a timer that re-calibrates the delay loops once a minute to
  166. compensate temperature drift of the sdram controller
  167. */
  168. NutTimerStart(60000, adjust_sdram_timing, NULL, 0);
  169. }