AVR MCU's Expansion of External RAM

Publisher:vnerwb池塘边Latest update time:2020-01-16 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

I use GCC compiler and C++ to write programs in the project. Theoretically, as long as the external memory is enabled and configured, the address allocation of variables can be completely handed over to the compiler, but the premise is that the memory enable and configuration code must be executed first after power-on reset. When using C or C++ to write programs, the first code to be executed after power-on reset is the startup code and constructor code automatically added by the compiler. I don't know how to make the memory enable and configuration code be executed first after power-on reset, so I wrote the following macro to control the access to the external memory.

AVR MCU's Expansion of External RAM

code show as below:

//ex te rn_ ram .h

#ifndef _H_EXTERN_RAM_H_

#define _H_EXTERN_RAM_H_

#include "type.h"

#define DEF_EX_VAR(name) EX_VAR name;

#define INIT_EX_VAR(name,ele_size,ele_n) do{

name.size_ele=ele_size;

name.n_ele=ele_n;

name.addr=p;

p+=((ele_size)*(ele_n));

}while(0)

#define WR_EX_VAR(name, pos, pdat) do {

for(UINT8 iiiii="0";iiiii(name.addr+(pos)*name.size_ele)[iiiii]=*((INT8 *)pdat+iiiii);

} while (0)

#define RD_EX_VAR(name, pos, pdat) do {

for(UINT8 iiiii="0";iiiii*((INT8 *)pdat+iiiii)=((INT8 *)(name.addr+(pos)*name.size_ele))[iiiii];

} while (0);

#define GET_P_EX_VAR(name,pos) (name.addr+(pos)*name.size_ele)

typedef struct _tag_ex_var

{

UINT8 size_ele;

UINT16 n_ele;

INT8 *addr;

} EX_VAR;

#endif

Application Examples

//main.cpp

#include "includes.h"

INT8 *p=(INT8*)0x3100; //The address of external RAM starts from 0X3100

DEF_EX_VAR(test); //define an external variable

INT16 main (void)

{

UINT8 i;

INT16 tmp;

INT16 *p_ele;

MCUCR|=0X80; // Enable XRAM and configure it for the fastest access speed

INIT_EX_VAR(test, sizeof(INT16), 100); //External variable initialization, the variable has 100 elements, the element size is sizeof(INT16)

tmp = "0xaaaa";

for (i=0;i<100;i++)

{

WR_EX_VAR (test, i, &tmp); //Write an example to assign the value 0Xaaaa to all elements of the variable test

}

for (i=0;i<100;i++)

{

RD_EX_VAR (test, i, &tmp); //Read example

}

p_ele = (INT16 *)GET_P_EX_VAR (test, 32); //Get the pointer to the 32nd element of the variable test

while(1);

return 0x00;

}

Reference address:AVR MCU's Expansion of External RAM

Previous article:SD card interface programming for AVR microcontroller
Next article:The operation steps and process of AVR MCU compare match clear counter mode

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号