コード例 #1
0
void Flash_eeprom_Erase_Test(void)
{
  u32 add, start_add, stop_add ;
  u8 block=0;
  TestStatus OperationStatus;
    /* Check the programmed block */
  start_add = FLASH_DATA_START_PHYSICAL_ADDRESS;
  stop_add = FLASH_DATA_START_PHYSICAL_ADDRESS + (u32)FLASH_BLOCK_SIZE;
      /* Erase block 0 and verify it */
  FLASH_EraseBlock(block, FLASH_MEMTYPE_DATA);
  FLASH_WaitForLastOperation(FLASH_MEMTYPE_DATA);
    for (add = start_add; add < stop_add; add++)
    {
        if (FLASH_ReadByte(add) != 0x00)
        {
            /* Error */
            OperationStatus = FAILED;
            /* OperationStatus = PASSED, if the data written/read to/from DATA EEPROM memory is correct */
            /* OperationStatus = FAILED, if the data written/read to/from DATA EEPROM memory is corrupted */
            while (1);
        }
    }

    /* Pass */
    OperationStatus = PASSED;
    /* OperationStatus = PASSED, if the data written/read to/from DATA EEPROM memory is correct */
    /* OperationStatus = FAILED, if the data written/read to/from DATA EEPROM memory is corrupted */
    UART1_SendString("The Flash_eeprom Erase Succeed ",sizeof("The Flash_eeprom Erase Succeed"));
}
コード例 #2
0
ファイル: main.c プロジェクト: KNVRK/STM8SProjects
/**
  * @brief How to Write byte / Write word / Erase a block on FLASH memory.
  * @par Example description
  * - Program 32/64 (FLASH_BLOCK_SIZE/2) bytes from flash program memory end physical address minus FLASH_BLOCK_SIZE up to 
	*   flash program memory end physical address minus FLASH_BLOCK_SIZE/2.
  * - Check programmed bytes
  * - Program 8/16 (FLASH_BLOCK_SIZE/8) words from flash program memory end physical address minus FLASH_BLOCK_SIZE/2 up to 
	*   flash program memory end physical address.
  * - Checked programmed words
  * - Erase the last block in flash program memory
  * - Check erase
  * @par Parameters:
  * None
  * @retval 
  * None
  */
void main(void)
{
    u32 add, start_add, stop_add, new_val2 =0;
    u8 new_val1, val =0;
    u16 block =0;
    u8 i =0;

    _fctcpy('b');

    /* Define flash programming Time */
    FLASH_SetProgrammingTime(FLASH_PROGRAMTIME_STANDARD);

    /* Unlock Program memory */
    FLASH_Unlock(FLASH_MEMTYPE_PROG);
    /* Program FLASH_BLOCK_SIZE/2 bytes & check */
    start_add = FLASH_PROG_END_PHYSICAL_ADDRESS - FLASH_BLOCK_SIZE +1;
    stop_add = start_add + FLASH_BLOCK_SIZE/2;
    new_val1 = 0x55;
    for (add = start_add; add < stop_add; add++)
            {
                FLASH_ProgramByte(add, new_val1);
                if (FLASH_ReadByte(add) != new_val1)
                {
                    /* Error */
                    OperationStatus = FAILED;
                    /* OperationStatus = PASSED, if the data written/read to/from FLASH Program memory is correct */
                    /* OperationStatus = FAILED, if the data written/read to/from FLASH Program memory is corrupted */
                    while (1);
                }
            }

    /* Program FLASH_BLOCK_SIZE/8 words & check */
    start_add = stop_add;
    stop_add = FLASH_PROG_END_PHYSICAL_ADDRESS;
    new_val2 = 0x12345678;
    add = start_add;
    for (i = 0; i < FLASH_BLOCK_SIZE/8; i++)
    {
        FLASH_ProgramWord(add, new_val2);
        add = add + 4;
    }

    /* check */
    for (add = start_add; add < stop_add; add++)
            {

                val = FLASH_ReadByte(add);
                if (val != BYTE_3(new_val2))
                {
                    /* Error */
                    OperationStatus = FAILED;
                    /* OperationStatus = PASSED, if the data written/read to/from FLASH Program memory is correct */
                    /* OperationStatus = FAILED, if the data written/read to/from FLASH Program memory is corrupted */
                    while (1);
                }

                add += 1;
                val = FLASH_ReadByte(add);
                if (val != BYTE_2(new_val2))
                {
                    /* Error */
                    OperationStatus = FAILED;
                    /* OperationStatus = PASSED, if the data written/read to/from FLASH Program memory is correct */
                    /* OperationStatus = FAILED, if the data written/read to/from FLASH Program memory is corrupted */
                    while (1);
                }

                add += 1;
                val = FLASH_ReadByte(add);
                if (val != BYTE_1(new_val2))
                {
                    /* Error */
                    OperationStatus = FAILED;
                    /* OperationStatus = PASSED, if the data written/read to/from FLASH Program memory is correct */
                    /* OperationStatus = FAILED, if the data written/read to/from FLASH Program memory is corrupted */
                    while (1);
                }

                add += 1;
                val = FLASH_ReadByte(add);
                if (val != BYTE_0(new_val2))
                {
                    /* Error */
                    OperationStatus = FAILED;
                    /* OperationStatus = PASSED, if the data written/read to/from FLASH Program memory is correct */
                    /* OperationStatus = FAILED, if the data written/read to/from FLASH Program memory is corrupted */
                    while (1);
                }
            }

    /* Erase the last block & check */
    block = FLASH_PROG_BLOCKS_NUMBER -1; /* Last block of Flash program memory */
    start_add = FLASH_PROG_END_PHYSICAL_ADDRESS - FLASH_BLOCK_SIZE +1;
    stop_add = FLASH_PROG_END_PHYSICAL_ADDRESS;
		/* Without calling the FLASH_WaitForLastOperation function */
		/* When the program goes back to Flash program memory, it is stalled untill the block erase operation is complete.*/
    FLASH_EraseBlock(block, FLASH_MEMTYPE_PROG);

    for (add = start_add; add < stop_add; add++)
            {
                if (FLASH_ReadByte(add) != 0x00)
                {
                    /* Error */
                    OperationStatus = FAILED;
                    /* OperationStatus = PASSED, if the data written/read to/from FLASH Program memory is correct */
                    /* OperationStatus = FAILED, if the data written/read to/from FLASH Program memory is corrupted */
                    while (1);
                }
            }

    /* Pass */
    OperationStatus = PASSED;
    /* OperationStatus = PASSED, if the data written/read to/from FLASH Program memory is correct */
    /* OperationStatus = FAILED, if the data written/read to/from FLASH Program memory is corrupted */
    while (1);

}
コード例 #3
0
ファイル: main.c プロジェクト: avr-master/Healty_Beck
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
  uint32_t add, startadd, stopadd = 0;
  uint8_t newval = 0xAA;
  uint8_t i = 0;

#ifdef _COSMIC_
/* Call the _fctcpy() function with the first segment character as parameter 
   "_fctcpy('F');"  for a manual copy of the declared moveable code segment
   (FLASH_CODE) in RAM before execution*/
  _fctcpy('F');
#endif /*_COSMIC_*/

#ifdef _RAISONANCE_
/* Call the standard C library: memcpy() or fmemcpy() functions available through 
   the <string.h> to copy the inram function to the RAM destination address */
  MEMCPY(FLASH_EraseBlock,
         (void PointerAttr*)&__address__FLASH_EraseBlock,
         (int)&__size__FLASH_EraseBlock);
  MEMCPY(FLASH_ProgramBlock,
         (void PointerAttr*)&__address__FLASH_ProgramBlock,
         (int)&__size__FLASH_ProgramBlock);
#endif /*_RAISONANCE_*/

  /* Initialize I/Os in Output Mode */
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);

  /* High speed internal clock prescaler */
  CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1);

  /* Define flash programming Time*/
  FLASH_SetProgrammingTime(FLASH_ProgramTime_Standard);

  FLASH_Unlock(FLASH_MemType_Program);
  /* Wait until Flash Program area unlocked flag is set*/
  while (FLASH_GetFlagStatus(FLASH_FLAG_PUL) == RESET)
  {}

  /* Unlock flash data eeprom memory */
  FLASH_Unlock(FLASH_MemType_Data);
  /* Wait until Data EEPROM area unlocked flag is set*/
  while (FLASH_GetFlagStatus(FLASH_FLAG_DUL) == RESET)
  {}

  /* Fill the buffer in RAM */
  for (i = 0; i < FLASH_BLOCK_SIZE; i++)
  {
    GBuffer[i] = newval;
  }
  /* This function is executed from RAM */
  FLASH_ProgramBlock(BLOCK_OPERATION, FLASH_MemType_Data, FLASH_ProgramMode_Standard, GBuffer);
  
  /* Wait until End of high voltage flag is set*/
  while (FLASH_GetFlagStatus(FLASH_FLAG_HVOFF) == RESET)
  {}
  /* Check the programmed block */
  startadd = FLASH_DATA_EEPROM_START_PHYSICAL_ADDRESS + ((uint16_t)BLOCK_OPERATION * (uint16_t)FLASH_BLOCK_SIZE);
  stopadd = startadd + (uint16_t)FLASH_BLOCK_SIZE;
  for (add = startadd; add < stopadd; add++)
      {
        if (FLASH_ReadByte(add) != newval)
        {
          /* Error */
          OperationStatus = FAILED;
          /* OperationStatus = PASSED, if the data written/read to/from Flash program memory is correct */
          /* OperationStatus = FAILED, if the data written/read to/from Flash program memory is corrupted */
          while (1)
          {
            STM_EVAL_LEDToggle(LED1); /*FAIL: write error */
            
            Delay(0xFFFF);
          }
        }
      }
  /* Erase block 0 and verify it */
  /* This function is executed from RAM */
  FLASH_EraseBlock(BLOCK_OPERATION, FLASH_MemType_Data);

  /* Wait until End of high voltage flag is set*/
  while (FLASH_GetFlagStatus(FLASH_FLAG_HVOFF) == RESET)
  {}

  for (add = startadd; add < stopadd; add++)
      {
        if (FLASH_ReadByte(add) != 0x00)
        {
          /* Error */
          OperationStatus = FAILED;
          /* OperationStatus = PASSED, if the data written/read to/from Flash program memory is correct */
          /* OperationStatus = FAILED, if the data written/read to/from Flash program memory is corrupted */
          while (1)
          {
            STM_EVAL_LEDToggle(LED2); /* FAIL: Erase error */
            
           Delay(0xFFFF);
          }
        }
      }

  /* Pass */
  OperationStatus = PASSED;
  /* OperationStatus = PASSED, if the data written/read to/from Flash program memory is correct */
  /* OperationStatus = FAILED, if the data written/read to/from Flash program memory is corrupted */
  while (1)
  {
    STM_EVAL_LEDToggle(LED3); /* PASS: without errors*/
    
    Delay(0xFFFF);
  }
}