Skip to content

Commit 2f498fe

Browse files
committed
lpc11u35 - add flash driver
Add an internal flash driver for the lpc11u35. This enables this interface to store settings.
1 parent 49eac2a commit 2f498fe

File tree

5 files changed

+134
-56
lines changed

5 files changed

+134
-56
lines changed

source/daplink/daplink.sct

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ LR_IROM1 DAPLINK_ROM_APP_START DAPLINK_ROM_APP_SIZE {
3333
RW_IRAM1 DAPLINK_RAM_APP_START DAPLINK_RAM_APP_SIZE { ; RW data
3434
.ANY (ram_func)
3535
.ANY (+RW +ZI)
36+
.ANY (RAM1)
3637
}
3738

3839
#if defined(DAPLINK_RAM_APP2_START)
3940
RW_IRAM2 DAPLINK_RAM_APP2_START DAPLINK_RAM_APP2_SIZE { ; RW data
4041
.ANY (+RW +ZI)
42+
.ANY (RAM2)
4143
}
4244
#endif
4345

source/hic_hal/nxp/lpc11u35/daplink_addr.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@
2828
#define DAPLINK_ROM_SIZE 0x00010000
2929

3030
#define DAPLINK_RAM_START 0x10000000
31-
#define DAPLINK_RAM_SIZE 0x00002000
31+
#define DAPLINK_RAM_SIZE (0x00002000 - DAPLINK_DEV_IAP_RESERVED)
32+
33+
// region at the end of RAM1 used by IAP driver
34+
#define DAPLINK_DEV_IAP_RESERVED 0x00000020
3235

3336
/* ROM sizes */
3437

@@ -39,17 +42,17 @@
3942
#define DAPLINK_ROM_CONFIG_ADMIN_SIZE 0x00000000
4043

4144
#define DAPLINK_ROM_IF_START 0x00000000
42-
#define DAPLINK_ROM_IF_SIZE 0x0000FF00
45+
#define DAPLINK_ROM_IF_SIZE 0x0000F000
4346

44-
#define DAPLINK_ROM_CONFIG_USER_START 0x0000FF00
45-
#define DAPLINK_ROM_CONFIG_USER_SIZE 0x00000100
47+
#define DAPLINK_ROM_CONFIG_USER_START 0x0000F000
48+
#define DAPLINK_ROM_CONFIG_USER_SIZE 0x00001000
4649

4750
/* RAM sizes */
4851

4952
#define DAPLINK_RAM_APP_START 0x10000000
50-
#define DAPLINK_RAM_APP_SIZE 0x00001F00
53+
#define DAPLINK_RAM_APP_SIZE (0x00001F00 - DAPLINK_DEV_IAP_RESERVED)
5154

52-
#define DAPLINK_RAM_SHARED_START 0x10001F00
55+
#define DAPLINK_RAM_SHARED_START (0x10001F00 - DAPLINK_DEV_IAP_RESERVED)
5356
#define DAPLINK_RAM_SHARED_SIZE 0x00000100
5457

5558
#define DAPLINK_RAM_APP2_START 0x20000000
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/**
2+
* @file flash.c
3+
* @brief
4+
*
5+
* DAPLink Interface Firmware
6+
* Copyright (c) 2017-2017, ARM Limited, All Rights Reserved
7+
* SPDX-License-Identifier: Apache-2.0
8+
*
9+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
10+
* not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
*/
21+
22+
#include "flash_hal.h"
23+
#include "iap.h"
24+
#include "macro.h"
25+
#include "LPC11Uxx.h"
26+
#include "string.h"
27+
28+
// page buffer must be 4 byte algined and must reside in ram bank 1
29+
static __attribute__((section("RAM1"))) uint32_t page_buf[64];
30+
31+
static uint32_t get_sector_num(uint32_t addr);
32+
33+
uint32_t Init(uint32_t adr, uint32_t clk, uint32_t fnc)
34+
{
35+
return 0; // No init needed
36+
}
37+
38+
uint32_t UnInit(uint32_t fnc)
39+
{
40+
return 0; // No init needed
41+
}
42+
43+
uint32_t EraseChip(void)
44+
{
45+
return (1); // IAP not supported
46+
}
47+
48+
uint32_t EraseSector(uint32_t adr)
49+
{
50+
uint32_t num = get_sector_num(adr);
51+
52+
iap_lock();
53+
54+
iap_op.cmd = 50; // Prepare Sector for Erase
55+
iap_op.par[0] = num; // Start Sector
56+
iap_op.par[1] = num; // End Sector
57+
iap_call(&iap_op);
58+
if (iap_op.stat != CMD_SUCCESS) {
59+
iap_unlock();
60+
return (1);
61+
}
62+
63+
iap_op.cmd = 52; // Erase Sector
64+
iap_op.par[0] = num; // Start Sector
65+
iap_op.par[1] = num; // End Sector
66+
iap_op.par[2] = SystemCoreClock / 1000; // Core Clock in kHz
67+
iap_call(&iap_op);
68+
if (iap_op.stat != CMD_SUCCESS) {
69+
iap_unlock();
70+
return (1);
71+
}
72+
73+
iap_unlock();
74+
75+
return 0; // Success
76+
}
77+
78+
uint32_t ProgramPage(uint32_t adr, uint32_t sz, uint32_t *buf)
79+
{
80+
uint32_t num = get_sector_num(adr);
81+
82+
iap_lock();
83+
84+
iap_op.cmd = 50; // Prepare Sector for Program
85+
iap_op.par[0] = num; // Start Sector
86+
iap_op.par[1] = num; // End Sector
87+
iap_call(&iap_op);
88+
if (iap_op.stat != CMD_SUCCESS) {
89+
iap_unlock();
90+
return (1);
91+
}
92+
93+
while (sz > 0) {
94+
uint32_t copy_size = MIN(sz, sizeof(page_buf));
95+
memset(page_buf, 0xFF, sizeof(page_buf));
96+
memcpy(page_buf, buf, copy_size);
97+
iap_op.cmd = 51; // Erase Sector
98+
iap_op.par[0] = adr; // Destination
99+
iap_op.par[1] = (uint32_t)page_buf; // Source
100+
iap_op.par[2] = 256; // Write size
101+
iap_op.par[3] = SystemCoreClock / 1000; // Core Clock in kHz
102+
iap_call(&iap_op);
103+
if (iap_op.stat != CMD_SUCCESS) {
104+
iap_unlock();
105+
return (1);
106+
}
107+
sz -= copy_size;
108+
adr += copy_size;
109+
buf += copy_size / 4;
110+
}
111+
112+
iap_unlock();
113+
114+
return 0; // Success
115+
}
116+
117+
static uint32_t get_sector_num(uint32_t addr)
118+
{
119+
return addr / 0x1000;
120+
}

source/hic_hal/nxp/lpc11u35/flash_hal_stub.c

Lines changed: 0 additions & 47 deletions
This file was deleted.

source/target/nxp/lpc812/target.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626

2727
// target information
2828
target_cfg_t target_device = {
29-
.sector_size = 1024,
30-
.sector_cnt = (KB(16) / 1024),
29+
.sector_size = 0x1000,
30+
.sector_cnt = (KB(64) / 0x1000),
3131
.flash_start = 0,
32-
.flash_end = KB(16),
32+
.flash_end = KB(64),
3333
.ram_start = 0x10000000,
3434
.ram_end = 0x10001000,
3535
.flash_algo = (program_target_t *) &flash,

0 commit comments

Comments
 (0)