Main Site Documentation

Snippet - Cerberus InternalFlashStorage


#1

Cerberus InternalFlashStorage

This class enables C# to write a byte array to the internal Cerberus Flash.
***** BE CAREFUL *****
Notice that there are no flash sectors available for this, so our current implementation uses the last 128K of the deployment area, thus reducing the deployments from 384k to 256k.

Another option would be to use sector 4, a 16Kb sector reserved for Configuration, but if we do that we should re-write whatever tinybooter has stored there. This is not currently implemented but would be easy.

Many thanks to Johny Seven for the initial code


#2

Well done. It should work fine as long as your programs do not become very large and use the entire flash deployment region.


#3

I forgot to mention that when you deploy your project, the contents of the “internalflashstorage” will probably be erased, but of course this should not be a problem in run time.


#4

I can imagine configuration values that need to survive a software update, would there be any solution for that?


#5

There is a dedicated config region


#6

How does this dedicated config section work?

I need a little space for configuration items like MAC address and such.


#7

would it be safe to use the last 1k 15-16k in sector 4?
would tinybooter be using that space or would it just be using the beginning?


#8

@ MikeCormier: We are using the last sector since our project is small.

More questions:
1 - Is it safe to use the config region?
2 - does tinybooter or CLR use that?
3 - if they do, we can always find an empty area and re-write the used area along with the new content we need, right?


#9

@ Gus or anybody else.
My question is it safe to use just the last 1k in sector 3 - the dedicated config region, for persistant storage or is there a possibility that tinybooter or CLR use that?
It would be nice to have a small amount of config data survive program updates.


#10

It is safer to use the end of deploy region. I wouldn’t use config.


#11

Hi vqp,
How you find all the Register Address (ex private const UInt32 Flash_CR = 0x40023C10;),
the Data sheet state that Address offset of the Flash control Register : 0xA0000000 + 0x40 + 0x20 * (x – 1), x = 2…4…?

Regards YuvaRaja…


#12

andre.m my last post is modified can you tell me how to find the address…?


#13

My Controller is STM32f407Zg
the Cerberus use STM32F40X both are same or different…?


#14

ok…its fine
Then how the Flash_CR Register got this 0x40023C10 Address…?


#15

Read the manual. It has register map information.


#16

Thank you guys…


#17

Hi,
I got a Flash programming manual (PM0081) from ST it is too help full for Program the FLASH
http://www.st.com/st-web-ui/static/active/en/resource/technical/document/programming_manual/DM00023388.pdf

Regards YuvaRaja…


#18

Hi vqp, when i am execute the below code, it start writing the data from the address of 6000.
Why its happening like that?
I want to write in address of 3000,for that what we have to do?
Is it correct or not…?

 InternalStorage.Write(bytes, 3000, 3000, bytes.Length);

#19

Hi the modified code is given below it over comes the previous post problems


        public static void Write(byte[] buffer, uint storageAddress, int bufferIndex, int lenght)
        {
           [b] uint address = StorageAddressBase;[/b]
            if (address > StorageAddressMax)
            {
                throw new IndexOutOfRangeException();
            }

            if (bufferIndex + lenght > buffer.Length)
            {
                throw new IndexOutOfRangeException();
            }

        [b]   if (StorageAddressMax < bufferIndex + lenght + StorageAddressBase)
            {
                throw new IndexOutOfRangeException();
            }[/b]
            try
            {
                UnlockFlash();
                if ((CR.Read() & FLASH_CR_LOCK) != 0)
                {
                    throw new NotSupportedException(); // problem unlocking 
                }

                uint myCR = CR.Read();
                myCR &= CR_PSIZE_MASK;
                CR.Write(myCR | FLASH_PSIZE_BYTE | FLASH_CR_PG);
                int count = bufferIndex;
             [b]   uint AddressOffset = storageAddress;[/b]
                while (count < (bufferIndex + lenght))
                {
                 [b]   AddressSpace.Write(address + AddressOffset, buffer, count, 1);[/b]
                    count++;
                    AddressOffset++;
                }
                CR.Write(CR.Read() & (~FLASH_CR_PG));
            }
            finally
            {
                LockFlash();
            }
        }


#20

Yes the size does not exceed to “StorageAddressMax”