예제 #1
0
/**
  * @brief   Reads one option byte
  * @param  Address  option byte address to read.
  * @retval Option byte read value + its complement
  */
uint16_t FLASH_ReadOptionByte(uint16_t Address)
{
    uint8_t value_optbyte, value_optbyte_complement = 0;
    uint16_t res_value = 0;

    /* Check parameter */
    assert_param(IS_OPTION_BYTE_ADDRESS_OK(Address));


    value_optbyte = *((NEAR uint8_t*)Address); /* Read option byte */
    value_optbyte_complement = *(((NEAR uint8_t*)Address) + 1); /* Read option byte complement */

    /* Read-out protection option byte */
    if (Address == 0x4800)
    {
        res_value =  value_optbyte;
    }
    else
    {
        if (value_optbyte == (uint8_t)(~value_optbyte_complement))
        {
            res_value = (uint16_t)((uint16_t)value_optbyte << 8);
            res_value = res_value | (uint16_t)value_optbyte_complement;
        }
        else
        {
            res_value = FLASH_OPTIONBYTE_ERROR;
        }
    }
    return(res_value);
}
예제 #2
0
/**
  * @brief   Erases option byte
  * @param  Address : Option byte address to erase
  * @retval None
  */
void FLASH_EraseOptionByte(uint16_t Address)
{
    /* Check parameter */
    assert_param(IS_OPTION_BYTE_ADDRESS_OK(Address));

    /* Enable write access to option bytes */
    FLASH->CR2 |= FLASH_CR2_OPT;
    FLASH->NCR2 &= (uint8_t)(~FLASH_NCR2_NOPT);

     /* check if the option byte to erase is ROP */
     if (Address == 0x4800)
    {
       /* Erase option byte */
       *((NEAR uint8_t*)Address) = FLASH_CLEAR_BYTE;
    }
    else
    {
       /* Erase option byte and his complement */
       *((NEAR uint8_t*)Address) = FLASH_CLEAR_BYTE;
       *((NEAR uint8_t*)((uint16_t)(Address + (uint16_t)1 ))) = FLASH_SET_BYTE;
    }
    FLASH_WaitForLastOperation(FLASH_MEMTYPE_PROG);

    /* Disable write access to option bytes */
    FLASH->CR2 &= (uint8_t)(~FLASH_CR2_OPT);
    FLASH->NCR2 |= FLASH_NCR2_NOPT;
}
예제 #3
0
/**
  * @brief Erases an option byte
  * @param[in] Address Option byte address to erase
  * @retval
  * None.
  */
void FLASH_EraseOptionByte(u16 Address)
{
    /* Check parameter */
    assert_param(IS_OPTION_BYTE_ADDRESS_OK(Address));

    /* Enable write access to option bytes */
    FLASH->CR2 |= FLASH_CR2_OPT;
    FLASH->NCR2 &= (u8)(~FLASH_NCR2_NOPT);

    /* Erase option byte and his complement */
    *((NEAR u8*)Address) = FLASH_CLEAR_BYTE;
    *((NEAR u8*)(Address + 1 )) = FLASH_SET_BYTE;

    FLASH_WaitForLastOperation(FLASH_MEMTYPE_DATA);

    /* Disable write access to option bytes */
    FLASH->CR2 &= (u8)(~FLASH_CR2_OPT);
    FLASH->NCR2 |= FLASH_NCR2_NOPT;
}
예제 #4
0
/**
  * @brief Reads one option byte
  * @param[in] Address  option byte address to read.
  * @retval u16 res_value (Value read + complement value read.)
  */
u16 FLASH_ReadOptionByte(u16 Address)
{
    u8 value_optbyte, value_optbyte_complement = 0;
    u16 res_value = 0;

    /* Check parameter */
    assert_param(IS_OPTION_BYTE_ADDRESS_OK(Address));


    value_optbyte = *((NEAR u8*)Address); /* Read option byte */
    value_optbyte_complement = *(((NEAR u8*)Address) + 1); /* Read option byte complement*/

    if (value_optbyte == (u8)(~value_optbyte_complement))
    {
        res_value = (u16)((u16)value_optbyte << 8);
        res_value = res_value | (u16)value_optbyte_complement;
    }
    else
    {
        res_value = FLASH_OPTIONBYTE_ERROR;
    }

    return(res_value);
}