示例#1
0
// See flash.h for documentation of this function.
status_t flash_read_once(flash_driver_t * driver, uint32_t index, uint32_t *dst, uint32_t lengthInBytes)
{
    if (dst == NULL)
    {
        return kStatus_InvalidArgument;
    }

    status_t returnCode = flash_check_access_ifr_range(driver, index, lengthInBytes);
    if (kStatus_Success != returnCode)
    {
        return returnCode;
    }

    // pass paramters to FTFx
    FTFx_WR_FCCOBx(FTFx, 0, FTFx_READ_ONCE);
    FTFx_WR_FCCOBx(FTFx, 1, index);

    // calling flash command sequence function to execute the command
    returnCode = flash_command_sequence();

    if (kStatus_Success == returnCode)
    {
        *dst = kFCCOBx[1];

        if ((index >= FLASH_PROGRAM_ONCE_MIN_ID_8BYTES) &&
                (index <= FLASH_PROGRAM_ONCE_MAX_ID_8BYTES) &&
                (lengthInBytes == 8))
        {
            *(dst + 1) = kFCCOBx[2];
        }
    }

    return returnCode;
}
示例#2
0
// See flash.h for documentation of this function.
status_t flash_verify_erase_all(flash_driver_t * driver, flash_margin_value_t margin)
{
    if (driver == NULL)
    {
        return kStatus_InvalidArgument;
    }

    // preparing passing parameter to verify all block command
    FTFx_WR_FCCOBx(FTFx, 0, FTFx_VERIFY_ALL_BLOCK);
    FTFx_WR_FCCOBx(FTFx, 1, margin);

    // calling flash command sequence function to execute the command
    return flash_command_sequence();
}
示例#3
0
// See flash.h for documentation of this function.
status_t flash_erase_all(flash_driver_t * driver, uint32_t key)
{
    if (driver == NULL)
    {
        return kStatus_InvalidArgument;
    }

    // preparing passing parameter to erase all flash blocks
    // 1st element for the FCCOB register
    FTFx_WR_FCCOBx(FTFx, 0, FTFx_ERASE_ALL_BLOCK);

    // Validate the user key
    status_t returnCode = flash_check_user_key(key);
    if (returnCode)
    {
        return returnCode;
    }

    // calling flash command sequence function to execute the command
    returnCode = flash_command_sequence(driver);

    flash_cache_clear(driver);

    return returnCode;
}
示例#4
0
// See flash.h for documentation of this function.
status_t flash_read_resource(flash_driver_t * driver, uint32_t start, uint32_t *dst, uint32_t lengthInBytes, flash_read_resource_option_t option)
{
    if (driver == NULL || dst == NULL)
    {
        return kStatus_InvalidArgument;
    }

    // Check the supplied address range.
    status_t returnCode =  flash_check_resource_range(start, lengthInBytes, option);
    if (returnCode != kStatus_Success)
    {
        return returnCode;
    }

    while(lengthInBytes > 0)
    {
        // preparing passing parameter
        kFCCOBx[0] = start;
        FTFx_WR_FCCOBx(FTFx, 0, FTFx_READ_RESOURCE);
#if (FSL_FEATURE_FLASH_PFLASH_RESOURCE_CMD_ADDRESS_ALIGMENT == 8)
        FTFx_WR_FCCOBx(FTFx, 4, option);
#else
        FTFx_WR_FCCOBx(FTFx, 8, option);
#endif
        // calling flash command sequence function to execute the command
        returnCode = flash_command_sequence(driver);

        if (kStatus_Success != returnCode)
        {
            break;
        }

         // fetch data
         *dst++ = kFCCOBx[1];
#if (FSL_FEATURE_FLASH_PFLASH_RESOURCE_CMD_ADDRESS_ALIGMENT > 4)
         *dst++ = kFCCOBx[2];
#endif
        // update start address for next iteration
        start += kFlashReadResource_UnitInBytes;
        // update lengthInBytes for next iteration
        lengthInBytes -= kFlashReadResource_UnitInBytes;
    }

    return (returnCode);
}
示例#5
0
// See flash.h for documentation of this function.
status_t flash_verify_program(flash_driver_t * driver,
                              uint32_t start,
                              uint32_t lengthInBytes,
                              const uint8_t * expectedData,
                              flash_margin_value_t margin,
                              uint32_t * failedAddress,
                              uint8_t * failedData)
{
    if (expectedData == NULL)
    {
        return kStatus_InvalidArgument;
    }

    status_t returnCode = flash_check_range(driver, start, lengthInBytes, FSL_FEATURE_FLASH_PFLASH_CHECK_CMD_ADDRESS_ALIGMENT);
    if (returnCode)
    {
        return returnCode;
    }

    while (lengthInBytes)
    {
        // preparing passing parameter to program check the flash block
        kFCCOBx[0] = start;
        FTFx_WR_FCCOBx(FTFx, 0, FTFx_PROGRAM_CHECK);
        FTFx_WR_FCCOBx(FTFx, 4, margin);
        kFCCOBx[2] = *(uint32_t *)expectedData;

        // calling flash command sequence function to execute the command
        returnCode = flash_command_sequence();

        // checking for the success of command execution
        if (kStatus_Success != returnCode)
        {
            if (failedAddress)
            {
                *failedAddress  =  start;
            }
            if (failedData)
            {
                *(uint32_t *)failedData = 0;
            }

        // Read fail returned data: if K70, Nevis2, L1PT, L2K are selected
        //! @todo Use a feature macro to determine whether this is supported.
// #if ((FTFx_KX_512K_512K_16K_4K_4K == FLASH_DERIVATIVE) || (FTFx_KX_1024K_0K_16K_4K_0K == FLASH_DERIVATIVE)\
//         ||(FTFx_NX_256K_32K_2K_2K_1K == FLASH_DERIVATIVE)||(FTFx_NX_128K_32K_2K_2K_1K == FLASH_DERIVATIVE)\
//         ||(FTFx_NX_96K_32K_2K_2K_1K == FLASH_DERIVATIVE)||(FTFx_NX_64K_32K_2K_2K_1K == FLASH_DERIVATIVE)\
//         ||(FTFx_LX_128K_0K_0K_1K_0K == FLASH_DERIVATIVE)||(FTFx_LX_96K_0K_0K_1K_0K == FLASH_DERIVATIVE)\
//         ||(FTFx_LX_64K_0K_0K_1K_0K == FLASH_DERIVATIVE)||(FTFx_LX_32K_0K_0K_1K_0K == FLASH_DERIVATIVE)\
//         ||(FTFx_LX_8K_0K_0K_1K_0K == FLASH_DERIVATIVE))
//                 *failedData     = 0x0;
//                 *(failedData+1) = 0x0;
//                 *(failedData+2) = 0x0;
//                 *(failedData+3) = 0x0;
// #else //other derivative
// #if (ENDIANNESS == BIG_ENDIAN)  // Big Endian
//                 *(failedData)   = FTFA->FCCOB4;
//                 *(failedData+1) = FTFA->FCCOB5;
//                 *(failedData+2) = FTFA->FCCOB6;
//                 *(failedData+3) = FTFA->FCCOB7;
// #else // Little Endian
//                 *(failedData+3) = FTFA->FCCOB4;
//                 *(failedData+2) = FTFA->FCCOB5;
//                 *(failedData+1) = FTFA->FCCOB6;
//                 *(failedData)   = FTFA->FCCOB7;
// #endif //of ENDIANNESS
// #endif // of FLASH_DERIVATIVE

            break;
        }

        lengthInBytes -= FSL_FEATURE_FLASH_PFLASH_CHECK_CMD_ADDRESS_ALIGMENT;
        expectedData += FSL_FEATURE_FLASH_PFLASH_CHECK_CMD_ADDRESS_ALIGMENT;
        start += FSL_FEATURE_FLASH_PFLASH_CHECK_CMD_ADDRESS_ALIGMENT;
    }

    return(returnCode);
}