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 not reading from Flash

Other Parts Discussed in Thread: CC2530

Hi,

I am trying to read from Flash adress 0x7900. But data is being read from Xdata 0x7900. I am not able to figure out why ?!!

I am Writing to Flash using DMA. I am able to get it write into 0x7800, 0x7900... but can't it to write into 0xA000. Is it locked? if so how to unlock?

Any info on Memory mapping in CC2530 and sample code to read from flash will be greatly appreciated. The datasheet  has very less info.

 

  • Hi!

    Please see http://focus.ti.com/lit/ug/swru191b/swru191b, section 2.2.1, for memory mapping.

    For sample code, please see any of our sample applications, e.g. in RemoTI. This package includes lots of detailed documentation of the code, see the Documents folder.

     

    Best regards,

    Torbjørn 

  • Hariprakash S R said:
    I am trying to read from Flash adress 0x7900. But data is being read from Xdata 0x7900. I am not able to figure out why ?!!

    You have to read from a code memory address (use MOVC in assembly or a pointer to __code in IAR C), or read from address 0xF900 with bank 0 mapped in the XBANK area (see the User Guide).

    Hariprakash S R said:
    I am Writing to Flash using DMA. I am able to get it write into 0x7800, 0x7900... but can't it to write into 0xA000. Is it locked? if so how to unlock?

    It might be, if so, erase the upper flash page to unlock. However, what do you mean by "can't write into 0xA000"? What happens if you try to do so?

    Hariprakash S R said:
    Any info on Memory mapping in CC2530 and sample code to read from flash will be greatly appreciated. The datasheet  has very less info.

    This information is found in the CC253x user guide. The data sheet is not intended to give the full information on the chip; the user guide gives all the information on how to operate it, while the data sheet gives information on the electrical parameters, mounting and so on.

  • Hi!!

    Thanks for the info.

    Best regards,

    Hariprakash

  • Hi hec!!

    I am able write and read till address 0x8000. From 0x8000 data doesn't get written. Even i tried erasing upper flash page to unlock as suggested by you. It din't make any difference.

    What would be the reason for data not getting written from 0x8000 onwards?


    Thanks & regards,

    Hariprakash.

  • Hi,

    What do you mean by "doesn't get written"? Do you check it by reading, or do you see a problem with the flash controller when you try to write?

    Is address 0x8000 the byte address used when reading or the 32-bit word address used when writing?

    First of all, what is the flash size of your CC2530? If the address 0x8000 was a byte address, this makes sense if you have the CC2530F32, and if it was a word address, it makes sense if you have CC2530F128.

    If the address 0x8000 was a byte address and your CC2530 has more than 32 KB flash, note that the address 0x8000 corresponds to a bank boundary. If you read from code memory space, you need to make sure that you map the correct flash bank into the bank area (upper 32 KB) of the code memory space. If you read from XDATA memory, you need to make sure that you select the correct bank in the XBANK area using the MEMCTR register.

     

  • Collected from ZStack CC2530 product. This document can be found inside the file called hal_flash.c

     

    /**************************************************************************************************
     * @fn          HalFlashRead
     *
     * @brief       This function reads 'cnt' bytes from the internal flash.
     *
     * input parameters
     *
     * @param       pg - A valid flash page number.
     * @param       offset - A valid offset into the page.
     * @param       buf - A valid buffer space at least as big as the 'cnt' parameter.
     * @param       cnt - A valid number of bytes to read.
     *
     * output parameters
     *
     * None.
     *
     * @return      None.
     **************************************************************************************************
     */
    void HalFlashRead(uint8 pg, uint16 offset, uint8 *buf, uint16 cnt)
    {
      // Calculate the offset into the containing flash bank as it gets mapped into XDATA.
      uint8 *pData = (uint8 *)(offset + HAL_FLASH_PAGE_MAP) +
                     ((pg % HAL_FLASH_PAGE_PER_BANK) * HAL_FLASH_PAGE_SIZE);
      uint8 memctr = MEMCTR;  // Save to restore.

    #if (!defined HAL_OAD_BOOT_CODE) && (!defined HAL_OTA_BOOT_CODE)
      halIntState_t is;
    #endif

      pg /= HAL_FLASH_PAGE_PER_BANK;  // Calculate the flash bank from the flash page.

    #if (!defined HAL_OAD_BOOT_CODE) && (!defined HAL_OTA_BOOT_CODE)
      HAL_ENTER_CRITICAL_SECTION(is);
    #endif

      // Calculate and map the containing flash bank into XDATA.
      MEMCTR = (MEMCTR & 0xF8) | pg;

      while (cnt--)
      {
        *buf++ = *pData++;
      }

      MEMCTR = memctr;

    #if (!defined HAL_OAD_BOOT_CODE) && (!defined HAL_OTA_BOOT_CODE)
      HAL_EXIT_CRITICAL_SECTION(is);
    #endif
    }

    /**************************************************************************************************
     * @fn          HalFlashWrite
     *
     * @brief       This function writes 'cnt' bytes to the internal flash.
     *
     * input parameters
     *
     * @param       addr - Valid HAL flash write address: actual addr / 4 and quad-aligned.
     * @param       buf - Valid buffer space at least as big as 'cnt' X 4.
     * @param       cnt - Number of 4-byte blocks to write.
     *
     * output parameters
     *
     * None.
     *
     * @return      None.
     **************************************************************************************************
     */
    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
    }

    /**************************************************************************************************
     * @fn          HalFlashErase
     *
     * @brief       This function erases the specified page of the internal flash.
     *
     * input parameters
     *
     * @param       pg - A valid flash page number to erase.
     *
     * output parameters
     *
     * None.
     *
     * @return      None.
     **************************************************************************************************
     */
    void HalFlashErase(uint8 pg)
    {
      FADDRH = pg * (HAL_FLASH_PAGE_SIZE / HAL_FLASH_WORD_SIZE / 256);
      FCTL |= 0x01;
    }

     

    Collected from ZStack CC2530 product. This document can be found inside the file called hal_flash.c