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.

CC2530 save Data in intern flash

Other Parts Discussed in Thread: CC2530

HIi,

I use the CC2530ZDK module to implement a ZigBee Device. So I will use the intern flash to save my sensors Data (16 Bytes in one day). I will reserv 2 Pages for this.

the 16 bytes can Be saved as structure or Array[16];

so how can I reserv 2 Pages to only save this data (reserv code or varaibles to use this Pages).

this reserved pages of the flash should be errased by Programming. Then I will append the data until the 2 pages are ful from data so I can re-errase it to begin from the firs Adress inthis Pages.

Any API Funktion to do this? and examples ? 

  • The OSAL API for non-volatile memory offers everything you need - please check out this document:

    C:\Texas Instruments\ZStack-CC2530-2.4.0-1.4.0\Documents\OSAL API.pdf

    In Chapter 10 you will read all about it - for you 16 bytes of sensors data you can create a new NV item with an Id in the range of 0x0401-0x0FFF.

     

  • Thank you for Help,

    I do not will use the API while it copie the flash page and write the Item with the specific ID then erase the page and rewrite it. (more ersae cycles)

    my Idee: in the linker should reserve two Pages for my data (with specific name e.g. SensorData ). than I have to put my variable with @SensorData in this memory blocks.

    at the beginning the flash is ersaed.
    write first block of data (16 bytes) at the beginning of the first page.
    look for the 0xFF then write next 16-byte block,
    look for the next 0xFF and write the next 16-bytes of data. ....etc  (two pages with 1024 => 2048/16bytes = 128 time for 4 pages 256 times)
    if the reserved Memory is full from Data (128 Blocks of 16 bytes) . reserved flash Memory should be ersed and beginn to save data at the first address from the reserved flash.

    so I can reserv erase cycles.

    how can do this. ? wich linker file should I change and how? wich pages(address ) can I use?

  • So, similar to OSAL_Nv, you will have a special "SensorData_NV". Thus, just copy what is done for OSAL_Nv - study how the system makes space for the NV pages with the variable '_nvBuf', how the IAR #pragma is used to place it, and how that pragma is defined in the linker file. Finally, you should be able to access your sensor data pages with the existing HalFlashRead() and HalFlashWrite(), using parameters that correspond to your sensor data pages, of course.

  • Hi,

    Now I receive my Hardware and can test my firmeware. So Writing in flash isn´t work.

    I reserve in Linker file a memory blolck at the start Address 0x7C000 the page 120 (2048 Bytes). using  #pragma Data should be saved in MyData Struct  (16 bytes) at this address.

    SO using the function  halflashwrite((uint16) &myData, data, 4);  dose not write in the flash.

    I think I tack a mistak in address. Itry deviding by 4 but it dosn´t work ?

    Address should uint16 and in my case it ist 0x7C000;

    thanks

  • Hi,

    I study this example. I and try do this but the the page 120 in flash is starting on 0x7C000-7C7FF(information in the  map file) . and this is not uint16 address.

    the function halflashwrite need 16bit address. so in my example this address 0xC000  is passed to the function?

     

  • An address like 0x7C000 is for the IAR debugger.

    After reading the data sheet for the CC2530, you see that there is 256K of flash, accessed as 128 2K pages organized into 8 banks of 16 pages each and that the minimum writable word size is 4 - all of this is summarized by compiler defines in hal_board_cfg.h - use those definitions to achieve addresses.

    So what the IAR debugger accesses as 0x7C000 is the 8th page in Bank 7, or the 7 X 16 + 8 --> flash page 120.

    Thus, the "long" address will be "120 X HAL_FLASH_PAGE_SIZE"

    But dealing with uint32 is very clumbsy and slow for the 8051, so many attempts are made to keep things down to uint16 sizes - such as the write address parameter in HalFlashWrite() which is especially useful since it corresponds with the minimum writable word size anyway - thus the "short" address will simply be

    "120 X HAL_FLASH_PAGE_SIZE / HAL_FLASH_WORD_SIZE"

    All of this could have been gleaned from simply skimming the code in OSAL_Nv.c

     

     

     

  • thank you for helping.

    and sorry to confuse you (sorry for my bade English). your explanation is very good and I understand it.

    in other posting I found this "Thus the uint16 is actually address bits 17..2 with address bits 1..0 assumed to be zero.  Note that the address bits 17..2 will fit within a uint16 after dividing by 4"

    I understand that Actually address is in my example

    &MyDat =  0x7C000

    so I have to do this:         uint16 Add = (uint16) (&MyData / 4) = 0xF000 .

    it dose not  work before  while I forget the parentheses.  (uint16) &MyData / 4

    is my understanding and analysing correct ?

    Regards

  • You need to study some more my previous post - the address 0x7C000 does not exist on the CC2530, it is an imaginary address used by the IAR debugger.

     

     

  • sorry but now I am confusing more.

    OK I will ask in other way : assuming I reserve a memory block in linker file nvMyData without looking in map file and IAR debugger (So i do not know the hex address) than use 

    #pragma location="nvMyData"

    __no_init myStruct  _nvBuf[128];  // myStruct is 16 bytes long

    #pragma required=_nvBuf

    now will write data in _nvBuf[1]. how can I do this?

    halflashwrite(wich short address?????, data, 4);

    PS: I am not in office so I can not post my source code parts!

    thanks

     

  • Hi,

    this is my Source code test:
    in Linker File :
                                  // MY test Flash reservation
                                 -D_MyNVData_SPACE_START=(_ZIGNV_ADDRESS_SPACE_START-0x800)
                                 -D_MyNVData_SPACE_END=(_MyNVData_SPACE_START+0x7FF)
                                 -Z(CODE)MyNVData_SPACE=_MyNVData_SPACE_START-_MyNVData_SPACE_END

    in App.c
                             #pragma location="MyNVData_SPACE"
                             __no_init strDataInFlash _nvDatenBuf[128];  // 128 Datensätze (strDataInFlash is a structur with 16 Bytes length)
                             #pragma required = _nvDatenBuf
    how can I write to _nvDatenBuf[index]???

    I used this HalFlashWrite( shortAdd ??, (uint8*) &strTest, cnt); but the Address as you mentioned is false.

    How can I get (calcultae) the short addres from the addres of the variable _nvDatenBuf ??

    thanks

  • Hi,

    now I use the solution as you mentioned in the previous posting ( normaly I will not use any flash mapping, but if no other solution I will do it) 

    __no_init strDataInFlash nvDatenBuf[128] @ 0xF800
    #define DataFlashPg  31

    my Probleme now is this page of  flash is not erased after dowlouding the Firmeware (in project options the erase flash is checked).

    I will that this page at the 1st time after downloding the firmeware to be erased. than I can write data and erase it programaticly.

    in the linker file I have this as in your posting example

    // Define segments for const data in flash.
    // First the segment with addresses as used by the program (flash mapped as XDATA)
    -P(CONST)XDATA_ROM_C=0x8000-0xFFFF
    //
    // Then the segment with addresses as put in the hex file (flash bank 1)
    -P(CODE)XDATA_ROM_C_FLASH=0x18000-0x1FFFF
    //
    // Finally link these segments (XDATA_ROM_C_FLASH is the initializer segment for XDATA_ROM_C,
    // we map the flash in the XDATA address range instead of copying the data to RAM)
    -QXDATA_ROM_C=XDATA_ROM_C_FLASH

     

    thanks  

  • Hi,

    now I use the solution as you mentioned in the previous posting ( normaly I will not use any flash mapping, but if no other solution I will do it) 

    __no_init strDataInFlash nvDatenBuf[128] @ 0xF800
    #define DataFlashPg  31

    my Probleme now is this page of  flash is not erased after dowlouding the Firmeware (in project options the erase flash is checked).

    I will that this page at the 1st time after downloding the firmeware to be erased. than I can write data and erase it programaticly.

    in the linker file I have this as in your posting example

    // Define segments for const data in flash.
    // First the segment with addresses as used by the program (flash mapped as XDATA)
    -P(CONST)XDATA_ROM_C=0x8000-0xFFFF
    //
    // Then the segment with addresses as put in the hex file (flash bank 1)
    -P(CODE)XDATA_ROM_C_FLASH=0x18000-0x1FFFF
    //
    // Finally link these segments (XDATA_ROM_C_FLASH is the initializer segment for XDATA_ROM_C,
    // we map the flash in the XDATA address range instead of copying the data to RAM)
    -QXDATA_ROM_C=XDATA_ROM_C_FLASH

     

    thanks  

  • Hi,

    now I use the solution as you mentioned in the previous posting ( normaly I will not use any flash mapping, but if no other solution I will do it) 

    __no_init strDataInFlash nvDatenBuf[128] @ 0xF800
    #define DataFlashPg  31

    my Probleme now is this page of  flash is not erased after dowlouding the Firmeware (in project options the erase flash is checked).

    I will that this page at the 1st time after downloding the firmeware to be erased. than I can write data and erase it programaticly.

    in the linker file I have this as in your posting example

    // Define segments for const data in flash.
    // First the segment with addresses as used by the program (flash mapped as XDATA)
    -P(CONST)XDATA_ROM_C=0x8000-0xFFFF
    //
    // Then the segment with addresses as put in the hex file (flash bank 1)
    -P(CODE)XDATA_ROM_C_FLASH=0x18000-0x1FFFF
    //
    // Finally link these segments (XDATA_ROM_C_FLASH is the initializer segment for XDATA_ROM_C,
    // we map the flash in the XDATA address range instead of copying the data to RAM)
    -QXDATA_ROM_C=XDATA_ROM_C_FLASH

     PS: is ZigBee stack using this Page at download time. so that is wile I I have data saved in this Pages afer downloading the firmeware?

    thanks