FlashIO Example
The FlashIO example is used test the various memory/flash operations erase/write and fetch
Hardware/Boards Required
Before you proceed with this tutorial, you must have the latest KoliadaESDK(TM) and KoliadaES environment setup. For more information on the setup check out Koliada Getting started. This example will run on any processor board that has UART serial communication and whereas this tutorial uses the PIEP CC2541, you can use any compatible processor board.
Step 1
Before working on this example, make sure you have set the latest KoliadaESDK(TM). For information on KoliadaESDK(TM) setup see here.
Note: After making sure the SDK is setup correctly, the BuildConfig needs be built & flashed only if you have changed any board configuration. You can find an example BoardConfig project here: KoliadaESDK(TM)/examples/BoardConfig.
In this particular example there are no I/O configuration changes, and we can move on to build and flash the TestFlash application.
Step 2
You find the source for TestFlashIO here KoliadaESDK(TM)/examples/TestFlashIO.
Now build the project and hit 'Download to Target'.
You should see the following output on your serial terminal
Fig. 2: Output of FlashIO Example
The output shows the TestFlashIO program being loaded which performs the memory operations erase/write/fetch and exits out of the application and back to KoliadaES.
Explanation
void TestFlashIO() { // test FLASH i/o debug(">>%s\n", __FUNC__); // 'safe' test addresses depend on the platform! //#define TEST_ADDR 0x14014 #define TEST_ADDR 0x20000 debug("Testing erase/write/fetch to 0x%06lx\n", (UInt32) TEST_ADDR); debug("bank %u\n", FlashBank(TEST_ADDR)); debug("page %u\n", FlashPage(TEST_ADDR)); debug("offset %u\n", FlashPageOffset(TEST_ADDR)); // erase the page flash.Erase(FlashPage(TEST_ADDR)); // takes 20 mS!! // can only write from RAM (strings are in FLASH) byte buf[64]; memset(buf, 0, sizeof(buf)); memcpy(buf, "Hello World", 12); // write to FLASH flash.Write(FlashAddr(TEST_ADDR), buf, 16); // 1 takes 100 uS 100/byte // 4 takes 210 uS 52/byte // 8 takes 250 uS 31/byte // 16 takes 475 uS 7/byte // reset the RAM buf memset(buf, 0, sizeof(buf)); // read from FLASH flash.Fetch(FlashAddr(TEST_ADDR), buf, 4); // 4 takes 175 uS 52/byte debug("%s\n", buf); debug("\n<<%s\n", __FUNC__); }
We can walkthrough TestFlashIO.c now.
FlashBank(TEST_ADDR), FlashPage(TEST_ADDR), FlashPageOffset(TEST_ADDR) specify the memory bank, page and page offset of the given address. The memory is erased using flash.Erase(FlashPage(TEST_ADDR)); and hello world is written to the memory address using flash.Write(FlashAddr(TEST_ADDR), buf, 16); and witten data can fetched from memory using flash.Fetch(FlashAddr(TEST_ADDR), buf, 4);