Yes, The array elements are just constants that the program will use. so I think it is better to load it to external flash using dfu-util as I dont have to recompile the program again when I want to change the values of the array later.
Can you the command I should use to load the arrays to external memory with dfu-util? How do I store the array elements in the file, do I have to change uint16_t array to a byte array?
ps. I tried declaring the arraysas a const but the program flash (internal flash) was not big enough to accomodate them.
Another consideration: since you block potentially indefinitely waiting on Serial.available(), both in setup() and on every single call to loop(), you are probably being disconnected from the Cloud due to timeout.
Try returning early from your loop so the Core can talk to the Cloud and call you again in a few milliseconds:
void loop() {
uint8_t _read[4];
/***** Instead of spin-wait, be nice, share. :) *****/
if (Serial.available() == 0)
return;
Serial.print("Value In array = ...");
// ...
@Dave wrote up some nice instructions for using dfu-util to load new keys into the external flash so perhaps he can comment too. The basic command below uses your 0x81000 address from the above code:
dfu-util -d 1d50:607f -a 1 -s 0x00081000 -v -D myfile.bin
Bad things can happen to your core if you mistype here, so be careful!
I am not sure what advice to give on getting your data into a binary file (myfile.bin); there are lots of ways to do that. It sounds like you have a C array initializer like
uint16_t array[] = {0x1234, 0xabcd, ...};
for the 16-bit data. The code you wrote above wants to store LSByte first, so you might have to reshape your array for the binary file so that the binary file was 0x34, 0x12, 0xcd, 0xab,⌠for the sample array above.
Well, Turning off interrupts for the CC3000 WiFi module during data access to external flash didnt help at all.
There is a 3 sec delay in loop() and there are only few writes to seial port so I dont think the while loop caused the hanging.
I have to write a C program to splitup the bytes of the elements of the array (uint16_t[], uint32_t []), rearrange it and save it to a .bin file. Do I write them one after another or every new line?
I dont really think this is convenient way of storing data into memory.
A hex editor may be the kind of program you need to just copy and paste into a binary file with a little hand editing. On mac, I use Hex Fiend. Honestly I use this program all the time while working on the core-communication-lib (combined with the hexdump command in my terminal) to compare encrypted versions of files, write CoAP message by hand, create test fixtures, inspect keys, etc. For windows or linux, google hex editor.
Chiming to recommend http://www.ultraedit.com/ Ultraedit for windows/mac/linux Iâve used it for many many years and I love it for hex files, comparing files (UltraCompare), creating wonderful parsing macros, and also use it to search through all of the files in a directory looking for code fragments or keywords.
I think you need to write an even number of bytes. You are writing nine bytes according to dfu-util.
The error at the end âError during download get_statusâ is a normal error that you always get.
iMac27:SparkCore bko$ dfu-util -d 1d50:607f -a 1 -s 0x00081000:leave -v -D test.bin
dfu-util 0.7
Copyright 2005-2008 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2012 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to dfu-util@lists.gnumonks.org
Filter on vendor = 0x1d50 product = 0x607f
Opening DFU capable USB device... ID 1d50:607f
Run-time device DFU version 011a
Found DFU: [1d50:607f] devnum=0, cfg=1, intf=0, alt=1, name="@SPI Flash : SST25x/0x00000000/512*04Kg"
Claiming USB DFU Interface...
Setting Alternate Setting #1 ...
Determining device status: state = dfuERROR, status = 10
dfuERROR, clearing status
Determining device status: state = dfuIDLE, status = 0
dfuIDLE, continuing
DFU mode device DFU version 011a
Device returned transfer size 1024
File too short for DFU suffix
Warning: File has no DFU suffix
DfuSe interface name: "SPI Flash : SST25x"
Memory segment at 0x00000000 512 x 4096 = 2097152 (rew)
Downloading to address = 0x00081000, size = 8
Poll timeout 50 ms
Download from image offset 00000000 to memory 00081000-00081007, size 8
Poll timeout 30 ms
File downloaded successfully
Transitioning to dfuMANIFEST state
Error during download get_status
bState = 10 and bStatus = 14
I got that , thats why I immediately tried to delete my post.
Downloading is successful now. Another problem is : In my application I want to read the data from that address but after I load the code to the spark, the spark is blinking blue again.
The problem not with the array, as it is blinking blue after removing the allocations.
I believe the problem is accessing a specific address in the external flash memory using sFLASH_ReadBuffer() without erasing a page and writing some data to it.
when I add erasing and writing data ( 200 bytes), it reads out the correct value. Some thing is wrong. I think I broke the board. Because I had another spark core board and reading from the external flash is working, with no need to erase first.
It sounds like your board might need a reset that is beyond the factory reset. I know that all of the flash can be restored or recreated, but you probably need @Dave or someone else from to help you more with that.
Finally, after a lot of Factory resets, it is working now.
I am able to write to external flash memory and read the data from my application.
one little problem, dfu-util writes the ASCII values of each number in the file and puts it in the flash as a byte. Example if there is 1234 in the file, the four bytes in flash are flash contains 49, 50, 51, 52.
I dont like the way it is getting stored in flash as I have to recover the number 1234 from those ascii values, but hey it is working.
I got an efficient EEPROM library âEMULATEDâ in Internal Flash of STM32 (The space between Bootloader and System Flags). Max 255 bytes. Configurable using EEPROM_SIZE define.
Thanks! Now I can go fishing tomorrow, having erased this TODO from my calendar.
Seriously, I had planned to write this, based on the same ST app note you used (and didn't credit? :-P) Hadn't thought of squeezing into that unused Flash space, though. Nice!