搜索
bottom↓
回复: 5

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

[复制链接]

出0入0汤圆

发表于 2010-4-22 17:19:24 | 显示全部楼层 |阅读模式
Mega128扩展32k的ram,片内的和片外的都使用会出现问题!

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

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

运行环境:avr studio
ram初始地址设置如下:

(原文件名: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[10000]    __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[1000]=0;

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


       
        }
}


如果将程序改一下:
增加:int temp2[1000];
并在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[10000]    __attribute__((section(".xdata")));

int temp2[1000];



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[1000]=0;
         for(k=0;k<2000;k++)
                 temp2[k]=0;

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

                temp2++;
                i++;


       
        }
}

出0入0汤圆

 楼主| 发表于 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 and  bootloaders.



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

Flash Size is specified in words while Sram Size and Eeprom Size  is 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 it  separates 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

出0入0汤圆

 楼主| 发表于 2010-4-22 17:27:35 | 显示全部楼层
生成的makefile文件:
## Linker flags
LDFLAGS = $(COMMON)
LDFLAGS +=
LDFLAGS += -Wl,-section-start=.xdata=0x801100

也是对的。

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

出0入0汤圆

 楼主| 发表于 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那样吗??

出0入0汤圆

 楼主| 发表于 2010-4-22 22:19:56 | 显示全部楼层
没有人回答???自己顶一下!!!

出0入0汤圆

 楼主| 发表于 2010-8-11 09:48:57 | 显示全部楼层
自己顶一下!!!原因:某个地址线虚焊了!!!!
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-4-29 13:24

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表