Skip to content

Commit 4e09b52

Browse files
committed
K20 uVision files, ld NVIC offset
- K20 KEIL files - clock set to 1 (48MHz) - offset in GCC ld for vectors in RAM - us ticker - PIT timer interrupt implementation
1 parent 8ca8014 commit 4e09b52

File tree

8 files changed

+733
-18
lines changed

8 files changed

+733
-18
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
LR_IROM1 0x00000000 0x20000 { ; load region size_region (132k)
3+
ER_IROM1 0x00000000 0x20000 { ; load address = execution address
4+
*.o (RESET, +First)
5+
*(InRoot$$Sections)
6+
.ANY (+RO)
7+
}
8+
; 8_byte_aligned(61 vect * 4 bytes) = 8_byte_aligned(0xF4) = 0xF8
9+
; 0x4000 - 0xF8 = 0x3F08
10+
RW_IRAM1 0x1FFFE0F8 0x3F08 {
11+
.ANY (+RW +ZI)
12+
}
13+
}
14+

libraries/mbed/targets/cmsis/TARGET_Freescale/TARGET_K20D5M/TOOLCHAIN_ARM_STD/startup_MK20D5.s

Lines changed: 654 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* mbed Microcontroller Library - stackheap
2+
* Copyright (C) 2009-2011 ARM Limited. All rights reserved.
3+
*
4+
* Setup a fixed single stack/heap memory model,
5+
* between the top of the RW/ZI region and the stackpointer
6+
*/
7+
8+
#ifdef __cplusplus
9+
extern "C" {
10+
#endif
11+
12+
#include <rt_misc.h>
13+
#include <stdint.h>
14+
15+
extern char Image$$RW_IRAM1$$ZI$$Limit[];
16+
17+
extern __value_in_regs struct __initial_stackheap __user_setup_stackheap(uint32_t R0, uint32_t R1, uint32_t R2, uint32_t R3) {
18+
uint32_t zi_limit = (uint32_t)Image$$RW_IRAM1$$ZI$$Limit;
19+
uint32_t sp_limit = __current_sp();
20+
21+
zi_limit = (zi_limit + 7) & ~0x7; // ensure zi_limit is 8-byte aligned
22+
23+
struct __initial_stackheap r;
24+
r.heap_base = zi_limit;
25+
r.heap_limit = sp_limit;
26+
return r;
27+
}
28+
29+
#ifdef __cplusplus
30+
}
31+
#endif

libraries/mbed/targets/cmsis/TARGET_Freescale/TARGET_K20D5M/TOOLCHAIN_GCC_ARM/MK20D5.ld

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/*
2-
* KL25Z ARM GCC linker script file
2+
* K20 ARM GCC linker script file
33
*/
44

55
MEMORY
66
{
77
VECTORS (rx) : ORIGIN = 0x00000000, LENGTH = 0x00000400
88
FLASH_PROTECTION (rx) : ORIGIN = 0x00000400, LENGTH = 0x00000010
99
FLASH (rx) : ORIGIN = 0x00000410, LENGTH = 128K - 0x00000410
10-
RAM (rwx) : ORIGIN = 0x1FFFE000, LENGTH = 16K
10+
RAM (rwx) : ORIGIN = 0x1FFFE0F8, LENGTH = 16K - 0xC8
1111
}
1212

1313
/* Linker script to place sections and symbol values. Should be used together

libraries/mbed/targets/cmsis/TARGET_Freescale/TARGET_K20D5M/TOOLCHAIN_GCC_ARM/startup_MK20D5.s

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,15 @@ Reset_Handler:
211211
def_irq_handler CPU_CLCD_IRQHandler
212212
def_irq_handler SPI_IRQHandler
213213

214+
/* Flash protection region, placed at 0x400 */
215+
.text
216+
.thumb
217+
.align 2
218+
.section .kinetis_flash_config_field,"a",%progbits
219+
kinetis_flash_config:
220+
.long 0xffffffff
221+
.long 0xffffffff
222+
.long 0xffffffff
223+
.long 0xfffffffe
224+
214225
.end

libraries/mbed/targets/cmsis/TARGET_Freescale/TARGET_K20D5M/system_MK20D5.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
#define DISABLE_WDOG 1
4646

47-
#define CLOCK_SETUP 0
47+
#define CLOCK_SETUP 1
4848
/* Predefined clock setups
4949
0 ... Multipurpose Clock Generator (MCG) in FLL Engaged Internal (FEI) mode
5050
Reference clock source for MCG module is the slow internal clock source 32.768kHz

libraries/mbed/targets/hal/TARGET_Freescale/TARGET_K20D5M/us_ticker.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,34 @@ void us_ticker_init(void) {
3030
lptmr_init();
3131
}
3232

33+
static uint32_t pit_us_ticker_counter = 0;
34+
35+
void pit0_isr(void) {
36+
pit_us_ticker_counter++;
37+
PIT->CHANNEL[0].LDVAL = 48; // 1us
38+
PIT->CHANNEL[0].TFLG = 1;
39+
}
40+
3341
/******************************************************************************
3442
* Timer for us timing.
3543
******************************************************************************/
3644
static void pit_init(void) {
37-
SIM->SCGC6 |= SIM_SCGC6_PIT_MASK; // Clock PIT
38-
PIT->MCR = 0; // Enable PIT
39-
40-
// Channel 1
41-
PIT->CHANNEL[1].LDVAL = 0xFFFFFFFF;
42-
PIT->CHANNEL[1].TCTRL = PIT_TCTRL_TIE_MASK; // Chain to timer 0, disable Interrupts
43-
PIT->CHANNEL[1].TCTRL |= PIT_TCTRL_TEN_MASK; // Start timer 1
44-
45-
// Use channel 0 as a prescaler for channel 1
46-
PIT->CHANNEL[0].LDVAL = 23;
47-
PIT->CHANNEL[0].TCTRL = PIT_TCTRL_TEN_MASK; // Start timer 0, disable interrupts
45+
SIM->SCGC6 |= SIM_SCGC6_PIT_MASK; // Clock PIT
46+
PIT->MCR = 0; // Enable PIT
47+
48+
PIT->CHANNEL[0].LDVAL = 48; // 1us
49+
PIT->CHANNEL[0].TCTRL |= PIT_TCTRL_TIE_MASK;
50+
PIT->CHANNEL[0].TCTRL |= PIT_TCTRL_TEN_MASK; // Start timer 1
51+
52+
NVIC_SetVector(PIT0_IRQn, (uint32_t)pit0_isr);
53+
NVIC_EnableIRQ(PIT0_IRQn);
4854
}
4955

5056
uint32_t us_ticker_read() {
5157
if (!us_ticker_inited)
5258
us_ticker_init();
53-
54-
// The PIT is a countdown timer
55-
return ~(PIT->CHANNEL[1].CVAL);
59+
60+
return pit_us_ticker_counter;
5661
}
5762

5863
/******************************************************************************

workspace_tools/targets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def __init__(self):
140140

141141
self.extra_labels = ['Freescale']
142142

143-
self.supported_toolchains = ["GCC_ARM"]
143+
self.supported_toolchains = ["GCC_ARM", "ARM"]
144144

145145
self.is_disk_virtual = True
146146

0 commit comments

Comments
 (0)