Browse Source

lpc15xx cleanup

pull/142/head
Gareth McMullin 8 years ago
parent
commit
419aae4940
  1. 4
      src/include/lpc_common.h
  2. 22
      src/lpc11xx.c
  3. 41
      src/lpc15xx.c
  4. 15
      src/lpc_common.c

4
src/include/lpc_common.h

@ -1,7 +1,7 @@
/*
* This file is part of the Black Magic Debug project.
*
* Copyright (C) 2015 Gareth McMullin <gareth@blacksphere.co.nz>
* Copyright (C) 2016 Gareth McMullin <gareth@blacksphere.co.nz>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -63,6 +63,8 @@ enum iap_status lpc_iap_call(struct lpc_flash *f, enum iap_cmd cmd, ...);
int lpc_flash_erase(struct target_flash *f, uint32_t addr, size_t len);
int lpc_flash_write(struct target_flash *f,
uint32_t dest, const void *src, size_t len);
int lpc_flash_write_magic_vect(struct target_flash *f,
uint32_t dest, const void *src, size_t len);
#endif

22
src/lpc11xx.c

@ -2,7 +2,7 @@
* This file is part of the Black Magic Debug project.
*
* Copyright (C) 2011 Mike Smith <drziplok@me.com>
* Copyright (C) 2015 Gareth McMullin <gareth@blacksphere.co.nz>
* Copyright (C) 2016 Gareth McMullin <gareth@blacksphere.co.nz>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -34,15 +34,12 @@
#define LPC11XX_DEVICE_ID 0x400483F4
#define LPC8XX_DEVICE_ID 0x400483F8
static int lpc11xx_flash_write(struct target_flash *f,
uint32_t dest, const void *src, size_t len);
void lpc11xx_add_flash(target *t, uint32_t addr, size_t len, size_t erasesize)
{
struct lpc_flash *lf = lpc_add_flash(t, addr, len);
lf->f.blocksize = erasesize;
lf->f.buf_size = IAP_PGM_CHUNKSIZE;
lf->f.write_buf = lpc11xx_flash_write;
lf->f.write_buf = lpc_flash_write_magic_vect;
lf->iap_entry = IAP_ENTRYPOINT;
lf->iap_ram = IAP_RAM_BASE;
lf->iap_msp = IAP_RAM_BASE + MIN_RAM_SIZE - RAM_USAGE_FOR_IAP_ROUTINES;
@ -118,18 +115,3 @@ lpc11xx_probe(target *t)
return false;
}
static int lpc11xx_flash_write(struct target_flash *f,
uint32_t dest, const void *src, size_t len)
{
if (dest == 0) {
/* Fill in the magic vector to allow booting the flash */
uint32_t *w = (uint32_t *)src;
uint32_t sum = 0;
for (unsigned i = 0; i < 7; i++)
sum += w[i];
w[7] = ~sum + 1;
}
return lpc_flash_write(f, dest, src, len);
}

41
src/lpc15xx.c

@ -1,3 +1,24 @@
/*
* This file is part of the Black Magic Debug project.
*
* Copyright (C) 2011 Mike Smith <drziplok@me.com>
* Copyright (C) 2016 Gareth McMullin <gareth@blacksphere.co.nz>
* Copyright (C) 2016 David Lawrence <dlaw@markforged.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "general.h"
#include "target.h"
#include "cortexm.h"
@ -13,15 +34,12 @@
#define LPC15XX_DEVICE_ID 0x400743F8
static int lpc15xx_flash_write(struct target_flash *f,
uint32_t dest, const void *src, size_t len);
void lpc15xx_add_flash(target *t, uint32_t addr, size_t len, size_t erasesize)
{
struct lpc_flash *lf = lpc_add_flash(t, addr, len);
lf->f.blocksize = erasesize;
lf->f.buf_size = IAP_PGM_CHUNKSIZE;
lf->f.write_buf = lpc15xx_flash_write;
lf->f.write_buf = lpc_flash_write_magic_vect;
lf->iap_entry = IAP_ENTRYPOINT;
lf->iap_ram = IAP_RAM_BASE;
lf->iap_msp = IAP_RAM_BASE + MIN_RAM_SIZE - RAM_USAGE_FOR_IAP_ROUTINES;
@ -59,18 +77,3 @@ lpc15xx_probe(target *t)
return false;
}
static int lpc15xx_flash_write(struct target_flash *f,
uint32_t dest, const void *src, size_t len)
{
if (dest == 0) {
/* Fill in the magic vector to allow booting the flash */
uint32_t *w = (uint32_t *)src;
uint32_t sum = 0;
for (unsigned i = 0; i < 7; i++)
sum += w[i];
w[7] = ~sum + 1;
}
return lpc_flash_write(f, dest, src, len);
}

15
src/lpc_common.c

@ -133,3 +133,18 @@ int lpc_flash_write(struct target_flash *tf,
return 0;
}
int lpc_flash_write_magic_vect(struct target_flash *f,
uint32_t dest, const void *src, size_t len)
{
if (dest == 0) {
/* Fill in the magic vector to allow booting the flash */
uint32_t *w = (uint32_t *)src;
uint32_t sum = 0;
for (unsigned i = 0; i < 7; i++)
sum += w[i];
w[7] = ~sum + 1;
}
return lpc_flash_write(f, dest, src, len);
}

Loading…
Cancel
Save