SAMV71 Xplained Ultra Software Package 1.3

main.c

Go to the documentation of this file.
00001 /* ----------------------------------------------------------------------------
00002  *         SAM Software Package License
00003  * ----------------------------------------------------------------------------
00004  * Copyright (c) 2014, Atmel Corporation
00005  *
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions are met:
00010  *
00011  * - Redistributions of source code must retain the above copyright notice,
00012  * this list of conditions and the disclaimer below.
00013  *
00014  * Atmel's name may not be used to endorse or promote products derived from
00015  * this software without specific prior written permission.
00016  *
00017  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00019  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
00020  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00022  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
00023  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00024  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00025  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
00026  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  * ----------------------------------------------------------------------------
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 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 SAM V71 Xplained Ultra board.
00042  *
00043  *  \section Description
00044  *
00045  *  \section Usage
00046  *
00047  *  -# Build the program and download it inside the SAM V71 Xplained Ultra board. 
00048  *     Please refer to the Getting Started with SAM V71 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 rates
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     /* Test for 55AA55AA/AA55AA55 pattern */
00102     printf(" Test for 55AA55AA/AA55AA55 pattern ... \n\r");
00103     for (i = 0; i < size ; i ++) {
00104         if (i & 1) {
00105             ptr32[i] = 0x55AA55AA ;
00106         }
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             }
00120         }
00121         else {
00122             if (ptr32[i] != 0xAA55AA55 ) {
00123                 printf("-E- Expected:%x, read %x @ %x \n\r" ,
00124                         0xAA55AA55 , (unsigned)(ptr32[i]), (unsigned)(baseAddr + i));
00125                 ret = 0;
00126             }
00127         }
00128     }
00129         
00130     if (!ret) return ret;
00131     printf(" Test for BYTE accessing... \n\r");
00132     /* Test for BYTE accessing */
00133     for (i = 0; i < size ; i ++) {
00134         ptr8[i] = (uint8_t)( i & 0xFF) ;
00135     }
00136     
00137     for (i = 0; i <  size ; i++) {
00138         if (ptr8[i] != (uint8_t)(i & 0xFF))  {
00139             printf("-E- Expected:%x, read %x @ %x \n\r" ,
00140                 (unsigned)(i & 0xFF), ptr8[i], (unsigned)(baseAddr + i));
00141             ret = 0;
00142         }
00143     }
00144     if (!ret) return ret;
00145     
00146     printf(" Test for WORD accessing... \n\r");
00147     /* Test for WORD accessing */
00148     for (i = 0; i < size / 2 ; i ++) {
00149         ptr16[i] = (uint16_t)( i & 0xFFFF) ;
00150     }
00151     
00152     for (i = 0; i <  size / 2 ; i++) {
00153         if (ptr16[i] != (uint16_t)(i & 0xFFFF))  {
00154             printf("-E- Expected:%x, read %x @ %x \n\r" ,
00155                 (unsigned)(i & 0xFFFF), ptr16[i], (unsigned)(baseAddr + i));
00156             ret = 0;
00157         }
00158     }
00159     if (!ret) return ret;
00160     printf(" Test for DWORD accessing... \n\r");
00161     /* Test for DWORD accessing */
00162     for (i = 0; i < size / 4 ; i ++) {
00163         ptr32[i] = (uint32_t)( i & 0xFFFFFFFF) ;
00164         memory_barrier() 
00165     }
00166     for (i = 0; i <  size / 4 ;  i++) {
00167         if (ptr32[i] != (uint32_t)(i & 0xFFFFFFFF))  {
00168             printf("-E- Expected:%x, read %x @ %x \n\r" ,
00169                 (unsigned)(i & 0xFFFFFFFF), (unsigned)(ptr32[i]),(unsigned)(baseAddr + i));
00170             ret = 0;
00171         }
00172     }
00173     return ret;
00174 }
00175 
00176 /*----------------------------------------------------------------------------
00177  *        Exported functions
00178  *----------------------------------------------------------------------------*/
00179 /**
00180  *  \brief getting-started Application entry point.
00181  *
00182  *  \return Unused (ANSI-C compatibility).
00183  */
00184 extern int main( void )
00185 {
00186     /* Disable watchdog */
00187     WDT_Disable( WDT ) ;
00188 
00189     /* Enable I and D cache */
00190     SCB_EnableICache();
00191     SCB_EnableDCache();
00192 
00193     /* Output example information */
00194     printf( "\n\r-- SDRAM Example %s --\n\r", SOFTPACK_VERSION ) ;
00195     printf( "-- %s\n\r", BOARD_NAME ) ;
00196     printf( "-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__ , COMPILER_NAME);
00197 
00198     TRACE_INFO("Configuring External SDRAM \n\r");
00199     /* SDRAM timing configuration */
00200     BOARD_ConfigureSdram();
00201 
00202     /* Full test SDRAM  */
00203     TRACE_INFO("Starting memory validation of External SDRAM \n\r");
00204 
00205     if (_sdramAccess(SDRAM_CS_ADDR, 0x200000)) {
00206         TRACE_INFO("Test succeeded!");
00207     } else {
00208         TRACE_INFO("Test failed!");
00209     }
00210     return 1;
00211 }
00212 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines