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.

How can i operate specific flash bank ? help

Other Parts Discussed in Thread: CC2541, CC2540

Hi,

i need help,I use cc2541.

HalFlashWrite(0x8000,buf,0x10);

after this code,buf's content write to which bank ?

so my question is,

how can i operate specific bank?

wait for your answer,thanks.

//blew//TI cc2541 source code about flash operate.

void HalFlashWrite(uint16 addr, uint8 *buf, uint16 cnt)
{
#if (defined HAL_DMA) && (HAL_DMA == TRUE)
halDMADesc_t *ch = HAL_NV_DMA_GET_DESC();

HAL_DMA_SET_SOURCE(ch, buf);
HAL_DMA_SET_DEST(ch, &FWDATA);
HAL_DMA_SET_VLEN(ch, HAL_DMA_VLEN_USE_LEN);
HAL_DMA_SET_LEN(ch, (cnt * HAL_FLASH_WORD_SIZE));
HAL_DMA_SET_WORD_SIZE(ch, HAL_DMA_WORDSIZE_BYTE);
HAL_DMA_SET_TRIG_MODE(ch, HAL_DMA_TMODE_SINGLE);
HAL_DMA_SET_TRIG_SRC(ch, HAL_DMA_TRIG_FLASH);
HAL_DMA_SET_SRC_INC(ch, HAL_DMA_SRCINC_1);
HAL_DMA_SET_DST_INC(ch, HAL_DMA_DSTINC_0);
// The DMA is to be polled and shall not issue an IRQ upon completion.
HAL_DMA_SET_IRQ(ch, HAL_DMA_IRQMASK_DISABLE);
HAL_DMA_SET_M8( ch, HAL_DMA_M8_USE_8_BITS);
HAL_DMA_SET_PRIORITY(ch, HAL_DMA_PRI_HIGH);
HAL_DMA_CLEAR_IRQ(HAL_NV_DMA_CH);
HAL_DMA_ARM_CH(HAL_NV_DMA_CH);

FADDRL = (uint8)addr;
FADDRH = (uint8)(addr >> 8);
FCTL |= 0x02; // Trigger the DMA writes.
while (FCTL & 0x80); // Wait until writing is done.
#endif
}

  • Flash is read 4 bytes at a time. The address you pass to HalFlashWrite is the 4 byte address, or physical address/4.

    The upper 3 bytes of the 19 bit logical address determines the page. All pages other than page 0 have the address range 0x8000 - 0xFFFF because they exist in the upper 32KB of the 64KB XDATA. Page 0 will always be the lower 32KB of CODE memory. 

    Examples: 0x28000 is on page 2, 0x5D000 is on page 5, 0x62000 is invalid because only page 0 has the range 0x0000-0x7FFFF

    Suppose we want to read logical address 0x49000, which is at page 4. 0x8000 is added to specify the upper 32KB of Xdata. Therefor the physical address is 0x21000 (4*0x8000+0x9000 - 0x8000).  To read/write this address using HalFlash functions, set addr = 0x9400 (0x21000 >> 2).

  • I‘m very thankful for your answer.

    i got something from your answer.

    logaddr -->phyaddr-->flashcontrolleraddr

    0x49000-->0x21000-->0x8400

    below

    //--------------------------//

    Examples: 0x28000 is on page 2, 0x5D000 is on page 5, 0x62000 is invalid because only page 0 has the range 0x0000-0x7FFFF

    this example i can not understand clearly.

    0x28000--->0x10000--->0x4000--->on page 2    //why ?

    0x5d000--->0x2d000--->0xb400--->on page 5    //why ?

    0x62000--->0x2a000--->0xa800--->on page 0    //why  ? //invaild  ? 

    6*0x8000+0x2000-0x8000 = 0x2a000 

    0x2a000>>2 = 0xa800

    //---------------//

    The upper 3 bytes of the 19 bit logical address determines the page.

    this sentence i also cannot understand.

    CC2540/1   --->256KB flash(my device) --->0~7(eight bank)---> a bank = 32KB 

    so 32KB*8 = 256KB 

    another a page = 2KB  so a bank = 16page .

    am i was right ??

    //------------------------------//

    hope your reply,thanks in advance.

     

  • Everything you're saying is correct. You need to understand why.

    "0x62000--->0x2a000--->0xa800--->on page 0    //why  ? //invaild  ? "

    Look at the TI CC2540/41 User's Guide: http://www.ti.com/lit/ug/swru191e/swru191e.pdf

    Look at figure 2-1 on page 26

    The flash banks will appear in the upper 32KB of the 64KB datasheet.  The logical address 0x62000 means you are accessing address 0x2000, which is 1 memory space above the SRAM in XDATA.  For example address 0x1000 would be accessing the 0x1000th (4096th) byte of SRAM. the Flash reads/writes must be in the 0x8000-0xFFFF range because that's where they exist in XDATA.

    "The upper 3 bytes of the 19 bit logical address determines the page."

    16 bits are needed to make the number 0xFFFF. 19 bits are needed to make the number 0x7FFFF. 0x7FFFF is the highest address of page 7, and the end of our memory. The greatest 3 bits are the page number:

    0x48000 page 4, upper 3 bits = 100 =4

    0x58000 page 5, upper 3 bits = 101 = 5

    Also, look here http://e2e.ti.com/support/low_power_rf/f/156/p/279926/977092.aspx#977092

    Pages are a different issue. I'm not sure how the HAL is programmed to handle paging. I'll read up on it and come back

  • ha ha ... my program works.

    thanks again.

    //---------------------------------------------//

    do you know FMAP ?

    at the begin ,i think FMAP can switch bank, so it makes me very confused.

    although the problem is solved,i don' t know the function of FMAP.

    i use you tell me the information to operate flash , and i indeed operate '256KB' flash .

    but i don't use FMAP.

    //----------------------------------------------------//

    how can i operate bank0 (page0~page15)?

    because the address is forbid (xbank 0x8000 ~ 0xFFFF  // As you say  As user's guide say)

    so i just can use seven bank of 224KB to store my code (32K*7).

    ps :of couse ,224KB is ' very ' enough , haha.

    //----------------------------------------------------------------------//

    thanks again

  • I'm glad you got your program working. 


    FMAP controls what 32KB bank is mapped into the upper 32KB of CODE memory. You should NEVER change FMAP. the IAR compiler will automatically create and executable to change FMAP for you.

    You should not try to access bank 0 (pages 0-15). Bank 0 will always hold the lower 32KB of your code memory. if you alter this, you will be altering you program code. The rest of your CODE memory will be described under the " SEGMENTS IN ADDRESS ORDER " part of the .map file. Check the IAR Compiler Reference for specifics on how to read this file.

    MEMCTR controls what 32KB bank is mapped into the uppper 32KB of XDATA.

    The 256Kb of memory is divided into 8 banks and 128 pages. I only see pages used when erasing memory. You have to erase a whole page at once. I don't think the pages are used for much else.

    HalFlashRead() takes a page number as an argument, but the function uses the page number to calculate what bank is needed. Asking for the page number is kind of a trick. You have to do some math to figure out what page your flash memory exists in before using HalFlashRead()

    Use HalFlashRead() and HalFlashWrite() to access flash and don't worry about accessing specific banks. Those two functions make life simple and easy.

  • Hello Peter, 

    Can you explain the procedure of finding the correct arguments for HalFlashRead() ? I tried several times bu tI didn't make it to work.

    What is hiding behind the tricks that "You have to do some math to figure out what page your flash memory exists in before using HalFlashRead()"

    Thank you!

  • 您好 :

        1 我想保存sensor的30k左右数据在256k flash,256k flash中哪些地方可以存放数据,

    2  请问xiao qi 能否把您的这个2个函数参考代码 发到我wanghgsz@163.com 邮箱 我参考一下,我测试代码导致CC2541不断复位

    HalFlashWrite();
    HalFlashRead();

    谢谢

  • Hello,

    Thank you very much for your valuable info. I understood many things from your description.
    I am new at the programming of cc2540 and I would like to verify that I can write "something" to the internal flash and then to read this "something" .
    1) Could you please help me which example to use? I have already started with Simple BLE Peripheral, changing the flash.h and flash.c
    2) Also, please could you explain me which is the difference between HalFlashWrite() and OSAL_snv_write() ? These funtions do the same operation and both of them addressed to the internal flash? I don't understand!
    3) If I successfuly define the functions of read and write of the NVM Flash, how I can check/verify that I have successfully written something and I have successfully read something ?

    Thank you in advance. I hope to receive any answer. Waiting for it.

    Kind Regards,
  • Hello,

    Any example of HalFlashRead() and HalFlashWrite() for 128K flash of cc2540 ?

    Thank you,
  • The CC2540 and CC2541 have the same flash control registers. The code is the same.
  • Thank you but I don't ask this! My question is how can write in a specific address something and then read to this adddress in rder for me to verify that I can store data in the flash and then to read them (for example through the memory view of IAR). Is there any example for cc2540?
  • Hello Peter,

    The 128K flash of cc2540 follows the same rules? Also, could you please provide some parts of the code of HalFlashWrite() and HalFlashRead() in order for us to understand ?
    Thank you
  • Ah. I thought you had example code for the CC2541 and wanted separate code for the CC2540. This flash code will work on both:

    #include "osal_snv.h"
    #define BLE_NVID_TEST 0x80
    static uint32 iWrite = 0xcafe;
    static uint32 iRead = 0x0;
    VOID osal_snv_write(BLE_NVID_TEST, sizeof( uint32 ), &iWrite );
    VOID osal_snv_read( BLE_NVID_TEST, sizeof( uint32 ), &iRead );

    osal_snv uses HAL flash functions. In IAR, put a breakpoint on that code. Click into those functions in debug mode and you will see the HAL functions used. I don't remember how to use the HAL functions directly...
  • Dear Peter,

    Please Could you help me?
    I am working on cc2540 128K flash and I would like to write something in the internal flash and then to read it in order to verify the process. I follow your valuable guidelines and the code is the following for the logical addres 0x49000:

    EA = 0;
    HalFlashRead(0x04,0, dataread, 16);
    HalFlashErase(0x04);
    while(FCTL & 0x80);
    HalFlashRead(0x2100,0, dataread, 16);
    HalDmaInit();
    HalFlashWrite(0x49000,datawrite,1);
    while(FCTL & 0x80);
    HalFlashRead(0x2100,0, dataread, 16);

    where uint8 datawrite [16]= {0x4f, 0x6c, 0x79, 0x6d}; and uint8 dataread [];

    WHICH IS MY WRONG ?
  • You can't erase page 4. Your program code is there. I think you should take the time to read the data sheet and user's guide for this chip.

  • Hello Peter,


    Indeed I read the user guide : http://www.ti.com/lit/ug/swru191f/swru191f.pdf

    especially the pages 25-28, as well as the Chapter 6. Especially, in the section 6.3.1, there is a part of code on how to erase a page, and this concerns the HalFlashErase() which is declared in the hal_flash.c of SimpleBLEPeripheral, for example. There is no example on how to call the HalFlashRead() or HalFlashWrite(), with which parameters.

    Could you please help with any guideline or indicating to me other source in order to understand the read/write process of internal flash of cc2540 of 128K flash?

    Thank you.