README.txt 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  1. README
  2. ======
  3. This README file discusses the port of NuttX to the Olimex LPC-H3131 board.
  4. NOTE: This is a minimal port to the Olimex LPC-H3131. According to Olimex
  5. documentation, the LPC-H3131 is similar in design to the Embedded Artists
  6. EA3131. As a consequence, it should be possible to leverage additional
  7. functionality from configs/ea3131 without too much difficulty.
  8. Contents
  9. ========
  10. o Development Environment
  11. o GNU Toolchain Options
  12. o IDEs
  13. o NuttX buildroot Toolchain
  14. o Boot Sequence
  15. o Buttons and LEDs
  16. o Image Format
  17. o Image Download to ISRAM
  18. o Using OpenOCD and GDB
  19. o ARM/LPC-H3131-specific Configuration Options
  20. o Configurations
  21. Development Environment
  22. =======================
  23. Either Linux or Cygwin on Windows can be used for the development environment.
  24. The source has been built only using the GNU toolchain (see below). Other
  25. toolchains will likely cause problems.
  26. GNU Toolchain Options
  27. =====================
  28. The NuttX make system has been modified to support the following different
  29. toolchain options.
  30. 1. The CodeSourcery GNU toolchain,
  31. 2. The devkitARM GNU toolchain,
  32. 3. Raisonance GNU toolchain,
  33. 4. The NuttX buildroot Toolchain (see below), or
  34. 5. Any generic arm-none-eabi GNU toolchain.
  35. All testing has been conducted using the NuttX buildroot toolchain. However,
  36. the make system is setup to default to use the devkitARM toolchain. To use
  37. the CodeSourcery, devkitARM or Raisonance GNU toolchain, you simply need to
  38. add one of the following configuration options to your .config (or defconfig)
  39. file:
  40. CONFIG_ARM_TOOLCHAIN_CODESOURCERYW=y : CodeSourcery under Windows
  41. CONFIG_ARM_TOOLCHAIN_CODESOURCERYL=y : CodeSourcery under Linux
  42. CONFIG_ARM_TOOLCHAIN_DEVKITARM=y : devkitARM under Windows
  43. CONFIG_ARM_TOOLCHAIN_BUILDROOT=y : NuttX buildroot under Linux or Cygwin (default)
  44. CONFIG_ARM_TOOLCHAIN_GNU_EABIL : Generic arm-none-eabi toolchain for Linux
  45. CONFIG_ARM_TOOLCHAIN_GNU_EABIW : Generic arm-none-eabi toolchain for Windows
  46. The toolchain may also be set using the kconfig-mconf utility (make menuconfig) or by
  47. passing CONFIG_ARM_TOOLCHAIN=<toolchain> to make, where <toolchain> is one
  48. of CODESOURCERYW, CODESOURCERYL, DEVKITARM, BUILDROOT or GNU_EABI as described
  49. above.
  50. NOTE: the CodeSourcery (for Windows), devkitARM, and Raisonance toolchains are
  51. Windows native toolchains. The CodeSourcey (for Linux) and NuttX buildroot
  52. toolchains are Cygwin and/or Linux native toolchains. There are several limitations
  53. to using a Windows based toolchain in a Cygwin environment. The three biggest are:
  54. 1. The Windows toolchain cannot follow Cygwin paths. Path conversions are
  55. performed automatically in the Cygwin makefiles using the 'cygpath' utility
  56. but you might easily find some new path problems. If so, check out 'cygpath -w'
  57. 2. Windows toolchains cannot follow Cygwin symbolic links. Many symbolic links
  58. are used in Nuttx (e.g., include/arch). The make system works around these
  59. problems for the Windows tools by copying directories instead of linking them.
  60. But this can also cause some confusion for you: For example, you may edit
  61. a file in a "linked" directory and find that your changes had no effect.
  62. That is because you are building the copy of the file in the "fake" symbolic
  63. directory. If you use a Windows toolchain, you should get in the habit of
  64. making like this:
  65. make clean_context all
  66. An alias in your .bashrc file might make that less painful.
  67. NOTE 1: The CodeSourcery toolchain (2009q1) does not work with default optimization
  68. level of -Os (See Make.defs). It will work with -O0, -O1, or -O2, but not with
  69. -Os.
  70. NOTE 2: The devkitARM toolchain includes a version of MSYS make. Make sure that
  71. the paths to Cygwin's /bin and /usr/bin directories appear BEFORE the devkitARM
  72. path or will get the wrong version of make.
  73. Generic arm-none-eabi GNU Toolchain
  74. -----------------------------------
  75. There are a number of toolchain projects providing support for ARMv4/v5
  76. class processors, including:
  77. GCC ARM Embedded
  78. https://developer.arm.com/open-source/gnu-toolchain/gnu-rm
  79. Summon ARM Toolchain
  80. https://github.com/esden/summon-arm-toolchain
  81. Yagarto
  82. http://www.yagarto.de
  83. Others exist for various Linux distributions, MacPorts, etc. Any version
  84. based on GCC 4.6.3 or later should work.
  85. IDEs
  86. ====
  87. NuttX is built using command-line make. It can be used with an IDE, but some
  88. effort will be required to create the project.
  89. Makefile Build
  90. --------------
  91. Under Eclipse, it is pretty easy to set up an "empty makefile project" and
  92. simply use the NuttX makefile to build the system. That is almost for free
  93. under Linux. Under Windows, you will need to set up the "Cygwin GCC" empty
  94. makefile project in order to work with Windows (Google for "Eclipse Cygwin" -
  95. there is a lot of help on the internet).
  96. Native Build
  97. ------------
  98. Here are a few tips before you start that effort:
  99. 1) Select the toolchain that you will be using in your .config file
  100. 2) Start the NuttX build at least one time from the Cygwin command line
  101. before trying to create your project. This is necessary to create
  102. certain auto-generated files and directories that will be needed.
  103. 3) Set up include pathes: You will need include/, arch/arm/src/lpc31xx,
  104. arch/arm/src/common, arch/arm/src/arm, and sched/.
  105. 4) All assembly files need to have the definition option -D __ASSEMBLY__
  106. on the command line.
  107. Startup files will probably cause you some headaches. The NuttX startup file
  108. is arch/arm/src/lpc31xx/lpc31_vectors.S. You may have to build NuttX
  109. one time from the Cygwin command line in order to obtain the pre-built
  110. startup object needed by an IDE.
  111. NuttX buildroot Toolchain
  112. =========================
  113. A GNU GCC-based toolchain is assumed. The PATH environment variable should
  114. be modified to point to the correct path to the Cortex-M3 GCC toolchain (if
  115. different from the default in your PATH variable).
  116. If you have no Cortex-M3 toolchain, one can be downloaded from the NuttX
  117. Bitbucket download site (https://bitbucket.org/nuttx/buildroot/downloads/).
  118. This GNU toolchain builds and executes in the Linux or Cygwin environment.
  119. 1. You must have already configured Nuttx in <some-dir>/nuttx.
  120. cd tools
  121. ./configure.sh olimex-lpc-h3131/<sub-dir>
  122. 2. Download the latest buildroot package into <some-dir>
  123. 3. unpack the buildroot tarball. The resulting directory may
  124. have versioning information on it like buildroot-x.y.z. If so,
  125. rename <some-dir>/buildroot-x.y.z to <some-dir>/buildroot.
  126. 4. cd <some-dir>/buildroot
  127. 5. cp configs/arm926t-defconfig-4.2.4 .config
  128. 6. make oldconfig
  129. 7. make
  130. 8. Make sure that the PATH variable includes the path to the newly built
  131. binaries.
  132. See the file configs/README.txt in the buildroot source tree. That has more
  133. detailed PLUS some special instructions that you will need to follow if you are
  134. building a Cortex-M3 toolchain for Cygwin under Windows.
  135. Boot Sequence
  136. =============
  137. LPC313x has on chip bootrom which loads properly formatted images from multiple
  138. sources into SRAM. These sources include including SPI Flash, NOR Flash, UART,
  139. USB, SD Card, and NAND Flash.
  140. In all configurations, NuttX is loaded directly into ISRAM. NuttX is linked
  141. to execute from ISRAM, regardless of the boot source.
  142. Buttons and LEDs
  143. ================
  144. Buttons
  145. -------
  146. There are no user buttons on the H3131
  147. LEDs
  148. ----
  149. There are two LEDs on the LPC-H3131 that can be controlled by software:
  150. LED GPIO
  151. ---------------- -----
  152. LED1 Yellow GPIO17 High output illuminates
  153. LED2 Green GPIO18 High output illuminates
  154. Both can be illuminated by driving the GPIO output to high.
  155. These LEDs are not used by the board port unless CONFIG_ARCH_LEDS is
  156. defined. In that case, the usage by the board port is defined in
  157. include/board.h and src/lpc31_leds.c. The LEDs are used to encode
  158. OS-related events as follows:
  159. SYMBOL Meaning LED state
  160. LED2 LED1
  161. ------------------- ----------------------- -------- --------
  162. LED_STARTED NuttX has been started OFF OFF
  163. LED_HEAPALLOCATE Heap has been allocated OFF OFF
  164. LED_IRQSENABLED Interrupts enabled OFF OFF
  165. LED_STACKCREATED Idle stack created ON OFF
  166. LED_INIRQ In an interrupt N/C N/C
  167. LED_SIGNAL In a signal handler N/C N/C
  168. LED_ASSERTION An assertion failed N/C N/C
  169. LED_PANIC The system has crashed N/C Blinking
  170. LED_IDLE MCU is is sleep mode Not used
  171. Thus if LED2 is statically on, NuttX has successfully booted and is,
  172. apparently, running normmally. If LED1 is flashing at approximately
  173. 2Hz, then a fatal error has been detected and the system has halted.
  174. NOTE: That LED2 is not used after completion of booting and may
  175. be used by other board-specific logic.
  176. Image Format
  177. ============
  178. In order to use the bootrom bootloader, a special header must be added to
  179. the beginning of the binary image that includes information about the
  180. binary (things like the entry point, the size, and CRC's to verify the image.
  181. NXP provides a Windows program to append such a header to the binary
  182. image. However, (1) that program won't run under Linux, and (2) when I
  183. try it under WinXP, Symantec immediately claims that the program is
  184. misbehaving and deletes it!
  185. To work around both of these issues, I have created a small program under
  186. configs/olimex-lpc-h3131/tools to add the header. This program can be
  187. built under either Linux or Cygwin (and probably other tool environments
  188. as well). That tool can be built as follows:
  189. - cd configs/olimex-lpc-h3131/tools
  190. - make
  191. Then, to build the NuttX binary ready to load with the bootloader, just
  192. following these steps:
  193. - cd tools/ # Configure Nuttx
  194. - ./configure.sh olimex-lpc-h3131/ostest # (using the ostest configuration for this example)
  195. - cd .. # Set up environment
  196. - make # Make NuttX. This will produce nuttx.bin
  197. - mklpc.sh # Make the bootloader binary (nuttx.lpc)
  198. NOTES:
  199. 1. Make sure to set your PATH variable appropriately or use the full path
  200. to mklpc.sh in the final step.
  201. 2. You can instruct Symantec to ignore the errors and it will stop
  202. quarantining the NXP program.
  203. 3. The CRC32 logic in configs/olimex-lpc-h3131/tools doesn't seem to
  204. work. As a result, the CRC is currently disabled in the header:
  205. RCS file: /cvsroot/nuttx/nuttx/configs/olimex-lpc-h3131/tools/lpchdr.c,v
  206. retrieving revision 1.2
  207. diff -r1.2 lpchdr.c
  208. 264c264
  209. < g_hdr.imageType = 0x0000000b;
  210. ---
  211. > g_hdr.imageType = 0x0000000a;
  212. Image Download to ISRAM
  213. =======================
  214. Assuming that you already have the FTDI driver installed*, then here is the
  215. are the steps that I use for loading new code into the LPC-H3131:
  216. 1. Create the bootloader binary, nuttx.lpc, as described above.
  217. 2. With the power off, set the boot jumpers to enable booting from UART.
  218. The boot jumpers are the block of three jumper just in-board from the
  219. JTAG connector; Jumper pair 1-2 is the pair furthest from the JTAG
  220. connector:
  221. 1-2: Closed
  222. 3-4: Closed
  223. 5-6: Open
  224. 3. Connected the LPC-H3131 using the FTDI USB port (not the lpc3131 USB port)
  225. This will power up the LPC-H3131 and start the bootloader.
  226. 4. Start a terminal emulator (such as TeraTerm) at 115200 8NI.
  227. 5. Reset the LPC-H3131 and you should see:
  228. LPC31xx READY FOR PLAIN IMAGE>
  229. 6. Send the nuttx.lpc file and you should see:
  230. Download finished
  231. That will load the NuttX binary into ISRAM and attempt to execute it.
  232. *See the LPC313x documentation if you do not have the FTDI driver installed.
  233. TeraTerm Note: This is how to send a file from TeraTerm. It is essentially
  234. step 6 exploded in more detail for the case of TeraTerm:
  235. 1. Start the ROM bootloader as described above.
  236. 2. At the "LPC31xx READY FOR PLAIN IMAGE>" prompt, open the File menu and
  237. select the "Send File..." option.
  238. 3. Select the file to send,
  239. 4. Before "Open" -ing the file MAKE SURE TO CHECK THE "Binary" BOX! This
  240. has cost me a few hours a few times because I forget to do this. The
  241. program will NOT RUN is sent non-binary.
  242. [NO, I am not SHOUTING. I am just making sure that I never forget to
  243. do this again].
  244. 5. "Open"-ing the file will send it to the ROM bootloader.
  245. 6. You should see "Download finished" from the bootloader followed
  246. immediately by any serial console output from your program.
  247. Using OpenOCD and GDB
  248. =====================
  249. [NOTE: As of this writing, my OpenOCD script does NOT work. It fails
  250. because it is unable to halt the LPC3131. So, unfortunately, OpenOCD
  251. is not a option right now.]
  252. I have been using the Olimex ARM-USB-OCD JTAG debugger with the LPC-H3131
  253. (http://www.olimex.com). The OpenOCD configuration file is here:
  254. tools/armusbocb.cfg. There is also a script on the tools directory that
  255. I used to start the OpenOCD daemon on my system called oocd.sh. That
  256. script would probably require some modifications to work in another
  257. environment:
  258. - possibly the value of OPENOCD_PATH
  259. - If you are working under Linux you will need to change any
  260. occurances of `cygpath -w blablabla` to just blablabla
  261. Then you should be able to start the OpenOCD daemon like:
  262. configs/olimex-lpc-h3131/tools/oocd.sh $PWD
  263. Where it is assumed that you are executing oocd.sh from the top level
  264. directory where NuttX is installed.
  265. Once the OpenOCD daemon has been started, you can connect to it via
  266. GDB using the following GDB command:
  267. arm-nuttx-elf-gdb
  268. (gdb) target remote localhost:3333
  269. And you can load the NuttX ELF file:
  270. (gdb) symbol-file nuttx
  271. (gdb) load nuttx
  272. ARM/LPC-H3131-specific Configuration Options
  273. ============================================
  274. CONFIG_ARCH - Identifies the arch/ subdirectory. This should
  275. be set to:
  276. CONFIG_ARCH=arm
  277. CONFIG_ARCH_family - For use in C code:
  278. CONFIG_ARCH_ARM=y
  279. CONFIG_ARCH_architecture - For use in C code:
  280. CONFIG_ARCH_ARM926EJS=y
  281. CONFIG_ARCH_CHIP - Identifies the arch/*/chip subdirectory
  282. CONFIG_ARCH_CHIP=lpc313x
  283. CONFIG_ARCH_CHIP_name - For use in C code
  284. CONFIG_ARCH_CHIP_LPC3131
  285. CONFIG_ARCH_BOARD - Identifies the configs subdirectory and
  286. hence, the board that supports the particular chip or SoC.
  287. CONFIG_ARCH_BOARD="olimex-lpc-h3131"
  288. CONFIG_ARCH_BOARD_name - For use in C code
  289. CONFIG_ARCH_BOARD_OLIMEX_LPC_H3131
  290. CONFIG_ARCH_LOOPSPERMSEC - Must be calibrated for correct operation
  291. of delay loops
  292. CONFIG_ENDIAN_BIG - define if big endian (default is little
  293. endian)
  294. CONFIG_RAM_SIZE - For most ARM9 architectures, this describes the
  295. size of installed DRAM. For the LPC313X, it is used only to
  296. deterimine how to map the executable regions. It is SDRAM size
  297. only if you are executing out of the external SDRAM; or it could
  298. be NOR FLASH size, external SRAM size, or internal SRAM size.
  299. CONFIG_RAM_START - The start address of installed DRAM (physical)
  300. CONFIG_RAM_VSTART - The startaddress of DRAM (virtual)
  301. CONFIG_ARCH_LEDS - Use LEDs to show state. Unique to boards that
  302. have LEDs
  303. CONFIG_ARCH_INTERRUPTSTACK - This architecture supports an interrupt
  304. stack. If defined, this symbol is the size of the interrupt
  305. stack in bytes. If not defined, the user task stacks will be
  306. used during interrupt handling.
  307. CONFIG_ARCH_STACKDUMP - Do stack dumps after assertions
  308. CONFIG_ARCH_LEDS - Use LEDs to show state. Unique to board architecture.
  309. CONFIG_ARCH_BUTTONS - Enable support for buttons. Unique to board architecture.
  310. CONFIG_ARCH_CALIBRATION - Enables some build in instrumentation that
  311. cause a 100 second delay during boot-up. This 100 second delay
  312. serves no purpose other than it allows you to calibratre
  313. CONFIG_ARCH_LOOPSPERMSEC. You simply use a stop watch to measure
  314. the 100 second delay then adjust CONFIG_ARCH_LOOPSPERMSEC until
  315. the delay actually is 100 seconds.
  316. CONFIG_ARCH_DMA - Support DMA initialization
  317. CONFIG_ARCH_LOWVECTORS - define if vectors reside at address 0x0000:00000
  318. Undefine if vectors reside at address 0xffff:0000
  319. CONFIG_ARCH_ROMPGTABLE - A pre-initialized, read-only page table is available.
  320. If defined, then board-specific logic must also define PGTABLE_BASE_PADDR,
  321. PGTABLE_BASE_VADDR, and all memory section mapping in a file named
  322. board_memorymap.h.
  323. Individual subsystems can be enabled:
  324. CONFIG_LPC31_MCI, CONFIG_LPC31_SPI, CONFIG_LPC31_UART
  325. External memory available on the board (see also CONFIG_MM_REGIONS)
  326. CONFIG_LPC31_EXTSRAM0 - Select if external SRAM0 is present
  327. CONFIG_LPC31_EXTSRAM0HEAP - Select if external SRAM0 should be
  328. configured as part of the NuttX heap.
  329. CONFIG_LPC31_EXTSRAM0SIZE - Size (in bytes) of the installed
  330. external SRAM0 memory
  331. CONFIG_LPC31_EXTSRAM1 - Select if external SRAM1 is present
  332. CONFIG_LPC31_EXTSRAM1HEAP - Select if external SRAM1 should be
  333. configured as part of the NuttX heap.
  334. CONFIG_LPC31_EXTSRAM1SIZE - Size (in bytes) of the installed
  335. external SRAM1 memory
  336. CONFIG_LPC31_EXTDRAM - Select if external SDRAM is present
  337. CONFIG_LPC31_EXTDRAMHEAP - Select if external SDRAM should be
  338. configured as part of the NuttX heap.
  339. CONFIG_LPC31_EXTDRAMSIZE - Size (in bytes) of the installed
  340. external SDRAM memory
  341. CONFIG_LPC31_EXTNAND - Select if external NAND is present
  342. CONFIG_LPC31_EXTNANDSIZE - Size (in bytes) of the installed
  343. external NAND memory
  344. LPC313X specific device driver settings
  345. CONFIG_UART_SERIAL_CONSOLE - selects the UART for the
  346. console and ttys0
  347. CONFIG_UART_RXBUFSIZE - Characters are buffered as received.
  348. This specific the size of the receive buffer
  349. CONFIG_UART_TXBUFSIZE - Characters are buffered before
  350. being sent. This specific the size of the transmit buffer
  351. CONFIG_UART_BAUD - The configure BAUD of the UART. Must be
  352. CONFIG_UART_BITS - The number of bits. Must be either 7 or 8.
  353. CONFIG_UART_PARTIY - 0=no parity, 1=odd parity, 2=even parity
  354. CONFIG_UART_2STOP - Two stop bits
  355. Configurations
  356. ==============
  357. Configurations
  358. ==============
  359. Information Common to All Configurations
  360. ----------------------------------------
  361. Each LPC-H3131 configuration is maintained in a sub-directory and can be
  362. selected as follow:
  363. cd tools
  364. ./configure.sh olimex-lpc-h3131/<subdir>
  365. cd -
  366. Before building, make sure the PATH environment variable includes the
  367. correct path to the directory than holds your toolchain binaries.
  368. And then build NuttX by simply typing the following. At the conclusion of
  369. the make, the nuttx binary will reside in an ELF file called, simply, nuttx.
  370. make
  371. The <subdir> that is provided above as an argument to the tools/configure.sh
  372. must be is one of the following.
  373. NOTES:
  374. 1. These configurations use the mconf-based configuration tool. To
  375. change any of these configurations using that tool, you should:
  376. a. Build and install the kconfig-mconf tool. See nuttx/README.txt
  377. see additional README.txt files in the NuttX tools repository.
  378. b. Execute 'make menuconfig' in nuttx/ in order to start the
  379. reconfiguration process.
  380. 2. Unless stated otherwise, all configurations generate console
  381. output on the UART0 associated with the FT232RL USB-to UART
  382. converter.
  383. 3. Unless otherwise stated, the configurations are setup for
  384. Windows undery Cygwin. This can, however, be easilty reconfigured.
  385. 4. All of these configurations use the Code Sourcery for Windows toolchain
  386. (unless stated otherwise in the description of the configuration). That
  387. toolchain selection can easily be reconfigured using 'make menuconfig'.
  388. Here are the relevant current settings:
  389. Build Setup:
  390. CONFIG_HOST_WINDOWS=y : Microsoft Windows
  391. CONFIG_WINDOWS_CYGWIN=y : Using Cygwin or other POSIX environment
  392. System Type -> Toolchain:
  393. CONFIG_ARM_TOOLCHAIN_GNU_EABIW=y : GNU EABI toolchain for windows
  394. Configuration sub-directories
  395. -----------------------------
  396. nsh:
  397. Configures the NuttShell (nsh) located at examples/nsh. The
  398. Configuration enables only the serial NSH interface.
  399. General Configuration. These are easily change by modifying the NuttX
  400. configuration:
  401. - Console on UART -> UART-to-USB converter
  402. - Platform: Windows with Cygwin
  403. - Toolchain: CodeSourcery for Windows
  404. NOTES:
  405. 1. Built-in applications are not supported by default. To enable NSH
  406. built-in applications:
  407. Binary
  408. CONFIG_BUILTIN=y : Support built-in applications
  409. Application Configuration -> NSH Library
  410. CONFIG_NSH_BUILTIN_APPS=y : Enable built-in applications
  411. 2. SDRAM support is not enabled by default. SDRAM support can be enabled
  412. by adding the following to your NuttX configuration file:
  413. [NOTE: There is still something wrong with the SDRAM setup. At present
  414. it hangs on the first access from SDRAM during configuration.]
  415. System Type->LPC31xx Peripheral Support
  416. CONFIG_LPC31_EXTDRAM=y : Enable external DRAM support
  417. CONFIG_LPC31_EXTDRAMSIZE=33554432 : 256Mbit -> 32Mbyte
  418. CONFIG_LPC31_SDRAM_16BIT=y : Organized 16Mbit x 16 bits wide
  419. Now that you have SDRAM enabled, what are you going to do with it? One
  420. thing you can is add it to the heap
  421. System Type->Heap Configuration
  422. CONFIG_LPC31_EXTDRAMHEAP=y : Add the SDRAM to the heap
  423. Memory Management
  424. CONFIG_MM_REGIONS=2 : Two memory regions: ISRAM and SDRAM
  425. Another thing you could do is to enable the RAM test built-in
  426. application:
  427. 3. You can enable the NuttX RAM test that may be used to verify the
  428. external SDAM. To do this, keep the SDRAM out of the heap so that
  429. it can be tested without crashing programs using the memory.
  430. First enable built-in applications as described above, then make
  431. the following additional modifications to the NuttX configuration:
  432. System Type->Heap Configuration
  433. CONFIG_LPC31_EXTDRAMHEAP=n : Don't add the SDRAM to the heap
  434. Memory Management
  435. CONFIG_MM_REGIONS=1 : One memory regions: ISRAM
  436. Then enable the RAM test built-in application:
  437. Application Configuration->System NSH Add-Ons->Ram Test
  438. CONFIG_SYSTEM_RAMTEST=y
  439. In this configuration, the SDRAM is not added to heap and so is not
  440. excessible to the applications. So the RAM test can be freely
  441. executed against the SRAM memory beginning at address 0x2000:0000
  442. (DDR CS):
  443. nsh> ramtest -h
  444. Usage: ramtest [-w|h|b] <hex-address> <decimal-size>
  445. Where:
  446. <hex-address> starting address of the test.
  447. <decimal-size> number of memory locations (in bytes).
  448. -w Sets the width of a memory location to 32-bits.
  449. -h Sets the width of a memory location to 16-bits (default).
  450. -b Sets the width of a memory location to 8-bits.
  451. To test the entire external 256MB SRAM:
  452. nsh> ramtest -w 30000000 33554432
  453. RAMTest: Marching ones: 30000000 33554432
  454. RAMTest: Marching zeroes: 30000000 33554432
  455. RAMTest: Pattern test: 30000000 33554432 55555555 aaaaaaaa
  456. RAMTest: Pattern test: 30000000 33554432 66666666 99999999
  457. RAMTest: Pattern test: 30000000 33554432 33333333 cccccccc
  458. RAMTest: Address-in-address test: 30000000 33554432
  459. 4. This configuration has been used to test USB host functionality. USB
  460. host is *not* enabled by default. If you will to enable USB host
  461. support in the NSH configuration, please modify the NuttX
  462. configuration as follows:
  463. a) Basic USB Host support
  464. Drivers -> USB Host Driver Support
  465. CONFIG_USBHOST=y : General USB host support
  466. CONFIG_USBHOST_INT_DISABLE=n : Interrupt EPs need with hub, HID keyboard, and HID mouse
  467. CONFIG_USBHOST_ISOC_DISABLE=y : Not needed (or supported)
  468. System Type -> Peripherals
  469. CONFIG_LPC31_USBOTG=y : Enable the USB OTG peripheral
  470. System Type -> USB host configuration
  471. CONFIG_LPC31_EHCI_BUFSIZE=128
  472. CONFIG_LPC31_EHCI_PREALLOCATE=y
  473. RTOS Features -> Work Queue Support
  474. CONFIG_SCHED_WORKQUEUE=y : High priority queue support is needed
  475. CONFIG_SCHED_HPWORK=y
  476. CONFIG_SCHED_HPWORKSTACKSIZE=1536 (1024 seems to work okay too)
  477. b. Hub Support.
  478. Drivers -> USB Host Driver Support
  479. CONFIG_USBHOST_INT_DISABLE=n : Interrupt endpoint support needed
  480. CONFIG_USBHOST_HUB=y : Enable the hub class
  481. CONFIG_USBHOST_ASYNCH=y : Asynchronous I/O supported needed for hubs
  482. RTOS Features -> Work Queue Support
  483. CONFIG_SCHED_LPWORK=y : Low priority queue support is needed
  484. CONFIG_SCHED_LPNTHREADS=1
  485. CONFIG_SCHED_LPWORKSTACKSIZE=1024
  486. NOTES:
  487. 1. It is necessary to perform work on the low-priority work queue
  488. (vs. the high priority work queue) because:
  489. a. Deferred work requires some delays and waiting, and
  490. b. There are dependencies between the waiting and driver
  491. interrupt related work. Since that interrupt related work
  492. will performed on the high priority work queue, there would
  493. be the likelihood of deadlocks if you wait for events on the
  494. high priority work thread that can only occur if the high
  495. priority work thread is available to post those events.
  496. 2. Logic nesting becomes deeper with a hub and it may also be
  497. necessary to increase some stack sizes.
  498. c. USB Mass Storage Class. With this class enabled, you can support
  499. connection of USB FLASH storage drives. Support for the USB
  500. mass storage class is enabled like this:
  501. Drivers -> USB Host Driver Support
  502. CONFIG_USBHOST_MSC=y : Mass storage class support
  503. The MSC class will work like this. When you first start NSH, you
  504. can look at the available devices like this:
  505. NuttShell (NSH) NuttX-6.31
  506. nsh> ls -l /dev
  507. /dev:
  508. crw-rw-rw- 0 console
  509. crw-rw-rw- 0 null
  510. crw-rw-rw- 0 ttyS0
  511. The crw-rw-rw- indicates a readable, write-able character device.
  512. nsh> ls -l /dev
  513. /dev:
  514. crw-rw-rw- 0 console
  515. crw-rw-rw- 0 null
  516. brw-rw-rw- 0 sda
  517. crw-rw-rw- 0 ttyS0
  518. The brw-rw-rw- indicates a readable, write-able block device.
  519. This block device can then be mounted like this:
  520. nsh> mount -t vfat /dev/sda /mnt/flash
  521. The USB FLASH drive contents are then visible under /mnt/flash and
  522. can be operated on with normal file system commands like:
  523. nsh> mount -t vfat /dev/sda /mnt/flash
  524. nsh> cat /mnt/flash/filec.c
  525. etc.
  526. It is recommended that the drive by unmounted BEFORE it is
  527. removed. That is not always possible so if the USB FLASH is
  528. removed BEFORE the drive is unmounted, the device at /dev/sda will
  529. persist in an unusable stack until it is unmounted with the
  530. following command (NOTE: If the FLASH drive is re-inserted in
  531. this state, it will appear as /dev/sdb):
  532. nsh> umount /mnt/flash
  533. d. HID Keyboard support. The following support will enable support
  534. for certain keyboard devices (only the so-called "boot" keyboard
  535. class is supported):
  536. Drivers -> USB Host Driver Support
  537. CONFIG_USBHOST_HIDKBD=y : HID keyboard class support
  538. Drivers -> USB Host Driver Support
  539. CONFIG_USBHOST_INT_DISABLE=n : Interrupt endpoint support needed
  540. In this case, when the HID keyboard is installed, you see a new
  541. character device called /dev/kbda.
  542. There is a HID keyboard test example that can be enabled with the
  543. following settings. NOTE: In this case, NSH is disabled because
  544. the HID keyboard test is a standalone test.
  545. This selects the HIDKBD example:
  546. Application Configuration -> Examples
  547. CONFIG_EXAMPLES_HIDKBD=y
  548. CONFIG_EXAMPLES_HIDKBD_DEVNAME="/dev/kbda"
  549. RTOS Features
  550. CONFIG_USER_ENTRYPOINT="hidkbd_main"
  551. These settings disable NSH:
  552. Application Configuration -> Examples
  553. CONFIG_EXAMPLES_NSH=n
  554. Application Configuration -> NSH Library
  555. CONFIG_NSH_LIBRARY=y
  556. Using the HID Keyboard example: Anything typed on the keyboard
  557. should be echoed on the serial console. Here is some sample of
  558. a session:
  559. Initialization
  560. hidkbd_main: Register class drivers
  561. hidkbd_main: Initialize USB host keyboard driver
  562. hidkbd_main: Start hidkbd_waiter
  563. hidkbd_waiter: Running
  564. The test example will periodically attempt to open /dev/kbda
  565. Opening device /dev/kbda
  566. Failed: 2
  567. Opening device /dev/kbda
  568. Failed: 2
  569. etc.
  570. The open will fail each time because there is no keyboard
  571. attached. When a USB keyboard is attached, the open of /dev/kbda
  572. will succeed and the test will begin echoing data to the serial
  573. console:
  574. hidkbd_waiter: connected
  575. Opening device /dev/kbda
  576. Device /dev/kbda opened
  577. For example, this text was entered from the keyboard:
  578. Now is the time for all good men to come to the aid of their party.
  579. Then when the device is removed, the test will resume attempting
  580. to open the driver until the next time it is connected
  581. Closing device /dev/kbda: -1
  582. Opening device /dev/kbda
  583. Failed: 19
  584. hidkbd_waiter: disconnected
  585. Opening device /dev/kbda
  586. Failed: 2
  587. etc.
  588. d. The USB monitor can also be enabled:
  589. Drivers -> USB Host Driver Support
  590. CONFIG_USBHOST_TRACE=y
  591. CONFIG_USBHOST_TRACE_NRECORDS=128
  592. CONFIG_USBHOST_TRACE_VERBOSE=y
  593. Application Configuration -> System Add-Ons
  594. CONFIG_USBMONITOR=y
  595. CONFIG_USBMONITOR_INTERVAL=1
  596. NOTE: I have found that if you enable USB DEBUG and/or USB tracing,
  597. the resulting image requires to much memory to execute out of
  598. internal SRAM. I was able to get the configurations to run out of
  599. SRAM with debug/tracing enabled by carefully going through the
  600. configuration and reducing stack sizes, disabling unused OS features,
  601. disabling un-necessary NSH commands, etc.
  602. 5. Making the Configuration Smaller. This configuration runs out of
  603. internal SRAM. If you enable many features, then your code image
  604. may outgrow the available SRAM; even if the code can be loaded into
  605. SRAM, it may still fail at runtime due to insufficient memory.
  606. Since SDRAM is not currently working (see above) and NAND support
  607. has not be integrated, the only really option is to put NSH "on a
  608. diet" to reduct the size so that it will fit into memory.
  609. Here are a few things you can do:
  610. 1. Try using smaller stack sizes,
  611. 2. Disable operating system features. Here some that can go:
  612. CONFIG_DISABLE_ENVIRON=y
  613. CONFIG_DISABLE_MQUEUE=y
  614. CONFIG_DISABLE_POSIX_TIMERS=y
  615. CONFIG_DISABLE_PTHREAD=y
  616. CONFIG_MQ_MAXMSGSIZE=0
  617. CONFIG_NPTHREAD_KEYS=0
  618. CONFIG_NUNGET_CHARS=0
  619. CONFIG_PREALLOC_MQ_MSGS=0
  620. 3. Disable NSH commands. I can life fine without these:
  621. CONFIG_NSH_DISABLE_ADDROUTE=y
  622. CONFIG_NSH_DISABLE_CD=y
  623. CONFIG_NSH_DISABLE_CMP=y
  624. CONFIG_NSH_DISABLE_CP=y
  625. CONFIG_NSH_DISABLE_DD=y
  626. CONFIG_NSH_DISABLE_DELROUTE=y
  627. CONFIG_NSH_DISABLE_EXEC=y
  628. CONFIG_NSH_DISABLE_EXIT=y
  629. CONFIG_NSH_DISABLE_GET=y
  630. CONFIG_NSH_DISABLE_HEXDUMP=y
  631. CONFIG_NSH_DISABLE_IFCONFIG=y
  632. CONFIG_NSH_DISABLE_LOSETUP=y
  633. CONFIG_NSH_DISABLE_MB=y
  634. CONFIG_NSH_DISABLE_MH=y
  635. CONFIG_NSH_DISABLE_MKFIFO=y
  636. CONFIG_NSH_DISABLE_MKRD=y
  637. CONFIG_NSH_DISABLE_NSFMOUNT=y
  638. CONFIG_NSH_DISABLE_PING=y
  639. CONFIG_NSH_DISABLE_PUT=y
  640. CONFIG_NSH_DISABLE_PWD=y
  641. CONFIG_NSH_DISABLE_RM=y
  642. CONFIG_NSH_DISABLE_RMDIR=y
  643. CONFIG_NSH_DISABLE_SET=y
  644. CONFIG_NSH_DISABLE_SH=y
  645. CONFIG_NSH_DISABLE_SLEEP=y
  646. CONFIG_NSH_DISABLE_TEST=y
  647. CONFIG_NSH_DISABLE_UNSET=y
  648. CONFIG_NSH_DISABLE_USLEEP=y
  649. CONFIG_NSH_DISABLE_WGET=y
  650. CONFIG_NSH_DISABLE_XD=y