aboutsummaryrefslogtreecommitdiff
path: root/src/lpc43xx.c
diff options
context:
space:
mode:
authorAllen Ibara2014-01-10 11:53:46 -0800
committerAllen Ibara2014-01-10 13:24:25 -0800
commit01244fc84dca3d63483a292945a8a1a28098d4d7 (patch)
tree8b15793e3ec76c5d951e8d944488bd1b4099d10e /src/lpc43xx.c
parent2b798fa8fc7b06de6053f09ad4394ee1454a5d82 (diff)
LPC43XX: Force target to use internal clock.
Without this, flash write timing might be incorrect.
Diffstat (limited to 'src/lpc43xx.c')
-rw-r--r--src/lpc43xx.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/lpc43xx.c b/src/lpc43xx.c
index 6954404..b3a48a9 100644
--- a/src/lpc43xx.c
+++ b/src/lpc43xx.c
@@ -121,6 +121,7 @@ static void lpc43xx_iap_call(struct target_s *target, struct flash_param *param,
static int lpc43xx_flash_prepare(struct target_s *target, uint32_t addr, int len);
static int lpc43xx_flash_erase(struct target_s *target, uint32_t addr, int len);
static int lpc43xx_flash_write(struct target_s *target, uint32_t dest, const uint8_t *src, int len);
+static void lpc43xx_set_internal_clock(struct target_s *target);
const struct command_s lpc43xx_cmd_list[] = {
{"erase_mass", lpc43xx_cmd_erase, "Erase entire flash memory"},
@@ -255,6 +256,9 @@ static int lpc43xx_flash_init(struct target_s *target)
{
struct flash_program flash_pgm;
+ /* Force internal clock */
+ lpc43xx_set_internal_clock(target);
+
/* Initialize flash IAP */
flash_pgm.p.command = IAP_CMD_INIT;
flash_pgm.p.result[0] = IAP_STATUS_CMD_SUCCESS;
@@ -427,6 +431,12 @@ lpc43xx_flash_erase(struct target_s *target, uint32_t addr, int len)
return 0;
}
+static void lpc43xx_set_internal_clock(struct target_s *target)
+{
+ const uint32_t val2 = (1 << 11) | (1 << 24);
+ target_mem_write_words(target, 0x40050000 + 0x06C, &val2, sizeof(val2));
+}
+
static int lpc43xx_flash_write(struct target_s *target, uint32_t dest, const uint8_t *src, int len)
{
unsigned first_chunk = dest / IAP_PGM_CHUNKSIZE;