CC2541 SNV扩容
时间:10-02
整理:3721RD
点击:
SNV可以使用的空间只有4K,在不是用OTA功能的情况下,如何把剩余的空间使用SNV管理使用呢?
官方有 dma方式操作内部flash的例程,可以下载。
下载地址
http://www.ti.com/product/CC2541/toolssoftware
把第96page~124page拿来存储数据,自己写了个FLASH写函数,使用DMA1,无备份。
uint8 BSPFlash_Write(uint16 offset, uint8 *buf, uint16 len) { halDMADesc_t *ch; ch = HAL_DMA_GET_DESC1234( FLASH_DMA_CH ); HAL_DMA_SET_SOURCE( ch, buf ); HAL_DMA_SET_DEST( ch, &FWDATA ); HAL_DMA_SET_VLEN( ch, HAL_DMA_VLEN_USE_LEN ); HAL_DMA_SET_LEN( ch, len ); HAL_DMA_SET_WORD_SIZE( ch, HAL_DMA_WORDSIZE_BYTE ); HAL_DMA_SET_TRIG_MODE( ch, HAL_DMA_TMODE_SINGLE ); HAL_DMA_SET_TRIG_SRC( ch, HAL_DMA_TRIG_FLASH ); HAL_DMA_SET_SRC_INC( ch, HAL_DMA_SRCINC_1 ); HAL_DMA_SET_DST_INC( ch, HAL_DMA_DSTINC_0 ); HAL_DMA_SET_IRQ( ch, HAL_DMA_IRQMASK_DISABLE ); HAL_DMA_SET_M8( ch, HAL_DMA_M8_USE_8_BITS ); HAL_DMA_SET_PRIORITY( ch, HAL_DMA_PRI_HIGH); // Waiting for the flash controller to be ready. while (FCTL & FCTL_BUSY); /* Configuring the flash controller. * FADDRH:FADDRL: point to the area in flash to write to. */ uint16 addr, page; page = SPACE_START_PAGE + (offset / HAL_FLASH_PAGE_SIZE); addr = ((offset % HAL_FLASH_PAGE_SIZE) >> 2) + (page << 9); // You address 32-bit words through the flash controller. FADDRH = (addr >> 8) & 0x00FF; FADDRL = addr & 0x00FF; uint8 firstByte = 0; BSPFlash_Read(offset, &firstByte, 1); if(firstByte != 0xFF){ FCTL |= FCTL_ERASE; while (FCTL & FCTL_BUSY); } HAL_DMA_CLEAR_IRQ(FLASH_DMA_CH); // Arm the DMA channel, takes 9 system clock cycles. HAL_DMA_ARM_CH(FLASH_DMA_CH); asm("nop");asm("nop");asm("nop");// 9 NOPs asm("nop");asm("nop");asm("nop"); asm("nop");asm("nop");asm("nop"); // Enable flash write. Generates a DMA trigger. FCTL |= FCTL_WRITE; // Wait until flash controller not busy. while (FCTL & (FCTL_BUSY | FCTL_FULL)); return 1; }