keilc 发表于 2010-4-22 17:19:24

Mega128扩展32k的ram,片内的和片外的都使用会出现问题!

Mega128扩展32k的ram,片内的和片外的都使用会出现问题!

下面的程序理论上来说是使用了外部的ram。

Data空间占用了29.2%。
如果将int temp    __attribute__((section(".xdata")));改为
int temp;Data空间变为:21194 bytes (517.4% Full)。
实际下载到电路板上小灯也是闪烁的。
说明确实是使用了外部空间,程序运行正确。

运行环境:avr studio
ram初始地址设置如下:
http://cache.amobbs.com/bbs_upload782111/files_28/ourdev_548454.JPG
(原文件名:0001.JPG)


//#include <avr/wdt.h>
#include "avrlibdefs.h"
#include "delay.h"
#include "uart.h"

void led_gprs_on()
{
cbi(PORTE,2);
}

void led_gprs_out()
{
sbi(PORTE,2);
}

int temp    __attribute__((section(".xdata")));

void main()
{


       MCUCR = 0x80; // 允许外部并行扩展接口,忽略高位0X8000的等待时间
       XMCRA = 0x00;//0x2c; //0x00 external memory
       XMCRB = 0x02; // 释放PC7,作为通用I/O引脚使用
       DDRC =0xff; // PC7用于输出,(不影响PC0-PC6地址线)
       PORTC = 0x00; // PC7输出0,(不影响PC0-PC6地址线)
       
       DDRE=0xFF;
       PORTE=0x00;
       uartInit();
       int k;
       int t;
       temp=0;

        while(1)
        {
                //send_test_word();
       
                temp++;
               
               t=temp;
                if(t==10)
                {
                        led_gprs_out();
                }
                if(t==20)
                {
                        led_gprs_on();
                }
                if(temp>30)
                        temp=0;
               
                _delay_ms(10);


       
        }
}


如果将程序改一下:
增加:int temp2;
并在while()中进行计算,小灯就不在闪烁了。


#include <avr/io.h>
//#include <avr/wdt.h>
#include "avrlibdefs.h"
#include "delay.h"
#include "uart.h"


//#include "uart2.h"

void led_gprs_on()
{
cbi(PORTE,2);
}

void led_gprs_out()
{
sbi(PORTE,2);
}



int temp    __attribute__((section(".xdata")));

int temp2;



void main()
{


       MCUCR |= 0x80; // 允许外部并行扩展接口,忽略高位0X8000的等待时间
       XMCRA |= 0x00;//0x2c; //0x00 external memory
       XMCRB |= 0x02; // 释放PC7,作为通用I/O引脚使用
       DDRC=0xff; // PC7用于输出,(不影响PC0-PC6地址线)
       PORTC = 0x00; // PC7输出0,(不影响PC0-PC6地址线)
       
       DDRE=0xFF;
       PORTE=0x00;
       uartInit();
       int k;
       int t;
       int i=0;
       temp=0;
       for(k=0;k<2000;k++)
               temp2=0;

        while(1)
        {
                //send_test_word();
       
                temp++;
               
               t=temp;
                if(t==10)
                {
                        led_gprs_out();
                }
                if(t==20)
                {
                        led_gprs_on();
                }
                if(temp>30)
                        temp=0;
               
                _delay_ms(10);

                temp2++;
                i++;


       
        }
}

keilc 发表于 2010-4-22 17:25:45

能查到的资料关于icc和cvavr的比较多,关于avr studio很少的。帮助文件中的Memory Settings,说的很简单。以flash为例说的。模模糊糊的。
The purpose of this property page is to enable easy configuration of memory segments andbootloaders.



The upper part of this page displays information about the currently selected part.

Flash Size is specified in words while Sram Size and Eeprom Sizeis specified in bytes.



A List Control is used for showing the defined segments.



To add a segment, double-click somewhere in the control or press the "Add" button

The following dialog appears:







Select the Memory Type, name and address for the new segment and press Ok.



To specify a bootloader for example, set memory type to "Flash", give the bootloader a name and specify one of

the allowed addresses for a bootloader on the current part. It is recommended to use .bootloader as name for

bootloaders. It has become more or less a standard and avr-libc supports this by providing a macro BOOTLOADER_SECTION

that can be put in front of a function to put that function into the section named .bootloader.

(defined in <avr/boot.h>).



The address must be given as a hexadecimal number prefixed with 0x. It is interpreted as a word address for flash memory

and as byte addresses for sram and eeprom memory.


If you want to relocate one of the predefined sections (.text, .eeprom or .data), just use the name of the section you

want to relocate. (Include the dot).



To edit an entry in the List Control, double-click the entry you want to edit.

To remove an entry, select the entry and press "Remove".



It is also possible to specify an initial stack address to use. This can be useful when setting up external memory.



Notes about the AVR port of gcc:



The AVR is a Harvard architecture CPU. This means that itseparates instruction memory and data memory.

The gcc was originally designed to support Von Neumann architectures which define a single storage structure to

hold both instructions and data.



This dichotomy is solved by a series of nifty tricks in the AVR port of gcc, of which three should be noted:

The .text segment starts at 0x0.

The .data segment starts at 0x800000.

The .eeprom segment starts at 0x810000.



These peculiarities have been abstracted away by the GUI of this plug-in, but users will see the truth when

building projects with relocated segments.

A relocation definition for flash will be passed to the GNU linker via avr-gcc as the option:



-Wl,-section-start=bootloader=0x1fc00

Note that the address has been multiplied by 2 to get the byte address.



A relocation definition for the .data section will be passed as:



-Wl,-section-start=anewdatasegment=0x800

keilc 发表于 2010-4-22 17:27:35

生成的makefile文件:
## Linker flags
LDFLAGS = $(COMMON)
LDFLAGS +=
LDFLAGS += -Wl,-section-start=.xdata=0x801100

也是对的。

不知道是不是还有其他注意事项???

keilc 发表于 2010-4-22 17:36:18

M128芯片资料给出的:
#define OFFSET 0x2000
void XRAM_example(void)
{
unsigned char *p = (unsigned char *) (OFFSET + 1);
DDRC = 0xFF;
PORTC = 0x00;
XMCRB = (1<<XMM1) | (1<<XMM0);
*p = 0xaa;
XMCRB = 0x00;
*p = 0x55;
}

常用的是这种方法:
//定义外部RAM地址
#define ext_PORT1 ((volatile unsigned char *)0x1100)
//定义一个指针指向外部RAM首地址
unsigned char *p=(unsigned char *)ext_PORT1;

假如我要使用片外的20多k的空间用起来比较麻烦的。不能像使用内部ram那样吗??

keilc 发表于 2010-4-22 22:19:56

没有人回答???自己顶一下!!!

keilc 发表于 2010-8-11 09:48:57

自己顶一下!!!原因:某个地址线虚焊了!!!!
页: [1]
查看完整版本: Mega128扩展32k的ram,片内的和片外的都使用会出现问题!