Beispiel #1
0
/**
  * @brief  Erase the contents of the specified block.
  * @param  BlockAddr: The block start address.
  * @retval FC_SUCCESS, FC_ERROR_PROTECTED, FC_ERROR_OVER_TIME.
  *
  */
FC_Result FC_EraseBlock(uint32_t BlockAddr)
{
    uint8_t BlockNum = FC_BLOCK_4;

    assert_param(IS_FC_ADDR(BlockAddr));        /* Check whether it is in the flash address range */

    BlockNum = FC_AddrToBlockNum(BlockAddr);

    if (ENABLE == FC_GetBlockProtectState(BlockNum)) {
        return FC_ERROR_PROTECTED;
    }
    
    return __FC_EraseBlock(BlockAddr);
}
Beispiel #2
0
/**
  * @brief  Write data to the specified page.
  * @param  PageAddr: The page start address.
  *         Data: The pointer to data buffer to be written into the page.
  *         The data size should be 256Byte.
  * @retval FC_SUCCESS, FC_ERROR_PROTECTED, FC_ERROR_OVER_TIME.
  *
  */
FC_Result FC_WritePage(uint32_t PageAddr, uint32_t * Data)
{
    uint8_t BlockNum = FC_BLOCK_4;

    assert_param(IS_FC_ADDR(PageAddr)); /* Check whether it is in the flash address range */
    assert_param(IS_FC_PAGE_ADDR(PageAddr));    /* Check whether it is a page start address */
    assert_param(IS_POINTER_NOT_NULL(Data));

    BlockNum = FC_AddrToBlockNum(PageAddr);

    if (ENABLE == FC_GetBlockProtectState(BlockNum)) {
        return FC_ERROR_PROTECTED;
    }
    
    return __FC_WritePage(PageAddr, Data);
}
Beispiel #3
0
/**
  * @brief  Write data to the specified page.
  * @param  PageAddr: The page start address.
  *         Data: The pointer to data buffer to be written into the page.
  *         The data size should be 256Byte.
  * @retval FC_SUCCESS, FC_ERROR_PROTECTED, FC_ERROR_OVER_TIME.
  *
  */
FC_Result FC_WritePage(uint32_t PageAddr, uint32_t * Data)
{
    FC_Result retval = FC_SUCCESS;
    volatile uint32_t *addr1 = (uint32_t *) (FLASH_START_ADDR + FC_CMD_BC1_ADDR);
    volatile uint32_t *addr2 = (uint32_t *) (FLASH_START_ADDR + FC_CMD_BC2_ADDR);
    volatile uint32_t *addr3 = (uint32_t *) PageAddr;
    uint32_t counter = FC_WRITE_PAGE_OVER_TIME;
    uint32_t i = 0U;
    uint32_t *source = Data;
    uint8_t BlockNum = 0U;

    assert_param(IS_FC_ADDR(PageAddr)); /* Check whether it is in the flash address range */
    assert_param(IS_FC_PAGE_ADDR(PageAddr));    /* Check whether it is a page start address */
    assert_param(IS_POINTER_NOT_NULL(Data));

    BlockNum = FC_AddrToBlockNum(PageAddr);

    if (ENABLE == FC_GetBlockProtectState(BlockNum)) {
        retval = FC_ERROR_PROTECTED;
    } else {
        *addr1 = (uint32_t) 0x000000AA; /* bus cycle 1 */
        *addr2 = (uint32_t) 0x00000055; /* bus cycle 2 */
        *addr1 = (uint32_t) 0x000000A0; /* bus cycle 3 */
        for (i = 0U; i < FC_PAGE_SIZE; i++) {   /* bus cycle 4~67 */
            *addr3 = *source;
            source++;
        }
        __DSB();

        while (BUSY == FC_GetBusyState()) {     /* check if FLASH is busy with overtime counter */
            if (!(counter--)) { /* check overtime */
                retval = FC_ERROR_OVER_TIME;
                break;
            } else {
                /* Do nothing */
            }
        }
    }

    return retval;
}
Beispiel #4
0
/**
  * @brief  Erase the contents of the specified block.
  * @param  BlockAddr: The block start address.
  * @retval FC_SUCCESS, FC_ERROR_PROTECTED, FC_ERROR_OVER_TIME.
  *
  */
FC_Result FC_EraseBlock(uint32_t BlockAddr)
{
    FC_Result retval = FC_SUCCESS;
    uint32_t blockaddr = BlockAddr & FC_BLOCK_ADDR_MASK;
    volatile uint32_t *addr1 = (uint32_t *) (FLASH_START_ADDR + FC_CMD_BC1_ADDR);
    volatile uint32_t *addr2 = (uint32_t *) (FLASH_START_ADDR + FC_CMD_BC2_ADDR);
    volatile uint32_t *BA = (uint32_t *) blockaddr;
    volatile uint32_t counter = FC_ERASE_BLOCK_OVER_TIME;
    uint8_t BlockNum = 0U;

    assert_param(IS_FC_ADDR(BlockAddr));        /* Check whether it is in the flash address range */

    BlockNum = FC_AddrToBlockNum(BlockAddr);

    if (ENABLE == FC_GetBlockProtectState(BlockNum)) {
        retval = FC_ERROR_PROTECTED;
    } else {
        *addr1 = (uint32_t) 0x000000AA; /* bus cycle 1 */
        *addr2 = (uint32_t) 0x00000055; /* bus cycle 2 */
        *addr1 = (uint32_t) 0x00000080; /* bus cycle 3 */
        *addr1 = (uint32_t) 0x000000AA; /* bus cycle 4 */
        *addr2 = (uint32_t) 0x00000055; /* bus cycle 5 */
        *BA = (uint32_t) 0x00000030;    /* bus cycle 6 */
        __DSB();

        while (BUSY == FC_GetBusyState()) {     /* check if FLASH is busy with overtime counter */
            if (!(counter--)) { /* check overtime */
                retval = FC_ERROR_OVER_TIME;
                break;
            } else {
                /* Do nothing */
            }
        }
    }

    return retval;
}