From 9bc92c640d026bef295a9d29e6182f74b21bda72 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 10 Mar 2014 15:18:46 -0600 Subject: [PATCH] SAM4E-EK: Add basic board support --- configs/Kconfig | 14 + configs/README.txt | 4 + configs/sam3u-ek/src/up_buttons.c | 4 +- configs/sam4e-ek/Kconfig | 19 + configs/sam4e-ek/README.txt | 624 +++++++++++++ configs/sam4e-ek/include/board.h | 306 ++++++ configs/sam4e-ek/nsh/Make.defs | 110 +++ configs/sam4e-ek/nsh/defconfig | 853 +++++++++++++++++ configs/sam4e-ek/nsh/setenv.sh | 68 ++ configs/sam4e-ek/scripts/flash.ld | 116 +++ configs/sam4e-ek/src/.gitignore | 2 + configs/sam4e-ek/src/Makefile | 110 +++ configs/sam4e-ek/src/sam4e-ek.h | 308 +++++++ configs/sam4e-ek/src/sam_boot.c | 112 +++ configs/sam4e-ek/src/sam_buttons.c | 199 ++++ configs/sam4e-ek/src/sam_cxxinitialize.c | 149 +++ configs/sam4e-ek/src/sam_lcd.c | 1078 ++++++++++++++++++++++ configs/sam4e-ek/src/sam_leds.c | 215 +++++ configs/sam4e-ek/src/sam_mmcsd.c | 149 +++ configs/sam4e-ek/src/sam_nsh.c | 164 ++++ configs/sam4e-ek/src/sam_spi.c | 204 ++++ configs/sam4e-ek/src/sam_touchscreen.c | 294 ++++++ configs/sam4e-ek/src/sam_usbdev.c | 108 +++ configs/sam4e-ek/src/sam_usbmsc.c | 148 +++ 24 files changed, 5356 insertions(+), 2 deletions(-) create mode 100644 configs/sam4e-ek/Kconfig create mode 100644 configs/sam4e-ek/README.txt create mode 100644 configs/sam4e-ek/include/board.h create mode 100644 configs/sam4e-ek/nsh/Make.defs create mode 100644 configs/sam4e-ek/nsh/defconfig create mode 100755 configs/sam4e-ek/nsh/setenv.sh create mode 100755 configs/sam4e-ek/scripts/flash.ld create mode 100644 configs/sam4e-ek/src/.gitignore create mode 100644 configs/sam4e-ek/src/Makefile create mode 100644 configs/sam4e-ek/src/sam4e-ek.h create mode 100644 configs/sam4e-ek/src/sam_boot.c create mode 100644 configs/sam4e-ek/src/sam_buttons.c create mode 100644 configs/sam4e-ek/src/sam_cxxinitialize.c create mode 100644 configs/sam4e-ek/src/sam_lcd.c create mode 100644 configs/sam4e-ek/src/sam_leds.c create mode 100644 configs/sam4e-ek/src/sam_mmcsd.c create mode 100644 configs/sam4e-ek/src/sam_nsh.c create mode 100644 configs/sam4e-ek/src/sam_spi.c create mode 100644 configs/sam4e-ek/src/sam_touchscreen.c create mode 100644 configs/sam4e-ek/src/sam_usbdev.c create mode 100644 configs/sam4e-ek/src/sam_usbmsc.c diff --git a/configs/Kconfig b/configs/Kconfig index cb7fd906bc..8b7f8c78a6 100644 --- a/configs/Kconfig +++ b/configs/Kconfig @@ -564,6 +564,16 @@ config ARCH_BOARD_SAM3UEK ---help--- The port of NuttX to the Atmel SAM3U-EK development board. +config ARCH_BOARD_SAM4EEK + bool "Atmel SAM4E-EK development board" + depends on ARCH_CHIP_ATSAM4E16E + select ARCH_HAVE_LEDS + select ARCH_HAVE_BUTTONS + select ARCH_HAVE_IRQBUTTONS + ---help--- + The port of NuttX to the Atmel SAM4E-EK development board. This + board features the SAM4E16 MCU running at up to 120MHz. + config ARCH_BOARD_SAM4L_XPLAINED bool "Atmel SAM4L-Xplained Pro development board" depends on ARCH_CHIP_ATSAM4LC4C @@ -949,6 +959,7 @@ config ARCH_BOARD default "sama5d3x-ek" if ARCH_BOARD_SAMA5D3X_EK default "samd20-xplained" if ARCH_BOARD_SAMD20_XPLAINED default "sam3u-ek" if ARCH_BOARD_SAM3UEK + default "sam4e-ek" if ARCH_BOARD_SAM4EEK default "sam4l-xplained" if ARCH_BOARD_SAM4L_XPLAINED default "sam4s-xplained" if ARCH_BOARD_SAM4S_XPLAINED default "shenzhou" if ARCH_BOARD_SHENZHOU @@ -1202,6 +1213,9 @@ endif if ARCH_BOARD_SAM3UEK source "configs/sam3u-ek/Kconfig" endif +if ARCH_BOARD_SAM4EEK +source "configs/sam4e-ek/Kconfig" +endif if ARCH_BOARD_SAM4L_XPLAINED source "configs/sam4l-xplained/Kconfig" endif diff --git a/configs/README.txt b/configs/README.txt index 133578e90a..b0499c2361 100644 --- a/configs/README.txt +++ b/configs/README.txt @@ -477,6 +477,10 @@ configs/samd20-xplained configs/sam3u-ek The port of NuttX to the Atmel SAM3U-EK development board. +configs/sam4e-ek + The port of NuttX to the Atmel SAM4E-EK development board. This board + features the SAM4E16 MCU running at up to 120MHz. + configs/sam4l-xplained The port of NuttX to the Atmel SAM4L-Xplained development board. diff --git a/configs/sam3u-ek/src/up_buttons.c b/configs/sam3u-ek/src/up_buttons.c index 81457162a3..40d0f910a1 100644 --- a/configs/sam3u-ek/src/up_buttons.c +++ b/configs/sam3u-ek/src/up_buttons.c @@ -143,8 +143,8 @@ uint8_t board_buttons(void) { uint8_t retval; - retval = sam_gpioread(GPIO_BUTTON1) ? 0 : GPIO_BUTTON1; - retval |= sam_gpioread(GPIO_BUTTON2) ? 0 : GPIO_BUTTON2; + retval = sam_gpioread(GPIO_BUTTON1) ? 0 : BUTTON1; + retval |= sam_gpioread(GPIO_BUTTON2) ? 0 : BUTTON2; return retval; } diff --git a/configs/sam4e-ek/Kconfig b/configs/sam4e-ek/Kconfig new file mode 100644 index 0000000000..d052da0074 --- /dev/null +++ b/configs/sam4e-ek/Kconfig @@ -0,0 +1,19 @@ +# +# For a description of the syntax of this configuration file, +# see misc/tools/kconfig-language.txt. +# + +if ARCH_BOARD_SAM4EEK + +choice + prompt "CPU Frequency" + default SAM4EEK_96MHZ + +config SAM4EEK_96MHZ + bool "96 MHz" + +config SAM4EEK_120MHZ + bool "120 MHz" + +endchoice # CPU Frequency +endif # ARCH_BOARD_SAM4EEK diff --git a/configs/sam4e-ek/README.txt b/configs/sam4e-ek/README.txt new file mode 100644 index 0000000000..0076c055a3 --- /dev/null +++ b/configs/sam4e-ek/README.txt @@ -0,0 +1,624 @@ +README +^^^^^^ + +This README discusses issues unique to NuttX configurations for the Atmel +SAM4E-EK development. This board features the SAM4E16 MCU running at 96 +or 120MHz. + +Contents +^^^^^^^^ + + - Development Environment + - GNU Toolchain Options + - IDEs + - NuttX EABI "buildroot" Toolchain + - NuttX OABI "buildroot" Toolchain + - NXFLAT Toolchain + - AtmelStudio6.1 + - LEDs + - Serial Console + - SAM4E-EK-specific Configuration Options + - Configurations + +Development Environment +^^^^^^^^^^^^^^^^^^^^^^^ + + Either Linux or Cygwin on Windows can be used for the development environment. + The source has been built only using the GNU toolchain (see below). Other + toolchains will likely cause problems. Testing was performed using the Cygwin + environment. + +GNU Toolchain Options +^^^^^^^^^^^^^^^^^^^^^ + + The NuttX make system can be configured to support the various different + toolchain options. All testing has been conducted using the NuttX buildroot + toolchain. To use alternative toolchain, you simply need to add change of + the following configuration options to your .config (or defconfig) file: + + CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYW=y : CodeSourcery under Windows + CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYL=y : CodeSourcery under Linux + CONFIG_ARMV7M_TOOLCHAIN_ATOLLIC=y : Atollic toolchain for Windos + CONFIG_ARMV7M_TOOLCHAIN_DEVKITARM=y : devkitARM under Windows + CONFIG_ARMV7M_TOOLCHAIN_BUILDROOT=y : NuttX buildroot under Linux or Cygwin (default) + CONFIG_ARMV7M_TOOLCHAIN_GNU_EABIL=y : Generic GCC ARM EABI toolchain for Linux + CONFIG_ARMV7M_TOOLCHAIN_GNU_EABIW=y : Generic GCC ARM EABI toolchain for Windows + + You may also have to modify the PATH in the setenv.h file if your + make cannot find the tools. + + NOTE about Windows native toolchains + ------------------------------------ + + There are basically three kinds of GCC toolchains that can be used: + + 1. A Linux native toolchain in a Linux environment, + 2. The buildroot Cygwin tool chain built in the Cygwin environment, + 3. A Windows native toolchain. + + There are several limitations to using a Windows based toolchain (#3) in a + Cygwin environment. The three biggest are: + + 1. The Windows toolchain cannot follow Cygwin paths. Path conversions are + performed automatically in the Cygwin makefiles using the 'cygpath' + utility but you might easily find some new path problems. If so, check + out 'cygpath -w' + + 2. Windows toolchains cannot follow Cygwin symbolic links. Many symbolic + links are used in Nuttx (e.g., include/arch). The make system works + around these problems for the Windows tools by copying directories + instead of linking them. But this can also cause some confusion for + you: For example, you may edit a file in a "linked" directory and find + that your changes had no effect. That is because you are building the + copy of the file in the "fake" symbolic directory. If you use a + Windows toolchain, you should get in the habit of making like this: + + make clean_context all + + An alias in your .bashrc file might make that less painful. + + 3. Dependencies are not made when using Windows versions of the GCC. This + is because the dependencies are generated using Windows paths which do + not work with the Cygwin make. + + MKDEP = $(TOPDIR)/tools/mknulldeps.sh + +IDEs +^^^^ + + NuttX is built using command-line make. It can be used with an IDE, but some + effort will be required to create the project (There is a simple RIDE project + in the RIDE subdirectory). + + Makefile Build + -------------- + Under Eclipse, it is pretty easy to set up an "empty makefile project" and + simply use the NuttX makefile to build the system. That is almost for free + under Linux. Under Windows, you will need to set up the "Cygwin GCC" empty + makefile project in order to work with Windows (Google for "Eclipse Cygwin" - + there is a lot of help on the internet). + + Native Build + ------------ + Here are a few tips before you start that effort: + + 1) Select the toolchain that you will be using in your .config file + 2) Start the NuttX build at least one time from the Cygwin command line + before trying to create your project. This is necessary to create + certain auto-generated files and directories that will be needed. + 3) Set up include pathes: You will need include/, arch/arm/src/sam34, + arch/arm/src/common, arch/arm/src/armv7-m, and sched/. + 4) All assembly files need to have the definition option -D __ASSEMBLY__ + on the command line. + + Startup files will probably cause you some headaches. The NuttX startup file + is arch/arm/src/sam34/sam_vectors.S. You may need to build NuttX + one time from the Cygwin command line in order to obtain the pre-built + startup object needed by RIDE. + +NuttX EABI "buildroot" Toolchain +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + A GNU GCC-based toolchain is assumed. The files */setenv.sh should + be modified to point to the correct path to the Cortex-M3 GCC toolchain (if + different from the default in your PATH variable). + + If you have no Cortex-M3 toolchain, one can be downloaded from the NuttX + SourceForge download site (https://sourceforge.net/projects/nuttx/files/buildroot/). + This GNU toolchain builds and executes in the Linux or Cygwin environment. + + 1. You must have already configured Nuttx in /nuttx. + + cd tools + ./configure.sh sam4e-ek/ + + 2. Download the latest buildroot package into + + 3. unpack the buildroot tarball. The resulting directory may + have versioning information on it like buildroot-x.y.z. If so, + rename /buildroot-x.y.z to /buildroot. + + 4. cd /buildroot + + 5. cp configs/cortexm3-eabi-defconfig-4.6.3 .config + + 6. make oldconfig + + 7. make + + 8. Edit setenv.h, if necessary, so that the PATH variable includes + the path to the newly built binaries. + + See the file configs/README.txt in the buildroot source tree. That has more + details PLUS some special instructions that you will need to follow if you are + building a Cortex-M3 toolchain for Cygwin under Windows. + + NOTE: Unfortunately, the 4.6.3 EABI toolchain is not compatible with the + the NXFLAT tools. See the top-level TODO file (under "Binary loaders") for + more information about this problem. If you plan to use NXFLAT, please do not + use the GCC 4.6.3 EABI toochain; instead use the GCC 4.3.3 OABI toolchain. + See instructions below. + +NuttX OABI "buildroot" Toolchain +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + The older, OABI buildroot toolchain is also available. To use the OABI + toolchain: + + 1. When building the buildroot toolchain, either (1) modify the cortexm3-eabi-defconfig-4.6.3 + configuration to use EABI (using 'make menuconfig'), or (2) use an exising OABI + configuration such as cortexm3-defconfig-4.3.3 + + 2. Modify the Make.defs file to use the OABI conventions: + + +CROSSDEV = arm-nuttx-elf- + +ARCHCPUFLAGS = -mtune=cortex-m3 -march=armv7-m -mfloat-abi=soft + +NXFLATLDFLAGS2 = $(NXFLATLDFLAGS1) -T$(TOPDIR)/binfmt/libnxflat/gnu-nxflat-gotoff.ld -no-check-sections + -CROSSDEV = arm-nuttx-eabi- + -ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft + -NXFLATLDFLAGS2 = $(NXFLATLDFLAGS1) -T$(TOPDIR)/binfmt/libnxflat/gnu-nxflat-pcrel.ld -no-check-sections + +NXFLAT Toolchain +^^^^^^^^^^^^^^^^ + + If you are *not* using the NuttX buildroot toolchain and you want to use + the NXFLAT tools, then you will still have to build a portion of the buildroot + tools -- just the NXFLAT tools. The buildroot with the NXFLAT tools can + be downloaded from the NuttX SourceForge download site + (https://sourceforge.net/projects/nuttx/files/). + + This GNU toolchain builds and executes in the Linux or Cygwin environment. + + 1. You must have already configured Nuttx in /nuttx. + + cd tools + ./configure.sh sam4e-ek/ + + 2. Download the latest buildroot package into + + 3. unpack the buildroot tarball. The resulting directory may + have versioning information on it like buildroot-x.y.z. If so, + rename /buildroot-x.y.z to /buildroot. + + 4. cd /buildroot + + 5. cp configs/cortexm3-defconfig-nxflat .config + + 6. make oldconfig + + 7. make + + 8. Edit setenv.h, if necessary, so that the PATH variable includes + the path to the newly builtNXFLAT binaries. + +AtmelStudio6.1 +^^^^^^^^^^^^^^ + + You can use AtmelStudio6.1 to load and debug code. + + - To load code: + + Tools -> Device Programming + + Configure the debugger and chip and you are in business. + + - To Debug Code: + + File -> Open -> Open Object File for Debugging + + Select the project name, the full path to the NuttX object (called + just nuttx with no extension), and chip. Take the time to resolve + all of the source file linkages or else you will not have source + level debug! + +LEDs +^^^^ + + The SAM4E-EK board has three, user-controllable LEDs labelled D2 (blue), + D3 (amber), and D4 (green) on the board. Usage of these LEDs is defined + in include/board.h and src/up_leds.c. They are encoded as follows: + + SYMBOL Meaning D3* D2 D4 + ------------------- ----------------------- ------- ------- ------- + LED_STARTED NuttX has been started OFF OFF OFF + LED_HEAPALLOCATE Heap has been allocated OFF OFF ON + LED_IRQSENABLED Interrupts enabled OFF ON OFF + LED_STACKCREATED Idle stack created OFF ON ON + LED_INIRQ In an interrupt** N/C FLASH N/C + LED_SIGNAL In a signal handler*** N/C N/C FLASH + LED_ASSERTION An assertion failed FLASH N/C N/C + LED_PANIC The system has crashed FLASH N/C N/C + + * If D2 and D4 are statically on, then NuttX probably failed to boot + and these LEDs will give you some indication of where the failure was + ** The normal state is D3=OFF, D4=ON and D2 faintly glowing. This faint + glow is because of timer interrupts that result in the LED being + illuminated on a small proportion of the time. +*** D4 may also flicker normally if signals are processed. + +Serial Console +^^^^^^^^^^^^^^ + + By default, all of these configurations use UART0 for the NuttX serial + console. UART0 corresponds to the DB-9 connector labelled "UART". This + is a male connector and will require a female-to-female, NUL modem cable + to connect to a PC. + + An alternate is USART1 which connects to the other DB-9 connector labeled + "USART". USART1 is not enabled by default unless specifically noted + otherwise in the configuration description. A NUL modem cable must be + used with the port as well. + + NOTE: One of the USART1 pins is shared with the audio CODEC. The audio + CODEC cannot be used of USART1 is enabled. + + By default serial console is configured for 115000, 8-bit, 1 stop bit, and + no parity. + +SAM4E-EK-specific Configuration Options +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + CONFIG_ARCH - Identifies the arch/ subdirectory. This should + be set to: + + CONFIG_ARCH=arm + + CONFIG_ARCH_family - For use in C code: + + CONFIG_ARCH_ARM=y + + CONFIG_ARCH_architecture - For use in C code: + + CONFIG_ARCH_CORTEXM3=y + + CONFIG_ARCH_CHIP - Identifies the arch/*/chip subdirectory + + CONFIG_ARCH_CHIP="sam34" + + CONFIG_ARCH_CHIP_name - For use in C code to identify the exact + chip: + + CONFIG_ARCH_CHIP_SAM34 + CONFIG_ARCH_CHIP_SAM3U + CONFIG_ARCH_CHIP_ATSAM3U4 + + CONFIG_ARCH_BOARD - Identifies the configs subdirectory and + hence, the board that supports the particular chip or SoC. + + CONFIG_ARCH_BOARD=sam4e-ek (for the SAM4E-EK development board) + + CONFIG_ARCH_BOARD_name - For use in C code + + CONFIG_ARCH_BOARD_SAM4EEK=y + + CONFIG_ARCH_LOOPSPERMSEC - Must be calibrated for correct operation + of delay loops + + CONFIG_ENDIAN_BIG - define if big endian (default is little + endian) + + CONFIG_RAM_SIZE - Describes the installed DRAM (SRAM in this case): + + CONFIG_RAM_SIZE=0x00020000 (128Kb) + + CONFIG_RAM_START - The start address of installed DRAM + + CONFIG_RAM_START=0x20000000 + + CONFIG_ARCH_IRQPRIO - The SAM3U supports interrupt prioritization + + CONFIG_ARCH_IRQPRIO=n + + CONFIG_ARCH_LEDS - Use LEDs to show state. Unique to boards that + have LEDs + + CONFIG_ARCH_INTERRUPTSTACK - This architecture supports an interrupt + stack. If defined, this symbol is the size of the interrupt + stack in bytes. If not defined, the user task stacks will be + used during interrupt handling. + + CONFIG_ARCH_STACKDUMP - Do stack dumps after assertions + + CONFIG_ARCH_LEDS - Use LEDs to show state. Unique to board architecture. + + CONFIG_ARCH_CALIBRATION - Enables some build in instrumentation that + cause a 100 second delay during boot-up. This 100 second delay + serves no purpose other than it allows you to calibratre + CONFIG_ARCH_LOOPSPERMSEC. You simply use a stop watch to measure + the 100 second delay then adjust CONFIG_ARCH_LOOPSPERMSEC until + the delay actually is 100 seconds. + + Individual subsystems can be enabled: + + CONFIG_SAM34_SPI0 - Serial Peripheral Interface 0 (SPI0) + CONFIG_SAM34_SPI1 - Serial Peripheral Interface 1 (SPI1) + CONFIG_SAM34_SSC - Synchronous Serial Controller (SSC) + CONFIG_SAM34_TC0 - Timer/Counter 0 (TC0) + CONFIG_SAM34_TC1 - Timer/Counter 1 (TC1) + CONFIG_SAM34_TC2 - Timer/Counter 2 (TC2) + CONFIG_SAM34_TC3 - Timer/Counter 3 (TC3) + CONFIG_SAM34_TC4 - Timer/Counter 4 (TC4) + CONFIG_SAM34_TC5 - Timer/Counter 5 (TC5) + CONFIG_SAM34_TC6 - Timer/Counter 6 (TC6) + CONFIG_SAM34_TC7 - Timer/Counter 7 (TC6) + CONFIG_SAM34_TC8 - Timer/Counter 6 (TC8) + CONFIG_SAM34_PWM - Pulse Width Modulation (PWM) Controller + CONFIG_SAM34_TWIM0 - Two-wire Master Interface 0 (TWIM0) + CONFIG_SAM34_TWIS0 - Two-wire Slave Interface 0 (TWIS0) + CONFIG_SAM34_TWIM1B - Two-wire Master Interface 1 (TWIM1) + CONFIG_SAM34_TWIS1 - Two-wire Slave Interface 1 (TWIS1) + CONFIG_SAM34_UART0 - UART 0 + CONFIG_SAM34_UART1 - UART 1 + CONFIG_SAM34_USART0 - USART 0 + CONFIG_SAM34_USART1 - USART 1 + CONFIG_SAM34_USART2 - USART 2 + CONFIG_SAM34_USART3 - USART 3 + CONFIG_SAM34_AFEC0 - Analog Front End 0 + CONFIG_SAM34_AFEC1 - Analog Front End 1 + CONFIG_SAM34_DACC - Digital-to-Analog Converter + CONFIG_SAM34_ACC - Analog Comparator + CONFIG_SAM34_EMAC - Ethernet MAC + CONFIG_SAM34_CAN0 - CAN 0 + CONFIG_SAM34_CAN1 - CAN 1 + CONFIG_SAM34_SMC - Static Memory Controller + CONFIG_SAM34_NAND - NAND support + CONFIG_SAM34_PDCA - Peripheral DMA controller + CONFIG_SAM34_DMAC - DMA controller + CONFIG_SAM34_UDP - USB 2.0 Full-Speed device + CONFIG_SAM34_CHIPID - Chip ID + CONFIG_SAM34_RTC - Real Time Clock + CONFIG_SAM34_RTT - Real Time Timer + CONFIG_SAM34_WDT - Watchdog Timer + CONFIG_SAM34_EIC - Interrupt controller + CONFIG_SAM34_HSMCI - High Speed Multimedia Card Interface + + Some subsystems can be configured to operate in different ways. The drivers + need to know how to configure the subsystem. + + CONFIG_GPIOA_IRQ + CONFIG_GPIOB_IRQ + CONFIG_GPIOC_IRQ + CONFIG_GPIOD_IRQ + CONFIG_GPIOE_IRQ + CONFIG_GPIOF_IRQ + CONFIG_GPIOG_IRQ + CONFIG_GPIOH_IRQ + CONFIG_GPIOJ_IRQ + CONFIG_GPIOK_IRQ + CONFIG_GPIOL_IRQ + CONFIG_GPIOM_IRQ + CONFIG_GPION_IRQ + CONFIG_GPIOP_IRQ + CONFIG_GPIOQ_IRQ + + CONFIG_USART0_ISUART + CONFIG_USART1_ISUART + CONFIG_USART2_ISUART + CONFIG_USART3_ISUART + + SAM3U specific device driver settings + + CONFIG_U[S]ARTn_SERIAL_CONSOLE - selects the USARTn (n=0,1,2,3) or UART + m (m=4,5) for the console and ttys0 (default is the USART1). + CONFIG_U[S]ARTn_RXBUFSIZE - Characters are buffered as received. + This specific the size of the receive buffer + CONFIG_U[S]ARTn_TXBUFSIZE - Characters are buffered before + being sent. This specific the size of the transmit buffer + CONFIG_U[S]ARTn_BAUD - The configure BAUD of the UART. Must be + CONFIG_U[S]ARTn_BITS - The number of bits. Must be either 7 or 8. + CONFIG_U[S]ARTn_PARTIY - 0=no parity, 1=odd parity, 2=even parity + CONFIG_U[S]ARTn_2STOP - Two stop bits + + LCD Options. Other than the standard LCD configuration options + (see configs/README.txt), the SAM4E-EK driver also supports: + + CONFIG_LCD_PORTRAIT - Present the display in the standard 240x320 + "Portrait" orientation. Default: The display is rotated to + support a 320x240 "Landscape" orientation. + +Configurations +^^^^^^^^^^^^^^ + + Information Common to All Configurations + ---------------------------------------- + Each SAM4E-EK configuration is maintained in a sub-directory and + can be selected as follow: + + cd tools + ./configure.sh sam4e-ek/ + cd - + . ./setenv.sh + + Before sourcing the setenv.sh file above, you should examine it and perform + edits as necessary so that BUILDROOT_BIN is the correct path to the directory + than holds your toolchain binaries. + + And then build NuttX by simply typing the following. At the conclusion of + the make, the nuttx binary will reside in an ELF file called, simply, nuttx. + + make + + The that is provided above as an argument to the tools/configure.sh + must be is one of the following. + + NOTES: + + 1. These configurations use the mconf-based configuration tool. To + change any of these configurations using that tool, you should: + + a. Build and install the kconfig-mconf tool. See nuttx/README.txt + and misc/tools/ + + b. Execute 'make menuconfig' in nuttx/ in order to start the + reconfiguration process. + + 2. Unless stated otherwise, all configurations generate console + output on UART0 (J3). + + 3. Unless otherwise stated, the configurations are setup for + Linux (or any other POSIX environment like Cygwin under Windows): + + Build Setup: + CONFIG_HOST_LINUX=y : Linux or other POSIX environment + + 4. All of these configurations use the older, OABI, buildroot toolchain + (unless stated otherwise in the description of the configuration). That + toolchain selection can easily be reconfigured using 'make menuconfig'. + Here are the relevant current settings: + + Build Setup: + CONFIG_HOST_LINUX=y : Linux or other pure POSIX invironment + : (including Cygwin) + System Type -> Toolchain: + CONFIG_ARMV7M_TOOLCHAIN_BUILDROOT=y : Buildroot toolchain + CONFIG_ARMV7M_OABI_TOOLCHAIN=y : Older, OABI toolchain + + If you want to use the Atmel GCC toolchain, for example, here are the + steps to do so: + + Build Setup: + CONFIG_HOST_WINDOWS=y : Windows + CONFIG_HOST_CYGWIN=y : Using Cygwin or other POSIX environment + + System Type -> Toolchain: + CONFIG_ARMV7M_TOOLCHAIN_GNU_EABIW=y : General GCC EABI toolchain under windows + + Library Routines -> + CONFIG_CXX_NEWLONG=n : size_t is an unsigned int, not long + + This re-configuration should be done before making NuttX or else the + subsequent 'make' will fail. If you have already attempted building + NuttX then you will have to 1) 'make distclean' to remove the old + configuration, 2) 'cd tools; ./configure.sh sam4e-ek/ksnh' to start + with a fresh configuration, and 3) perform the configuration changes + above. + + Also, make sure that your PATH variable has the new path to your + Atmel tools. Try 'which arm-none-eabi-gcc' to make sure that you + are selecting the right tool. setenv.sh is available for you to + use to set or PATH variable. The path in the that file may not, + however, be correct for your installation. + + See also the "NOTE about Windows native toolchains" in the section call + "GNU Toolchain Options" above. + + Configuration sub-directories + ----------------------------- + + nsh: + Configures the NuttShell (nsh) located at examples/nsh. The + Configuration enables both the serial and telnetd NSH interfaces. + + NOTES: + + 1. NSH built-in applications are supported. However, there are + no built-in applications built with the default configuration. + + Binary Formats: + CONFIG_BUILTIN=y : Enable support for built-in programs + + Applicaton Configuration: + CONFIG_NSH_BUILTIN_APPS=y : Enable starting apps from NSH command line + + 2. This configuration has been used for verifying the touchscreen on + on the SAM4E-EK LCD. With these modifications, you can include the + touchscreen test program at apps/examples/touchscreen as an NSH built-in + application. You can enable the touchscreen and test by modifying the + default configuration in the following ways: + + Device Drivers + CONFIG_SPI=y : Enable SPI support + CONFIG_SPI_EXCHANGE=y : The exchange() method is supported + CONFIG_SPI_OWNBUS=y : Smaller code if this is the only SPI device + + CONFIG_INPUT=y : Enable support for input devices + CONFIG_INPUT_ADS7843E=y : Enable support for the XPT2046 + CONFIG_ADS7843E_SPIDEV=2 : Use SPI CS 2 for communication + CONFIG_ADS7843E_SPIMODE=0 : Use SPI mode 0 + CONFIG_ADS7843E_FREQUENCY=1000000 : SPI BAUD 1MHz + CONFIG_ADS7843E_SWAPXY=y : If landscpe orientation + CONFIG_ADS7843E_THRESHX=51 : These will probably need to be tuned + CONFIG_ADS7843E_THRESHY=39 + + System Type -> Peripherals: + CONFIG_SAM34_SPI0=y : Enable support for SPI + + System Type: + CONFIG_GPIO_IRQ=y : GPIO interrupt support + CONFIG_GPIOA_IRQ=y : Enable GPIO interrupts from port A + + RTOS Features: + CONFIG_DISABLE_SIGNALS=n : Signals are required + + Library Support: + CONFIG_SCHED_WORKQUEUE=y : Work queue support required + + Applicaton Configuration: + CONFIG_EXAMPLES_TOUCHSCREEN=y : Enable the touchscreen built-int test + + Defaults should be okay for related touchscreen settings. Touchscreen + debug output on UART0 can be enabled with: + + Build Setup: + CONFIG_DEBUG=y : Enable debug features + CONFIG_DEBUG_VERBOSE=y : Enable verbose debug output + CONFIG_DEBUG_INPUT=y : Enable debug output from input devices + + 3. Enabling HSMCI support. The SAM3U-KE provides a an SD memory card + slot. Support for the SD slot can be enabled with the following + settings: + + System Type->ATSAM3/4 Peripheral Support + CONFIG_SAM34_HSMCI=y : Enable HSMCI support + CONFIG_SAM34_DMAC=y : DMAC support is needed by HSMCI + + System Type + CONFIG_SAM34_GPIO_IRQ=y : PIO interrupts needed + CONFIG_SAM34_GPIOA_IRQ=y : Card detect pin is on PIOA + + Device Drivers -> MMC/SD Driver Support + CONFIG_MMCSD=y : Enable MMC/SD support + CONFIG_MMSCD_NSLOTS=1 : One slot per driver instance + CONFIG_MMCSD_HAVECARDDETECT=y : Supports card-detect PIOs + CONFIG_MMCSD_SDIO=y : SDIO-based MMC/SD support + CONFIG_SDIO_DMA=y : Use SDIO DMA + CONFIG_SDIO_BLOCKSETUP=y : Needs to know block sizes + + Library Routines + CONFIG_SCHED_WORKQUEUE=y : Driver needs work queue support + + Application Configuration -> NSH Library + CONFIG_NSH_ARCHINIT=y : NSH board-initialization + + STATUS: + 2013-6-28: The touchscreen is functional. + 2013-6-29: Hmmm... but there appear to be conditions when the + touchscreen driver locks up. Looks like some issue with + managing the interrupts. + 2013-6-30: Those lock-ups appear to be due to poorly placed + debug output statements. If you do not enable debug output, + the touchscreen is rock-solid. + 2013-8-10: Added the comments above above enabling HSMCI memory + card support and verified that the configuration builds without + error. However, that configuration has not yet been tested (and + is may even be incomplete). diff --git a/configs/sam4e-ek/include/board.h b/configs/sam4e-ek/include/board.h new file mode 100644 index 0000000000..92dfa50887 --- /dev/null +++ b/configs/sam4e-ek/include/board.h @@ -0,0 +1,306 @@ +/************************************************************************************ + * configs/sam4e-ek/include/board.h + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************************************/ + +#ifndef __ARCH_SAM4E_EK_INCLUDE_BOARD_H +#define __ARCH_SAM4E_EK_INCLUDE_BOARD_H + +/************************************************************************************ + * Included Files + ************************************************************************************/ + +#include + +#ifndef __ASSEMBLY__ +# include +# ifdef CONFIG_GPIO_IRQ +# include +# endif +#endif + +/************************************************************************************ + * Definitions + ************************************************************************************/ + +/* Clocking *************************************************************************/ +/* After power-on reset, the SAM4E16 device is running on a 4MHz internal RC. These + * definitions will configure clocking + * + * MAINOSC: Frequency = 12MHz (crysta) + * + * CONFIG_SAM4EEK_120MHZ + * PLLA: PLL Divider = 1, Multiplier = 20 to generate PLLACK = 240MHz + * Master Clock (MCK): Source = PLLACK, Prescalar = 1 to generate MCK = 120MHz + * CPU clock: 120MHz + * + * CONFIG_SAM4EEK_196MHZ + * PLLA: PLL Divider = 1, Multiplier = 16 to generate PLLACK = 192MHz + * Master Clock (MCK): Source = PLLACK, Prescalar = 1 to generate MCK = 96MHz + * CPU clock: 96MHz + */ + +/* Main oscillator register settings. + * + * The start up time should be should be: + * Start Up Time = 8 * MOSCXTST / SLCK = 56 Slow Clock Cycles. + */ + +#define BOARD_CKGR_MOR_MOSCXTST (62 << PMC_CKGR_MOR_MOSCXTST_SHIFT) /* Start-up Time */ + +/* PLLA configuration. + * + * Divider = 1 + * Multipler = 16 or 20 + */ + +#ifdef CONFIG_SAM4EEK_120MHZ +# define BOARD_CKGR_PLLAR_MUL (20 << PMC_CKGR_PLLAR_MUL_SHIFT) +#else +# define BOARD_CKGR_PLLAR_MUL (16 << PMC_CKGR_PLLAR_MUL_SHIFT) +#endif + +#define BOARD_CKGR_PLLAR_STMODE PMC_CKGR_PLLAR_STMODE_FAST +#define BOARD_CKGR_PLLAR_COUNT (63 << PMC_CKGR_PLLAR_COUNT_SHIFT) +#define BOARD_CKGR_PLLAR_DIV PMC_CKGR_PLLAR_DIV_BYPASS + +/* PMC master clock register settings. + * + * Source = PLLA + * Divider = 2 + */ + +#define BOARD_PMC_MCKR_CSS PMC_MCKR_CSS_PLLA +#define BOARD_PMC_MCKR_PRES PMC_MCKR_PRES_DIV2 + +/* USB UTMI PLL start-up time */ + +#define BOARD_CKGR_UCKR_UPLLCOUNT (3 << PMC_CKGR_UCKR_UPLLCOUNT_SHIFT) + +/* Resulting frequencies */ + +#define BOARD_MAINOSC_FREQUENCY (12000000) /* MAINOSC: 12MHz crystal on-board */ + +#ifdef CONFIG_SAM4EEK_120MHZ +# define BOARD_PLLA_FREQUENCY (240000000) /* PLLACK: 20 * 12Mhz / 1 */ +# define BOARD_MCK_FREQUENCY (120000000) /* MCK: PLLACK / 2 */ +# define BOARD_CPU_FREQUENCY (120000000) /* CPU: MCK */ +#else +# define BOARD_MAINOSC_FREQUENCY (12000000) /* MAINOSC: 12MHz crystal on-board */ +# define BOARD_PLLA_FREQUENCY (192000000) /* PLLACK: 16 * 12Mhz / 1 */ +# define BOARD_MCK_FREQUENCY (96000000) /* MCK: PLLACK / 2 */ +# define BOARD_CPU_FREQUENCY (96000000) /* CPU: MCK */ +#endif + +/* HSMCI clocking + * + * Multimedia Card Interface clock (MCCK or MCI_CK) is Master Clock (MCK) + * divided by (2*(CLKDIV+1)). + * + * MCI_SPEED = MCK / (2*(CLKDIV+1)) + * CLKDIV = MCK / MCI_SPEED / 2 - 1 + * + * Where CLKDIV has a range of 0-255. + */ + +#ifdef CONFIG_SAM4EEK_120MHZ + /* MCK = 120MHz, CLKDIV = 149, MCI_SPEED = 120MHz / 2 * (149+1) = 400 KHz */ + +# define HSMCI_INIT_CLKDIV (149 << HSMCI_MR_CLKDIV_SHIFT) + + /* MCK = 120MHz, CLKDIV = 2, MCI_SPEED = 120MHz / 2 * (2+1) = 20 MHz */ + +# define HSMCI_MMCXFR_CLKDIV (3 << HSMCI_MR_CLKDIV_SHIFT) + + /* MCK = 120MHz, CLKDIV = 2, MCI_SPEED = 120MHz / 2 * (2+1) = 20 MHz */ + +# define HSMCI_SDXFR_CLKDIV (1 << HSMCI_MR_CLKDIV_SHIFT) + +#else +/* MCK = 96MHz, CLKDIV = 119, MCI_SPEED = 96MHz / 2 * (119+1) = 400 KHz */ + +# define HSMCI_INIT_CLKDIV (119 << HSMCI_MR_CLKDIV_SHIFT) + +/* MCK = 96MHz, CLKDIV = 3, MCI_SPEED = 96MHz / 2 * (3+1) = 12 MHz */ + +# define HSMCI_MMCXFR_CLKDIV (3 << HSMCI_MR_CLKDIV_SHIFT) + +/* MCK = 96MHz, CLKDIV = 1, MCI_SPEED = 96MHz / 2 * (1+1) = 24 MHz */ + +# define HSMCI_SDXFR_CLKDIV (1 << HSMCI_MR_CLKDIV_SHIFT) +#endif + +#define HSMCI_SDWIDEXFR_CLKDIV HSMCI_SDXFR_CLKDIV + +/* FLASH wait states. + * + * SAM4E-EK documetion says: + * VDDCORE: "The voltage ranges from 1.08V to 1.32V." + * VDDIO: Looks like it is at 3.3V + * + * FWS Max frequency + * (1) (2) (3) (4) + * --- ------- ------- ------- ------- + * 0 17 MHz 20 MHz 17 MHz 21 MHz + * 1 34 MHz 41 MHz 35 MHz 43 MHz + * 2 51 MHz 62 MHz 53 MHz 64 MHz + * 3 69 MHz 83 MHz 71 MHz 86 MHz + * 4 86 MHz 96 MHz 88 MHz 107 MHz + * 5 100 MHz 104 MHz 106 MHz 129 MHz + * 6 124 MHz + + * (1) VDDCORE set at 1.08V and VDDIO 1.62V to 3.6V @105C + * (2) VDDCORE set at 1.08V and VDDIO 2.7V to 3.6V @105C + * (3) VDDCORE set at 1.20V and VDDIO 1.62V to 3.6V @ 105C + * (4) VDDCORE set at 1.20V and VDDIO 2.7V to 3.6V @ 105C + */ + +#ifdef CONFIG_SAM4EEK_120MHZ +# define BOARD_FWS 5 +#else +# define BOARD_FWS 4 +#endif + +/* LED definitions ******************************************************************/ +/* The SAM4E-EK board has three, user-controllable LEDs labelled D2 (blue), + * D3 (amber), and D4 (green) on the board. Usage of these LEDs is defined + * in include/board.h and src/up_leds.c. They are encoded as follows: + * + * SYMBOL Meaning D3* D2 D4 + * ------------------- ----------------------- ------- ------- ------- + * LED_STARTED NuttX has been started OFF OFF OFF + * LED_HEAPALLOCATE Heap has been allocated OFF OFF ON + * LED_IRQSENABLED Interrupts enabled OFF ON OFF + * LED_STACKCREATED Idle stack created OFF ON ON + * LED_INIRQ In an interrupt** N/C FLASH N/C + * LED_SIGNAL In a signal handler*** N/C N/C FLASH + * LED_ASSERTION An assertion failed FLASH N/C N/C + * LED_PANIC The system has crashed FLASH N/C N/C + * + * * If D2 and D4 are statically on, then NuttX probably failed to boot + * and these LEDs will give you some indication of where the failure was + * ** The normal state is D3=OFF, D4=ON and D2 faintly glowing. This faint + * glow is because of timer interrupts that result in the LED being + * illuminated on a small proportion of the time. + * *** D4 may also flicker normally if signals are processed. + */ + +#define LED_STARTED 0 /* LED0=OFF LED1=OFF LED2=OFF */ +#define LED_HEAPALLOCATE 1 /* LED0=OFF LED1=OFF LED2=ON */ +#define LED_IRQSENABLED 2 /* LED0=OFF LED1=ON LED2=OFF */ +#define LED_STACKCREATED 3 /* LED0=OFF LED1=ON LED2=ON */ + +#define LED_INIRQ 4 /* LED0=XXX LED1=TOG LED2=XXX */ +#define LED_SIGNAL 5 /* LED0=XXX LED1=XXX LED2=TOG */ +#define LED_ASSERTION 6 /* LED0=TOG LED1=XXX LED2=XXX */ +#define LED_PANIC 7 /* LED0=TOG LED1=XXX LED2=XXX */ + +/* LED index values for use with sam_setled() */ + +#define BOARD_LED_D3 0 +#define BOARD_LED_D2 1 +#define BOARD_LED_D4 2 +#define BOARD_NLEDS 3 + +/* LED bits for use with sam_setleds() */ + +#define BOARD_LED_D3_BIT (1 << BOARD_LED_D3) +#define BOARD_LED_D2_BIT (1 << BOARD_LED_D2) +#define BOARD_LED_D4_BIT (1 << BOARD_LED_D4) + +/* Button definitions ***************************************************************/ +/* Four buttons for software inputs: + * + * PA1 BUTTON_SCROLL-UP Grounded + * PA2 BUTTON_SCROLL-DOWN Grounded + * PA19 BUTTON_WAKU Grounded + * PA20 BUTTON_TAMP Grounded + */ + +#define BUTTON_SCROLLUP 1 /* Bit 0: Scroll-up button */ +#define BUTTON_SCROLLDOWN 2 /* Bit 1: Scroll-down button */ +#define BUTTON_WAKU 4 /* Bit 2: Waku button */ +#define BUTTON_TAMP 8 /* Bit 3: Tamp button */ + +/************************************************************************************ + * Public Data + ************************************************************************************/ + +#ifndef __ASSEMBLY__ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" { +#else +#define EXTERN extern +#endif + +/************************************************************************************ + * Public Function Prototypes + ************************************************************************************/ +/************************************************************************************ + * Name: sam_boardinitialize + * + * Description: + * All SAM3U architectures must provide the following entry point. This entry point + * is called early in the initialization -- after all memory has been configured + * and mapped but before any devices have been initialized. + * + ************************************************************************************/ + +void sam_boardinitialize(void); + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +/************************************************************************************ + * Name: sam_ledinit, sam_setled, and sam_setleds + * + * Description: + * If CONFIG_ARCH_LEDS is defined, then NuttX will control the on-board LEDs. If + * CONFIG_ARCH_LEDS is not defined, then the following interfacesare available to + * control the LEDs from user applications. + * + ************************************************************************************/ + +#ifndef CONFIG_ARCH_LEDS +void sam_ledinit(void); +void sam_setled(int led, bool ledon); +void sam_setleds(uint8_t ledset); +#endif + +#endif /* __ASSEMBLY__ */ +#endif /* __ARCH_SAM4E_EK_INCLUDE_BOARD_H */ diff --git a/configs/sam4e-ek/nsh/Make.defs b/configs/sam4e-ek/nsh/Make.defs new file mode 100644 index 0000000000..ac2d55439f --- /dev/null +++ b/configs/sam4e-ek/nsh/Make.defs @@ -0,0 +1,110 @@ +############################################################################ +# configs/sam4e-ek/nsh/Make.defs +# +# Copyright (C) 2014 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +include ${TOPDIR}/.config +include ${TOPDIR}/tools/Config.mk +include ${TOPDIR}/arch/arm/src/armv7-m/Toolchain.defs + +ifeq ($(WINTOOL),y) + # Windows-native toolchains + DIRLINK = $(TOPDIR)/tools/copydir.sh + DIRUNLINK = $(TOPDIR)/tools/unlink.sh + MKDEP = $(TOPDIR)/tools/mknulldeps.sh + ARCHINCLUDES = -I. -isystem "${shell cygpath -w $(TOPDIR)/include}" + ARCHXXINCLUDES = -I. -isystem "${shell cygpath -w $(TOPDIR)/include}" -isystem "${shell cygpath -w $(TOPDIR)/include/cxx}" + ARCHSCRIPT = -T "${shell cygpath -w $(TOPDIR)/configs/$(CONFIG_ARCH_BOARD)/scripts/flash.ld}" +else + # Linux/Cygwin-native toolchain + MKDEP = $(TOPDIR)/tools/mkdeps.sh + ARCHINCLUDES = -I. -isystem $(TOPDIR)/include + ARCHXXINCLUDES = -I. -isystem $(TOPDIR)/include -isystem $(TOPDIR)/include/cxx + ARCHSCRIPT = -T$(TOPDIR)/configs/$(CONFIG_ARCH_BOARD)/scripts/flash.ld +endif + +CC = $(CROSSDEV)gcc +CXX = $(CROSSDEV)g++ +CPP = $(CROSSDEV)gcc -E +LD = $(CROSSDEV)ld +AR = $(CROSSDEV)ar rcs +NM = $(CROSSDEV)nm +OBJCOPY = $(CROSSDEV)objcopy +OBJDUMP = $(CROSSDEV)objdump + +ARCHCCVERSION = ${shell $(CC) -v 2>&1 | sed -n '/^gcc version/p' | sed -e 's/^gcc version \([0-9\.]\)/\1/g' -e 's/[-\ ].*//g' -e '1q'} +ARCHCCMAJOR = ${shell echo $(ARCHCCVERSION) | cut -d'.' -f1} + +ifeq ($(CONFIG_DEBUG_SYMBOLS),y) + ARCHOPTIMIZATION = -g +endif + +ifneq ($(CONFIG_DEBUG_NOOPT),y) + ARCHOPTIMIZATION += $(MAXOPTIMIZATION) -fno-strict-aliasing -fno-strength-reduce -fomit-frame-pointer +endif + +ARCHCFLAGS = -fno-builtin +ARCHCXXFLAGS = -fno-builtin -fno-exceptions -fno-rtti +ARCHWARNINGS = -Wall -Wstrict-prototypes -Wshadow +ARCHWARNINGSXX = -Wall -Wshadow +ARCHDEFINES = +ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10 + +CFLAGS = $(ARCHCFLAGS) $(ARCHWARNINGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRADEFINES) -pipe +CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS) +CXXFLAGS = $(ARCHCXXFLAGS) $(ARCHWARNINGSXX) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRADEFINES) -pipe +CXXPICFLAGS = $(ARCHPICFLAGS) $(CXXFLAGS) +CPPFLAGS = $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRADEFINES) +AFLAGS = $(CFLAGS) -D__ASSEMBLY__ + +NXFLATLDFLAGS1 = -r -d -warn-common +NXFLATLDFLAGS2 = $(NXFLATLDFLAGS1) -T$(TOPDIR)/binfmt/libnxflat/gnu-nxflat-pcrel.ld -no-check-sections +LDNXFLATFLAGS = -e main -s 2048 + +OBJEXT = .o +LIBEXT = .a +EXEEXT = + +ifneq ($(CROSSDEV),arm-nuttx-elf-) + LDFLAGS += -nostartfiles -nodefaultlibs +endif +ifeq ($(CONFIG_DEBUG_SYMBOLS),y) + LDFLAGS += -g +endif + + +HOSTCC = gcc +HOSTINCLUDES = -I. +HOSTCFLAGS = -Wall -Wstrict-prototypes -Wshadow -g -pipe +HOSTLDFLAGS = + diff --git a/configs/sam4e-ek/nsh/defconfig b/configs/sam4e-ek/nsh/defconfig new file mode 100644 index 0000000000..cdf401ff5d --- /dev/null +++ b/configs/sam4e-ek/nsh/defconfig @@ -0,0 +1,853 @@ +# +# Automatically generated file; DO NOT EDIT. +# Nuttx/ Configuration +# + +# +# Build Setup +# +# CONFIG_EXPERIMENTAL is not set +# CONFIG_DEFAULT_SMALL is not set +CONFIG_HOST_LINUX=y +# CONFIG_HOST_OSX is not set +# CONFIG_HOST_WINDOWS is not set +# CONFIG_HOST_OTHER is not set + +# +# Build Configuration +# +# CONFIG_APPS_DIR="../apps" +# CONFIG_BUILD_2PASS is not set + +# +# Binary Output Formats +# +# CONFIG_RRLOAD_BINARY is not set +# CONFIG_INTELHEX_BINARY is not set +# CONFIG_MOTOROLA_SREC is not set +CONFIG_RAW_BINARY=y + +# +# Customize Header Files +# +# CONFIG_ARCH_STDINT_H is not set +# CONFIG_ARCH_STDBOOL_H is not set +# CONFIG_ARCH_MATH_H is not set +# CONFIG_ARCH_FLOAT_H is not set +# CONFIG_ARCH_STDARG_H is not set + +# +# Debug Options +# +# CONFIG_DEBUG is not set +CONFIG_ARCH_HAVE_STACKCHECK=y +# CONFIG_ARCH_HAVE_HEAPCHECK is not set +# CONFIG_DEBUG_SYMBOLS is not set +CONFIG_ARCH_HAVE_CUSTOMOPT=y +# CONFIG_DEBUG_NOOPT is not set +# CONFIG_DEBUG_CUSTOMOPT is not set +CONFIG_DEBUG_FULLOPT=y + +# +# System Type +# +# CONFIG_ARCH_8051 is not set +CONFIG_ARCH_ARM=y +# CONFIG_ARCH_AVR is not set +# CONFIG_ARCH_HC is not set +# CONFIG_ARCH_MIPS is not set +# CONFIG_ARCH_RGMP is not set +# CONFIG_ARCH_SH is not set +# CONFIG_ARCH_SIM is not set +# CONFIG_ARCH_X86 is not set +# CONFIG_ARCH_Z16 is not set +# CONFIG_ARCH_Z80 is not set +CONFIG_ARCH="arm" + +# +# ARM Options +# +# CONFIG_ARCH_CHIP_A1X is not set +# CONFIG_ARCH_CHIP_C5471 is not set +# CONFIG_ARCH_CHIP_CALYPSO is not set +# CONFIG_ARCH_CHIP_DM320 is not set +# CONFIG_ARCH_CHIP_IMX is not set +# CONFIG_ARCH_CHIP_KINETIS is not set +# CONFIG_ARCH_CHIP_KL is not set +# CONFIG_ARCH_CHIP_LM is not set +# CONFIG_ARCH_CHIP_TIVA is not set +# CONFIG_ARCH_CHIP_LPC17XX is not set +# CONFIG_ARCH_CHIP_LPC214X is not set +# CONFIG_ARCH_CHIP_LPC2378 is not set +# CONFIG_ARCH_CHIP_LPC31XX is not set +# CONFIG_ARCH_CHIP_LPC43XX is not set +# CONFIG_ARCH_CHIP_NUC1XX is not set +# CONFIG_ARCH_CHIP_SAMA5 is not set +# CONFIG_ARCH_CHIP_SAMD is not set +CONFIG_ARCH_CHIP_SAM34=y +# CONFIG_ARCH_CHIP_STM32 is not set +# CONFIG_ARCH_CHIP_STR71X is not set +# CONFIG_ARCH_ARM7TDMI is not set +# CONFIG_ARCH_ARM926EJS is not set +# CONFIG_ARCH_ARM920T is not set +# CONFIG_ARCH_CORTEXM0 is not set +# CONFIG_ARCH_CORTEXM3 is not set +CONFIG_ARCH_CORTEXM4=y +# CONFIG_ARCH_CORTEXA5 is not set +# CONFIG_ARCH_CORTEXA8 is not set +CONFIG_ARCH_FAMILY="armv7-m" +CONFIG_ARCH_CHIP="sam34" +# CONFIG_ARMV7M_USEBASEPRI is not set +# CONFIG_ARCH_HAVE_FPU is not set +CONFIG_ARCH_HAVE_MPU=y +# CONFIG_ARMV7M_MPU is not set + +# +# ARMV7M Configuration Options +# +CONFIG_ARMV7M_TOOLCHAIN_BUILDROOT=y +# CONFIG_ARMV7M_TOOLCHAIN_CODEREDL is not set +# CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYL is not set +# CONFIG_ARMV7M_TOOLCHAIN_GNU_EABIL is not set +# CONFIG_ARMV7M_OABI_TOOLCHAIN is not set +# CONFIG_GPIO_IRQ is not set +CONFIG_ARCH_HAVE_EXTNAND=y +CONFIG_ARCH_HAVE_EXTNOR=y +CONFIG_ARCH_HAVE_EXTSRAM0=y +CONFIG_ARCH_HAVE_EXTSRAM1=y + +# +# AT91SAM3/4 Configuration Options +# +# CONFIG_ARCH_CHIP_ATSAM3U4E is not set +# CONFIG_ARCH_CHIP_ATSAM3U4C is not set +# CONFIG_ARCH_CHIP_ATSAM3U2E is not set +# CONFIG_ARCH_CHIP_ATSAM3U2C is not set +# CONFIG_ARCH_CHIP_ATSAM3U1E is not set +# CONFIG_ARCH_CHIP_ATSAM3U1C is not set +# CONFIG_ARCH_CHIP_ATSAM3X8E is not set +# CONFIG_ARCH_CHIP_ATSAM3X8C is not set +# CONFIG_ARCH_CHIP_ATSAM3X4E is not set +# CONFIG_ARCH_CHIP_ATSAM3X4C is not set +# CONFIG_ARCH_CHIP_ATSAM3A8C is not set +# CONFIG_ARCH_CHIP_ATSAM3A4C is not set +# CONFIG_ARCH_CHIP_ATSAM4LC2C is not set +# CONFIG_ARCH_CHIP_ATSAM4LC2B is not set +# CONFIG_ARCH_CHIP_ATSAM4LC2A is not set +# CONFIG_ARCH_CHIP_ATSAM4LC4C is not set +# CONFIG_ARCH_CHIP_ATSAM4LC4B is not set +# CONFIG_ARCH_CHIP_ATSAM4LC4A is not set +# CONFIG_ARCH_CHIP_ATSAM4LS2C is not set +# CONFIG_ARCH_CHIP_ATSAM4LS2B is not set +# CONFIG_ARCH_CHIP_ATSAM4LS2A is not set +# CONFIG_ARCH_CHIP_ATSAM4LS4C is not set +# CONFIG_ARCH_CHIP_ATSAM4LS4B is not set +# CONFIG_ARCH_CHIP_ATSAM4LS4A is not set +# CONFIG_ARCH_CHIP_ATSAM4SD32C is not set +# CONFIG_ARCH_CHIP_ATSAM4SD32B is not set +# CONFIG_ARCH_CHIP_ATSAM4SD16C is not set +# CONFIG_ARCH_CHIP_ATSAM4SD16B is not set +# CONFIG_ARCH_CHIP_ATSAM4SA16C is not set +# CONFIG_ARCH_CHIP_ATSAM4SA16B is not set +# CONFIG_ARCH_CHIP_ATSAM4S16C is not set +# CONFIG_ARCH_CHIP_ATSAM4S16B is not set +# CONFIG_ARCH_CHIP_ATSAM4S8C is not set +# CONFIG_ARCH_CHIP_ATSAM4S8B is not set +CONFIG_ARCH_CHIP_ATSAM4E16E=y +# CONFIG_ARCH_CHIP_ATSAM4E16C is not set +# CONFIG_ARCH_CHIP_ATSAM4E8E is not set +# CONFIG_ARCH_CHIP_ATSAM4E8C is not set +# CONFIG_ARCH_CHIP_SAM3U is not set +# CONFIG_ARCH_CHIP_SAM3X is not set +# CONFIG_ARCH_CHIP_SAM3A is not set +# CONFIG_ARCH_CHIP_SAM4L is not set +CONFIG_ARCH_CHIP_SAM4E=y +# CONFIG_ARCH_CHIP_SAM4S is not set + +# +# AT91SAM3/4 Peripheral Support +# +# CONFIG_SAM34_SPI0 is not set +# CONFIG_SAM34_TC0 is not set +# CONFIG_SAM34_TC1 is not set +# CONFIG_SAM34_TC2 is not set +# CONFIG_SAM34_TC3 is not set +# CONFIG_SAM34_TC4 is not set +# CONFIG_SAM34_TC5 is not set +# CONFIG_SAM34_TC6 is not set +# CONFIG_SAM34_TC7 is not set +# CONFIG_SAM34_TC8 is not set +# CONFIG_SAM34_PWM is not set +# CONFIG_SAM34_TWIM0 is not set +# CONFIG_SAM34_TWIS0 is not set +# CONFIG_SAM34_TWIM1 is not set +# CONFIG_SAM34_TWIS1 is not set +CONFIG_SAM34_UART0=y +# CONFIG_SAM34_UART1 is not set +# CONFIG_SAM34_USART0 is not set +CONFIG_SAM34_USART1=y +# CONFIG_SAM34_AFEC0 is not set +# CONFIG_SAM34_AFEC1 is not set +# CONFIG_SAM34_DACC is not set +# CONFIG_SAM34_ACC is not set +# CONFIG_SAM34_AES is not set +# CONFIG_SAM34_EMAC is not set +# CONFIG_SAM34_CAN0 is not set +# CONFIG_SAM34_CAN1 is not set +# CONFIG_SAM34_SMC is not set +# CONFIG_SAM34_NAND is not set +# CONFIG_SAM34_PDCA is not set +# CONFIG_SAM34_DMAC is not set +# CONFIG_SAM34_UDP is not set +# CONFIG_SAM34_CHIPID is not set +# CONFIG_SAM34_RTC is not set +# CONFIG_SAM34_RTT is not set +# CONFIG_SAM34_WDT is not set +# CONFIG_SAM34_EIC is not set +# CONFIG_SAM34_HSMCI is not set + +# +# External Memory Configuration +# +# CONFIG_SAM34_EXTNAND is not set +# CONFIG_SAM34_EXTNOR is not set +# CONFIG_SAM34_EXTSRAM0 is not set +# CONFIG_SAM34_EXTSRAM1 is not set + +# +# AT91SAM3/4 GPIO Interrupt Configuration +# + +# +# Architecture Options +# +# CONFIG_ARCH_NOINTC is not set +# CONFIG_ARCH_VECNOTIRQ is not set +# CONFIG_ARCH_DMA is not set +CONFIG_ARCH_HAVE_IRQPRIO=y +# CONFIG_CUSTOM_STACK is not set +# CONFIG_ADDRENV is not set +CONFIG_ARCH_HAVE_VFORK=y +# CONFIG_ARCH_HAVE_MMU is not set +# CONFIG_ARCH_NAND_HWECC is not set +# CONFIG_ARCH_IRQPRIO is not set +CONFIG_ARCH_STACKDUMP=y +# CONFIG_ENDIAN_BIG is not set +# CONFIG_ARCH_IDLE_CUSTOM is not set +CONFIG_ARCH_HAVE_RAMFUNCS=y +# CONFIG_ARCH_RAMFUNCS is not set +CONFIG_ARCH_HAVE_RAMVECTORS=y +# CONFIG_ARCH_RAMVECTORS is not set + +# +# Board Settings +# +CONFIG_BOARD_LOOPSPERMSEC=8720 +# CONFIG_ARCH_CALIBRATION is not set + +# +# Interrupt options +# +CONFIG_ARCH_HAVE_INTERRUPTSTACK=y +CONFIG_ARCH_INTERRUPTSTACK=0 +CONFIG_ARCH_HAVE_HIPRI_INTERRUPT=y +# CONFIG_ARCH_HIPRI_INTERRUPT is not set + +# +# Boot options +# +# CONFIG_BOOT_RUNFROMEXTSRAM is not set +CONFIG_BOOT_RUNFROMFLASH=y +# CONFIG_BOOT_RUNFROMISRAM is not set +# CONFIG_BOOT_RUNFROMSDRAM is not set +# CONFIG_BOOT_COPYTORAM is not set + +# +# Boot Memory Configuration +# +CONFIG_RAM_START=0x20000000 +CONFIG_RAM_SIZE=131072 +# CONFIG_ARCH_HAVE_SDRAM is not set + +# +# Board Selection +# +CONFIG_ARCH_BOARD_SAM4EEK=y +# CONFIG_ARCH_BOARD_CUSTOM is not set +CONFIG_ARCH_BOARD="sam4e-ek" + +# +# Common Board Options +# +CONFIG_ARCH_HAVE_LEDS=y +CONFIG_ARCH_LEDS=y +CONFIG_ARCH_HAVE_BUTTONS=y +CONFIG_ARCH_BUTTONS=y +CONFIG_ARCH_HAVE_IRQBUTTONS=y +# CONFIG_ARCH_IRQBUTTONS is not set +CONFIG_NSH_MMCSDMINOR=0 + +# +# Board-Specific Options +# +CONFIG_SAM4EEK_96MHZ=y +# CONFIG_SAM4EEK_120MHZ is not set + +# +# RTOS Features +# +# CONFIG_BOARD_INITIALIZE is not set +CONFIG_MSEC_PER_TICK=10 +# CONFIG_SYSTEM_TIME64 is not set +CONFIG_RR_INTERVAL=200 +# CONFIG_SCHED_CPULOAD is not set +# CONFIG_SCHED_INSTRUMENTATION is not set +CONFIG_TASK_NAME_SIZE=0 +# CONFIG_SCHED_HAVE_PARENT is not set +# CONFIG_JULIAN_TIME is not set +CONFIG_START_YEAR=2009 +CONFIG_START_MONTH=9 +CONFIG_START_DAY=21 +CONFIG_DEV_CONSOLE=y +# CONFIG_MUTEX_TYPES is not set +# CONFIG_PRIORITY_INHERITANCE is not set +# CONFIG_FDCLONE_DISABLE is not set +# CONFIG_FDCLONE_STDIO is not set +CONFIG_SDCLONE_DISABLE=y +CONFIG_SCHED_WAITPID=y +# CONFIG_SCHED_STARTHOOK is not set +# CONFIG_SCHED_ATEXIT is not set +# CONFIG_SCHED_ONEXIT is not set +CONFIG_USER_ENTRYPOINT="nsh_main" +CONFIG_DISABLE_OS_API=y +# CONFIG_DISABLE_CLOCK is not set +# CONFIG_DISABLE_POSIX_TIMERS is not set +# CONFIG_DISABLE_PTHREAD is not set +# CONFIG_DISABLE_SIGNALS is not set +# CONFIG_DISABLE_MQUEUE is not set +# CONFIG_DISABLE_ENVIRON is not set + +# +# Signal Numbers +# +CONFIG_SIG_SIGUSR1=1 +CONFIG_SIG_SIGUSR2=2 +CONFIG_SIG_SIGALARM=3 +CONFIG_SIG_SIGCONDTIMEDOUT=16 + +# +# Sizes of configurable things (0 disables) +# +CONFIG_MAX_TASKS=16 +CONFIG_MAX_TASK_ARGS=4 +CONFIG_NPTHREAD_KEYS=4 +CONFIG_NFILE_DESCRIPTORS=8 +CONFIG_NFILE_STREAMS=8 +CONFIG_NAME_MAX=32 +CONFIG_PREALLOC_MQ_MSGS=4 +CONFIG_MQ_MAXMSGSIZE=32 +CONFIG_MAX_WDOGPARMS=2 +CONFIG_PREALLOC_WDOGS=4 +CONFIG_PREALLOC_TIMERS=4 + +# +# Stack and heap information +# +CONFIG_IDLETHREAD_STACKSIZE=1024 +CONFIG_USERMAIN_STACKSIZE=2048 +CONFIG_PTHREAD_STACK_MIN=256 +CONFIG_PTHREAD_STACK_DEFAULT=2048 + +# +# Device Drivers +# +CONFIG_DISABLE_POLL=y +CONFIG_DEV_NULL=y +# CONFIG_DEV_ZERO is not set +# CONFIG_LOOP is not set +# CONFIG_RAMDISK is not set +# CONFIG_CAN is not set +# CONFIG_ARCH_HAVE_PWM_PULSECOUNT is not set +# CONFIG_PWM is not set +# CONFIG_ARCH_HAVE_I2CRESET is not set +# CONFIG_I2C is not set +# CONFIG_SPI is not set +# CONFIG_I2S is not set +# CONFIG_RTC is not set +# CONFIG_WATCHDOG is not set +# CONFIG_ANALOG is not set +# CONFIG_AUDIO_DEVICES is not set +# CONFIG_VIDEO_DEVICES is not set +# CONFIG_BCH is not set +# CONFIG_INPUT is not set +# CONFIG_LCD is not set +# CONFIG_MMCSD is not set +# CONFIG_MTD is not set +# CONFIG_PIPES is not set +# CONFIG_PM is not set +# CONFIG_POWER is not set +# CONFIG_SENSORS is not set +# CONFIG_SERCOMM_CONSOLE is not set +CONFIG_SERIAL=y +# CONFIG_DEV_LOWCONSOLE is not set +# CONFIG_16550_UART is not set +# CONFIG_ARCH_HAVE_UART is not set +CONFIG_ARCH_HAVE_UART0=y +# CONFIG_ARCH_HAVE_UART1 is not set +# CONFIG_ARCH_HAVE_UART2 is not set +# CONFIG_ARCH_HAVE_UART3 is not set +# CONFIG_ARCH_HAVE_UART4 is not set +# CONFIG_ARCH_HAVE_UART5 is not set +# CONFIG_ARCH_HAVE_UART6 is not set +# CONFIG_ARCH_HAVE_UART7 is not set +# CONFIG_ARCH_HAVE_UART8 is not set +# CONFIG_ARCH_HAVE_SCI0 is not set +# CONFIG_ARCH_HAVE_SCI1 is not set +# CONFIG_ARCH_HAVE_USART0 is not set +CONFIG_ARCH_HAVE_USART1=y +# CONFIG_ARCH_HAVE_USART2 is not set +# CONFIG_ARCH_HAVE_USART3 is not set +# CONFIG_ARCH_HAVE_USART4 is not set +# CONFIG_ARCH_HAVE_USART5 is not set +# CONFIG_ARCH_HAVE_USART6 is not set +# CONFIG_ARCH_HAVE_USART7 is not set +# CONFIG_ARCH_HAVE_USART8 is not set + +# +# USART Configuration +# +CONFIG_USART1_ISUART=y +CONFIG_MCU_SERIAL=y +CONFIG_STANDARD_SERIAL=y +CONFIG_UART0_SERIAL_CONSOLE=y +# CONFIG_USART1_SERIAL_CONSOLE is not set +# CONFIG_NO_SERIAL_CONSOLE is not set + +# +# UART0 Configuration +# +CONFIG_UART0_RXBUFSIZE=256 +CONFIG_UART0_TXBUFSIZE=256 +CONFIG_UART0_BAUD=115200 +CONFIG_UART0_BITS=8 +CONFIG_UART0_PARITY=0 +CONFIG_UART0_2STOP=0 +# CONFIG_UART0_IFLOWCONTROL is not set +# CONFIG_UART0_OFLOWCONTROL is not set + +# +# USART1 Configuration +# +CONFIG_USART1_RXBUFSIZE=256 +CONFIG_USART1_TXBUFSIZE=256 +CONFIG_USART1_BAUD=115200 +CONFIG_USART1_BITS=8 +CONFIG_USART1_PARITY=0 +CONFIG_USART1_2STOP=0 +# CONFIG_USART1_IFLOWCONTROL is not set +# CONFIG_USART1_OFLOWCONTROL is not set +# CONFIG_SERIAL_IFLOWCONTROL is not set +# CONFIG_SERIAL_OFLOWCONTROL is not set +# CONFIG_USBDEV is not set +# CONFIG_USBHOST is not set +# CONFIG_WIRELESS is not set + +# +# System Logging Device Options +# + +# +# System Logging +# +# CONFIG_RAMLOG is not set + +# +# Networking Support +# +# CONFIG_ARCH_HAVE_NET is not set +# CONFIG_ARCH_HAVE_PHY is not set +# CONFIG_NET is not set + +# +# File Systems +# + +# +# File system configuration +# +# CONFIG_DISABLE_MOUNTPOINT is not set +# CONFIG_DISABLE_PSEUDOFS_OPERATIONS is not set +CONFIG_FS_READABLE=y +CONFIG_FS_WRITABLE=y +# CONFIG_FS_RAMMAP is not set +CONFIG_FS_FAT=y +# CONFIG_FAT_LCNAMES is not set +# CONFIG_FAT_LFN is not set +# CONFIG_FS_FATTIME is not set +# CONFIG_FAT_DMAMEMORY is not set +# CONFIG_FS_NXFFS is not set +# CONFIG_FS_ROMFS is not set +# CONFIG_FS_SMARTFS is not set +# CONFIG_FS_BINFS is not set +# CONFIG_FS_PROCFS is not set + +# +# System Logging +# +# CONFIG_SYSLOG_ENABLE is not set +# CONFIG_SYSLOG is not set + +# +# Graphics Support +# +# CONFIG_NX is not set + +# +# Memory Management +# +# CONFIG_MM_MULTIHEAP is not set +# CONFIG_MM_SMALL is not set +CONFIG_MM_REGIONS=2 +# CONFIG_ARCH_HAVE_HEAP2 is not set +# CONFIG_GRAN is not set + +# +# Audio Support +# +# CONFIG_AUDIO is not set + +# +# Binary Formats +# +# CONFIG_BINFMT_DISABLE is not set +# CONFIG_BINFMT_EXEPATH is not set +# CONFIG_NXFLAT is not set +# CONFIG_ELF is not set +CONFIG_BUILTIN=y +# CONFIG_PIC is not set +# CONFIG_SYMTAB_ORDEREDBYNAME is not set + +# +# Library Routines +# + +# +# Standard C Library Options +# +CONFIG_STDIO_BUFFER_SIZE=64 +CONFIG_STDIO_LINEBUFFER=y +CONFIG_NUNGET_CHARS=2 +CONFIG_LIB_HOMEDIR="/" +# CONFIG_LIBM is not set +# CONFIG_NOPRINTF_FIELDWIDTH is not set +# CONFIG_LIBC_FLOATINGPOINT is not set +CONFIG_LIB_RAND_ORDER=1 +# CONFIG_EOL_IS_CR is not set +# CONFIG_EOL_IS_LF is not set +# CONFIG_EOL_IS_BOTH_CRLF is not set +CONFIG_EOL_IS_EITHER_CRLF=y +# CONFIG_LIBC_EXECFUNCS is not set +CONFIG_POSIX_SPAWN_PROXY_STACKSIZE=1024 +CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE=2048 +# CONFIG_LIBC_STRERROR is not set +# CONFIG_LIBC_PERROR_STDOUT is not set +CONFIG_ARCH_LOWPUTC=y +CONFIG_LIB_SENDFILE_BUFSIZE=512 +# CONFIG_ARCH_ROMGETC is not set +# CONFIG_ARCH_OPTIMIZED_FUNCTIONS is not set + +# +# Non-standard Library Support +# +# CONFIG_SCHED_WORKQUEUE is not set +# CONFIG_LIB_KBDCODEC is not set +# CONFIG_LIB_SLCDCODEC is not set + +# +# Basic CXX Support +# +# CONFIG_C99_BOOL8 is not set +# CONFIG_HAVE_CXX is not set + +# +# Application Configuration +# + +# +# Built-In Applications +# +CONFIG_BUILTIN_PROXY_STACKSIZE=1024 + +# +# Examples +# +# CONFIG_EXAMPLES_BUTTONS is not set +# CONFIG_EXAMPLES_CAN is not set +# CONFIG_EXAMPLES_CONFIGDATA is not set +# CONFIG_EXAMPLES_DHCPD is not set +# CONFIG_EXAMPLES_ELF is not set +# CONFIG_EXAMPLES_FTPC is not set +# CONFIG_EXAMPLES_FTPD is not set +# CONFIG_EXAMPLES_HELLO is not set +# CONFIG_EXAMPLES_HELLOXX is not set +# CONFIG_EXAMPLES_JSON is not set +# CONFIG_EXAMPLES_HIDKBD is not set +# CONFIG_EXAMPLES_KEYPADTEST is not set +# CONFIG_EXAMPLES_IGMP is not set +# CONFIG_EXAMPLES_LCDRW is not set +# CONFIG_EXAMPLES_MM is not set +# CONFIG_EXAMPLES_MODBUS is not set +# CONFIG_EXAMPLES_MOUNT is not set +# CONFIG_EXAMPLES_NRF24L01TERM is not set +CONFIG_EXAMPLES_NSH=y +# CONFIG_EXAMPLES_NULL is not set +# CONFIG_EXAMPLES_NX is not set +# CONFIG_EXAMPLES_NXCONSOLE is not set +# CONFIG_EXAMPLES_NXFFS is not set +# CONFIG_EXAMPLES_NXFLAT is not set +# CONFIG_EXAMPLES_NXHELLO is not set +# CONFIG_EXAMPLES_NXIMAGE is not set +# CONFIG_EXAMPLES_NXLINES is not set +# CONFIG_EXAMPLES_NXTEXT is not set +# CONFIG_EXAMPLES_OSTEST is not set +# CONFIG_EXAMPLES_PASHELLO is not set +# CONFIG_EXAMPLES_PIPE is not set +# CONFIG_EXAMPLES_POSIXSPAWN is not set +# CONFIG_EXAMPLES_QENCODER is not set +# CONFIG_EXAMPLES_RGMP is not set +# CONFIG_EXAMPLES_ROMFS is not set +# CONFIG_EXAMPLES_SENDMAIL is not set +# CONFIG_EXAMPLES_SERLOOP is not set +# CONFIG_EXAMPLES_SLCD is not set +# CONFIG_EXAMPLES_SMART_TEST is not set +# CONFIG_EXAMPLES_SMART is not set +# CONFIG_EXAMPLES_TCPECHO is not set +# CONFIG_EXAMPLES_TELNETD is not set +# CONFIG_EXAMPLES_THTTPD is not set +# CONFIG_EXAMPLES_TIFF is not set +# CONFIG_EXAMPLES_TOUCHSCREEN is not set +# CONFIG_EXAMPLES_UDP is not set +# CONFIG_EXAMPLES_UIP is not set +# CONFIG_EXAMPLES_USBSERIAL is not set +# CONFIG_EXAMPLES_USBTERM is not set +# CONFIG_EXAMPLES_WATCHDOG is not set + +# +# Graphics Support +# +# CONFIG_TIFF is not set + +# +# Interpreters +# +# CONFIG_INTERPRETERS_FICL is not set +# CONFIG_INTERPRETERS_PCODE is not set + +# +# Network Utilities +# + +# +# Networking Utilities +# +# CONFIG_NETUTILS_CODECS is not set +# CONFIG_NETUTILS_DHCPD is not set +# CONFIG_NETUTILS_FTPC is not set +# CONFIG_NETUTILS_FTPD is not set +# CONFIG_NETUTILS_JSON is not set +# CONFIG_NETUTILS_SMTP is not set +# CONFIG_NETUTILS_TFTPC is not set +# CONFIG_NETUTILS_THTTPD is not set +# CONFIG_NETUTILS_UIPLIB is not set +# CONFIG_NETUTILS_WEBCLIENT is not set + +# +# FreeModBus +# +# CONFIG_MODBUS is not set + +# +# NSH Library +# +CONFIG_NSH_LIBRARY=y +CONFIG_NSH_READLINE=y +# CONFIG_NSH_CLE is not set +CONFIG_NSH_BUILTIN_APPS=y + +# +# Disable Individual commands +# +# CONFIG_NSH_DISABLE_ADDROUTE is not set +# CONFIG_NSH_DISABLE_CAT is not set +# CONFIG_NSH_DISABLE_CD is not set +# CONFIG_NSH_DISABLE_CP is not set +# CONFIG_NSH_DISABLE_CMP is not set +# CONFIG_NSH_DISABLE_DD is not set +# CONFIG_NSH_DISABLE_DF is not set +# CONFIG_NSH_DISABLE_DELROUTE is not set +# CONFIG_NSH_DISABLE_ECHO is not set +# CONFIG_NSH_DISABLE_EXEC is not set +# CONFIG_NSH_DISABLE_EXIT is not set +# CONFIG_NSH_DISABLE_FREE is not set +# CONFIG_NSH_DISABLE_GET is not set +# CONFIG_NSH_DISABLE_HELP is not set +# CONFIG_NSH_DISABLE_HEXDUMP is not set +# CONFIG_NSH_DISABLE_IFCONFIG is not set +# CONFIG_NSH_DISABLE_KILL is not set +# CONFIG_NSH_DISABLE_LOSETUP is not set +# CONFIG_NSH_DISABLE_LS is not set +# CONFIG_NSH_DISABLE_MB is not set +# CONFIG_NSH_DISABLE_MKDIR is not set +# CONFIG_NSH_DISABLE_MKFATFS is not set +# CONFIG_NSH_DISABLE_MKFIFO is not set +# CONFIG_NSH_DISABLE_MKRD is not set +# CONFIG_NSH_DISABLE_MH is not set +# CONFIG_NSH_DISABLE_MOUNT is not set +# CONFIG_NSH_DISABLE_MW is not set +# CONFIG_NSH_DISABLE_PS is not set +# CONFIG_NSH_DISABLE_PUT is not set +# CONFIG_NSH_DISABLE_PWD is not set +# CONFIG_NSH_DISABLE_RM is not set +# CONFIG_NSH_DISABLE_RMDIR is not set +# CONFIG_NSH_DISABLE_SET is not set +# CONFIG_NSH_DISABLE_SH is not set +# CONFIG_NSH_DISABLE_SLEEP is not set +# CONFIG_NSH_DISABLE_TEST is not set +# CONFIG_NSH_DISABLE_UMOUNT is not set +# CONFIG_NSH_DISABLE_UNSET is not set +# CONFIG_NSH_DISABLE_USLEEP is not set +# CONFIG_NSH_DISABLE_WGET is not set +# CONFIG_NSH_DISABLE_XD is not set + +# +# Configure Command Options +# +# CONFIG_NSH_CMDOPT_DF_H is not set +CONFIG_NSH_CODECS_BUFSIZE=128 +CONFIG_NSH_CMDOPT_HEXDUMP=y +CONFIG_NSH_FILEIOSIZE=512 +CONFIG_NSH_LINELEN=64 +# CONFIG_NSH_DISABLE_SEMICOLON is not set +CONFIG_NSH_CMDPARMS=y +CONFIG_NSH_TMPDIR="/tmp" +CONFIG_NSH_MAXARGUMENTS=6 +CONFIG_NSH_ARGCAT=y +CONFIG_NSH_NESTDEPTH=3 +# CONFIG_NSH_DISABLESCRIPT is not set +# CONFIG_NSH_DISABLE_ITEF is not set +# CONFIG_NSH_DISABLE_LOOPS is not set +# CONFIG_NSH_DISABLEBG is not set +CONFIG_NSH_CONSOLE=y + +# +# USB Trace Support +# +# CONFIG_NSH_CONDEV is not set +CONFIG_NSH_ARCHINIT=y + +# +# NxWidgets/NxWM +# + +# +# Platform-specific Support +# +# CONFIG_PLATFORM_CONFIGDATA is not set + +# +# System Libraries and NSH Add-Ons +# + +# +# USB CDC/ACM Device Commands +# + +# +# USB Composite Device Commands +# + +# +# Custom Free Memory Command +# +# CONFIG_SYSTEM_FREE is not set + +# +# I2C tool +# + +# +# INI File Parser +# +# CONFIG_SYSTEM_INIFILE is not set + +# +# FLASH Program Installation +# +# CONFIG_SYSTEM_INSTALL is not set + +# +# FLASH Erase-all Command +# + +# +# NxPlayer media player library / command Line +# +# CONFIG_SYSTEM_NXPLAYER is not set + +# +# RAM test +# +# CONFIG_SYSTEM_RAMTEST is not set + +# +# readline() +# +CONFIG_SYSTEM_READLINE=y +CONFIG_READLINE_ECHO=y + +# +# Power Off +# +# CONFIG_SYSTEM_POWEROFF is not set + +# +# RAMTRON +# +# CONFIG_SYSTEM_RAMTRON is not set + +# +# SD Card +# +# CONFIG_SYSTEM_SDCARD is not set + +# +# Sysinfo +# +# CONFIG_SYSTEM_SYSINFO is not set + +# +# USB Monitor +# + +# +# EMACS-like Command Line Editor +# +# CONFIG_SYSTEM_CLE is not set + +# +# VI Work-Alike Editor +# +# CONFIG_SYSTEM_VI is not set + +# +# Stack Monitor +# + +# +# USB Mass Storage Device Commands +# + +# +# Zmodem Commands +# +# CONFIG_SYSTEM_ZMODEM is not set diff --git a/configs/sam4e-ek/nsh/setenv.sh b/configs/sam4e-ek/nsh/setenv.sh new file mode 100755 index 0000000000..922e4eebfb --- /dev/null +++ b/configs/sam4e-ek/nsh/setenv.sh @@ -0,0 +1,68 @@ +#!/bin/bash +# configs/sam4e-ek/nsh/setenv.sh +# +# Copyright (C) 2014 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +if [ "$_" = "$0" ] ; then + echo "You must source this script, not run it!" 1>&2 + exit 1 +fi + +WD=`pwd` +if [ ! -x "setenv.sh" ]; then + echo "This script must be executed from the top-level NuttX build directory" + exit 1 +fi + +if [ -z "${PATH_ORIG}" ]; then + export PATH_ORIG="${PATH}" +fi + +# This is the Cygwin path to the location where I installed the Atmel GCC +# toolchain under Windows. You will also have to edit this if you install +# this toolchain in any other location +#export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/Atmel/Atmel Toolchain/ARM GCC/Native/4.7.3.99/arm-gnu-toolchain/bin" +#export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_EABI/bin" + +# This is the Cygwin path to the location where I installed the CodeSourcery +# toolchain under windows. You will also have to edit this if you install +# the CodeSourcery toolchain in any other location +#export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/CodeSourcery/Sourcery G++ Lite/bin" + +# This is the Cygwin path to the location where I build the buildroot +# toolchain. +export TOOLCHAIN_BIN="${WD}/../misc/buildroot/build_arm_nofpu/staging_dir/bin" + +# Add the path to the toolchain to the PATH varialble +export PATH="${TOOLCHAIN_BIN}:/sbin:/usr/sbin:${PATH_ORIG}" + +echo "PATH : ${PATH}" diff --git a/configs/sam4e-ek/scripts/flash.ld b/configs/sam4e-ek/scripts/flash.ld new file mode 100755 index 0000000000..cc61cfa475 --- /dev/null +++ b/configs/sam4e-ek/scripts/flash.ld @@ -0,0 +1,116 @@ +/**************************************************************************** + * configs/sam4e-ek/scripts/flash.ld + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/* The SAM4E16 has 1025KB of FLASH beginning at address 0x0008:0000, + * 128KB of SRAM beginning at address 0x2000:0000. When booting from FLASH, + * FLASH memory is aliased to address 0x0000:0000 where the code expects to + * begin execution by jumping to the entry point in the 0x0800:0000 address + * range. + */ + +MEMORY +{ + flash (rx) : ORIGIN = 0x00080000, LENGTH = 1024K + sram (rwx) : ORIGIN = 0x20000000, LENGTH = 128K +} + +OUTPUT_ARCH(arm) +ENTRY(_stext) +SECTIONS +{ + .text : { + _stext = ABSOLUTE(.); + *(.vectors) + *(.text .text.*) + *(.fixup) + *(.gnu.warning) + *(.rodata .rodata.*) + *(.gnu.linkonce.t.*) + *(.glue_7) + *(.glue_7t) + *(.got) + *(.gcc_except_table) + *(.gnu.linkonce.r.*) + _etext = ABSOLUTE(.); + } > flash + + .init_section : { + _sinit = ABSOLUTE(.); + *(.init_array .init_array.*) + _einit = ABSOLUTE(.); + } > flash + + .ARM.extab : { + *(.ARM.extab*) + } > flash + + __exidx_start = ABSOLUTE(.); + .ARM.exidx : { + *(.ARM.exidx*) + } > flash + __exidx_end = ABSOLUTE(.); + + _eronly = ABSOLUTE(.); + + .data : { + _sdata = ABSOLUTE(.); + *(.data .data.*) + *(.gnu.linkonce.d.*) + CONSTRUCTORS + _edata = ABSOLUTE(.); + } > sram AT > flash + + .bss : { + _sbss = ABSOLUTE(.); + *(.bss .bss.*) + *(.gnu.linkonce.b.*) + *(COMMON) + _ebss = ABSOLUTE(.); + } > sram + + /* Stabs debugging sections. */ + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + .stab.excl 0 : { *(.stab.excl) } + .stab.exclstr 0 : { *(.stab.exclstr) } + .stab.index 0 : { *(.stab.index) } + .stab.indexstr 0 : { *(.stab.indexstr) } + .comment 0 : { *(.comment) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_info 0 : { *(.debug_info) } + .debug_line 0 : { *(.debug_line) } + .debug_pubnames 0 : { *(.debug_pubnames) } + .debug_aranges 0 : { *(.debug_aranges) } +} diff --git a/configs/sam4e-ek/src/.gitignore b/configs/sam4e-ek/src/.gitignore new file mode 100644 index 0000000000..726d936e1e --- /dev/null +++ b/configs/sam4e-ek/src/.gitignore @@ -0,0 +1,2 @@ +/.depend +/Make.dep diff --git a/configs/sam4e-ek/src/Makefile b/configs/sam4e-ek/src/Makefile new file mode 100644 index 0000000000..75d9029d33 --- /dev/null +++ b/configs/sam4e-ek/src/Makefile @@ -0,0 +1,110 @@ +############################################################################ +# configs/sam4e-ek/src/Makefile +# +# Copyright (C) 2014 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +-include $(TOPDIR)/Make.defs + +CFLAGS += -I$(TOPDIR)/sched + +ASRCS = +AOBJS = $(ASRCS:.S=$(OBJEXT)) + +CSRCS = sam_boot.c sam_leds.c sam_buttons.c sam_spi.c sam_usbdev.c + +ifeq ($(CONFIG_HAVE_CXXINITIALIZE),y) +CSRCS += sam_cxxinitialize.c +endif + +ifeq ($(CONFIG_LCD),y) +CSRCS += sam_lcd.c +endif + +ifeq ($(CONFIG_NSH_ARCHINIT),y) +CSRCS += sam_nsh.c +endif + +ifeq ($(CONFIG_SAM34_HSMCI),y) +CSRCS += sam_mmcsd.c +endif + +ifeq ($(CONFIG_USBMSC),y) +CSRCS += sam_usbmsc.c +endif + +ifeq ($(CONFIG_INPUT_ADS7843E),y) +CSRCS += sam_touchscreen.c +endif + +COBJS = $(CSRCS:.c=$(OBJEXT)) + +SRCS = $(ASRCS) $(CSRCS) +OBJS = $(AOBJS) $(COBJS) + +ARCH_SRCDIR = $(TOPDIR)/arch/$(CONFIG_ARCH)/src +ifeq ($(WINTOOL),y) + CFLAGS += -I "${shell cygpath -w $(ARCH_SRCDIR)/chip}" + CFLAGS += -I "${shell cygpath -w $(ARCH_SRCDIR)/common}" + CFLAGS += -I "${shell cygpath -w $(ARCH_SRCDIR)/armv7-m}" +else + CFLAGS += -I$(ARCH_SRCDIR)/chip + CFLAGS += -I$(ARCH_SRCDIR)/common + CFLAGS += -I$(ARCH_SRCDIR)/armv7-m +endif + +all: libboard$(LIBEXT) + +$(AOBJS): %$(OBJEXT): %.S + $(call ASSEMBLE, $<, $@) + +$(COBJS) $(LINKOBJS): %$(OBJEXT): %.c + $(call COMPILE, $<, $@) + +libboard$(LIBEXT): $(OBJS) + $(call ARCHIVE, $@, $(OBJS)) + +.depend: Makefile $(SRCS) + $(Q) $(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep + $(Q) touch $@ + +depend: .depend + +clean: + $(call DELFILE, libboard$(LIBEXT)) + $(call CLEAN) + +distclean: clean + $(call DELFILE, Make.dep) + $(call DELFILE, .depend) + +-include Make.dep diff --git a/configs/sam4e-ek/src/sam4e-ek.h b/configs/sam4e-ek/src/sam4e-ek.h new file mode 100644 index 0000000000..87b441a1bc --- /dev/null +++ b/configs/sam4e-ek/src/sam4e-ek.h @@ -0,0 +1,308 @@ +/************************************************************************************ + * configs/sam4e-ek/src/sam4e-ek.h + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************************************/ + +#ifndef __CONFIGS_SAM4E_EK_SRC_SAM4E_EK_H +#define __CONFIGS_SAM4E_EK_SRC_SAM4E_EK_H + +/************************************************************************************ + * Included Files + ************************************************************************************/ + +#include +#include + +#include + +#include +#include + +#include "chip/sam_pinmap.h" + +/************************************************************************************ + * Definitions + ************************************************************************************/ + +/* External Memory Usage ************************************************************/ +/* LCD on CS2 */ + +#define LCD_BASE SAM_EXTCS2_BASE + +/* Touchscreen controller (TSC) */ + +#define CONFIG_TSC_ADS7843 1 /* ADS7843 present on board */ +#define CONFIG_TSC_SPI 0 /* On SPI0 */ + +/* SAM4E-EK GPIO Pin Definitions ****************************************************/ + +/* LCD: + * LCD Module Pin Out: SAM3U PIO: + * -------------------------------------------- -------------------------------------- + * Pin Symbol Function LCD PeriphA PeriphB Extra + * ---- ------ -------------------------------- -------------- -------- ------- ------ + * 1 GND Ground N/A --- --- --- + * 2 CS Chip Select PC16 NCS2 PWML3 AD12BAD5 + * 3 RS Register select signal PB8 (see A1) CTS0 A1 AD3 + * 4 WR Write operation signal PB23 (NWE) NWR0/NEW PCK1 --- + * 5 RD Read operation signal PB19 (NRD) NRD PWML2 --- + * 6 DB0 Data bus PB9 D0 DTR0 --- + * 7 DB1 Data bus PB10 D1 DSR0 --- + * 8 DB2 Data bus PB11 D2 DCD0 --- + * 9 DB3 Data bus PB12 D3 RI0 --- + * 10 DB4 Data bus PB13 D4 PWMH0 --- + * 11 DB5 Data bus PB14 D5 PWMH1 --- + * 12 DB6 Data bus PB15 D6 PWMH2 --- + * 13 DB7 Data bus PB16 D7 PMWH3 --- + * 14 DB8 Data bus PB25 D8 PWML0 --- + * 15 DB9 Data bus PB26 D9 PWML1 --- + * 16 DB10 Data bus PB27 D10 PWML2 --- + * 17 DB11 Data bus PB28 D11 PWML3 --- + * 18 DB12 Data bus PB29 D12 --- --- + * 19 DB13 Data bus PB30 D13 --- --- + * 20 DB14 Data bus PB31 D14 --- --- + * 21 DB15 Data bus PB6 TIOA1 D15 AD1 + * 22 NC No connection N/A --- --- --- + * 23 NC No connection N/A --- --- --- + * 24 RESET Reset signal N/A --- --- --- + * 25 GND Ground N/A --- --- --- + * 26 X+ Touch panel X_RIGHT PA15 SPCK PWMH2 --- + * 27 Y+ Touch panel Y_UP PA14 MOSI --- --- + * 28 X- Touch panel X_LEFT PA13 MISO --- --- + * 29 Y- Touch panel Y_DOWN PC14 A3 NPCS2 --- + * 30 GND Ground N/A --- --- --- + * 31 VDD1 Power supply for digital IO Pad N/A --- --- --- + * 32 VDD2 Power supply for analog circuit N/A --- --- --- + * 33 A1 Power supply for backlight PB8 (see RS) CTS0 A1 AD3 + * 34 A2 Power supply for backlight N/A --- --- --- + * 35 A3 Power supply for backlight N/A --- --- --- + * 36 A4 Power supply for backlight N/A --- --- --- + * 37 NC No connection N/A --- --- --- + * 38 NC No connection N/A --- --- --- + * 39 K Backlight ground N/A --- --- --- + */ + +#define GPIO_LCD_NCS2 (GPIO_PERIPHA | GPIO_CFG_PULLUP | GPIO_PORT_PIOC | GPIO_PIN16) +#define GPIO_LCD_RS (GPIO_PERIPHB | GPIO_CFG_PULLUP | GPIO_PORT_PIOB | GPIO_PIN8) +#define GPIO_LCD_NWE (GPIO_PERIPHA | GPIO_CFG_PULLUP | GPIO_PORT_PIOB | GPIO_PIN23) +#define GPIO_LCD_NRD (GPIO_PERIPHA | GPIO_CFG_PULLUP | GPIO_PORT_PIOB | GPIO_PIN19) + +#define GPIO_LCD_D0 (GPIO_PERIPHA | GPIO_CFG_PULLUP | GPIO_PORT_PIOB | GPIO_PIN9) +#define GPIO_LCD_D1 (GPIO_PERIPHA | GPIO_CFG_PULLUP | GPIO_PORT_PIOB | GPIO_PIN10) +#define GPIO_LCD_D2 (GPIO_PERIPHA | GPIO_CFG_PULLUP | GPIO_PORT_PIOB | GPIO_PIN11) +#define GPIO_LCD_D3 (GPIO_PERIPHA | GPIO_CFG_PULLUP | GPIO_PORT_PIOB | GPIO_PIN12) +#define GPIO_LCD_D4 (GPIO_PERIPHA | GPIO_CFG_PULLUP | GPIO_PORT_PIOB | GPIO_PIN13) +#define GPIO_LCD_D5 (GPIO_PERIPHA | GPIO_CFG_PULLUP | GPIO_PORT_PIOB | GPIO_PIN14) +#define GPIO_LCD_D6 (GPIO_PERIPHA | GPIO_CFG_PULLUP | GPIO_PORT_PIOB | GPIO_PIN15) +#define GPIO_LCD_D7 (GPIO_PERIPHA | GPIO_CFG_PULLUP | GPIO_PORT_PIOB | GPIO_PIN16) +#define GPIO_LCD_D8 (GPIO_PERIPHA | GPIO_CFG_PULLUP | GPIO_PORT_PIOB | GPIO_PIN25) +#define GPIO_LCD_D9 (GPIO_PERIPHA | GPIO_CFG_PULLUP | GPIO_PORT_PIOB | GPIO_PIN26) +#define GPIO_LCD_D10 (GPIO_PERIPHA | GPIO_CFG_PULLUP | GPIO_PORT_PIOB | GPIO_PIN27) +#define GPIO_LCD_D11 (GPIO_PERIPHA | GPIO_CFG_PULLUP | GPIO_PORT_PIOB | GPIO_PIN28) +#define GPIO_LCD_D12 (GPIO_PERIPHA | GPIO_CFG_PULLUP | GPIO_PORT_PIOB | GPIO_PIN29) +#define GPIO_LCD_D13 (GPIO_PERIPHA | GPIO_CFG_PULLUP | GPIO_PORT_PIOB | GPIO_PIN30) +#define GPIO_LCD_D14 (GPIO_PERIPHA | GPIO_CFG_PULLUP | GPIO_PORT_PIOB | GPIO_PIN31) +#define GPIO_LCD_D15 (GPIO_PERIPHB | GPIO_CFG_PULLUP | GPIO_PORT_PIOB | GPIO_PIN6) + +/* LCD Backlight pin definition. */ + +#define GPIO_LCD_BKL (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLEAR | \ + GPIO_PORT_PIOC | GPIO_PIN19) + +/* Touchscreen controller (TSC) + * + * The IRQ is active low and pulled up. + * + * Pen Interrupt. Open anode output, requires 10kO to 100kO pull-up resistor + * externally. There is a 100KO pull-up on the SAM4E-EK board so no additional + * pull-up should be required. + * + * BUSY is high impedance when CS is high (not selected). When CS is + * is low, BUSY is active high. Since the pin is pulled up, it will appear + * busy if CS is not selected (there is no pull-up onboard). + */ + +#define GPIO_TCS_IRQ (GPIO_INPUT | GPIO_CFG_PULLUP | GPIO_INT_BOTHEDGES | \ + GPIO_PORT_PIOA | GPIO_PIN24) +#define GPIO_TCS_BUSY (GPIO_INPUT | GPIO_CFG_PULLUP | GPIO_PORT_PIOA | \ + GPIO_PIN2) + +#define SAM_TCS_IRQ SAM_IRQ_PA24 + +/* LEDs + * + * D2 PA0 Blue Pulled high + * D3 PD20 Amber Pulled high + * D4 PD21 Green Pulled high + */ + +#define GPIO_D3 (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_PORT_PIOD | \ + GPIO_OUTPUT_CLEAR | GPIO_PIN20) +#define GPIO_D2 (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_PORT_PIOA | \ + GPIO_OUTPUT_SET | GPIO_PIN0) +#define GPIO_D4 (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_PORT_PIOD | \ + GPIO_OUTPUT_SET | GPIO_PIN21) + +/* Buttons + * + * Four buttons for software inputs: + * + * PA1 BUTTON_SCROLL-UP Grounded + * PA2 BUTTON_SCROLL-DOWN Grounded + * PA19 BUTTON_WAKU Grounded + * PA20 BUTTON_TAMP Grounded + */ + +#define GPIO_SCROLLUP (GPIO_INPUT | GPIO_CFG_PULLUP | GPIO_CFG_DEGLITCH | \ + GPIO_INT_BOTHEDGES | GPIO_PORT_PIOA | GPIO_PIN1) +#define GPIO_SCROLLDWN (GPIO_INPUT | GPIO_CFG_PULLUP | GPIO_CFG_DEGLITCH | \ + GPIO_INT_BOTHEDGES | GPIO_PORT_PIOA | GPIO_PIN2) +#define GPIO_WAKU (GPIO_INPUT | GPIO_CFG_PULLUP | GPIO_CFG_DEGLITCH | \ + GPIO_INT_BOTHEDGES | GPIO_PORT_PIOA | GPIO_PIN19) +#define GPIO_TAMP (GPIO_INPUT | GPIO_CFG_PULLUP | GPIO_CFG_DEGLITCH | \ + GPIO_INT_BOTHEDGES | GPIO_PORT_PIOA | GPIO_PIN20) + +#define IRQ_SCROLLUP SAM_IRQ_PA1 +#define IRQ_SCROLLDWN SAM_IRQ_PA2 +#define IRQ_WAKU SAM_IRQ_PA19 +#define IRQ_TAMP SAM_IRQ_PA20 +#define IRQ_SCROLLUP SAM_IRQ_PA1 +#define IRQ_SCROLLDWN SAM_IRQ_PA2 +#define IRQ_WAKU SAM_IRQ_PA19 +#define IRQ_TAMP SAM_IRQ_PA20 + +/* SD Card Detect */ + +#define GPIO_MCI_CD (GPIO_INPUT | GPIO_CFG_PULLUP | GPIO_PORT_PIOA | GPIO_PIN25) + +/* SPI Chip Selects */ + +/* Chip select pin connected to the touchscreen controller and to the ZigBee module + * connector. Notice that the touchscreen chip select is implemented as a GPIO + * OUTPUT that must be controlled by board-specific. This is because the ADS7843E + * driver must be able to sample the device BUSY GPIO input between SPI transfers. + * However, the AD7843E will tri-state the BUSY input whenever the chip select is + * de-asserted. So the only option is to control the chip select manually and hold + * it low throughout the SPI transfer. + */ + +#define GPIO_TSC_NPCS2 (GPIO_OUTPUT | GPIO_CFG_PULLUP | GPIO_OUTPUT_SET | \ + GPIO_PORT_PIOC | GPIO_PIN14) +#define TSC_CSNUM 2 + +/************************************************************************************ + * Public Types + ************************************************************************************/ + +/************************************************************************************ + * Public data + ************************************************************************************/ + +#ifndef __ASSEMBLY__ + +/************************************************************************************ + * Public Functions + ************************************************************************************/ + +/************************************************************************************ + * Name: sam_spiinitialize + * + * Description: + * Called to configure SPI chip select GPIO pins for the SAM4E-EK board. + * + ************************************************************************************/ + +void weak_function sam_spiinitialize(void); + +/************************************************************************************ + * Name: sam_usbinitialize + * + * Description: + * Called to setup USB-related GPIO pins for the SAM4E-EK board. + * + ************************************************************************************/ + +void weak_function sam_usbinitialize(void); + +/************************************************************************************ + * Name: sam_hsmciinit + * + * Description: + * Initialize HSMCI support + * + ************************************************************************************/ + +#ifdef CONFIG_SAM34_HSMCI +int weak_function sam_hsmciinit(void); +#else +# define sam_hsmciinit() +#endif + +/************************************************************************************ + * Name: board_led_initialize + ************************************************************************************/ + +#ifdef CONFIG_ARCH_LEDS +void board_led_initialize(void); +#endif + +/************************************************************************************ + * Name: sam_cardinserted + * + * Description: + * Check if a card is inserted into the selected HSMCI slot + * + ************************************************************************************/ + +#ifdef CONFIG_SAM34_HSMCI +bool sam_cardinserted(unsigned char slot); +#else +# define sam_cardinserted(slot) (false) +#endif + +/************************************************************************************ + * Name: sam_writeprotected + * + * Description: + * Check if a card is inserted into the selected HSMCI slot + * + ************************************************************************************/ + +#ifdef CONFIG_SAM34_HSMCI +bool sam_writeprotected(unsigned char slot); +#else +# define sam_writeprotected(slot) (false) +#endif + +#endif /* __ASSEMBLY__ */ +#endif /* __CONFIGS_SAM4E_EK_SRC_SAM4E_EK_H */ diff --git a/configs/sam4e-ek/src/sam_boot.c b/configs/sam4e-ek/src/sam_boot.c new file mode 100644 index 0000000000..647c0d197c --- /dev/null +++ b/configs/sam4e-ek/src/sam_boot.c @@ -0,0 +1,112 @@ +/************************************************************************************ + * configs/sam4e-ek/src/sam_boot.c + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************************************/ + +/************************************************************************************ + * Included Files + ************************************************************************************/ + +#include + +#include + +#include + +#include "up_arch.h" +#include "sam4e-ek.h" + +/************************************************************************************ + * Definitions + ************************************************************************************/ + +/************************************************************************************ + * Private Functions + ************************************************************************************/ + +/************************************************************************************ + * Public Functions + ************************************************************************************/ + +/************************************************************************************ + * Name: sam_boardinitialize + * + * Description: + * All SAM3U architectures must provide the following entry point. This entry point + * is called early in the intitialization -- after all memory has been configured + * and mapped but before any devices have been initialized. + * + ************************************************************************************/ + +void sam_boardinitialize(void) +{ + /* Configure SPI chip selects if 1) SPI is not disabled, and 2) the weak function + * sam_spiinitialize() has been brought into the link. + */ + +#ifdef CONFIG_SAM34_SPI0 + if (sam_spiinitialize) + { + sam_spiinitialize(); + } +#endif + + /* Initialize USB if 1) USBDEV is selected, 2) the USB controller is not + * disabled, and 3) the weak function sam_usbinitialize() has been brought + * into the build. + */ + +#if defined(CONFIG_USBDEV) && defined(CONFIG_SAM34_USB) + if (sam_usbinitialize) + { + sam_usbinitialize(); + } +#endif + + /* Configure on-board LEDs if LED support has been selected. */ + +#ifdef CONFIG_ARCH_LEDS + board_led_initialize(); +#endif + + /* Setup SD card-related PIOs if 1) HSMCI is selected and 2) the weak + * function sam_hsmciinit() has been brought into the build. + */ + +#ifdef CONFIG_SAM34_HSMCI + if (sam_hsmciinit) + { + sam_hsmciinit(); + } +#endif +} diff --git a/configs/sam4e-ek/src/sam_buttons.c b/configs/sam4e-ek/src/sam_buttons.c new file mode 100644 index 0000000000..42d6f3ec29 --- /dev/null +++ b/configs/sam4e-ek/src/sam_buttons.c @@ -0,0 +1,199 @@ +/**************************************************************************** + * configs/sam4e-ek/src/sam_buttons.c + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include +#include + +#include +#include + +#include "sam_gpio.h" +#include "sam4e-ek.h" + +#ifdef CONFIG_ARCH_BUTTONS + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +#if defined(CONFIG_GPIOA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) +static xcpt_t g_irq_scrollup; +static xcpt_t g_irq_scrolldown; +static xcpt_t g_irq_waku; +static xcpt_t g_irq_tamp; +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_button_irqx + * + * Description: + * This function implements the core of the board_button_irq() logic. + * + ****************************************************************************/ + +#if defined(CONFIG_GPIOA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) +static xcpt_t board_button_irqx(int irq, xcpt_t irqhandler, xcpt_t *store) +{ + xcpt_t oldhandler; + irqstate_t flags; + + /* Disable interrupts until we are done. This guarantees that the following + * operations are atomic. + */ + + flags = irqsave(); + + /* Get the old button interrupt handler and save the new one */ + + oldhandler = *store; + *store = irqhandler; + + /* Configure the interrupt */ + + sam_gpioirq(irq); + (void)irq_attach(irq, irqhandler); + sam_gpioirqenable(irq); + irqrestore(flags); + + /* Return the old button handler (so that it can be restored) */ + + return oldhandler; +} +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_button_initialize + * + * Description: + * board_button_initialize() must be called to initialize button resources. After + * that, board_buttons() may be called to collect the current state of all + * buttons or board_button_irq() may be called to register button interrupt + * handlers. + * + ****************************************************************************/ + +void board_button_initialize(void) +{ + (void)sam_configgpio(GPIO_SCROLLUP); + (void)sam_configgpio(GPIO_SCROLLDWN); + (void)sam_configgpio(GPIO_WAKU); + (void)sam_configgpio(GPIO_TAMP); +} + +/************************************************************************************ + * Name: board_buttons + * + * Description: + * After board_button_initialize() has been called, board_buttons() may be called to collect + * the state of all buttons. board_buttons() returns an 8-bit bit set with each bit + * associated with a button. See the BUTTON* definitions above for the meaning of + * each bit in the returned value. + * + ************************************************************************************/ + +uint8_t board_buttons(void) +{ + uint8_t retval; + + retval = sam_gpioread(GPIO_SCROLLUP) ? 0 : BUTTON_SCROLLUP; + retval |= sam_gpioread(GPIO_SCROLLDWN) ? 0 : BUTTON_SCROLLDOWN; + retval |= sam_gpioread(GPIO_WAKU) ? 0 : BUTTON_WAKU; + retval |= sam_gpioread(GPIO_TAMP) ? 0 : BUTTON_TAMP; + + return retval; +} + +/**************************************************************************** + * Name: board_button_irq + * + * Description: + * This function may be called to register an interrupt handler that will + * be called when a button is depressed or released. The ID value is one + * of the BUTTON* definitions provided above. The previous interrupt + * handler address isreturned (so that it may restored, if so desired). + * + * Configuration Notes: + * Configuration CONFIG_AVR32_GPIOIRQ must be selected to enable the + * overall GPIO IRQ feature and CONFIG_AVR32_GPIOIRQSETA and/or + * CONFIG_AVR32_GPIOIRQSETB must be enabled to select GPIOs to support + * interrupts on. For button support, bits 2 and 3 must be set in + * CONFIG_AVR32_GPIOIRQSETB (PB2 and PB3). + * + ****************************************************************************/ + +#if defined(CONFIG_GPIOA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) +xcpt_t board_button_irq(int id, xcpt_t irqhandler) +{ + switch (id) + { + case BUTTON_SCROLLUP: + return board_button_irqx(IRQ_SCROLLUP, irqhandler, &g_irq_scrollup); + + case BUTTON_SCROLLDOWN: + return board_button_irqx(IRQ_SCROLLDWN, irqhandler, &g_irq_scrolldown); + + case BUTTON_WAKU: + return board_button_irqx(IRQ_WAKU, irqhandler, &g_irq_waku); + + case BUTTON_TAMP: + return board_button_irqx(IRQ_WAKU, irqhandler, &g_irq_tamp); + + default: + return NULL; + } +} +#endif + +#endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/sam4e-ek/src/sam_cxxinitialize.c b/configs/sam4e-ek/src/sam_cxxinitialize.c new file mode 100644 index 0000000000..e5a92f3af6 --- /dev/null +++ b/configs/sam4e-ek/src/sam_cxxinitialize.c @@ -0,0 +1,149 @@ +/************************************************************************************ + * configs/sam4e-ek/src/sam_cxxinitialize.c + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************************************/ + +/************************************************************************************ + * Included Files + ************************************************************************************/ + +#include + +#include +#include + +#if defined(CONFIG_HAVE_CXX) && defined(CONFIG_HAVE_CXXINITIALIZE) + +/************************************************************************************ + * Definitions + ************************************************************************************/ +/* Debug ****************************************************************************/ +/* Non-standard debug that may be enabled just for testing the static constructors */ + +#ifndef CONFIG_DEBUG +# undef CONFIG_DEBUG_CXX +#endif + +#ifdef CONFIG_DEBUG_CXX +# define cxxdbg dbg +# define cxxlldbg lldbg +# ifdef CONFIG_DEBUG_VERBOSE +# define cxxvdbg vdbg +# define cxxllvdbg llvdbg +# else +# define cxxvdbg(x...) +# define cxxllvdbg(x...) +# endif +#else +# define cxxdbg(x...) +# define cxxlldbg(x...) +# define cxxvdbg(x...) +# define cxxllvdbg(x...) +#endif + +/************************************************************************************ + * Private Types + ************************************************************************************/ +/* This type defines one entry in initialization array */ + +typedef void (*initializer_t)(void); + +/************************************************************************************ + * External references + ************************************************************************************/ +/* _sinit and _einit are symbols exported by the linker script that mark the + * beginning and the end of the C++ initialization section. + */ + +extern initializer_t _sinit; +extern initializer_t _einit; + +/* _stext and _etext are symbols exported by the linker script that mark the + * beginning and the end of text. + */ + +extern uint32_t _stext; +extern uint32_t _etext; + +/************************************************************************************ + * Private Functions + ************************************************************************************/ + +/************************************************************************************ + * Public Functions + ************************************************************************************/ + +/**************************************************************************** + * Name: up_cxxinitialize + * + * Description: + * If C++ and C++ static constructors are supported, then this function + * must be provided by board-specific logic in order to perform + * initialization of the static C++ class instances. + * + * This function should then be called in the application-specific + * user_start logic in order to perform the C++ initialization. NOTE + * that no component of the core NuttX RTOS logic is involved; This + * function defintion only provides the 'contract' between application + * specific C++ code and platform-specific toolchain support + * + ***************************************************************************/ + +void up_cxxinitialize(void) +{ + initializer_t *initp; + + cxxdbg("_sinit: %p _einit: %p _stext: %p _etext: %p\n", + &_sinit, &_einit, &_stext, &_etext); + + /* Visit each entry in the initialzation table */ + + for (initp = &_sinit; initp != &_einit; initp++) + { + initializer_t initializer = *initp; + cxxdbg("initp: %p initializer: %p\n", initp, initializer); + + /* Make sure that the address is non-NULL and lies in the text region + * defined by the linker script. Some toolchains may put NULL values + * or counts in the initialization table + */ + + if ((void*)initializer > (void*)&_stext && (void*)initializer < (void*)&_etext) + { + cxxdbg("Calling %p\n", initializer); + initializer(); + } + } +} + +#endif /* CONFIG_HAVE_CXX && CONFIG_HAVE_CXXINITIALIZE */ diff --git a/configs/sam4e-ek/src/sam_lcd.c b/configs/sam4e-ek/src/sam_lcd.c new file mode 100644 index 0000000000..e081baecbd --- /dev/null +++ b/configs/sam4e-ek/src/sam_lcd.c @@ -0,0 +1,1078 @@ +/************************************************************************************** + * configs/sam4e-ek/src/sam_lcd.c + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************************/ + +/************************************************************************************** + * The SAM4E-EK carries a TFT transmissive LCD module with touch panel, FTM280C34D. + * Its integrated driver IC is ILI9325. The LCD display area is 2.8 inches diagonally + * measured, with a native resolution of 240 x 320 dots. + * + * LCD Module Pin Out: SAM3U PIO: + * -------------------------------------------- -------------------------------------- + * Pin Symbol Function LCD PeriphA PeriphB Extra + * ---- ------ -------------------------------- -------------- -------- ------- ------ + * 1 GND Ground N/A --- --- --- + * 2 CS Chip Select PC16 NCS2 PWML3 AD12BAD5 + * 3 RS Register select signal PB8 (see A1) CTS0 A1 AD3 + * 4 WR Write operation signal PB23 (NWE) NWR0/NEW PCK1 --- + * 5 RD Read operation signal PB19 (NRD) NRD PWML2 --- + * 6 DB0 Data bus PB9 D0 DTR0 --- + * 7 DB1 Data bus PB10 D1 DSR0 --- + * 8 DB2 Data bus PB11 D2 DCD0 --- + * 9 DB3 Data bus PB12 D3 RI0 --- + * 10 DB4 Data bus PB13 D4 PWMH0 --- + * 11 DB5 Data bus PB14 D5 PWMH1 --- + * 12 DB6 Data bus PB15 D6 PWMH2 --- + * 13 DB7 Data bus PB16 D7 PMWH3 --- + * 14 DB8 Data bus PB25 D8 PWML0 --- + * 15 DB9 Data bus PB26 D9 PWML1 --- + * 16 DB10 Data bus PB27 D10 PWML2 --- + * 17 DB11 Data bus PB28 D11 PWML3 --- + * 18 DB12 Data bus PB29 D12 --- --- + * 19 DB13 Data bus PB30 D13 --- --- + * 20 DB14 Data bus PB31 D14 --- --- + * 21 DB15 Data bus PB6 TIOA1 D15 AD1 + * 22 NC No connection N/A --- --- --- + * 23 NC No connection N/A --- --- --- + * 24 RESET Reset signal N/A --- --- --- + * 25 GND Ground N/A --- --- --- + * 26 X+ Touch panel X_RIGHT PA15 SPCK PWMH2 --- + * 27 Y+ Touch panel Y_UP PA14 MOSI --- --- + * 28 X- Touch panel X_LEFT PA13 MISO --- --- + * 29 Y- Touch panel Y_DOWN PC14 A3 NPCS2 --- + * 30 GND Ground N/A --- --- --- + * 31 VDD1 Power supply for digital IO Pad N/A --- --- --- + * 32 VDD2 Power supply for analog circuit N/A --- --- --- + * 33 A1 Power supply for backlight PB8 (see RS) CTS0 A1 AD3 + * 34 A2 Power supply for backlight N/A --- --- --- + * 35 A3 Power supply for backlight N/A --- --- --- + * 36 A4 Power supply for backlight N/A --- --- --- + * 37 NC No connection N/A --- --- --- + * 38 NC No connection N/A --- --- --- + * 39 K Backlight ground N/A --- --- --- + * + * The LCD module gets its reset from NRST. As explained previously, this NRST is + * shared with the JTAG port and the push button BP1. The LCD chip select signal is + * connected to NCS2 (a dedicated jumper can disable it, making NCS2 available for + * other custom usage). + * + * The SAM3U4E communicates with the LCD through PIOB where a 16-bit parallel + * 8080-like protocol data bus has to be implemented by software. + * + * LCD backlight is made of 4 white chip LEDs in parallel, driven by an AAT3194 + * charge pump, MN4. The AAT3194 is controlled by the SAM3U4E through a single line + * Simple Serial Control (S2Cwire) interface, which permits to enable, disable, and + * set the LED drive current (LED brightness control) from a 32-level logarithmic + * scale. Four resistors R93/R94/R95/R96 are implemented for optional current + * limitation. + * + * The LCD module integrates a 4-wire touch screen panel controlled by + * MN5, ADS7843, which is a slave device on the SAM3U4E SPI bus. The ADS7843 touch + * ADC auxiliary inputs IN3/IN4 are connected to test points for optional function + * extension. + * + **************************************************************************************/ + +/************************************************************************************** + * Included Files + **************************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include "up_arch.h" +#include "sam_gpio.h" +#include "chip/sam_pmc.h" +#include "chip/sam_smc.h" +#include "sam4e-ek.h" + +/************************************************************************************** + * Pre-processor Definitions + **************************************************************************************/ + +/* Configuration **********************************************************************/ + +/* Define the following to enable register-level debug output */ + +#undef CONFIG_LCD_REGDEBUG + +/* Verbose debug must also be enabled */ + +#ifndef CONFIG_DEBUG +# undef CONFIG_DEBUG_VERBOSE +# undef CONFIG_DEBUG_LED +#endif + +#ifndef CONFIG_DEBUG_VERBOSE +# undef CONFIG_LCD_REGDEBUG +#endif + +/* CONFIG_LCD_MAXCONTRAST -- must be defined and less than 32 */ + +#if !defined(CONFIG_LCD_MAXCONTRAST) || CONFIG_LCD_MAXCONTRAST < 1 || CONFIG_LCD_MAXCONTRAST > 31 +# error "CONFIG_LCD_MAXCONTRAST must be defined in the range 1 to 31" +#endif + +/* Debug ******************************************************************************/ + +#ifdef CONFIG_LCD_REGDEBUG +# define regdbg(format, arg...) vdbg(format, ##arg) +#else +# define regdbg(x...) +#endif + +#ifdef CONFIG_DEBUG_LCD +# define lcddbg(format, arg...) dbg(format, ##arg) +# define lcdvdbg(format, arg...) vdbg(format, ##arg) +#else +# define lcddbg(x...) +# define lcdvdbg(x...) +#endif + +/* Graphics Capbilities ***************************************************************/ + +/* LCD resolution: 320 (columns) by 240 (rows). The physical dimensions of the device + * are really 240 (columns) by 320 (rows), but unless CONFIG_LCD_PORTRAIT is defined, + * we swap rows and columns in setcursor to make things behave nicer (there IS a + * performance hit for this swap!). + */ + +#ifdef CONFIG_LCD_PORTRAIT +# define SAM4EEK_XRES 240 +# define SAM4EEK_YRES 320 +#else +# define SAM4EEK_XRES 320 +# define SAM4EEK_YRES 240 +#endif + +/* Color depth and format. BPP=16 R=6, G=6, B=5: RRRR RBBB BBBG GGGG */ + +#define SAM4EEK_BPP 16 +#define SAM4EEK_RGBFMT FB_FMT_RGB16_565 + +/* HX834x Definitions ****************************************************************/ + +/* HX834x register select */ + +#define HX843X_LCD_RS (1 << 1) + +/* HX8347 ID code */ + +#define HX8347_CHIPID 0x47 + +/* HX8347 LCD Registers */ + +#define HX8347_R00H 0x00 +#define HX8347_R01H 0x01 +#define HX8347_R02H 0x02 +#define HX8347_R03H 0x03 +#define HX8347_R04H 0x04 +#define HX8347_R05H 0x05 +#define HX8347_R06H 0x06 +#define HX8347_R07H 0x07 +#define HX8347_R08H 0x08 +#define HX8347_R09H 0x09 +#define HX8347_R0AH 0x0a +#define HX8347_R0CH 0x0c +#define HX8347_R0DH 0x0d +#define HX8347_R0EH 0x0e +#define HX8347_R0FH 0x0f +#define HX8347_R10H 0x10 +#define HX8347_R11H 0x11 +#define HX8347_R12H 0x12 +#define HX8347_R13H 0x13 +#define HX8347_R14H 0x14 +#define HX8347_R15H 0x15 +#define HX8347_R16H 0x16 +#define HX8347_R18H 0x18 +#define HX8347_R19H 0x19 +#define HX8347_R1AH 0x1a +#define HX8347_R1BH 0x1b +#define HX8347_R1CH 0x1c +#define HX8347_R1DH 0x1d +#define HX8347_R1EH 0x1e +#define HX8347_R1FH 0x1f +#define HX8347_R20H 0x20 +#define HX8347_R21H 0x21 +#define HX8347_R22H 0x22 +#define HX8347_R23H 0x23 +#define HX8347_R24H 0x24 +#define HX8347_R25H 0x25 +#define HX8347_R26H 0x26 +#define HX8347_R27H 0x27 +#define HX8347_R28H 0x28 +#define HX8347_R29H 0x29 +#define HX8347_R2AH 0x2a +#define HX8347_R2BH 0x2b +#define HX8347_R2CH 0x2c +#define HX8347_R2DH 0x2d +#define HX8347_R35H 0x35 +#define HX8347_R36H 0x36 +#define HX8347_R37H 0x37 +#define HX8347_R38H 0x38 +#define HX8347_R39H 0x39 +#define HX8347_R3AH 0x3a +#define HX8347_R3BH 0x3b +#define HX8347_R3CH 0x3c +#define HX8347_R3DH 0x3d +#define HX8347_R3EH 0x3e +#define HX8347_R40H 0x40 +#define HX8347_R41H 0x41 +#define HX8347_R42H 0x42 +#define HX8347_R43H 0x43 +#define HX8347_R44H 0x44 +#define HX8347_R45H 0x45 +#define HX8347_R46H 0x46 +#define HX8347_R47H 0x47 +#define HX8347_R48H 0x48 +#define HX8347_R49H 0x49 +#define HX8347_R4AH 0x4a +#define HX8347_R4BH 0x4b +#define HX8347_R4CH 0x4c +#define HX8347_R4DH 0x4d +#define HX8347_R4EH 0x4e +#define HX8347_R4FH 0x4f +#define HX8347_R50H 0x50 +#define HX8347_R51H 0x51 +#define HX8347_R64H 0x64 +#define HX8347_R65H 0x65 +#define HX8347_R66H 0x66 +#define HX8347_R67H 0x67 +#define HX8347_R70H 0x70 +#define HX8347_R72H 0x72 +#define HX8347_R90H 0x90 +#define HX8347_R91H 0x91 +#define HX8347_R93H 0x93 +#define HX8347_R94H 0x94 +#define HX8347_R95H 0x95 + +/************************************************************************************** + * Private Type Definition + **************************************************************************************/ + +/* This structure describes the state of this driver */ + +struct sam_dev_s +{ + /* Publically visible device structure */ + + struct lcd_dev_s dev; + + /* Private device state */ + + uint8_t power; /* The current power setting */ +}; + +/************************************************************************************** + * Private Function Protototypes + **************************************************************************************/ + +/* Low-level HX834x Register access */ + +static void sam_putreg(uint16_t reg, uint16_t data); +#ifdef CONFIG_DEBUG_LCD +static uint16_t sam_getreg(uint16_t reg); +#endif + +/* Misc. LCD Helper Functions */ + +static void sam_setcursor(fb_coord_t row, fb_coord_t col); +static inline void sam_wrsetup(void); +static inline void sam_wrram(uint16_t color); +static inline uint16_t sam_rdram(void); +static void sam_lcdon(void); +static void sam_lcdoff(void); + +#if 0 /* CONFIG_DEBUG_LCD */ +static void sam_dumpreg(uint8_t startreg, uint8_t endreg); +#endif + +/* LCD Data Transfer Methods */ + +static int sam_putrun(fb_coord_t row, fb_coord_t col, FAR const uint8_t *buffer, + size_t npixels); +static int sam_getrun(fb_coord_t row, fb_coord_t col, FAR uint8_t *buffer, + size_t npixels); + +/* LCD Configuration */ + +static int sam_getvideoinfo(FAR struct lcd_dev_s *dev, + FAR struct fb_videoinfo_s *vinfo); +static int sam_getplaneinfo(FAR struct lcd_dev_s *dev, unsigned int planeno, + FAR struct lcd_planeinfo_s *pinfo); + +/* LCD RGB Mapping */ + +#ifdef CONFIG_FB_CMAP +# error "RGB color mapping not supported by this driver" +#endif + +/* Cursor Controls */ + +#ifdef CONFIG_FB_HWCURSOR +# error "Cursor control not supported by this driver" +#endif + +/* LCD Specific Controls */ + +static int sam_getpower(struct lcd_dev_s *dev); +static int sam_setpower(struct lcd_dev_s *dev, int power); +static int sam_getcontrast(struct lcd_dev_s *dev); +static int sam_setcontrast(struct lcd_dev_s *dev, unsigned int contrast); + +/************************************************************************************** + * Private Data + **************************************************************************************/ + +/* This is working memory allocated by the LCD driver for each LCD device + * and for each color plane. This memory will hold one raster line of data. + * The size of the allocated run buffer must therefor be at least + * (bpp * xres / 8). Actual alignment of the buffer must conform to the + * bitwidth of the underlying pixel type. + * + * If there are multiple planes, they may share the same working buffer + * because different planes will not be operate on concurrently. However, + * if there are multiple LCD devices, they must each have unique run buffers. + */ + +static uint16_t g_runbuffer[SAM4EEK_XRES]; + +/* This structure describes the overall LCD video controller */ + +static const struct fb_videoinfo_s g_videoinfo = +{ + .fmt = SAM4EEK_RGBFMT, /* Color format: RGB16-565: RRRR RGGG GGGB BBBB */ + .xres = SAM4EEK_XRES, /* Horizontal resolution in pixel columns */ + .yres = SAM4EEK_YRES, /* Vertical resolution in pixel rows */ + .nplanes = 1, /* Number of color planes supported */ +}; + +/* This is the standard, NuttX Plane information object */ + +static const struct lcd_planeinfo_s g_planeinfo = +{ + .putrun = sam_putrun, /* Put a run into LCD memory */ + .getrun = sam_getrun, /* Get a run from LCD memory */ + .buffer = (uint8_t*)g_runbuffer, /* Run scratch buffer */ + .bpp = SAM4EEK_BPP, /* Bits-per-pixel */ +}; + +/* This is the standard, NuttX LCD driver object */ + +static struct sam_dev_s g_lcddev_s = +{ + .dev = + { + /* LCD Configuration */ + + .getvideoinfo = sam_getvideoinfo, + .getplaneinfo = sam_getplaneinfo, + + /* LCD RGB Mapping -- Not supported */ + /* Cursor Controls -- Not supported */ + + /* LCD Specific Controls */ + + .getpower = sam_getpower, + .setpower = sam_setpower, + .getcontrast = sam_getcontrast, + .setcontrast = sam_setcontrast, + }, +}; + +/************************************************************************************** + * Private Functions + **************************************************************************************/ + +/************************************************************************************** + * Name: sam_putreg + * + * Description: + * Write to a HX834x register + * + **************************************************************************************/ + +static void sam_putreg(uint16_t reg, uint16_t data) +{ + regdbg("base: %08x RS: %04x data: %04x\n", LCD_BASE, LCD_BASE + HX843X_LCD_RS, data); + putreg16(reg, LCD_BASE); + putreg16(data, LCD_BASE + HX843X_LCD_RS); +} + +/************************************************************************************** + * Name: sam_getreg + * + * Description: + * Read from a HX834x register + * + **************************************************************************************/ + +#ifdef CONFIG_DEBUG_LCD +static uint16_t sam_getreg(uint16_t reg) +{ + uint16_t data; + putreg16(reg, LCD_BASE); + data = getreg16(LCD_BASE + HX843X_LCD_RS); + regdbg("base: %08x RS: %04x data: %04x\n", LCD_BASE, LCD_BASE + HX843X_LCD_RS, data); + return data; +} +#endif + +/************************************************************************************** + * Name: sam_setcursor + * + * Description: + * Set the LCD cursor position. + * + **************************************************************************************/ + +static void sam_setcursor(fb_coord_t row, fb_coord_t col) +{ + uint8_t x1; + uint8_t x2; + uint8_t y1; + uint8_t y2; + + /* Get the upper and lower x and y positions */ + + x1 = (uint8_t)col; + x2 = (uint8_t)((uint16_t)col >> 8); + + y1 = (uint8_t)row; + y2 = (uint8_t)((uint16_t)row >> 8); + + /* Then set the cursor position */ + + sam_putreg(HX8347_R02H, x2); /* column high */ + sam_putreg(HX8347_R03H, x1); /* column low */ + sam_putreg(HX8347_R06H, y2); /* row high */ + sam_putreg(HX8347_R07H, y1); /* row low */ +} + +/************************************************************************************** + * Name: sam_wrsetup + * + * Description: + * Set up for a GRAM write operation. + * + **************************************************************************************/ + +static inline void sam_wrsetup(void) +{ + putreg16(HX8347_R22H, LCD_BASE); +} + +/************************************************************************************** + * Name: sam_wrram + * + * Description: + * Write to the 16-bit GRAM register + * + **************************************************************************************/ + +static inline void sam_wrram(uint16_t color) +{ + putreg16(color, LCD_BASE + HX843X_LCD_RS); +} + +/************************************************************************************** + * Name: sam_rdram + * + * Description: + * Read from the 16-bit GRAM register + * + **************************************************************************************/ + +static inline uint16_t sam_rdram(void) +{ + return getreg16(LCD_BASE + HX843X_LCD_RS); +} + +/************************************************************************************** + * Name: sam_lcdon + * + * Description: + * Turn the LCD on + * + **************************************************************************************/ + +static void sam_lcdon(void) +{ + /* Display ON Setting */ + + lcdvdbg("ON\n"); + sam_putreg(HX8347_R90H, 0x7f); /* SAP=0111 1111 */ + sam_putreg(HX8347_R26H, 0x04); /* GON=0 DTE=0 D=01 */ + up_mdelay(100); + sam_putreg(HX8347_R26H, 0x24); /* GON=1 DTE=0 D=01 */ + sam_putreg(HX8347_R26H, 0x2c); /* GON=1 DTE=0 D=11 */ + up_mdelay(100); + sam_putreg(HX8347_R26H, 0x3c); /* GON=1 DTE=1 D=11 */ +} + +/************************************************************************************** + * Name: sam_lcdoff + * + * Description: + * Turn the LCD off + * + **************************************************************************************/ + +static void sam_lcdoff(void) +{ + lcdvdbg("OFF\n"); + sam_putreg(HX8347_R90H, 0x00); /* SAP=0000 0000 */ + sam_putreg(HX8347_R26H, 0x00); /* GON=0 DTE=0 D=00 */ +} + +/************************************************************************************** + * Name: sam_dumpreg + * + * Description: + * Dump a range of LCD registers. + * + **************************************************************************************/ + +#if 0 /* CONFIG_DEBUG_LCD */ +static void sam_dumpreg(uint8_t startreg, uint8_t endreg) +{ + uint16_t value; + uint8_t addr; + + for (addr = startreg; addr <= endreg; addr++) + { + value = sam_getreg(addr); + lcddbg(" %02x: %04x\n", addr, value); + } +} +#endif + +/************************************************************************************** + * Name: sam_putrun + * + * Description: + * This method can be used to write a partial raster line to the LCD: + * + * row - Starting row to write to (range: 0 <= row < yres) + * col - Starting column to write to (range: 0 <= col <= xres-npixels) + * buffer - The buffer containing the run to be written to the LCD + * npixels - The number of pixels to write to the LCD + * (range: 0 < npixels <= xres-col) + * + **************************************************************************************/ + +static int sam_putrun(fb_coord_t row, fb_coord_t col, FAR const uint8_t *buffer, + size_t npixels) +{ + uint16_t *run = (uint16_t*)buffer; + unsigned int i; + + /* Buffer must be provided and aligned to a 16-bit address boundary */ + + lcdvdbg("row: %d col: %d npixels: %d\n", row, col, npixels); + DEBUGASSERT(buffer && ((uintptr_t)buffer & 1) == 0); + +#ifdef CONFIG_LCD_PORTRAIT + /* Set up to write the run. */ + + sam_setcursor(row, col); + sam_wrsetup(); + + /* Write the run to GRAM. */ + + for (i = 0; i < npixels; i++) + { + /* Write the pixel pixel to GRAM */ + + sam_wrram(*run++); + } +#else + /* Write the run to GRAM. Because rows and colums are swapped, we need to reset + * the cursor position for every pixel. We could do this much faster if we + * adapted to the strange device aspect ratio. + */ + + col = 319-col; + for (i = 0; i < npixels; i++) + { + /* Set up to write the next pixel. Swapping x and y orientations so that the image + * comes out with the 320x240 aspect ratio (not the native 240x320). That is: + * + * row: 0-239 maps to x: 0-239 + * col: 0-319 maps to y: 319-0 + */ + + sam_setcursor(col--, row); + sam_wrsetup(); + + /* Write the pixel pixel to GRAM */ + + sam_wrram(*run++); + } +#endif + return OK; +} + +/************************************************************************************** + * Name: sam_getrun + * + * Description: + * This method can be used to read a partial raster line from the LCD: + * + * row - Starting row to read from (range: 0 <= row < yres) + * col - Starting column to read read (range: 0 <= col <= xres-npixels) + * buffer - The buffer in which to return the run read from the LCD + * npixels - The number of pixels to read from the LCD + * (range: 0 < npixels <= xres-col) + * + **************************************************************************************/ + +static int sam_getrun(fb_coord_t row, fb_coord_t col, FAR uint8_t *buffer, + size_t npixels) +{ + uint16_t *run = (uint16_t*)buffer; + unsigned int i; + + /* Buffer must be provided and aligned to a 16-bit address boundary */ + + lcdvdbg("row: %d col: %d npixels: %d\n", row, col, npixels); + DEBUGASSERT(buffer && ((uintptr_t)buffer & 1) == 0); + +#ifdef CONFIG_LCD_PORTRAIT + /* Set up to read the run */ + + sam_setcursor(row, col); + + /* Read the run from GRAM. */ + + for (i = 0; i < npixels; i++) + { + /* Read the next pixel */ + + *run++ = sam_rdram(); + } +#else + /* Read the run from GRAM Because rows and colums are swapped, we need to reset + * the cursor position for every pixel. We could do this much faster if we + * adapted to the strange device aspect ratio. + */ + + col = 319 - col; + for (i = 0; i < npixels; i++) + { + /* Read the next pixel.. Swapping x and y orientations so that the image + * comes out with the 320x240 aspect ratio (not the native 240x320). That is: + * + * row: 0-239 maps to x: 0-239 + * col: 0-319 maps to y: 319-0 + */ + + sam_setcursor(col--, row); + *run++ = sam_rdram(); + } +#endif + return OK; +} + +/************************************************************************************** + * Name: sam_getvideoinfo + * + * Description: + * Get information about the LCD video controller configuration. + * + **************************************************************************************/ + +static int sam_getvideoinfo(FAR struct lcd_dev_s *dev, + FAR struct fb_videoinfo_s *vinfo) +{ + DEBUGASSERT(dev && vinfo); + lcdvdbg("fmt: %d xres: %d yres: %d nplanes: %d\n", + g_videoinfo.fmt, g_videoinfo.xres, g_videoinfo.yres, g_videoinfo.nplanes); + memcpy(vinfo, &g_videoinfo, sizeof(struct fb_videoinfo_s)); + return OK; +} + +/************************************************************************************** + * Name: sam_getplaneinfo + * + * Description: + * Get information about the configuration of each LCD color plane. + * + **************************************************************************************/ + +static int sam_getplaneinfo(FAR struct lcd_dev_s *dev, unsigned int planeno, + FAR struct lcd_planeinfo_s *pinfo) +{ + DEBUGASSERT(dev && pinfo && planeno == 0); + lcdvdbg("planeno: %d bpp: %d\n", planeno, g_planeinfo.bpp); + memcpy(pinfo, &g_planeinfo, sizeof(struct lcd_planeinfo_s)); + return OK; +} + +/************************************************************************************** + * Name: sam_getpower + * + * Description: + * Get the LCD panel power status (0: full off - CONFIG_LCD_MAXPOWER: full on. On + * backlit LCDs, this setting may correspond to the backlight setting. + * + **************************************************************************************/ + +static int sam_getpower(struct lcd_dev_s *dev) +{ + struct sam_dev_s *priv = (struct sam_dev_s *)dev; + DEBUGASSERT(dev); + lcdvdbg("power: %d\n", priv->power); + return priv->power; +} + +/************************************************************************************** + * Name: sam_setpower + * + * Description: + * Enable/disable LCD panel power (0: full off - CONFIG_LCD_MAXPOWERL: full on). On + * backlit LCDs, this setting may correspond to the backlight setting. + * + * LCD backlight is made of 4 white chip LEDs in parallel, driven by an AAT3194 charge + * pump, MN4. The AAT3194 is controlled by the SAM3U4E through a single line. Simple + * Serial Control (S2Cwire) interface, which permits to enable, disable, and set the + * LED drive current (LED brightness control) from a 32-level logarithmic scale. Four + * resistors R93/R94/R95/R96 are implemented for optional current limitation. + * + **************************************************************************************/ + +static int sam_setpower(struct lcd_dev_s *dev, int power) +{ + struct sam_dev_s *priv = (struct sam_dev_s *)dev; + unsigned int i; + + lcdvdbg("power: %d\n", power); + DEBUGASSERT(power <= CONFIG_LCD_MAXPOWER); + + /* Switch off backlight */ + + sam_gpiowrite(GPIO_LCD_BKL, false); + + /* For for at least 500uS to drain the charge pump */ + + up_udelay(500); + + /* Set new backlight level by pumping "level" times */ + + for (i = 0; i < power; i++) + { + sam_gpiowrite(GPIO_LCD_BKL, false); + sam_gpiowrite(GPIO_LCD_BKL, false); + sam_gpiowrite(GPIO_LCD_BKL, false); + sam_gpiowrite(GPIO_LCD_BKL, true); + sam_gpiowrite(GPIO_LCD_BKL, true); + sam_gpiowrite(GPIO_LCD_BKL, true); + } + + /* This delay seems to be required... perhaps because of the big current jump? */ + + if (power != LCD_FULL_OFF) + { + up_mdelay(100); + } + + priv->power = power; + return OK; +} + +/************************************************************************************** + * Name: sam_getcontrast + * + * Description: + * Get the current contrast setting (0-CONFIG_LCD_MAXCONTRAST). + * + **************************************************************************************/ + +static int sam_getcontrast(struct lcd_dev_s *dev) +{ + lcdvdbg("Not implemented\n"); + return -ENOSYS; +} + +/************************************************************************************** + * Name: sam_getcontrast + * + * Description: + * Set LCD panel contrast (0-CONFIG_LCD_MAXCONTRAST). + * + **************************************************************************************/ + +static int sam_setcontrast(struct lcd_dev_s *dev, unsigned int contrast) +{ + lcdvdbg("contrast: %d\n", contrast); + return -ENOSYS; +} + +/************************************************************************************** + * Public Functions + **************************************************************************************/ + +/************************************************************************************** + * Name: up_lcdinitialize + * + * Description: + * Initialize the LCD video hardware. The initial state of the LCD is fully + * initialized, display memory cleared, and the LCD ready to use, but with the power + * setting at 0 (full off). + * + **************************************************************************************/ + +int up_lcdinitialize(void) +{ +#ifdef CONFIG_DEBUG_LCD + uint16_t hxregval; +#endif + uint32_t regval; + unsigned int i; + + lcdvdbg("Initializing\n"); + + /* Enable LCD EXTCS2 pins */ + + sam_configgpio(GPIO_LCD_NCS2); + sam_configgpio(GPIO_LCD_RS); + sam_configgpio(GPIO_LCD_NWE); + sam_configgpio(GPIO_LCD_NRD); + + sam_configgpio(GPIO_LCD_D0); + sam_configgpio(GPIO_LCD_D1); + sam_configgpio(GPIO_LCD_D2); + sam_configgpio(GPIO_LCD_D3); + sam_configgpio(GPIO_LCD_D4); + sam_configgpio(GPIO_LCD_D5); + sam_configgpio(GPIO_LCD_D6); + sam_configgpio(GPIO_LCD_D7); + sam_configgpio(GPIO_LCD_D8); + sam_configgpio(GPIO_LCD_D9); + sam_configgpio(GPIO_LCD_D10); + sam_configgpio(GPIO_LCD_D11); + sam_configgpio(GPIO_LCD_D12); + sam_configgpio(GPIO_LCD_D13); + sam_configgpio(GPIO_LCD_D14); + sam_configgpio(GPIO_LCD_D15); + +#ifdef CONFIG_LCD_REGDEBUG + sam_dumpgpio(GPIO_PORT_PIOB, "PORTB"); + sam_dumpgpio(GPIO_PORT_PIOC, "PORTC"); +#endif + + /* Configure LCD Backlight Pin */ + + sam_configgpio(GPIO_LCD_BKL); + + /* Enable SMC peripheral clock */ + + putreg32((1 << SAM_PID_SMC), SAM_PMC_PCER); + regdbg("PMC PCSR: %08x SMC: %08x\n", getreg32(SAM_PMC_PCSR), (1 << SAM_PID_SMC)); + + /* Configure SMC CS2 */ + + regval = (4 << SMCCS_SETUP_NWESETUP_SHIFT) | (2 << SMCCS_SETUP_NCSWRSETUP_SHIFT) | + (4 << SMCCS_SETUP_NRDSETUP_SHIFT) | (2 << SMCCS_SETUP_NCSRDSETUP_SHIFT); + putreg32(regval, SAM_SMCCS_SETUP(2)); + + regval = (5 << SMCCS_PULSE_NWEPULSE_SHIFT) | (18 << SMCCS_PULSE_NCSWRPULSE_SHIFT) | + (5 << SMCCS_PULSE_NRDPULSE_SHIFT) | (18 << SMCCS_PULSE_NCSRDPULSE_SHIFT); + putreg32(regval, SAM_SMCCS_PULSE(2)); + + regval = (22 << SMCCS_CYCLE_NWECYCLE_SHIFT) | (22 << SMCCS_CYCLE_NRDCYCLE_SHIFT); + putreg32(regval, SAM_SMCCS_CYCLE(2)); + + regval = getreg32(SAM_SMCCS_MODE(2)); + regval &= ~(SMCCS_MODE_DBW_MASK | SMCCS_MODE_PMEN); + regval |= (SMCCS_MODE_READMODE) | (SMCCS_MODE_WRITEMODE) | (SMCCS_MODE_DBW_16BITS); + putreg32(regval, SAM_SMCCS_MODE(2)); + + regdbg("SMC SETUP[%08x]: %08x PULSE[%08x]: %08x\n", + SAM_SMCCS_SETUP(2), getreg32(SAM_SMCCS_SETUP(2)), + SAM_SMCCS_PULSE(2), getreg32(SAM_SMCCS_PULSE(2))); + regdbg(" CYCLE[%08x]: %08x MODE[%08x]: %08x\n", + SAM_SMCCS_CYCLE(2), getreg32(SAM_SMCCS_CYCLE(2)), + SAM_SMCCS_MODE(2), getreg32(SAM_SMCCS_MODE(2))); + + /* Check HX8347 Chip ID */ + +#ifdef CONFIG_DEBUG_LCD + hxregval = sam_getreg(HX8347_R67H); + lcdvdbg("Chip ID: %04x\n", hxregval); + if (hxregval != HX8347_CHIPID) + { + lcddbg("Bad chip ID: %04x Expected: %04x\n", hxregval, HX8347_CHIPID); + return -ENODEV; + } +#endif + + /* Initialize LCD controller (HX8347) -- Magic code from Atmel LCD example */ + + /* Start internal OSC */ + + sam_putreg(HX8347_R19H, 0x49); /* OSCADJ=10 0000 OSD_EN=1 60Hz */ + sam_putreg(HX8347_R93H, 0x0C); /* RADJ=1100 */ + + /* Power on flow */ + + sam_putreg(HX8347_R44H, 0x4D); /* VCM=100 1101 */ + sam_putreg(HX8347_R45H, 0x11); /* VDV=1 0001 */ + sam_putreg(HX8347_R20H, 0x40); /* BT=0100 */ + sam_putreg(HX8347_R1DH, 0x07); /* VC1=111 */ + sam_putreg(HX8347_R1EH, 0x00); /* VC3=000 */ + sam_putreg(HX8347_R1FH, 0x04); /* VRH=0100 */ + sam_putreg(HX8347_R1CH, 0x04); /* AP=100 */ + sam_putreg(HX8347_R1BH, 0x10); /* GASENB=0 PON=1 DK=0 XDK=0 DDVDH_TRI=0 STB=0 */ + up_mdelay(50); + sam_putreg(HX8347_R43H, 0x80); /* Set VCOMG=1 */ + up_mdelay(50); + + /* Gamma for CMO 2.8 */ + + sam_putreg(HX8347_R46H, 0x95); + sam_putreg(HX8347_R47H, 0x51); + sam_putreg(HX8347_R48H, 0x00); + sam_putreg(HX8347_R49H, 0x36); + sam_putreg(HX8347_R4AH, 0x11); + sam_putreg(HX8347_R4BH, 0x66); + sam_putreg(HX8347_R4CH, 0x14); + sam_putreg(HX8347_R4DH, 0x77); + sam_putreg(HX8347_R4EH, 0x13); + sam_putreg(HX8347_R4FH, 0x4c); + sam_putreg(HX8347_R50H, 0x46); + sam_putreg(HX8347_R51H, 0x46); + + /* 240x320 window setting */ + + sam_putreg(HX8347_R02H, 0x00); /* Column address start2 */ + sam_putreg(HX8347_R03H, 0x00); /* Column address start1 */ + sam_putreg(HX8347_R04H, 0x00); /* Column address end2 */ + sam_putreg(HX8347_R05H, 0xef); /* Column address end1 */ + sam_putreg(HX8347_R06H, 0x00); /* Row address start2 */ + sam_putreg(HX8347_R07H, 0x00); /* Row address start1 */ + sam_putreg(HX8347_R08H, 0x01); /* Row address end2 */ + sam_putreg(HX8347_R09H, 0x3f); /* Row address end1 */ + + /* Display Setting */ + + sam_putreg(HX8347_R01H, 0x06); /* IDMON=0 INVON=1 NORON=1 PTLON=0 */ + sam_putreg(HX8347_R16H, 0xc8); /* MY=1 MX=1 MV=0 BGR=1 */ + sam_putreg(HX8347_R23H, 0x95); /* N_DC=1001 0101 */ + sam_putreg(HX8347_R24H, 0x95); /* P_DC=1001 0101 */ + sam_putreg(HX8347_R25H, 0xff); /* I_DC=1111 1111 */ + sam_putreg(HX8347_R27H, 0x06); /* N_BP=0000 0110 */ + sam_putreg(HX8347_R28H, 0x06); /* N_FP=0000 0110 */ + sam_putreg(HX8347_R29H, 0x06); /* P_BP=0000 0110 */ + sam_putreg(HX8347_R2AH, 0x06); /* P_FP=0000 0110 */ + sam_putreg(HX8347_R2CH, 0x06); /* I_BP=0000 0110 */ + sam_putreg(HX8347_R2DH, 0x06); /* I_FP=0000 0110 */ + sam_putreg(HX8347_R3AH, 0x01); /* N_RTN=0000 N_NW=001 */ + sam_putreg(HX8347_R3BH, 0x01); /* P_RTN=0000 P_NW=001 */ + sam_putreg(HX8347_R3CH, 0xf0); /* I_RTN=1111 I_NW=000 */ + sam_putreg(HX8347_R3DH, 0x00); /* DIV=00 */ + sam_putreg(HX8347_R3EH, 0x38); /* SON=38h */ + sam_putreg(HX8347_R40H, 0x0f); /* GDON=0Fh */ + sam_putreg(HX8347_R41H, 0xf0); /* GDOF=F0h */ + + /* Set LCD backlight to FULL off */ + + sam_setpower(&g_lcddev_s.dev, LCD_FULL_OFF); + + /* Fill the display memory with the color BLACK */ + + sam_setcursor(0, 0); + sam_wrsetup(); + for (i = 0; i < (SAM4EEK_XRES * SAM4EEK_YRES); i++) + { + sam_wrram(RGB16_BLACK); + } + + /* Turn the LCD on (but with the backlight off) */ + + sam_lcdon(); + return OK; +} + +/************************************************************************************** + * Name: up_lcdgetdev + * + * Description: + * Return a a reference to the LCD object for the specified LCD. This allows + * support for multiple LCD devices. + * + **************************************************************************************/ + +FAR struct lcd_dev_s *up_lcdgetdev(int lcddev) +{ + lcdvdbg("lcddev: %d\n", lcddev); + return lcddev == 0 ? &g_lcddev_s.dev : NULL; +} + +/************************************************************************************** + * Name: up_lcduninitialize + * + * Description: + * Unitialize the framebuffer support. + * + **************************************************************************************/ + +void up_lcduninitialize(void) +{ + /* Turn the LCD off */ + + sam_lcdoff(); + + /* Set LCD backlight to FULL off */ + + sam_setpower(&g_lcddev_s.dev, LCD_FULL_OFF); + + /* Disable SMC peripheral clock */ + + putreg32((1 << SAM_PID_SMC), SAM_PMC_PCDR); +} + + diff --git a/configs/sam4e-ek/src/sam_leds.c b/configs/sam4e-ek/src/sam_leds.c new file mode 100644 index 0000000000..3e093bb159 --- /dev/null +++ b/configs/sam4e-ek/src/sam_leds.c @@ -0,0 +1,215 @@ +/**************************************************************************** + * configs/sam4e-ek/src/sam_leds.c + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include + +#include "chip.h" +#include "up_arch.h" +#include "up_internal.h" +#include "sam_gpio.h" +#include "sam4e-ek.h" + +#ifdef CONFIG_ARCH_LEDS + +/**************************************************************************** + * Definitions + ****************************************************************************/ +/* The SAM4E-EK board has three, user-controllable LEDs labelled D2 (blue), + * D3 (amber), and D4 (green) on the board. Usage of these LEDs is defined + * in include/board.h and src/up_leds.c. They are encoded as follows: + * + * SYMBOL Meaning D3* D2 D4 + * ------------------- ----------------------- ------- ------- ------- + * LED_STARTED NuttX has been started OFF OFF OFF + * LED_HEAPALLOCATE Heap has been allocated OFF OFF ON + * LED_IRQSENABLED Interrupts enabled OFF ON OFF + * LED_STACKCREATED Idle stack created OFF ON ON + * LED_INIRQ In an interrupt** N/C FLASH N/C + * LED_SIGNAL In a signal handler*** N/C N/C FLASH + * LED_ASSERTION An assertion failed FLASH N/C N/C + * LED_PANIC The system has crashed FLASH N/C N/C + * + * * If D2 and D4 are statically on, then NuttX probably failed to boot + * and these LEDs will give you some indication of where the failure was + * ** The normal state is D3=OFF, D4=ON and D2 faintly glowing. This faint + * glow is because of timer interrupts that result in the LED being + * illuminated on a small proportion of the time. + * *** D4 may also flicker normally if signals are processed. + */ + +#define LED_OFF 0 +#define LED_ON 1 +#define LED_NOCHANGE 2 +#define LED_MASK 3 + +#define D3_SHIFT 0 +#define D3_OFF (LED_OFF << D3_SHIFT) +#define D3_ON (LED_ON << D3_SHIFT) +#define D3_NOCHANGE (LED_NOCHANGE << D3_SHIFT) +#define D2_SHIFT 2 +#define D2_OFF (LED_OFF << D2_SHIFT) +#define D2_ON (LED_ON << D2_SHIFT) +#define D2_NOCHANGE (LED_NOCHANGE << D2_SHIFT) +#define D4_SHIFT 4 +#define D4_OFF (LED_OFF << D4_SHIFT) +#define D4_ON (LED_ON << D4_SHIFT) +#define D4_NOCHANGE (LED_NOCHANGE << D4_SHIFT) + +/* CONFIG_DEBUG_LEDS enables debug output from this file (needs CONFIG_DEBUG + * with CONFIG_DEBUG_VERBOSE too) + */ + +#ifdef CONFIG_DEBUG_LEDS +# define leddbg lldbg +# define ledvdbg llvdbg +#else +# define leddbg(x...) +# define ledvdbg(x...) +#endif + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const uint8_t g_ledon[8] = +{ + (D3_OFF |D2_OFF |D4_OFF), /* LED_STARTED */ + (D3_ON |D2_OFF |D4_ON), /* LED_HEAPALLOCATE */ + (D3_OFF |D2_ON |D4_OFF), /* LED_IRQSENABLED */ + (D3_ON |D2_ON |D4_ON), /* LED_STACKCREATED */ + + (D3_NOCHANGE|D2_OFF |D4_NOCHANGE), /* LED_INIRQ */ + (D3_NOCHANGE|D2_NOCHANGE|D4_OFF), /* LED_SIGNAL */ + (D3_ON |D2_NOCHANGE|D4_NOCHANGE), /* LED_ASSERTION */ + (D3_ON |D2_NOCHANGE|D4_NOCHANGE) /* LED_PANIC */ +}; + +static const uint8_t g_ledoff[8] = +{ + (D3_OFF |D2_OFF |D4_OFF), /* LED_STARTED (does not happen) */ + (D3_ON |D2_OFF |D4_ON), /* LED_HEAPALLOCATE (does not happen) */ + (D3_OFF |D2_ON |D4_OFF), /* LED_IRQSENABLED (does not happen) */ + (D3_ON |D2_ON |D4_ON), /* LED_STACKCREATED (does not happen) */ + + (D3_NOCHANGE|D2_ON |D4_NOCHANGE), /* LED_INIRQ */ + (D3_NOCHANGE|D2_NOCHANGE|D4_ON), /* LED_SIGNAL */ + (D3_OFF |D2_NOCHANGE|D4_NOCHANGE), /* LED_ASSERTION */ + (D3_OFF |D2_NOCHANGE|D4_NOCHANGE) /* LED_PANIC */ +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: sam_setled + ****************************************************************************/ + +static void sam_setled(gpio_pinset_t pinset, uint8_t state) +{ + /* Assume active high. Initial state == 0 means active high */ + + bool polarity = ((pinset & GPIO_OUTPUT_SET) == 0); + switch (state) + { + case LED_OFF: + polarity = !polarity; + + case LED_ON: + break; + + case LED_NOCHANGE: + default: + return; + } + + sam_gpiowrite(pinset, polarity); +} + +/**************************************************************************** + * Name: sam_setleds + ****************************************************************************/ + +static void sam_setleds(uint8_t state) +{ + sam_setled(GPIO_D3, (state >> D3_SHIFT) & LED_MASK); + sam_setled(GPIO_D2, (state >> D2_SHIFT) & LED_MASK); + sam_setled(GPIO_D4, (state >> D4_SHIFT) & LED_MASK); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_led_initialize + ****************************************************************************/ + +void board_led_initialize(void) +{ + (void)sam_configgpio(GPIO_D3); + (void)sam_configgpio(GPIO_D2); + (void)sam_configgpio(GPIO_D4); +} + +/**************************************************************************** + * Name: board_led_on + ****************************************************************************/ + +void board_led_on(int led) +{ + sam_setleds(g_ledon[led & 7]); +} + +/**************************************************************************** + * Name: board_led_off + ****************************************************************************/ + +void board_led_off(int led) +{ + sam_setleds(g_ledoff[led & 7]); +} + +#endif /* CONFIG_ARCH_LEDS */ diff --git a/configs/sam4e-ek/src/sam_mmcsd.c b/configs/sam4e-ek/src/sam_mmcsd.c new file mode 100644 index 0000000000..a9cc11ac3e --- /dev/null +++ b/configs/sam4e-ek/src/sam_mmcsd.c @@ -0,0 +1,149 @@ +/************************************************************************************ + * configs/sam4e-ek/src/sam_mmcsd.c + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************************************/ + +/************************************************************************************ + * Included Files + ************************************************************************************/ + +#include + +#include +#include + +#include "sam_gpio.h" +#include "sam4e-ek.h" + +#ifdef CONFIG_SAM34_HSMCI + +/************************************************************************************ + * Definitions + ************************************************************************************/ + +/* This needs to be extended. The card detect GPIO must be configured as an interrupt. + * when the interrupt indicating that a card has been inserted or removed is received, + * this function must call sio_mediachange() to handle that event. See + * arch/arm/src/sam34/sam_hsmci.h for more information. + * + * Also see the SAMA5D3x-EK implementation of this same logic. The card detect + * interrupt handling should be a drop-in. + */ + +#ifdef GPIO_MCI_CD +# warning "Card detect interrupt handling needed" +#endif + +/* Usually defined in NuttX header files */ + +#ifndef OK +# define OK 0 +#endif + +/************************************************************************************ + * Private Functions + ************************************************************************************/ + +/************************************************************************************ + * Public Functions + ************************************************************************************/ + +/************************************************************************************ + * Name: sam_hsmciinit + * + * Description: + * Initialize HSMCI support. This function is called very early in board + * initialization. + * + ************************************************************************************/ + +int sam_hsmciinit(void) +{ +#ifdef GPIO_MCI_CD + sam_configgpio(GPIO_MCI_CD); +#endif +#ifdef GPIO_MCI_WP + sam_configgpio(GPIO_MCI_WP); +#endif + return OK; +} + +/************************************************************************************ + * Name: sam_cardinserted + * + * Description: + * Check if a card is inserted into the selected HSMCI slot + * + ************************************************************************************/ + +bool sam_cardinserted(unsigned char slot) +{ + if (slot == 0) + { +#ifdef GPIO_MCI_CD + bool inserted = sam_gpioread(GPIO_MCI_CD); + fvdbg("inserted: %s\n", inserted ? "NO" : "YES"); + return !inserted; +#else + return true; +#endif + } + + return false; +} + +/************************************************************************************ + * Name: sam_writeprotected + * + * Description: + * Check if a card is inserted into the selected HSMCI slot + * + ************************************************************************************/ + +bool sam_writeprotected(unsigned char slot) +{ + if (slot == 0) + { +#ifdef GPIO_MCI_WP + bool protected = sam_gpioread(GPIO_MCI_WP); + fvdbg("protected: %s\n", inserted ? "YES" : "NO"); + return protected; +#else + return false; +#endif + } + + return false; +} + +#endif /* CONFIG_SAM34_HSMCI */ diff --git a/configs/sam4e-ek/src/sam_nsh.c b/configs/sam4e-ek/src/sam_nsh.c new file mode 100644 index 0000000000..b03c49ab91 --- /dev/null +++ b/configs/sam4e-ek/src/sam_nsh.c @@ -0,0 +1,164 @@ +/**************************************************************************** + * config/sam4e-ek/src/sam_nsh.c + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include + +#include +#include + +#include "sam_hsmci.h" +#include "sam4e-ek.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/* Configuration ************************************************************/ + +/* PORT and SLOT number probably depend on the board configuration */ + +#define NSH_HAVE_USBDEV 1 +#define NSH_HAVE_MMCSD 1 + +/* Can't support MMC/SD if the card interface is not enable */ + +#ifndef CONFIG_SAM34_HSMCI +# undef NSH_HAVE_MMCSD +#endif + +/* Can't support MMC/SD features if mountpoints are disabled or if SDIO support + * is not enabled. + */ + +#if defined(CONFIG_DISABLE_MOUNTPOINT) || !defined(CONFIG_SAM34_HSMCI) +# undef NSH_HAVE_MMCSD +#endif + +#ifdef NSH_HAVE_MMCSD +# if defined(CONFIG_NSH_MMCSDSLOTNO) && CONFIG_NSH_MMCSDSLOTNO != 0 +# error "Only one MMC/SD slot" +# undef CONFIG_NSH_MMCSDSLOTNO +# endif + +# ifndef CONFIG_NSH_MMCSDMINOR +# define CONFIG_NSH_MMCSDMINOR 0 +# endif + +# ifndef CONFIG_NSH_MMCSDSLOTNO +# define CONFIG_NSH_MMCSDSLOTNO 0 +# endif +#endif + +/* Can't support USB features if USB is not enabled */ + +#ifndef CONFIG_USBDEV +# undef NSH_HAVE_USBDEV +#endif + +/* Debug ********************************************************************/ + +#ifdef CONFIG_CPP_HAVE_VARARGS +# ifdef CONFIG_DEBUG +# define message(...) syslog(__VA_ARGS__) +# else +# define message(...) printf(__VA_ARGS__) +# endif +#else +# ifdef CONFIG_DEBUG +# define message syslog +# else +# define message printf +# endif +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nsh_archinitialize + * + * Description: + * Perform architecture specific initialization + * + ****************************************************************************/ + +int nsh_archinitialize(void) +{ +#ifdef NSH_HAVE_MMCSD + FAR struct sdio_dev_s *sdio; + int ret; + + /* Mount the SDIO-based MMC/SD block driver */ + /* First, get an instance of the SDIO interface */ + + message("nsh_archinitialize: Initializing SDIO slot %d\n", + CONFIG_NSH_MMCSDSLOTNO); + sdio = sdio_initialize(CONFIG_NSH_MMCSDSLOTNO); + if (!sdio) + { + message("nsh_archinitialize: Failed to initialize SDIO slot %d\n", + CONFIG_NSH_MMCSDSLOTNO); + return -ENODEV; + } + + /* Now bind the SDIO interface to the MMC/SD driver */ + + message("nsh_archinitialize: Bind SDIO to the MMC/SD driver, minor=%d\n", + CONFIG_NSH_MMCSDMINOR); + ret = mmcsd_slotinitialize(CONFIG_NSH_MMCSDMINOR, sdio); + if (ret != OK) + { + message("nsh_archinitialize: Failed to bind SDIO to the MMC/SD driver: %d\n", ret); + return ret; + } + message("nsh_archinitialize: Successfully bound SDIO to the MMC/SD driver\n"); + + /* Then inform the HSMCI driver if there is or is not a card in the slot. */ + + sdio_mediachange(sdio, sam_cardinserted(0)); +#endif + + return OK; +} diff --git a/configs/sam4e-ek/src/sam_spi.c b/configs/sam4e-ek/src/sam_spi.c new file mode 100644 index 0000000000..5338d1ffe5 --- /dev/null +++ b/configs/sam4e-ek/src/sam_spi.c @@ -0,0 +1,204 @@ +/************************************************************************************ + * configs/sam4e-ek/src/sam_spi.c + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************************************/ + +/************************************************************************************ + * Included Files + ************************************************************************************/ + +#include + +#include +#include +#include +#include + +#include +#include + +#include "up_arch.h" +#include "chip.h" +#include "sam_gpio.h" +#include "sam_spi.h" +#include "sam4e-ek.h" + +#if defined(CONFIG_SAM34_SPI0) || defined(CONFIG_SAM34_SPI1) + +/************************************************************************************ + * Definitions + ************************************************************************************/ + +/* Enables debug output from this file (needs CONFIG_DEBUG too) */ + +#undef SPI_DEBUG /* Define to enable debug */ +#undef SPI_VERBOSE /* Define to enable verbose debug */ + +#ifdef SPI_DEBUG +# define spidbg lldbg +# ifdef SPI_VERBOSE +# define spivdbg lldbg +# else +# define spivdbg(x...) +# endif +#else +# undef SPI_VERBOSE +# define spidbg(x...) +# define spivdbg(x...) +#endif + +/************************************************************************************ + * Private Functions + ************************************************************************************/ + +/************************************************************************************ + * Public Functions + ************************************************************************************/ + +/************************************************************************************ + * Name: sam_spiinitialize + * + * Description: + * Called to configure SPI chip select GPIO pins for the SAM4E-EK board. + * + ************************************************************************************/ + +void weak_function sam_spiinitialize(void) +{ + /* The ZigBee module connects used NPCS0. However, there is not yet any + * ZigBee support. + */ + + /* The touchscreen connects using NPCS2 (PC14). */ + +#if defined(CONFIG_INPUT) && defined(CONFIG_INPUT_ADS7843E) + sam_configgpio(GPIO_TSC_NPCS2); +#endif +} + +/**************************************************************************** + * Name: sam_spiselect, sam_spistatus, and sam_spicmddata + * + * Description: + * These external functions must be provided by board-specific logic. They + * include: + * + * o sam_spiselect is a functions tomanage the board-specific chip selects + * o sam_spistatus and sam_spicmddata: Implementations of the status + * and cmddata methods of the SPI interface defined by struct spi_ops_ + * (see include/nuttx/spi/spi.h). All other methods including + * up_spiinitialize()) are provided by common SAM3/4 logic. + * + * To use this common SPI logic on your board: + * + * 1. Provide logic in sam_boardinitialize() to configure SPI chip select + * pins. + * 2. Provide sam_spiselect() and sam_spistatus() functions in your board- + * specific logic. These functions will perform chip selection and + * status operations using GPIOs in the way your board is configured. + * 2. If CONFIG_SPI_CMDDATA is defined in the NuttX configuration, provide + * sam_spicmddata() functions in your board-specific logic. This + * function will perform cmd/data selection operations using GPIOs in + * the way your board is configured. + * 3. Add a call to up_spiinitialize() in your low level application + * initialization logic + * 4. The handle returned by up_spiinitialize() may then be used to bind the + * SPI driver to higher level logic (e.g., calling + * mmcsd_spislotinitialize(), for example, will bind the SPI driver to + * the SPI MMC/SD driver). + * + ****************************************************************************/ + +/**************************************************************************** + * Name: sam_spiselect + * + * Description: + * PIO chip select pins may be programmed by the board specific logic in + * one of two different ways. First, the pins may be programmed as SPI + * peripherals. In that case, the pins are completely controlled by the + * SPI driver. This method still needs to be provided, but it may be only + * a stub. + * + * An alternative way to program the PIO chip select pins is as a normal + * GPIO output. In that case, the automatic control of the CS pins is + * bypassed and this function must provide control of the chip select. + * NOTE: In this case, the GPIO output pin does *not* have to be the + * same as the NPCS pin normal associated with the chip select number. + * + * Input Parameters: + * devid - Identifies the (logical) device + * selected - TRUE:Select the device, FALSE:De-select the device + * + * Returned Values: + * None + * + ****************************************************************************/ + +void sam_spiselect(enum spi_dev_e devid, bool selected) +{ + /* The touchscreen chip select is implemented as a GPIO OUTPUT that must + * be controlled by this function. This is because the ADS7843E driver + * must be able to sample the device BUSY GPIO input between SPI transfers. + * However, the AD7843E will tri-state the BUSY input whenever the chip + * select is de-asserted. So the only option is to control the chip select + * manually and hold it low throughout the SPI transfer. + */ + +#if defined(CONFIG_INPUT) && defined(CONFIG_INPUT_ADS7843E) + if (devid == SPIDEV_TOUCHSCREEN) + { + sam_gpiowrite(GPIO_TSC_NPCS2, !selected); + } +#endif +} + +/**************************************************************************** + * Name: sam_spistatus + * + * Description: + * Return status information associated with the SPI device. + * + * Input Parameters: + * devid - Identifies the (logical) device + * + * Returned Values: + * Bit-encoded SPI status (see include/nuttx/spi/spi.h. + * + ****************************************************************************/ + +uint8_t sam_spistatus(FAR struct spi_dev_s *dev, enum spi_dev_e devid) +{ + return 0; +} + +#endif /* CONFIG_SAM34_SPI0 || CONFIG_SAM34_SPI1 */ diff --git a/configs/sam4e-ek/src/sam_touchscreen.c b/configs/sam4e-ek/src/sam_touchscreen.c new file mode 100644 index 0000000000..19a8dad1ec --- /dev/null +++ b/configs/sam4e-ek/src/sam_touchscreen.c @@ -0,0 +1,294 @@ +/************************************************************************************ + * configs/sam4e-ek/src/sam_touchscreen.c + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "sam_gpio.h" +#include "sam4e-ek.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ +/* Configuration ************************************************************/ + +#ifdef CONFIG_INPUT_ADS7843E +#ifndef CONFIG_INPUT +# error "Touchscreen support requires CONFIG_INPUT" +#endif + +#ifndef CONFIG_SAM34_SPI0 +# error "Touchscreen support requires CONFIG_SAM34_SPI0" +#endif + +#ifndef CONFIG_GPIOA_IRQ +# error "Touchscreen support requires CONFIG_GPIOA_IRQ" +#endif + +#ifndef CONFIG_ADS7843E_FREQUENCY +# define CONFIG_ADS7843E_FREQUENCY 500000 +#endif + +#ifndef CONFIG_ADS7843E_SPIDEV +# define CONFIG_ADS7843E_SPIDEV TSC_CSNUM +#endif + +#if CONFIG_ADS7843E_SPIDEV != TSC_CSNUM +# error "CONFIG_ADS7843E_SPIDEV must have the same value as TSC_CSNUM" +#endif + +#ifndef CONFIG_ADS7843E_DEVMINOR +# define CONFIG_ADS7843E_DEVMINOR 0 +#endif + +/**************************************************************************** + * Static Function Prototypes + ****************************************************************************/ + +/* IRQ/GPIO access callbacks. These operations all hidden behind + * callbacks to isolate the ADS7843E driver from differences in GPIO + * interrupt handling by varying boards and MCUs. If possible, + * interrupts should be configured on both rising and falling edges + * so that contact and loss-of-contact events can be detected. + * + * attach - Attach the ADS7843E interrupt handler to the GPIO interrupt + * enable - Enable or disable the GPIO interrupt + * clear - Acknowledge/clear any pending GPIO interrupt + * pendown - Return the state of the pen down GPIO input + */ + +static int tsc_attach(FAR struct ads7843e_config_s *state, xcpt_t isr); +static void tsc_enable(FAR struct ads7843e_config_s *state, bool enable); +static void tsc_clear(FAR struct ads7843e_config_s *state); +static bool tsc_busy(FAR struct ads7843e_config_s *state); +static bool tsc_pendown(FAR struct ads7843e_config_s *state); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* A reference to a structure of this type must be passed to the ADS7843E + * driver. This structure provides information about the configuration + * of the ADS7843E and provides some board-specific hooks. + * + * Memory for this structure is provided by the caller. It is not copied + * by the driver and is presumed to persist while the driver is active. The + * memory must be writable because, under certain circumstances, the driver + * may modify frequency or X plate resistance values. + */ + +static struct ads7843e_config_s g_tscinfo = +{ + .frequency = CONFIG_ADS7843E_FREQUENCY, + + .attach = tsc_attach, + .enable = tsc_enable, + .clear = tsc_clear, + .busy = tsc_busy, + .pendown = tsc_pendown, +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/* IRQ/GPIO access callbacks. These operations all hidden behind + * callbacks to isolate the ADS7843E driver from differences in GPIO + * interrupt handling by varying boards and MCUs. If possible, + * interrupts should be configured on both rising and falling edges + * so that contact and loss-of-contact events can be detected. + * + * attach - Attach the ADS7843E interrupt handler to the GPIO interrupt + * enable - Enable or disable the GPIO interrupt + * clear - Acknowledge/clear any pending GPIO interrupt + * pendown - Return the state of the pen down GPIO input + */ + +static int tsc_attach(FAR struct ads7843e_config_s *state, xcpt_t isr) +{ + /* Attach the ADS7843E interrupt */ + + ivdbg("Attaching %p to IRQ %d\n", isr, SAM_TCS_IRQ); + return irq_attach(SAM_TCS_IRQ, isr); +} + +static void tsc_enable(FAR struct ads7843e_config_s *state, bool enable) +{ + /* Attach and enable, or detach and disable */ + + ivdbg("IRQ:%d enable:%d\n", SAM_TCS_IRQ, enable); + if (enable) + { + sam_gpioirqenable(SAM_TCS_IRQ); + } + else + { + sam_gpioirqdisable(SAM_TCS_IRQ); + } +} + +static void tsc_clear(FAR struct ads7843e_config_s *state) +{ + /* Does nothing */ +} + +static bool tsc_busy(FAR struct ads7843e_config_s *state) +{ +#if defined(CONFIG_DEBUG_INPUT) && defined(CONFIG_DEBUG_VERBOSE) + static bool last = (bool)-1; +#endif + + /* BUSY is high impedance when CS is high (not selected). When CS is + * is low, BUSY is active high. + */ + + bool busy = sam_gpioread(GPIO_TCS_BUSY); +#if defined(CONFIG_DEBUG_INPUT) && defined(CONFIG_DEBUG_VERBOSE) + if (busy != last) + { + ivdbg("busy:%d\n", busy); + last = busy; + } +#endif + + return busy; +} + +static bool tsc_pendown(FAR struct ads7843e_config_s *state) +{ + /* The /PENIRQ value is active low */ + + bool pendown = !sam_gpioread(GPIO_TCS_IRQ); + ivdbg("pendown:%d\n", pendown); + return pendown; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: arch_tcinitialize + * + * Description: + * Each board that supports a touchscreen device must provide this function. + * This function is called by application-specific, setup logic to + * configure the touchscreen device. This function will register the driver + * as /dev/inputN where N is the minor device number. + * + * Input Parameters: + * minor - The input device minor number + * + * Returned Value: + * Zero is returned on success. Otherwise, a negated errno value is + * returned to indicate the nature of the failure. + * + ****************************************************************************/ + +int arch_tcinitialize(int minor) +{ + FAR struct spi_dev_s *dev; + int ret; + + idbg("minor %d\n", minor); + DEBUGASSERT(minor == 0); + + /* Configure and enable the ADS7843E interrupt pin as an input */ + + (void)sam_configgpio(GPIO_TCS_BUSY); + (void)sam_configgpio(GPIO_TCS_IRQ); + + /* Configure the PIO interrupt */ + + sam_gpioirq(GPIO_TCS_IRQ); + + /* Get an instance of the SPI interface for the touchscreen chip select */ + + dev = up_spiinitialize(TSC_CSNUM); + if (!dev) + { + idbg("Failed to initialize SPI chip select %d\n", TSC_CSNUM); + return -ENODEV; + } + + /* Initialize and register the SPI touschscreen device */ + + ret = ads7843e_register(dev, &g_tscinfo, CONFIG_ADS7843E_DEVMINOR); + if (ret < 0) + { + idbg("Failed to initialize SPI chip select %d\n", TSC_CSNUM); + /* up_spiuninitialize(dev); */ + return -ENODEV; + } + + return OK; +} + +/**************************************************************************** + * Name: arch_tcuninitialize + * + * Description: + * Each board that supports a touchscreen device must provide this function. + * This function is called by application-specific, setup logic to + * uninitialized the touchscreen device. + * + * Input Parameters: + * None + * + * Returned Value: + * None. + * + ****************************************************************************/ + +void arch_tcuninitialize(void) +{ + /* No support for un-initializing the touchscreen ADS7843E device yet */ +} + +#endif /* CONFIG_INPUT_ADS7843E */ + diff --git a/configs/sam4e-ek/src/sam_usbdev.c b/configs/sam4e-ek/src/sam_usbdev.c new file mode 100644 index 0000000000..947ccb13b6 --- /dev/null +++ b/configs/sam4e-ek/src/sam_usbdev.c @@ -0,0 +1,108 @@ +/************************************************************************************ + * configs/sam4e-ek/src/sam_usbdev.c + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************************************/ + +/************************************************************************************ + * Included Files + ************************************************************************************/ + +#include + +#include +#include +#include +#include + +#include +#include + +#include "up_arch.h" +#include "sam4e-ek.h" + +/************************************************************************************ + * Definitions + ************************************************************************************/ + +/************************************************************************************ + * Private Functions + ************************************************************************************/ + +/************************************************************************************ + * Public Functions + ************************************************************************************/ + +/************************************************************************************ + * Name: sam_usbinitialize + * + * Description: + * Called to setup USB-related GPIO pins for the SAM4E-EK board. + * + ************************************************************************************/ + +void sam_usbinitialize(void) +{ +} + +/************************************************************************************ + * Name: sam_usbpullup + * + * Description: + * If USB is supported and the board supports a pullup via GPIO (for USB software + * connect and disconnect), then the board software must provide sam_pullup. + * See include/nuttx/usb/usbdev.h for additional description of this method. + * Alternatively, if no pull-up GPIO the following EXTERN can be redefined to be + * NULL. + * + ************************************************************************************/ + +int sam_usbpullup(FAR struct usbdev_s *dev, bool enable) +{ + return 0; +} + +/************************************************************************************ + * Name: sam_usbsuspend + * + * Description: + * Board logic must provide the sam_usbsuspend logic if the USBDEV driver is + * used. This function is called whenever the USB enters or leaves suspend mode. + * This is an opportunity for the board logic to shutdown clocks, power, etc. + * while the USB is suspended. + * + ************************************************************************************/ + +void sam_usbsuspend(FAR struct usbdev_s *dev, bool resume) +{ + ulldbg("resume: %d\n", resume); +} diff --git a/configs/sam4e-ek/src/sam_usbmsc.c b/configs/sam4e-ek/src/sam_usbmsc.c new file mode 100644 index 0000000000..63e6538985 --- /dev/null +++ b/configs/sam4e-ek/src/sam_usbmsc.c @@ -0,0 +1,148 @@ +/**************************************************************************** + * configs/sam4e-ek/src/sam_usbmsc.c + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Configure and register the SAM3U MMC/SD SDIO block driver. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include +#include + +#include "sam_hsmci.h" + +#ifdef CONFIG_SAM34_HSMCI + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/* Configuration ************************************************************/ + +#ifndef CONFIG_SYSTEM_USBMSC_DEVMINOR1 +# define CONFIG_SYSTEM_USBMSC_DEVMINOR1 0 +#endif + +/* SLOT number(s) depends on the board configuration */ + +#undef SAM_MMCSDSLOTNO +#define SAM_MMCSDSLOTNO 0 + +/* Debug ********************************************************************/ + +#ifdef CONFIG_CPP_HAVE_VARARGS +# ifdef CONFIG_DEBUG +# define message(...) lowsyslog(__VA_ARGS__) +# define msgflush() +# else +# define message(...) printf(__VA_ARGS__) +# define msgflush() fflush(stdout) +# endif +#else +# ifdef CONFIG_DEBUG +# define message lowsyslog +# define msgflush() +# else +# define message printf +# define msgflush() fflush(stdout) +# endif +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: usbmsc_archinitialize + * + * Description: + * Perform architecture specific initialization + * + ****************************************************************************/ + +int usbmsc_archinitialize(void) +{ + FAR struct sdio_dev_s *sdio; + int ret; + + /* First, get an instance of the SDIO interface */ + + message("usbmsc_archinitialize: " + "Initializing SDIO slot %d\n", + SAM_MMCSDSLOTNO); + + sdio = sdio_initialize(SAM_MMCSDSLOTNO); + if (!sdio) + { + message("usbmsc_archinitialize: Failed to initialize SDIO slot %d\n", + SAM_MMCSDSLOTNO); + return -ENODEV; + } + + /* Now bind the SPI interface to the MMC/SD driver */ + + message("usbmsc_archinitialize: " + "Bind SDIO to the MMC/SD driver, minor=%d\n", + CONFIG_SYSTEM_USBMSC_DEVMINOR1); + + ret = mmcsd_slotinitialize(CONFIG_SYSTEM_USBMSC_DEVMINOR1, sdio); + if (ret != OK) + { + message("usbmsc_archinitialize: " + "Failed to bind SDIO to the MMC/SD driver: %d\n", + ret); + return ret; + } + + message("usbmsc_archinitialize: " + "Successfully bound SDIO to the MMC/SD driver\n"); + + /* Then let's guess and say that there is a card in the slot. I need to check to + * see if the SAM3U10E-EVAL board supports a GPIO to detect if there is a card in + * the slot. + */ + + sdio_mediachange(sdio, true); + return OK; +} + +#endif /* CONFIG_SAM34_HSMCI */