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.

cc2640 flash read & write

Other Parts Discussed in Thread: CC2640

I have some trouble with the flash read and write on CC2640.Although i have read carefully all the relative topics,i faile to find my solution.

I am trying to realize the IAP(in application program) function on cc2640 through UART. I can write some certain bytes to the internal flash by the funtions FlashProgram() and FlashSectorErase() in the dirverlib. but the write funtion can be called only one time, and then the uart stop  echo to my input. The erase function can be called rightly.some key functions I used is listed bellow:

//Power on the VIMS domain at task_init
PRCM_PowerDomainOn(PRCM_DOMAIN_VIMS);

//************************************//
//flash erase

void flash_erase(void)
{
   //addr begin to erase
   uint32_t addr = 0x0000b000;
   //disable interrupts
   IntDisable(49);
   //do flash sector erase
   if(FlashSectorErase(addr) == 0)
    printf("erase ok!\r\n");
   //re-enable interrupts
   IntEnable(49);
}
//flash write
void flash_write(void)
{
   //addr begin to write
   uint32_t addr = 0x0000b000;
   //counters
   uint16_t i = 0;
   //data to write
   uint8_t data[256] = {0};
   //fill the data buff
   for(i = 0; i < 256; i++)
      data[i] = i;

   //disable interrupts
   IntDisable(49);
   //do flash write
   if(FlashProgram(data,addr,256) == 0)
    printf("flash write ok!\r\n");
   //re-enable interrupts
   IntEnable(49);   
}

Where did I make mistakes? Besides,I couled not find the read function in the driverlib, and tried the HalFlashRead(),but it only work when the page is 29 or 30.I don't know why.

  • I have scaned the relative topics about flash read and write,but still don't know how to read and write flash corectly.

    I am trying to realize the IAP(in application program) function on cc2640 through UART.I use the function  FlashSectorErase() and  FlahProgram() to erase and

    write some data,and it indeed works.but my problems is that the FlashProgram() can only run one time.

    some key codes are listed bellow.

    //power on VIMS in task_init process
    PRCMPowerDomainOn(PRCM_DOMAIN_VISM);
    //**********************************//
    //flash erase 
    void flash_erase(void)
    {
       //the begin address to be erased
       uint32_t addr = 0x0000b000;
       //disable general interrupts
       IntDisable(49);
       //erase a certain sector
       if(FlashSectorErase(addr) == 0)
       printf("Sector eraseed ok!\r\n");
       //enable interrupts
       IntEnable(49);
    }
    
    //flash write
    void flash_write(void)
    {
      //begin addr to be writed
      uint32_t addr = 0x0000b000;
      //for count
      uint16_t i = 0;
      //data buff
      uint8_t data[256]= {0};
      //fill in data buff
      for(i = 0; i < 256; i++)
         data[i] = i;
      //disable interrupts
      IntDisable(49);
      //write data
      if(FlashProgram(data,addr,256) == 0)
        printf("flash writed ok!\r\n");
      //enable interrupts
      IntEnable(49);  
    }

    the two functions are called by my uart command,the flash_erase() function can be called times,while the falsh_wtire() can only work one time.and the uart will have no echo any more.Where I make mistakes?

    Besides,I tryed HalFlashRead(),but it did not work, is there some guide to do flash read, just like the TI flash programmer 2 ,which can read and write freely. 

     

  • Hello,

    Are you calling the APIs in a callback function? If so, please use a task context. Also, check the implementation in osal_snv.c, you are likely not disabling the cache during the write/erase.

    Best wishes
  • JXS,

    Yes,I Transplant the "uart command" from  Linux, to call the corresponding function according to my uart input.It seems like the callback function situation.I will try to use a task context.

    JSX,Can u show me a way to read flash,such as sector read,word read,or page read? 

  • Hello,

    I would again recommend looking at osal_snv.c, it has read/write/erase examples.

    Best wishes
  • Hello JXS,

    I am sorry to pick up the old question.

    Could you please confirm that it is necessary to Disable the cache to
    Write/Erase during internal flash programming?
    Even if we are writing to a un-programmed memory block?

    Best Regards
    Kummi
  • Hi Kummi,

    Yes, you should disable the cache for both programmed and unprogrammed blocks.

    In additional to what JXS referenced, take a look at BIM for onchip oad for a Internal read/write example. (oad_target_internal_flash.c)

    Feel free to open another thread referencing this if you have additional questions, (so it doesn't accidentally get missed)

    Regards,
    -Rebel