Beispiel #1
0
/**
  * @brief  Get the specified block protection state.
  * @param  BlockNum: The flash block number.
  *   This parameter can be one of the following values:
  *   FC_BLOCK_0, FC_BLOCK_1
  * @retval DISABLE or ENABLE.
  *
  */
FunctionalState FC_GetBlockProtectState(uint8_t BlockNum)
{
    uint32_t tmp = PSRA_BLOCK_FLAG;
    FunctionalState retval = ENABLE;

    /* Check the parameters */
    assert_param(IS_FC_BLOCK_NUM(BlockNum));

    switch (BlockNum) {
    case FC_BLOCK_0:
        tmp = TSB_FC->PSRA & PSRA_BLOCK0_MASK;
        break;
    case FC_BLOCK_1:
        tmp = TSB_FC->PSRA & PSRA_BLOCK1_MASK;
        break;
    default:
        /* Do nothing */
        break;
    }
    if (tmp == PSRA_BLOCK_FLAG) {
        /* The block is unprotected */
        retval = DISABLE;
    } else {
        /* The block is protected */
        retval = ENABLE;
    }
    return retval;
}
Beispiel #2
0
/**
  * @brief  Program the protection bit to make the specified block protected.
  * @param  BlockNum: The flash block number.
  *   This parameter can be one of the following values:
  *   FC_BLOCK_0,FC_BLOCK_1,FC_BLOCK_2,
  *   FC_BLOCK_3, FC_BLOCK_4, FC_BLOCK_5.
  * @retval FC_SUCCESS, FC_ERROR_PROTECTED, FC_ERROR_OVER_TIME.
  *
  */
FC_Result FC_ProgramBlockProtectState(uint8_t BlockNum)
{
    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 *PBA = FC_PBA_BLOCK_4;
    uint32_t counter = FC_SET_PROTECT_STATE_OVER_TIME;

    /* Check the parameters */
    assert_param(IS_FC_BLOCK_NUM(BlockNum));

    switch (BlockNum) {

    case FC_BLOCK_0:
        PBA = FC_PBA_BLOCK_0;
        break;
    case FC_BLOCK_1:
        PBA = FC_PBA_BLOCK_1;
        break;
    case FC_BLOCK_2:
        PBA = FC_PBA_BLOCK_2;
        break;
    case FC_BLOCK_3:
        PBA = FC_PBA_BLOCK_3;
        break;
    case FC_BLOCK_4:
        PBA = FC_PBA_BLOCK_4;
        break;
    case FC_BLOCK_5:
        PBA = FC_PBA_BLOCK_5;
        break;
    default:
        /* Do nothing */
        break;
    }

    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) 0x0000009A; /* bus cycle 3 */
        *addr1 = (uint32_t) 0x000000AA; /* bus cycle 4 */
        *addr2 = (uint32_t) 0x00000055; /* bus cycle 5 */
        *addr1 = (uint32_t) 0x0000009A; /* bus cycle 6 */
        *PBA = (uint32_t) 0x0000009A;   /* bus cycle 7 */
        __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 #3
0
/**
  * @brief  Retrieve size of block
  * @param  BlockNum
  * @retval Size
  *
  */
int FC_GetNumPages(uint8_t BlockNum)
{
    static int BlockSizes[] = { 256, 256, 256, 128, 64, 64, };

    assert_param(IS_FC_BLOCK_NUM(BlockNum));

    return BlockSizes[BlockNum];
}
Beispiel #4
0
/**
  * @brief  Convert block number to address
  * @param  BlockNum
  * @retval Addr
  *
  */
uint32_t FC_BlockNumToAddr(uint8_t BlockNum)
{
    static int BlockOffsets[] = { 0x30000, 0x20000, 0x10000, 0x8000, 0x0, 0x4000 };

    assert_param(IS_FC_BLOCK_NUM(BlockNum));

    return FLASH_START_ADDR + BlockOffsets[BlockNum];
}
Beispiel #5
0
/**
  * @brief  Get the block Protection status.
  * @param  BlockNum: The flash block number.
  *   This parameter can be one of the following values:
  *   FC_BLOCK_0, FC_BLOCK_1, FC_BLOCK_2, FC_BLOCK_3,
  *   FC_BLOCK_4, FC_BLOCK_5, FC_BLOCK_6, FC_BLOCK_7,
  *   FC_BLOCK_8, FC_BLOCK_9
  * @retval DISABLE or ENABLE
  *
  */
FunctionalState FC_GetBlockProtectState(FC_BlockNum BlockNum)
{
    uint32_t tmp = FLCS_BLOCK_FLAG;
    FunctionalState retval = ENABLE;

    /* Check the parameters */
    assert_param(IS_FC_BLOCK_NUM(BlockNum));

    switch (BlockNum) {
    case FC_BLOCK_0:
        tmp = TSB_FC->FLCS & FLCS_BLOCK0_MASK;
        break;
    case FC_BLOCK_1:
        tmp = TSB_FC->FLCS & FLCS_BLOCK1_MASK;
        break;
    case FC_BLOCK_2:
        tmp = TSB_FC->FLCS & FLCS_BLOCK2_MASK;
        break;
    case FC_BLOCK_3:
        tmp = TSB_FC->FLCS & FLCS_BLOCK3_MASK;
        break;
    case FC_BLOCK_4:
        tmp = TSB_FC->FLCS & FLCS_BLOCK4_MASK;
        break;
    case FC_BLOCK_5:
        tmp = TSB_FC->FLCS & FLCS_BLOCK5_MASK;
        break;
    case FC_BLOCK_6:
        tmp = TSB_FC->FLCS & FLCS_BLOCK6_MASK;
        break;
    case FC_BLOCK_7:
        tmp = TSB_FC->FLCS & FLCS_BLOCK7_MASK;
        break;
    case FC_BLOCK_8:
        tmp = TSB_FC->FLCS & FLCS_BLOCK8_MASK;
        break;
    case FC_BLOCK_9:
        tmp = TSB_FC->FLCS & FLCS_BLOCK9_MASK;
        break;
    default:
        /* Do nothing */
        break;
    }
    if (tmp == FLCS_BLOCK_FLAG) {
        /* Return protection status of each block */
        retval = DISABLE;
    } else {
        retval = ENABLE;
    }
    return retval;
}
Beispiel #6
0
/**
  * @brief  Get the specified block protection state.
  * @param  BlockNum: The flash block number.
  *   This parameter can be one of the following values:
  *   FC_BLOCK_0, FC_BLOCK_1, FC_BLOCK_2, FC_BLOCK_3,
  *   FC_BLOCK_4(for TMPM37xFY), FC_BLOCK_5(for TMPM37xFY).
  * @retval DISABLE or ENABLE.
  *
  */
FunctionalState FC_GetBlockProtectState(uint8_t BlockNum)
{
    uint32_t tmp = FLCS_BLOCK_FLAG;
    FunctionalState retval = ENABLE;

    /* Check the parameters */
    assert_param(IS_FC_BLOCK_NUM(BlockNum));

    switch (BlockNum) {
    case FC_BLOCK_0:
        tmp = TSB_FC->FLCS & FLCS_BLOCK0_MASK;
        break;
    case FC_BLOCK_1:
        tmp = TSB_FC->FLCS & FLCS_BLOCK1_MASK;
        break;
    case FC_BLOCK_2:
        tmp = TSB_FC->FLCS & FLCS_BLOCK2_MASK;
        break;
    case FC_BLOCK_3:
        tmp = TSB_FC->FLCS & FLCS_BLOCK3_MASK;
        break;
#ifdef TSB_M37xFY
    case FC_BLOCK_4:
        tmp = TSB_FC->FLCS & FLCS_BLOCK4_MASK;
        break;
    case FC_BLOCK_5:
        tmp = TSB_FC->FLCS & FLCS_BLOCK5_MASK;
        break;
#endif
    default:
        /* Do nothing */
        break;
    }
    if (tmp == FLCS_BLOCK_FLAG) {
        /* The block is unprotected */
        retval = DISABLE;
    } else {
        /* The block is protected */
        retval = ENABLE;
    }
    return retval;
}
Beispiel #7
0
/**
  * @brief  Get the block Protection status.
  * @param  BlockNum: The flash block number.
  *   This parameter can be one of the following values:
  *   FC_BLOCK_0, FC_BLOCK_1, FC_BLOCK_2, FC_BLOCK_3,
  *   FC_BLOCK_4 (for M330 and M333), FC_BLOCK_5 (for M330 and M333).
  * @retval DISABLE or ENABLE
  *
  */
FunctionalState FC_GetBlockProtectState(FC_BlockNum BlockNum)
{
    uint32_t tmp = FLCS_BLOCK_FLAG;
    FunctionalState retval = ENABLE;

    /* Check the parameters */
    assert_param(IS_FC_BLOCK_NUM(BlockNum));

    switch (BlockNum) {
    case FC_BLOCK_0:
        tmp = TSB_FC->FLCS & FLCS_BLOCK0_MASK;
        break;
    case FC_BLOCK_1:
        tmp = TSB_FC->FLCS & FLCS_BLOCK1_MASK;
        break;
    case FC_BLOCK_2:
        tmp = TSB_FC->FLCS & FLCS_BLOCK2_MASK;
        break;
    case FC_BLOCK_3:
        tmp = TSB_FC->FLCS & FLCS_BLOCK3_MASK;
        break;
#if defined(__TMPM330_FC_H) || defined(__TMPM333_FC_H)
    case FC_BLOCK_4:
        tmp = TSB_FC->FLCS & FLCS_BLOCK4_MASK;
        break;
    case FC_BLOCK_5:
        tmp = TSB_FC->FLCS & FLCS_BLOCK5_MASK;
        break;
#endif                          /*  __TMPM330_FC_H) ||  __TMPM333_FC_H */
    default:
        /* Do nothing */
        break;
    }
    if (tmp == FLCS_BLOCK_FLAG) {
        /* Return protection status of each block */
        retval = DISABLE;
    } else {
        retval = ENABLE;
    }
    return retval;
}