This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

cc2430flash 读内容

Other Parts Discussed in Thread: Z-STACK

请问下如何读flash的内容呢?我可以用DMA方式给flash写内容,但是我想读出写入的内容,查了下手册,没有相关的寄存器,不知道如何操作。请指导,谢谢!

  • unsigned char ReadFlash(unsigned int addr)

    {

     return (*(unsigned char *)addr);

    }

  • z-stack里有对FLASH进行操作的文件,先下载安装z-stack,在安装目录下搜索Hal_flash.c,可移植里面的代码实现你的功能

    void HalFlashRead(uint8 pg, uint16 offset, uint8 *buf, uint16 cnt)

    {

     // Calculate the offset into the containing flash bank as it gets mapped into XDATA.

     uint8 *pData = (uint8 *)(offset + HAL_FLASH_PAGE_MAP) +

                    ((pg % HAL_FLASH_PAGE_PER_BANK) * HAL_FLASH_PAGE_SIZE);

     uint8 memctr = MEMCTR;  // Save to restore.

    #if (!defined HAL_OAD_BOOT_CODE) && (!defined HAL_OTA_BOOT_CODE)

     halIntState_t is;

    #endif

     pg /= HAL_FLASH_PAGE_PER_BANK;  // Calculate the flash bank from the flash page.

    #if (!defined HAL_OAD_BOOT_CODE) && (!defined HAL_OTA_BOOT_CODE)

     HAL_ENTER_CRITICAL_SECTION(is);

    #endif

     // Calculate and map the containing flash bank into XDATA.

     MEMCTR = (MEMCTR & 0xF8) | pg;

     while (cnt--)

     {

       *buf++ = *pData++;

     }

     MEMCTR = memctr;

    #if (!defined HAL_OAD_BOOT_CODE) && (!defined HAL_OTA_BOOT_CODE)

     HAL_EXIT_CRITICAL_SECTION(is);

    #endif

    }

  • 如果我不想用DMA的方式来读写呢?我想知道怎么实现,谢谢