Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Uing SDRAM in AT91SAM9260
PostPosted: Mon Mar 14, 2011 9:58 am 
Offline

Joined: Mon Mar 14, 2011 9:46 am
Posts: 8
I am using the AT91SAM9260 development board. I think there are no files with the kit for the SDRAM interface. Can anyone guide how can we use SDRAM?

Thankyou


Top
 Profile  
 
 Post subject: Re: Uing SDRAM in AT91SAM9260
PostPosted: Mon Mar 14, 2011 3:42 pm 
Offline

Joined: Sat Oct 30, 2010 6:04 pm
Posts: 574
The AT91SAM9260-EK?

The ATMEL code examples include code to initialize the SDRAM, for one example look at the AT91BootStrap code. ie \driver\sdramc.c and \board\at91sam9260ek\at91sam9260ek.c

The SDRAM resides at 0x20000000. You can build applications for this address, and load/execute them directly using SAM-BA.

There are also projects that support the SAM-ICE JTAG pod, and allow you to write/download/debug code directly into SDRAM or SRAM from Keil, etc.

Look also at the SAM-BA applet source code.



/* Initialize the matrix */
writel(readl(AT91C_BASE_CCFG + CCFG_EBICSA) | AT91C_EBI_CS1A_SDRAMC, AT91C_BASE_CCFG + CCFG_EBICSA);

/* Configure SDRAM Controller */
sdram_init( AT91C_SDRAMC_NC_9 |
AT91C_SDRAMC_NR_13 |
AT91C_SDRAMC_CAS_2 |
AT91C_SDRAMC_NB_4_BANKS |
AT91C_SDRAMC_DBW_32_BITS |
AT91C_SDRAMC_TWR_2 |
AT91C_SDRAMC_TRC_7 |
AT91C_SDRAMC_TRP_2 |
AT91C_SDRAMC_TRCD_2 |
AT91C_SDRAMC_TRAS_5 |
AT91C_SDRAMC_TXSR_8, /* Control Register */
(MASTER_CLOCK * 7)/1000000, /* Refresh Timer Register */
AT91C_SDRAMC_MD_SDRAM); /* SDRAM (no low power) */


Top
 Profile  
 
 Post subject: Re: Uing SDRAM in AT91SAM9260
PostPosted: Mon Mar 14, 2011 6:51 pm 
Offline

Joined: Wed Jan 09, 2008 5:09 pm
Posts: 186
Location: Mounds View, MN
Download the at91sam9260 SW kit from Atmel. It should have a full library of support files for different subsystems on the processor. This SW kit is what was used to develop SAM-BA and the bootstrap codes.

_________________
Tim Barr
Multitech Inc.


Top
 Profile  
 
 Post subject: Re: Uing SDRAM in AT91SAM9260
PostPosted: Tue Mar 15, 2011 8:13 am 
Offline

Joined: Mon Mar 14, 2011 9:46 am
Posts: 8
I dont have the /driver/sdramc.c file. but in another file board_memories.c file which has a function to initialize and configure the SDRAM. What i am unclear about is that what about data lines. I read in the documentation that the PIO and the SDRAM data lines are multiplesxed, i understand it also with the schematics, but what if i need to use 32 bit bus.........can anyone explain the procedure if i want to use sdram for storage with 32-bit data bus?

Thankyou


Top
 Profile  
 
 Post subject: Re: Using SDRAM in AT91SAM9260
PostPosted: Tue Mar 15, 2011 9:14 am 
Offline

Joined: Sat Oct 30, 2010 6:04 pm
Posts: 574
Heaven forbid you download the suggested code and look at it.
ftp://www.at91.com/pub/at91bootstrap/
ftp://www.at91.com/pub/at91bootstrap/AT ... ap1.16.zip

The BUS

void sdramc_hw_init(void)
{
// PC16..32 PERIPH_A -> D16..31
writel(0xFFFF0000, AT91C_BASE_PIOC + PIO_ASR(0));
writel(0xFFFF0000, AT91C_BASE_PIOC + PIO_PDR(0));
}

The address is multiplexed as rows/columns. The SDRAM bus can be 16 or 32-bits wide. You'll have to initialize PIOC[16..32] if you chose the board's 2 x16 bit configuration.

The CONTROLLER

/* Initialize the matrix */
writel(readl(AT91C_BASE_CCFG + CCFG_EBICSA) | AT91C_EBI_CS1A_SDRAMC, AT91C_BASE_CCFG + CCFG_EBICSA);

/* Configure SDRAM Controller */
sdram_init( AT91C_SDRAMC_NC_9 | // ROWS
AT91C_SDRAMC_NR_13 | // COLUMNS
AT91C_SDRAMC_CAS_2 |
AT91C_SDRAMC_NB_4_BANKS | // BANKS
AT91C_SDRAMC_DBW_32_BITS | // BUS WIDTH, TOTAL
AT91C_SDRAMC_TWR_2 |
AT91C_SDRAMC_TRC_7 |
AT91C_SDRAMC_TRP_2 |
AT91C_SDRAMC_TRCD_2 |
AT91C_SDRAMC_TRAS_5 |
AT91C_SDRAMC_TXSR_8, /* Control Register */
(MASTER_CLOCK * 7)/1000000, /* Refresh Timer Register */
AT91C_SDRAMC_MD_SDRAM); /* SDRAM (no low power) */


Top
 Profile  
 
 Post subject: Re: Uing SDRAM in AT91SAM9260
PostPosted: Thu Mar 17, 2011 9:00 am 
Offline

Joined: Mon Mar 14, 2011 9:46 am
Posts: 8
I understand the initialization and the basic configuration of SDRAM. Being very new to the processors, i dont understand how are we writing the SDRAM. I do know that we have the PIO C multiplexed to the SDRAM data pins. Does that mean that now i need to have a device that should send the data through the PIO to SDRAM. Or i can directly use SDRAM for input output. I am unable to identify that what needs to be done if i want to write four chunks of 32 bit data to some address of sdram.

Please help.


Top
 Profile  
 
 Post subject: Re: Uing SDRAM in AT91SAM9260
PostPosted: Wed Mar 23, 2011 9:19 pm 
Offline

Joined: Wed Mar 23, 2011 9:12 pm
Posts: 2
No You dont need any other device.

void sdramc_hw_init(void)
{
// PC16..32 PERIPH_A -> D16..31
writel(0xFFFF0000, AT91C_BASE_PIOC + PIO_ASR(0));
writel(0xFFFF0000, AT91C_BASE_PIOC + PIO_PDR(0));
}

The above code selects the functionality of the pin. There is a table in datasheet describing which peripheral gets connected to the pin depending on the values in the above code.

Once SDRAM controller part is initialized (As shown in one of the posts above) you can directly read write to sdram.


Top
 Profile  
 
 Post subject: Re: Uing SDRAM in AT91SAM9260
PostPosted: Thu Mar 31, 2011 1:55 pm 
Offline

Joined: Mon Mar 14, 2011 9:46 am
Posts: 8
I have the following code settled for me. I can read the specific registers for the SDRAM. Now i intend to write forexample ABCD, ABCC, ABDD, ABAA to SDRAM at starting addreses.

What should i do?

//------------------------------------------------------------------------------
// Headers
//------------------------------------------------------------------------------

#include <board.h>
#include <pio/pio.h>
#include <pio/pio_it.h>
#include <usart/usart.h>
#include <usart/usart.c>
#if defined(AT91C_BASE_PITC)
#include <pit/pit.h>
#endif
#include <irq/irq.h>
#include <tc/tc.h>
#include <utility/led.h>
#include <utility/trace.h>
#include <rtt/rtt.h>
#include <rtt/rtt.c>
#include <string.h>

#include <board_memories.h>

#include <stdio.h>
#include <stdlib.h>
#if defined(cortexm3)
#include <systick/systick.h>
#endif

//------------------------------------------------------------------------------
// Local definitions
//------------------------------------------------------------------------------

/// Delay for pushbutton debouncing (in milliseconds).
#define DEBOUNCE_TIME 500

#if defined(AT91C_BASE_PITC)
/// PIT period value in µseconds.
#define PIT_PERIOD 1000
#endif


#define READ(peripheral, register) (peripheral->register)
#define WRITE(peripheral, register, value) (peripheral->register = value)

//------------------------------------------------------------------------------
/// Application entry point. Configures the DBGU, PIT for SAM7 & SAM9
/// microcontrollers, UART and System tick for SAM3 microcontrollers.
/// Configures TC0, LEDs and buttons and makes LED\#1 blink in its infinite
/// loop, using the Wait function.
/// \return Unused (ANSI-C compatibility).
//------------------------------------------------------------------------------
int main(void)
{

char str1[50];
char pString[25];
char pString_set[11];
char pString2[20];
char pString1[16];
char str2[25];

const Pin pPins[] = {PIN_USART0_TXD, PIN_USART0_RXD};
PIO_Configure(pPins, 2);

PMC_EnablePeripheral(BOARD_ID_USART);
unsigned int mode = AT91C_US_USMODE_HWHSH
| AT91C_US_CLKS_CLOCK
| AT91C_US_CHRL_8_BITS
| AT91C_US_PAR_NONE
| AT91C_US_NBSTOP_1_BIT
| AT91C_US_CHMODE_NORMAL;

USART_Configure(BOARD_USART_BASE, mode, 115200, BOARD_MCK);
USART_SetTransmitterEnabled(BOARD_USART_BASE, 1);
USART_SetReceiverEnabled(BOARD_USART_BASE, 1);

RTT_SetPrescaler(AT91C_BASE_RTTC,0x8000);

sprintf(pString, "\n\rSTART_Configure\n\r");
USART_WriteBuffer(BOARD_USART_BASE, pString, sizeof(pString));

BOARD_ConfigureSdram(0x16);

unsigned int tmp = 0;

tmp=READ(AT91C_BASE_SDRAMC, SDRAMC_TR);
sprintf(pString, "\n\rValue read is %d \n\r",tmp);
USART_WriteBuffer(BOARD_USART_BASE, pString, sizeof(pString));
}


Top
 Profile  
 
 Post subject: Re: Uing SDRAM in AT91SAM9260
PostPosted: Thu Mar 31, 2011 8:55 pm 
Offline

Joined: Sat Oct 30, 2010 6:04 pm
Posts: 574
On the AT91SAM9260-EK is 32-bit wide

BOARD_ConfigureSdram(32);

Writing to it as you would for any arbitrary memory in C

unsigned long *p = (unsigned long *)0x20000000; // Base of SDRAM

for(i=0; i<((64 * 1024 * 1024) / sizeof(unsigned long)); i++) // 64 MB
p[i] = 0xDEADBEEF;


Top
 Profile  
 
 Post subject: Re: Uing SDRAM in AT91SAM9260
PostPosted: Fri Apr 01, 2011 2:31 pm 
Offline

Joined: Mon Mar 14, 2011 9:46 am
Posts: 8
The line in the above code with for loop doesnot executes.........the program gets stuck at the said line.......any solution??


Top
 Profile  
 
 Post subject: Re: Uing SDRAM in AT91SAM9260
PostPosted: Mon Apr 04, 2011 12:13 pm 
Offline

Joined: Mon Mar 14, 2011 9:46 am
Posts: 8
Fianlly i am able to run the code with the following out put

1-Value is deadba0f

2-Value is deadba1f

3-Value is deadba2f

and my code was:

//------------------------------------------------------------------------------
/// Waits for the given number of milliseconds (using the timestamp generated
/// by the SAM7 & SAM9 microcontrollers's PIT, or SAM3's microcontrollers's system tick).
/// \param delay Delay to wait for, in milliseconds.
//------------------------------------------------------------------------------
void Wait(unsigned long delay)
{
volatile unsigned int start = timestamp;
unsigned int elapsed;
do {
elapsed = timestamp;
elapsed -= start;
}
while (elapsed < delay);
}

//------------------------------------------------------------------------------
// Exported functions
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
/// Application entry point. Configures the DBGU, PIT for SAM7 & SAM9
/// microcontrollers, UART and System tick for SAM3 microcontrollers.
/// Configures TC0, LEDs and buttons and makes LED\#1 blink in its infinite
/// loop, using the Wait function.
/// \return Unused (ANSI-C compatibility).
//------------------------------------------------------------------------------
int main(void)
{

char str1[50];
char pString[50];
char pString_set[30];
char pString2[25];
char pString1[25];
char str2[25];

const Pin pPins[] = {PIN_USART0_TXD, PIN_USART0_RXD};
PIO_Configure(pPins, 2);

PMC_EnablePeripheral(BOARD_ID_USART);
unsigned int mode = AT91C_US_USMODE_HWHSH
| AT91C_US_CLKS_CLOCK
| AT91C_US_CHRL_8_BITS
| AT91C_US_PAR_NONE
| AT91C_US_NBSTOP_1_BIT
| AT91C_US_CHMODE_NORMAL;

USART_Configure(BOARD_USART_BASE, mode, 115200, BOARD_MCK);
USART_SetTransmitterEnabled(BOARD_USART_BASE, 1);
USART_SetReceiverEnabled(BOARD_USART_BASE, 1);


//USART_Configure(uart1,USART_MODE_ASYNCHRONOUS, 57600, BOARD_MCK);
//USART_SetTransmitterEnabled(uart1,1);


RTT_SetPrescaler(AT91C_BASE_RTTC,0x8000);

sprintf(pString_set, "\n\rSTART_Configure \n\r");
USART_WriteBuffer(BOARD_USART_BASE, pString_set, sizeof(pString_set));


// DBGU output configuration
TRACE_CONFIGURE(DBGU_STANDARD, 115200, BOARD_MCK);
printf("-- Getting Started Project %s --\n\r", SOFTPACK_VERSION);
printf("-- %s\n\r", BOARD_NAME);
printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);

// Configuration
#if defined(AT91C_BASE_PITC)
TRACE_INFO("configure pit.\n\r");
ConfigurePit();
#else
// 1ms tick
TRACE_INFO("configure sys tick.\n\r");
SysTick_Configure(1, BOARD_MCK/1000, SysTick_Handler);
#endif

ConfigureTc();
ConfigureButtons();
ConfigureLeds();

AT91S_USART * uart1;
//uart1 -> US_MR = AT91C_US_USMODE_NORMAL | AT91C_US_CLKS_CLOCK | AT91C_US_CHRL_8_BITS | AT91C_US_NBSTOP_1_BIT;

//USART_Configure(uart1,USART_MODE_ASYNCHRONOUS, 57600, BOARD_MCK);

BOARD_ConfigureSdram(32);

//unsigned int i=0;
//unsigned int j=0;
unsigned long *p = (unsigned long *)0x20200040; // Base of SDRAM

//for(i=0; i<3; i++) // 64 MB
//p[i] = 0xDEADBAEF;
p[0] = 0xDEADBA0F;
p[1] = 0xDEADBA1F;
p[2] = 0xDEADBA2F;

unsigned long tmp;
/*for(j=0; j<3; j++) // 64 MB
{ tmp = p[j];
sprintf(pString, "\n\r%x \n\r",tmp);
USART_WriteBuffer(BOARD_USART_BASE, pString, sizeof(pString));
}*/

tmp = p[0];
sprintf(pString_set, "\n\r1-Value is %x \n\r",tmp);
USART_WriteBuffer(BOARD_USART_BASE, pString_set, sizeof(pString_set));
Wait(50);
tmp = p[1];
sprintf(pString2, "\n\r2-Value is %x \n\r",tmp);
USART_WriteBuffer(BOARD_USART_BASE, pString2, sizeof(pString2));
Wait(50);
tmp = p[2];
sprintf(pString1, "\n\r3-Value is %x \n\r",tmp);
USART_WriteBuffer(BOARD_USART_BASE, pString1, sizeof(pString1));

// Wait for 500ms
Wait(500);
}
}


Top
 Profile  
 
 Post subject: Re: Uing SDRAM in AT91SAM9260
PostPosted: Mon Apr 04, 2011 12:16 pm 
Offline

Joined: Mon Mar 14, 2011 9:46 am
Posts: 8
In the last reply, i want to know that is it confirmed that the sram is being written as i cant see the memory mapping any where in my system...........also i had to add the wait statement , without which the USART_Writebuffer was not working for third time.

Still thankyou everyone for the help.


Top
 Profile  
 
 Post subject: Re: Uing SDRAM in AT91SAM9260
PostPosted: Mon Apr 04, 2011 7:31 pm 
Offline

Joined: Sat Oct 30, 2010 6:04 pm
Posts: 574
The SDRAM hangs off the EBI (CS1) at address 0x20000000, it's address is hard coded into the memory map of the device. Linux can appear to move it around by using the MMU and virtualization.

You have two banks of SRAM located at 0x00200000..0x00200FFF and 0x00300000..0x00300FFF, which are both relatively small at 4K, and internal to the part.

It's going to be hard to fit much of an application in SRAM, which is why the 9260 is typically multi-staged booted, with a small boot loader initializing the SDRAM before copying code into it and running the next stage or application from there.

The internal SRAM in the 9G20 and 9G45 is bigger, providing an opportunity to load more complete single applications/demos


Top
 Profile  
 
 Post subject: Re: Uing SDRAM in AT91SAM9260
PostPosted: Tue Apr 05, 2011 11:47 am 
Offline

Joined: Mon Mar 14, 2011 9:46 am
Posts: 8
I understand that SRAM is smaller to run whole applications...........thus this now again creates a new problem of using the SDRAM. As far as i have studied, to access the SDRAM, we need to program the SDRAM controller and then provide our inputs and outputs at the address and data pins of the EBI.............please comment.

Also if someone could add some example code for a simple read and write to SDRAM.


Top
 Profile  
 
 Post subject: Re: Uing SDRAM in AT91SAM9260
PostPosted: Tue Apr 05, 2011 3:31 pm 
Offline

Joined: Sat Oct 30, 2010 6:04 pm
Posts: 574
Once you program the SDRAM/Controller the CPU is going to handle the EBI address/data pins when you access the memory window (ie at 0x20000000 thru 0x23FFFFFF for 64MB). It is all done automatically, once the system knows the size and timing parameters, which you've programmed into the controller.

You've already read/written to this memory. How do you expect to access this memory?

If you want your compiler/linker to use this memory you'll need to create a scatter file or linker script, depending on your tools, to describe the memory regions and sizes to the tool chain. The application can use a portion of the memory, and the rest can be used for the heap and stack.

Perhaps now would be a good time to review some books/texts on embedded programming.

I'll also suggest you download the Keil uVision Demo/Eval, it has project code for the AT91SAM9260-EK (in \ARM\boards\atmel), including an option to initialize and download code into the SDRAM via a SAM-ICE/J-Link JTAG pod and run it directly. Despite the 32KB code limit, this should allow you to experiment more easily.

You can also use AT91BootStrap, compiled with GNU/GCC, for the NAND flash. The BootRom will download this into SRAM at start up, it will initialize the SDRAM and load additional code from NAND, nominally up to 256 KB into SDRAM at 0x23F00000 and run it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: Google [Bot] and 21 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: