ULINK2 User's Guide

Init

Summary
int Init(
  unsigned long adr,     /*  Device base address  */
  unsigned long clk,     /*  Clock frequency (Hz) */
  unsigned long fnc);    /*  Function code        */
Description

The Init function initializes the microcontroller for Flash programming. It is invoked whenever an attempt is made to download the program to Flash.

The last parameter fnc is a number:

  • 1 - that stands for Erase.
  • 2 - that stands for Program.
  • 3 - that stands for Verify.

Thus, different initialization sections can be implemented for each individual Flash programming step.

Return Value

The Init function returns a value:

  • 0 - on success.
  • 1 - on failure.

 

See Also

EraseChip, EraseSector, ProgramPage, Verify

Example
int Init (unsigned long adr, unsigned long clk, unsigned long fnc) {

  // Zero Wait State
  FLASH->ACR  = 0x00000000;

  // Unlock Flash
  FLASH->KEYR = FLASH_KEY1;
  FLASH->KEYR = FLASH_KEY2;

  // Test if IWDG is running (IWDG in HW mode)
  if ((FLASH->OBR & 0x04) == 0x00) {
    // Set IWDG time out to ~32.768 second
    IWDG->KR  = 0x5555; // Enable write access to IWDG_PR and IWDG_RLR
    IWDG->PR  = 0x06;   // Set prescaler to 256
    IWDG->RLR = 4095;   // Set reload value to 4095
  }

  return (0);
}

Complete example exists in folder \KEIL\ARM\FLASH\STM32F10x.