cc2530 通过DMA访问flash问题
2019-03-24 17:50发布
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
两个问题:首先,我用这段代码擦除35页的数据,但是在XDATA窗口看到的和读取出来放到数组里看到的都是0x00,并没有擦除,这是为什么啊?- void Flash_PageErase( int pg)
- {
- FADDRH = pg<<1;
- FCTL |= 0x01; //启动页面擦除
- while (FCTL & 0x80); //等待擦除完成
- }
复制代码其次,我用DMA传输内存到flash的4字节数据,怎么都写不进去,底下是我的写函数,有没有高手指教一下。- void WriteFlashDMA( uint16 saddr, uint16 length, uint16 flashadr) //Write Flash, DMA Method
- //Length Must be Divisible by 4 or last bytes fail to write
- {
- //配置DMA通道每次传送一个字节
- DMA_DESC dmaConfig0;//定义DMA通道
- //MEMCTR|=0X07;//将bank 7 映射到Xdata区
- dmaConfig0.SRCADDRH = (saddr >> 8) & 0x00FF; //XData - To Be Written to Flash - Gets Incremented;存储data的高8位;
- dmaConfig0.SRCADDRL = saddr & 0x00FF;//存储data地址的低8位;
- dmaConfig0.DESTADDRH = (((int)&FWDATA) >> 8) & 0x00FF; //Flash Controller Data Address - Flash Controller Writes Data//存储写寄存器的地址的高8位
- dmaConfig0.DESTADDRL = ((int)&FWDATA) & 0x00FF;//存储写寄存器的低8位;
- dmaConfig0.VLEN = 0; //Variable Length Transfer - 0=Fixed LEN Transfer//采用LEN作为传送长度
- dmaConfig0.LENH = (length>>8) & 0x00FF; //Number of WORDSZIE in Transfer - Must be Divisible by 4 - NET_ADDR_SIZE=4//存储传送长度高5位
- dmaConfig0.LENL = length & 0x00FF;//存储长度低8位;
- dmaConfig0.WORDSIZE = 0; //Size of Each Transfer - 0=8 Bit;每个DMA传送采用8位传送
- dmaConfig0.TMODE = 0; //Transfer Mode - 1=Block, 0=Single,传送模式为单一模式
- dmaConfig0.TRIG = 18; //DMA Trigger - 0=Manual Via DMAREQ, 18=Flash;flash触发
- dmaConfig0.SRCINC = 0; //Source Address Increment - 1=1 Byte//源地址增量模式为1字节/字
- dmaConfig0.DESTINC = 1; //Destination Address Increment - 0=0 Bytes (Always Write to FWDATA, No Need to Increment)目标地址增量模式0字节/字
- dmaConfig0.IRQMASK = 0; //Interrupt Mask - 0=Disable Interrupts//禁止通道完成中断产生
- dmaConfig0.M8 = 0; //8th Bit Mode - 0=Use All 8 Bits使用全部8位作为传送长度
- dmaConfig0.PRIORITY = 2; //Priority - 10(2)=High Priority优先级为DMA优先
- //DMA模式写
- while (FCTL & 0x80); //Wait Until DMA Controller is Available - Busy Bit 7//等待写或擦除状态被激活
-
- /********* 存储写入flash页地址 ***********************************************/
-
- FADDRH =(flashadr >> 8) & 0x00FF; //
- FADDRL =(flashadr >> 0) & 0x00FF; //
- //通道0配置地址
- DMA0CFGH = (((int)&dmaConfig0) >> 8) & 0x00FF; //Pass DmaConfig0
- DMA0CFGL = ((int)&dmaConfig0) & 0x00FF;
-
-
- DMAARM |= 0x01; //Arm the DMA Channel//通道0进去工作状态
- FCTL |= 0x02; //Start Write
- //while (!(DMAIRQ & 0x01)); //Wait Until Write Complete
- //DMAIRQ &= 0xFE; //Clear Any DMA IRQ on Channel 0 - Bit 0
- while (FCTL & (0x80)); //Wait Until Flash Controller is Not Busy - Busy Bit 7//等待或者擦除状态激活
- }
复制代码
此帖出自
小平头技术问答
一周热门 更多>