SAMV71 Xplained Ultra Software Package 1.5

main.c

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------- */
00002 /*                  Atmel Microcontroller Software Support                      */
00003 /*                       SAM Software Package License                           */
00004 /* ---------------------------------------------------------------------------- */
00005 /* Copyright (c) 2015, Atmel Corporation                                        */
00006 /*                                                                              */
00007 /* All rights reserved.                                                         */
00008 /*                                                                              */
00009 /* Redistribution and use in source and binary forms, with or without           */
00010 /* modification, are permitted provided that the following condition is met:    */
00011 /*                                                                              */
00012 /* - Redistributions of source code must retain the above copyright notice,     */
00013 /* this list of conditions and the disclaimer below.                            */
00014 /*                                                                              */
00015 /* Atmel's name may not be used to endorse or promote products derived from     */
00016 /* this software without specific prior written permission.                     */
00017 /*                                                                              */
00018 /* DISCLAIMER:  THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR   */
00019 /* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
00020 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE   */
00021 /* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,      */
00022 /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */
00023 /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,  */
00024 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    */
00025 /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING         */
00026 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
00027 /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                           */
00028 /* ---------------------------------------------------------------------------- */
00029 
00030 /**
00031  *  \page sdram SDRAM example
00032  *
00033  *  \section Purpose
00034  *
00035  *  The SDRAM example will help new users get familiar with Atmel's
00036  *  SAMV7/E7 family of micro-controllers. This basic application shows Shows how
00037  *  to initialize and perform read and write a SDRAM memory.
00038  *
00039  *  \section Requirements
00040  *
00041  *  This package can be used with SAMV71 Xplained Ultra board or SAME70 Xplained board.
00042  *
00043  *  \section Description
00044  *
00045  *  \section Usage
00046  *
00047  *  -# Build the program and download it inside the board.
00048  *     Please refer to the Getting Started with SAM V71/E70 Microcontrollers.pdf
00049  *  -# On the computer, open and configure a terminal application
00050  *     (e.g. HyperTerminal on Microsoft Windows) with these settings:
00051  *    - 115200 baud rate
00052  *    - 8 bits of data
00053  *    - No parity
00054  *    - 1 stop bit
00055  *    - No flow control
00056  *  -# Start the application.
00057  *  -#In the terminal window, the
00058  *     following text should appear (values depend on the board and chip used):
00059  *     \code
00060  *      -- SDRAM Example xxx --
00061  *      -- xxxxxx-xx
00062  *      -- Compiled: xxx xx xxxx xx:xx:xx --
00063  *     \endcode
00064  *
00065  *  \section References
00066  *  - sdram/main.c
00067  *  - trace.h
00068  */
00069 
00070 /** \file
00071  *
00072  *  This file contains all the specific code for the SDRAM example.
00073  *
00074  */
00075 
00076 /*----------------------------------------------------------------------------
00077  *        Headers
00078  *----------------------------------------------------------------------------*/
00079 
00080 #include "board.h"
00081 
00082 #include <stdbool.h>
00083 #include <stdio.h>
00084 
00085 /*----------------------------------------------------------------------------
00086  *        Local functions
00087  *----------------------------------------------------------------------------*/
00088 /**
00089  * \brief Test SDRAM access
00090  * \param baseAddr Base address of SDRAM
00091  * \param size  Size of memory in byte
00092  * \return 1: OK, 0: Error
00093  */
00094 static uint32_t _sdramAccess(uint32_t baseAddr, uint32_t size)
00095 {
00096     uint32_t i;
00097     uint32_t ret = 1;
00098     uint32_t *ptr32 = (uint32_t *) baseAddr;
00099     uint16_t *ptr16 = (uint16_t *) baseAddr;
00100     uint8_t *ptr8 = (uint8_t *) baseAddr;
00101 
00102     /* Test for 55AA55AA/AA55AA55 pattern */
00103     printf(" Test for 55AA55AA/AA55AA55 pattern ... \n\r");
00104     for (i = 0; i < size; i++) {
00105         if (i & 1) {
00106             ptr32[i] = 0x55AA55AA;
00107         } else {
00108             ptr32[i] = 0xAA55AA55;
00109         }
00110         memory_barrier()
00111     }
00112     for (i = 0; i < size; i++) {
00113         if (i & 1) {
00114             if (ptr32[i] != 0x55AA55AA) {
00115                 printf("-E- Expected:%x, read %x @ %x \n\r",
00116                     0x55AA55AA, (unsigned)(ptr32[i]), (unsigned)(baseAddr + i));
00117                 ret = 0;
00118             }
00119         } else {
00120             if (ptr32[i] != 0xAA55AA55) {
00121                 printf("-E- Expected:%x, read %x @ %x \n\r" ,
00122                         0xAA55AA55 , (unsigned)(ptr32[i]), (unsigned)(baseAddr + i));
00123                 ret = 0;
00124             }
00125         }
00126     }
00127 
00128     if (!ret)
00129         return ret;
00130     printf(" Test for BYTE accessing... \n\r");
00131     /* Test for BYTE accessing */
00132     for (i = 0; i < size; i++)
00133         ptr8[i] = (uint8_t)( i & 0xFF);
00134 
00135     for (i = 0; i < size; i++) {
00136         if (ptr8[i] != (uint8_t)(i & 0xFF)) {
00137             printf("-E- Expected:%x, read %x @ %x \n\r" ,
00138                 (unsigned)(i & 0xFF), ptr8[i], (unsigned)(baseAddr + i));
00139             ret = 0;
00140         }
00141     }
00142     if (!ret)
00143         return ret;
00144 
00145     printf(" Test for WORD accessing... \n\r");
00146     /* Test for WORD accessing */
00147     for (i = 0; i < size / 2; i++)
00148         ptr16[i] = (uint16_t)( i & 0xFFFF);
00149 
00150     for (i = 0; i < size / 2; i++) {
00151         if (ptr16[i] != (uint16_t)(i & 0xFFFF))  {
00152             printf("-E- Expected:%x, read %x @ %x \n\r" ,
00153                 (unsigned)(i & 0xFFFF), ptr16[i], (unsigned)(baseAddr + i));
00154             ret = 0;
00155         }
00156     }
00157     if (!ret)
00158         return ret;
00159     printf(" Test for DWORD accessing... \n\r");
00160     /* Test for DWORD accessing */
00161     for (i = 0; i < size / 4; i++) {
00162         ptr32[i] = (uint32_t)( i & 0xFFFFFFFF);
00163         memory_barrier()
00164     }
00165     for (i = 0; i < size / 4; i++) {
00166         if (ptr32[i] != (uint32_t)(i & 0xFFFFFFFF))  {
00167             printf("-E- Expected:%x, read %x @ %x \n\r" ,
00168                 (unsigned)(i & 0xFFFFFFFF), (unsigned)(ptr32[i]),(unsigned)(baseAddr + i));
00169             ret = 0;
00170         }
00171     }
00172     return ret;
00173 }
00174 
00175 /*----------------------------------------------------------------------------
00176  *        Exported functions
00177  *----------------------------------------------------------------------------*/
00178 /**
00179  *  \brief getting-started Application entry point.
00180  *
00181  *  \return Unused (ANSI-C compatibility).
00182  */
00183 extern int main(void)
00184 {
00185     /* Disable watchdog */
00186     WDT_Disable(WDT);
00187 
00188     /* Enable I and D cache */
00189     SCB_EnableICache();
00190     SCB_EnableDCache();
00191 
00192     /* Output example information */
00193     printf("\n\r-- SDRAM Example %s --\n\r", SOFTPACK_VERSION );
00194     printf("-- %s\n\r", BOARD_NAME);
00195     printf("-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__, COMPILER_NAME);
00196 
00197     TRACE_INFO("Configuring External SDRAM \n\r");
00198     /* SDRAM timing configuration */
00199     BOARD_ConfigureSdram();
00200 
00201     /* Full test SDRAM  */
00202     TRACE_INFO("Starting memory validation of External SDRAM \n\r");
00203 
00204     if (_sdramAccess(SDRAM_CS_ADDR, 0x200000)){
00205       TRACE_INFO("Test succeeded!");
00206     } else {
00207       TRACE_INFO("Test failed!");
00208     }
00209 
00210     return 1;
00211 }
00212 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines