 | ULINK2 User's Guide |  |
|
|
| ProgramPage| Summary |
int ProgramPage(
unsigned long adr, /* Page start address */
unsigned long sz, /* Page size */
unsigned char *buf); /* Data */
| | Description | The ProgramPage function is used to write the code into the Flash memory. It is invoked whenever an attempt is made to download the program to Flash. | | Return Value | The ProgramPage function returns a value: - 0 - on success.
- 1 - on failure.
| | Example |
int ProgramPage (unsigned long adr, unsigned long sz, unsigned char *buf) {
sz = (sz + 1) & ~1; // Adjust size for Half Words
while (sz) {
FLASH->CR |= FLASH_PG; // Programming Enabled
M16(adr) = *((unsigned short *)buf); // Program Half Word
while (FLASH->SR & FLASH_BSY);
FLASH->CR &= ~FLASH_PG; // Programming Disabled
// Check for Errors
if (FLASH->SR & (FLASH_PGERR | FLASH_WRPRTERR)) {
FLASH->SR |= FLASH_PGERR | FLASH_WRPRTERR;
return (1); // Failed
}
// Go to next Half Word
adr += 2;
buf += 2;
sz -= 2;
}
return (0); // Done
}
Complete example exists in folder \KEIL\ARM\FLASH\STM32F10x. |
|
|