Skip to content

Commit a0b624b

Browse files
Merge pull request #5038 from chrissnow/LPC1768-Bootloader
Lpc1768 bootloader support
2 parents 4dff32a + 82ae53a commit a0b624b

File tree

10 files changed

+141
-54
lines changed

10 files changed

+141
-54
lines changed

platform/mbed_toolchain.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,26 @@
9292
#endif
9393
#endif
9494

95+
/** MBED_USED
96+
* Inform the compiler that a static variable is to be retained in the object file, even if it is unreferenced.
97+
*
98+
* @code
99+
* #include "mbed_toolchain.h"
100+
*
101+
* MBED_USED int foo;
102+
*
103+
* @endcode
104+
*/
105+
#ifndef MBED_USED
106+
#if defined(__GNUC__) || defined(__clang__) || defined(__CC_ARM)
107+
#define MBED_USED __attribute__((used))
108+
#elif defined(__ICCARM__)
109+
#define MBED_USED __root
110+
#else
111+
#define MBED_USED
112+
#endif
113+
#endif
114+
95115
/** MBED_WEAK
96116
* Mark a function as being weak.
97117
*
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2017 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "mbed_toolchain.h"
18+
19+
/* Code Read Protection
20+
21+
NONE 0xFFFFFFFF - No code protection.
22+
23+
CRP1 0x12345678 - Write to RAM command can not access RAM below 0x10000200.
24+
- Read Memory command: disabled.
25+
- Copy RAM to Flash command: cannot write to Sector 0.
26+
- "Go" command: disabled.
27+
- Erase sector(s) command: can erase any individual sector except
28+
sector 0 only, or can erase all sectors at once.
29+
- Compare command: disabled
30+
31+
CRP2 0x87654321 - Write to RAM command: disabled.
32+
- Copy RAM to Flash: disabled.
33+
- Erase command: only allows erase of all sectors.
34+
35+
CRP3 0x43218765 - Access to chip via the SWD pins is disabled. ISP entry
36+
by pulling PIO0_1 LOW is disabled if a valid user code is
37+
present in flash sector 0.
38+
Caution: If CRP3 is selected, no future factory testing can be
39+
performed on the device.
40+
*/
41+
#if !defined(APPLICATION_ADDR) // Relocate CRP if there is a bootloader.
42+
#define APPLICATION_ADDR 0
43+
#endif
44+
45+
#define CRP_NONE 0xFFFFFFFF
46+
#define CRP_1 0x12345678
47+
#define CRP_2 0x87654321
48+
#define CRP_3 0x43218765
49+
50+
#ifndef CRP
51+
#define CRP CRP_NONE
52+
#endif
53+
54+
MBED_SECTION(".CRPSection") MBED_USED const long CRP_Key = CRP;

targets/TARGET_NXP/TARGET_LPC176X/device/TOOLCHAIN_ARM_MICRO/LPC1768.sct

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
1+
#! armcc -E
12

2-
LR_IROM1 0x00000000 0x80000 { ; load region size_region
3-
ER_IROM1 0x00000000 0x80000 { ; load address = execution address
4-
*.o (RESET, +First)
5-
*(InRoot$$Sections)
6-
.ANY (+RO)
3+
#if !defined(MBED_APP_START)
4+
#define MBED_APP_START 0x00000000
5+
#endif
6+
7+
#if !defined(MBED_APP_SIZE)
8+
#define MBED_APP_SIZE 0x80000
9+
#endif
10+
11+
LR_IROM1 MBED_APP_START MBED_APP_SIZE { ; load region size_region
12+
ER_IROM0 MBED_APP_START 0x2FC { ; load address = execution address
13+
*.o (RESET, +First)
14+
.ANY (+RO)
15+
}
16+
ER_CRP (MBED_APP_START + 0x2FC) FIXED 4 {
17+
*.o (.CRPSection)
18+
}
19+
ER_IROM1 (MBED_APP_START + (0x2FC + 4)) FIXED (MBED_APP_SIZE - (0x2FC + 4)) {
20+
*(InRoot$$Sections)
21+
.ANY (+RO)
722
}
823
; 8_byte_aligned(49 vect * 4 bytes) = 8_byte_aligned(0xC4) = 0xC8
924
; 32KB (RAM size) - 0xC8 (NIVT) - 32 (topmost 32 bytes used by IAP functions) = 0x7F18

targets/TARGET_NXP/TARGET_LPC176X/device/TOOLCHAIN_ARM_MICRO/startup_LPC17xx.S

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,6 @@ __Vectors DCD __initial_sp ; Top of Stack
9999
DCD PLL1_IRQHandler ; 48: PLL1 Lock (USB PLL)
100100

101101

102-
IF :LNOT::DEF:NO_CRP
103-
AREA |.ARM.__at_0x02FC|, CODE, READONLY
104-
CRP_Key DCD 0xFFFFFFFF
105-
ENDIF
106-
107-
108102
AREA |.text|, CODE, READONLY
109103

110104

targets/TARGET_NXP/TARGET_LPC176X/device/TOOLCHAIN_ARM_STD/LPC1768.sct

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
1+
#! armcc -E
12

2-
LR_IROM1 0x00000000 0x80000 { ; load region size_region
3-
ER_IROM1 0x00000000 0x80000 { ; load address = execution address
4-
*.o (RESET, +First)
5-
*(InRoot$$Sections)
6-
.ANY (+RO)
3+
#if !defined(MBED_APP_START)
4+
#define MBED_APP_START 0x00000000
5+
#endif
6+
7+
#if !defined(MBED_APP_SIZE)
8+
#define MBED_APP_SIZE 0x80000
9+
#endif
10+
11+
LR_IROM1 MBED_APP_START MBED_APP_SIZE { ; load region size_region
12+
ER_IROM0 MBED_APP_START 0x2FC { ; load address = execution address
13+
*.o (RESET, +First)
14+
.ANY (+RO)
15+
}
16+
ER_CRP (MBED_APP_START + 0x2FC) FIXED 4 {
17+
*.o (.CRPSection)
18+
}
19+
ER_IROM1 (MBED_APP_START + (0x2FC + 4)) FIXED (MBED_APP_SIZE - (0x2FC + 4)) {
20+
*(InRoot$$Sections)
21+
.ANY (+RO)
722
}
823
; 8_byte_aligned(49 vect * 4 bytes) = 8_byte_aligned(0xC4) = 0xC8
924
; 32KB (RAM size) - 0xC8 (NIVT) - 32 (topmost 32 bytes used by IAP functions) = 0x7F18

targets/TARGET_NXP/TARGET_LPC176X/device/TOOLCHAIN_ARM_STD/startup_LPC17xx.S

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,6 @@ __Vectors DCD __initial_sp ; Top of Stack
8282
DCD PLL1_IRQHandler ; 48: PLL1 Lock (USB PLL)
8383

8484

85-
IF :LNOT::DEF:NO_CRP
86-
AREA |.ARM.__at_0x02FC|, CODE, READONLY
87-
CRP_Key DCD 0xFFFFFFFF
88-
ENDIF
89-
90-
9185
AREA |.text|, CODE, READONLY
9286

9387

targets/TARGET_NXP/TARGET_LPC176X/device/TOOLCHAIN_GCC_ARM/LPC1768.ld

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
/* Linker script for mbed LPC1768 */
2+
#if !defined(MBED_APP_START)
3+
#define MBED_APP_START 0x00000000
4+
#endif
25

6+
#if !defined(MBED_APP_SIZE)
7+
#define MBED_APP_SIZE 512K
8+
#endif
39
/* Linker script to configure memory regions. */
410
MEMORY
511
{
6-
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 512K
12+
FLASH (rx) : ORIGIN = MBED_APP_START, LENGTH = MBED_APP_SIZE
713
RAM (rwx) : ORIGIN = 0x100000C8, LENGTH = (32K - 0xC8 - 32) /* topmost 32 bytes used by IAP functions */
814

915
USB_RAM(rwx) : ORIGIN = 0x2007C000, LENGTH = 16K
@@ -43,6 +49,10 @@ SECTIONS
4349
.text :
4450
{
4551
KEEP(*(.isr_vector))
52+
/* Code Read Protect data */
53+
. = 0x000002FC ;
54+
KEEP(*(.CRPSection))
55+
/* End of Code Read Protect */
4656
*(.text*)
4757

4858
KEEP(*(.init))
@@ -65,6 +75,8 @@ SECTIONS
6575
*(.rodata*)
6676

6777
KEEP(*(.eh_frame*))
78+
79+
6880
} > FLASH
6981

7082
.ARM.extab :

targets/TARGET_NXP/TARGET_LPC176X/device/TOOLCHAIN_IAR/LPC17xx.icf

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
if (!isdefinedsymbol(MBED_APP_START)) { define symbol MBED_APP_START = 0x00000000; }
2+
if (!isdefinedsymbol(MBED_APP_SIZE)) { define symbol MBED_APP_SIZE = 0x80000; }
13
/*###ICF### Section handled by ICF editor, don't touch! ****/
24
/*-Editor annotation file-*/
35
/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */
46
/*-Specials-*/
5-
define symbol __ICFEDIT_intvec_start__ = 0x00000000;
7+
define symbol __ICFEDIT_intvec_start__ = MBED_APP_START;
68
/*-Memory Regions-*/
7-
define symbol __ICFEDIT_region_ROM_start__ = 0x00000000;
8-
define symbol __ICFEDIT_region_ROM_end__ = 0x0007FFFF;
9+
define symbol __ICFEDIT_region_ROM_start__ = MBED_APP_START;
10+
define symbol __ICFEDIT_region_ROM_end__ = MBED_APP_START + MBED_APP_SIZE - 1;
911
define symbol __ICFEDIT_region_NVIC_start__ = 0x10000000;
1012
define symbol __ICFEDIT_region_NVIC_end__ = 0x100000C7;
1113
define symbol __ICFEDIT_region_RAM_start__ = 0x100000C8;
@@ -17,8 +19,8 @@ define symbol __ICFEDIT_size_cstack__ = 0x1000;
1719
define symbol __ICFEDIT_size_heap__ = 0x2000;
1820
/**** End of ICF editor section. ###ICF###*/
1921

20-
define symbol __CRP_start__ = 0x000002FC;
21-
define symbol __CRP_end__ = 0x000002FF;
22+
define symbol __CRP_start__ = MBED_APP_START + 0x000002FC;
23+
define symbol __CRP_end__ = MBED_APP_START + 0x000002FF;
2224

2325
define symbol __RAM1_start__ = 0x2007C000;
2426
define symbol __RAM1_end__ = 0x20083FFF;
@@ -41,5 +43,5 @@ place in ROM_region { readonly };
4143
place in RAM_region { readwrite,
4244
block HEAP, block CSTACK };
4345

44-
place in CRP_region { section .crp };
46+
place in CRP_region { section .CRPSection };
4547
place in RAM1_region { section .ethusbram };

targets/TARGET_NXP/TARGET_LPC176X/device/TOOLCHAIN_IAR/startup_LPC17xx.S

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -350,26 +350,4 @@ USBActivity_IRQHandler
350350
CANActivity_IRQHandler
351351
B CANActivity_IRQHandler
352352

353-
#ifndef SRAM
354-
SECTION .crp:CODE:ROOT(2)
355-
DATA
356-
/* Code Read Protection
357-
CRP1 0x12345678 - Write to RAM command can not access RAM below 0x10000200.
358-
- Read Memory command: disabled.
359-
- Copy RAM to Flash command: cannot write to Sector 0.
360-
- "Go" command: disabled.
361-
- Erase sector(s) command: can erase any individual sector except
362-
sector 0 only, or can erase all sectors at once.
363-
- Compare command: disabled
364-
CRP2 0x87654321 - Write to RAM command: disabled.
365-
- Copy RAM to Flash: disabled.
366-
- Erase command: only allows erase of all sectors.
367-
CRP3 0x43218765 - Access to chip via the SWD pins is disabled. ISP entry
368-
by pulling PIO0_1 LOW is disabled if a valid user code is
369-
present in flash sector 0.
370-
Caution: If CRP3 is selected, no future factory testing can be
371-
performed on the device.
372-
*/
373-
DCD 0xFFFFFFFF
374-
#endif
375353
END

targets/targets.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@
241241
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "DEBUG_AWARENESS", "ETHERNET", "I2C", "I2CSLAVE", "INTERRUPTIN", "LOCALFILESYSTEM", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SEMIHOST", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES", "FLASH"],
242242
"release_versions": ["2", "5"],
243243
"features": ["LWIP"],
244-
"device_name": "LPC1768"
244+
"device_name": "LPC1768",
245+
"bootloader_supported": true
245246
},
246247
"ARCH_PRO": {
247248
"supported_form_factors": ["ARDUINO"],
@@ -253,7 +254,8 @@
253254
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "DEBUG_AWARENESS", "ETHERNET", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES", "FLASH"],
254255
"release_versions": ["2", "5"],
255256
"features": ["LWIP"],
256-
"device_name": "LPC1768"
257+
"device_name": "LPC1768",
258+
"bootloader_supported": true
257259
},
258260
"UBLOX_C027": {
259261
"supported_form_factors": ["ARDUINO"],
@@ -277,7 +279,8 @@
277279
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "DEBUG_AWARENESS", "ETHERNET", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES", "FLASH"],
278280
"release_versions": ["2", "5"],
279281
"features": ["LWIP"],
280-
"device_name": "LPC1768"
282+
"device_name": "LPC1768",
283+
"bootloader_supported": true
281284
},
282285
"XBED_LPC1768": {
283286
"inherits": ["LPCTarget"],

0 commit comments

Comments
 (0)