Ejemplo n.º 1
0
//-----------------------------------------------------------------------------
static void target_cm7_program(char *name)
{
  uint32_t addr = device->flash_start;
  uint32_t size, number_of_pages;
  uint32_t offs = 0;
  uint8_t *buf;

  buf = buf_alloc(device->flash_size);

  size = load_file(name, buf, device->flash_size);

  memset(&buf[size], 0xff, device->flash_size - size);

  verbose("Programming...");

  number_of_pages = (size + device->page_size - 1) / device->page_size;

  for (uint32_t page = 0; page < number_of_pages; page += 8)
  {
    dap_write_word(EEFC_FCR, CMD_EPA | ((page | 1) << 8));
    while (0 == (dap_read_word(EEFC_FSR) & FSR_FRDY));

    verbose(".");
  }

  verbose(",");

  for (uint32_t page = 0; page < number_of_pages; page++)
  {
    for (uint32_t sector = 0; sector < device->page_size / SECTOR_SIZE; sector++)
    {
      dap_write_block(addr, &buf[offs], SECTOR_SIZE);
      addr += SECTOR_SIZE;
      offs += SECTOR_SIZE;
    }

    dap_write_word(EEFC_FCR, CMD_WP | (page << 8));
    while (0 == (dap_read_word(EEFC_FSR) & FSR_FRDY));

    verbose(".");
  }

  buf_free(buf);

  verbose(" done.\n");
}
Ejemplo n.º 2
0
//-----------------------------------------------------------------------------
static void target_cm0p_program(char *name)
{
  uint32_t addr = device->flash_start;
  uint32_t size;
  uint32_t offs = 0;
  uint32_t number_of_rows;
  uint8_t *buf;

  if (dap_read_word(DSU_CTRL_STATUS) & 0x00010000)
    error_exit("devices is locked, perform a chip erase before programming");

  buf = buf_alloc(device->flash_size);

  size = load_file(name, buf, device->flash_size);

  memset(&buf[size], 0xff, device->flash_size - size);

  verbose("Programming...");

  number_of_rows = (size + device->row_size - 1) / device->row_size;

  for (uint32_t row = 0; row < number_of_rows; row++)
  {
    dap_write_word(0x4100401c, addr >> 1);

    dap_write_word(0x41004000, 0x0000a541); // Unlock Region
    while (0 == (dap_read_word(0x41004014) & 1));

    dap_write_word(0x41004000, 0x0000a502); // Erase Row
    while (0 == (dap_read_word(0x41004014) & 1));

    dap_write_block(addr, &buf[offs], device->row_size);

    addr += device->row_size;
    offs += device->row_size;

    verbose(".");
  }

  buf_free(buf);

  verbose(" done.\n");
}
Ejemplo n.º 3
0
//-----------------------------------------------------------------------------
static void target_program(void)
{
  uint32_t addr = target_device.flash_start + target_options.offset;
  uint32_t number_of_pages, plane, page_offset;
  uint32_t offs = 0;
  uint8_t *buf = target_options.file_data;
  uint32_t size = target_options.file_size;

  number_of_pages = (size + target_device.page_size - 1) / target_device.page_size;
  page_offset = target_options.offset / target_device.page_size;

  for (uint32_t page = 0; page < number_of_pages; page += PAGES_IN_ERASE_BLOCK)
  {
    plane = (page + page_offset) / (target_device.flash_size / target_device.page_size);

    dap_write_word(EEFC_FCR(plane), CMD_EPA | (((page + page_offset) | 1) << 8));
    while (0 == (dap_read_word(EEFC_FSR(plane)) & FSR_FRDY));

    verbose(".");
  }

  verbose(",");

  for (uint32_t page = 0; page < number_of_pages; page++)
  {
    dap_write_block(addr, &buf[offs], target_device.page_size);
    addr += target_device.page_size;
    offs += target_device.page_size;

    plane = (page + page_offset) / (target_device.flash_size / target_device.page_size);

    dap_write_word(EEFC_FCR(plane), CMD_WP | ((page + page_offset) << 8));
    while (0 == (dap_read_word(EEFC_FSR(plane)) & FSR_FRDY));

    verbose(".");
  }
}
Ejemplo n.º 4
0
//-----------------------------------------------------------------------------
static void target_program(char *name)
{
    uint32_t addr = device->flash_start;
    uint32_t flash_size = device->flash_size * device->n_planes;
    uint32_t size, number_of_pages, plane;
    uint32_t offs = 0;
    uint8_t *buf;

    buf = buf_alloc(flash_size);

    size = load_file(name, buf, flash_size);

    memset(&buf[size], 0xff, flash_size - size);

    verbose("Programming...");

    number_of_pages = (size + device->page_size - 1) / device->page_size;

    for (uint32_t page = 0; page < number_of_pages; page++)
    {
        dap_write_block(addr, &buf[offs], device->page_size);
        addr += device->page_size;
        offs += device->page_size;

        plane = page / (device->flash_size / device->page_size);

        dap_write_word(EEFC_FCR(plane), CMD_EWP | (page << 8));
        while (0 == (dap_read_word(EEFC_FSR(plane)) & FSR_FRDY));

        verbose(".");
    }

    buf_free(buf);

    verbose(" done.\n");
}