Go to the source code of this file.
Defines | |
| #define | USB_EP_SIZE 64 |
| #define | FLASH_PAGE_SIZE 512 |
| #define | NUM_FLASH_BLOCKS FLASH_PAGE_SIZE / USB_EP_SIZE |
| #define | MAX_FLASH_SIZE 32*1024 |
Functions | |
| int | flash_prog (usb_dev_handle *hdev, unsigned low_addr, unsigned high_addr, unsigned flash_size, unsigned char *hex_buf) |
| #define USB_EP_SIZE 64 |
Definition at line 17 of file flashprog.h.
| #define FLASH_PAGE_SIZE 512 |
Definition at line 18 of file flashprog.h.
| #define NUM_FLASH_BLOCKS FLASH_PAGE_SIZE / USB_EP_SIZE |
Definition at line 19 of file flashprog.h.
| #define MAX_FLASH_SIZE 32*1024 |
Definition at line 20 of file flashprog.h.
| int flash_prog | ( | usb_dev_handle * | hdev, |
| unsigned | low_addr, | ||
| unsigned | high_addr, | ||
| unsigned | flash_size, | ||
| unsigned char * | hex_buf | ||
| ) |
Definition at line 98 of file flashprog.c.
{
unsigned num_flash_pages = flash_size/FLASH_PAGE_SIZE;
fprintf(stdout, "Programming flash pages 1-%d...\n", num_flash_pages - 5);
//
// First program and verify the flash pages above page 0 and below the bootloader
// (last four pages of the flash):
flash_program(hdev, hex_buf, 1, num_flash_pages - 5);
fprintf(stdout, "Verifying flash pages 1-%d...\n", num_flash_pages - 5);
if (flash_verify(hdev, hex_buf, 1, num_flash_pages - 5) == 0)
{
return 0;
}
//
// Then program page 0 and the pages containing the bootloader:
fprintf(stdout, "Programming flash page 0...\n", num_flash_pages - 5);
flash_program(hdev, hex_buf, 0, 1);
if (high_addr > (num_flash_pages - 4)*FLASH_PAGE_SIZE)
{
// Only program pages containing bootloader if user program uses these pages
fprintf(stdout, "Programming flash pages %d-%d...\n", num_flash_pages - 4, num_flash_pages - 1);
flash_program(hdev, hex_buf, num_flash_pages - 4, 4);
}
fprintf(stdout, "Verifying flash page 0...\n", num_flash_pages - 5);
if (flash_verify(hdev, hex_buf, 0, 1) == 0)
return 0;
if (high_addr > (num_flash_pages - 4)*FLASH_PAGE_SIZE)
{
fprintf(stdout, "Verifying flash pages %d-%d...\n", num_flash_pages - 4, num_flash_pages - 1);
if(flash_verify(hdev, hex_buf, num_flash_pages - 4, 4) == 0)
{
return 0;
}
}
return 1;
}
1.7.2