Let's get (non)volatile

Hi @bko

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.

regards,
Muez

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 = ...");
  // ...
1 Like

Hi @Muez

@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.

1 Like

@bko @zachary @Dave

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.

regards,
Muez

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.

Hi Guys,

I appreciate a good hex editor as much as the next guy and you’ll have pry emacs and hexl-mode out of my cold, dead fingers, but…

I think he has the data in {0x1234, 0xabcd…} format already, so maybe a C or Python program on a desktop would be faster for the 20KB+ array.

3 Likes

Hi @Muez

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

Hi @bko,

I got that :smile:, 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.

Any idea why that could be?

Muez

I think you have to running out of memory and clobbering something. Do you still allocated large arrays?

When you compile locally with make clean all, what are the last lines out? Something like this:


arm-none-eabi-size --format=berkeley core-firmware.elf
   text	   data	    bss	    dec	    hex	filename
  83164	   2964	  11500	  97628	  17d5c	core-firmware.elf

The RAM used is data+bss; the FLASH used used text+data.

Hi @bko

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 :spark: to help you more with that.

@Muez could you do a factory reset and see if everything goes well first? :slight_smile:

It’s not going to be difficult to fix even if something got overwrite in the External flash.

Let me know :smile:

Hi @kennethlimcp

Factory reset didnt help, it is still not working .

Muez

What’s happening now? Just blinking blue? Then are you able to send wifi credentials over?

Hi @kennethlimcp, @Dave @zach @zachary @satishgn

It just blinks blue.
I have serial print statements and they are not getting printed.

But if I erase, write some data and then read, it works perfectly, very wierd.

regards

@muez,

Let me maybe put it more clearly.

  1. Factory reset your core

  2. Send the wifi credentials using Tinker App or USB

  3. The core should connect to the cloud, blink magenta and eventually become breathing cyan.

Can you verify this works?

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.

Muez

1 Like

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.

https://github.com/spark/core-firmware/tree/feature/flash-eeprom-emulation

Provided Arduino APIs : EEPROM.write() and EEPROM.read() for accessibility.

Planning to add conditional compilation code for CC3000 NVMEM as an alternative if that helps.

7 Likes

Thanks! Now I can go fishing tomorrow, having erased this TODO from my calendar. :smiley:

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!