cancel
Showing results for 
Search instead for 
Did you mean: 

STM8 how to check if flash memory filled

GunkutA
Senior

Hello I am using STM8L052 and in my program I am writing my vectorTable to my flash memory for every power on, but I want to make it only once so once the flash is written with vectorTable I will not write to flash again. There is how I write to flash:

FLASH_Unlock( FLASH_MemType_Program );
  /* Note that all interrupt handlers are in sector 1 due to the location of
     the application being forced to start at 0x10000! */
  offset = OFFSVECTOR( VECTOR_TIM2_USART2_TX );
  vector = SECTOR1_BASE | (U32) TIM2_IRQHandler;
  flashWriteProgram( offset, address, 3 );
  offset = OFFSVECTOR( VECTOR_IIC_SPI2 );
  vector = SECTOR1_BASE | (U32) I2C1_IRQHandler;
  flashWriteProgram( offset, address, 3 );
  offset = OFFSVECTOR( VECTOR_TIM5_CAPCOM_USART1_RX );
  vector = SECTOR1_BASE | (U32) UART_IRQHandler;
  flashWriteProgram( offset, address, 3 );
  offset = OFFSVECTOR( VECTOR_TIM3_USART3_TX );
  vector = SECTOR1_BASE | (U32) modbus_timerIRQHandler;
  flashWriteProgram( offset, address, 3 );

And I want to put this part into an if statement so that I will not write to flash over and over again. For that I made a function like that :

U1 isApplPresent( void )
{
  U1 result = 0;
  U8 byte = 0;
  /* read start of vector table APPLICATION */
  flashReadProgram(FLASH_PROG_CODE_START_ADDR_OFFS, &byte, 1);
  if (byte == 0x82)
  {
      result = 1;
  }
  return result;
}

Here is related definitions :

#define FLASH_ADDR_START              0x008000
 
#define FLASH_ADDR_END                0x017FFF
 
#define FLASH_PROG_START_ADDR         (FLASH_ADDR_START + FLASH_BOOTLOADER_SIZE)
 
#define FLASH_PROG_CODE_START_ADDR    0x10000

And if the result is 1 then I will not write to flash again. But I am not sure if it is the correct way to check. Since the vector table starts at address 0x0 of the program(at 0x08000) and has 32-bit entries for every interrupt vector. The first 2 values are reserved. The first byte per vector has the reserved value 0x82.

0 REPLIES 0