-
Notifications
You must be signed in to change notification settings - Fork 0
/
arm_kinetis_debug.h
155 lines (135 loc) · 5.25 KB
/
arm_kinetis_debug.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
* Simple ARM debug interface for Arduino, using the SWD (Serial Wire Debug) port.
* Extensions for Freescale Kinetis chips.
*
* Copyright (c) 2013 Micah Elizabeth Scott
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include "arm_debug.h"
class ARMKinetisDebug : public ARMDebug
{
public:
ARMKinetisDebug(unsigned clockPin, unsigned dataPin, LogLevel logLevel = LOG_NORMAL);
// First-time initialization, resetting into system halt state.
bool startup();
bool detect(); // Detect supported Kinetis hardware
bool reset(); // System reset
// Even more hardware-specific
bool initK20(); // Initialize K20 peripherals into default state
// High-level GPIO interface.
bool pinMode(unsigned p, int mode);
bool digitalWrite(unsigned p, int value);
int digitalRead(unsigned p);
bool digitalWritePort(unsigned port, unsigned value);
// Bit-band operations on IO space
bool memStoreBit(uint32_t addr, unsigned bit, uint32_t data);
bool memLoadBit(uint32_t addr, unsigned bit, uint32_t &data);
// USB controller pull-up resistor
bool usbSetPullup(bool enable);
// Flash mass-erase operation. Works even on protected devices.
bool flashMassErase();
// Initialize the FlexRAM buffer for flash sector programming
bool flashSectorBufferInit();
// Write a chunk of data to the flash sector buffer
bool flashSectorBufferWrite(uint32_t bufferOffset, const uint32_t *data, unsigned count);
// Write one flash sector from the buffer
bool flashSectorProgram(uint32_t address);
/*
* High-level flash programming manager. Handles the entire programming process,
* including protection resets and verification.
*/
class FlashProgrammer {
public:
FlashProgrammer(ARMKinetisDebug &target, const uint32_t *image, unsigned numSectors);
bool begin();
bool isComplete();
bool next();
private:
ARMKinetisDebug ⌖
const uint32_t *image;
unsigned numSectors;
unsigned nextSector;
bool isVerifying;
};
static const uint32_t kFlashSectorSize = 1024;
// Port constants. (Corresponds to PCR address base)
enum Port {
PTA = 0x0000,
PTB = 0x1000,
PTC = 0x2000,
PTD = 0x3000,
PTE = 0x4000,
};
// Pin constants. (Corresponds to PCR address map)
enum Pin {
PTA0 = 0x0000 + 4 * 0,
PTA1 = 0x0000 + 4 * 1,
PTA2 = 0x0000 + 4 * 2,
PTA3 = 0x0000 + 4 * 3,
PTA4 = 0x0000 + 4 * 4,
PTA5 = 0x0000 + 4 * 5,
PTA12 = 0x0000 + 4 * 12,
PTA13 = 0x0000 + 4 * 13,
PTA18 = 0x0000 + 4 * 18,
PTA19 = 0x0000 + 4 * 19,
PTB0 = 0x1000 + 4 * 0,
PTB1 = 0x1000 + 4 * 1,
PTB2 = 0x1000 + 4 * 2,
PTB3 = 0x1000 + 4 * 3,
PTB16 = 0x1000 + 4 * 16,
PTB17 = 0x1000 + 4 * 17,
PTB18 = 0x1000 + 4 * 18,
PTB19 = 0x1000 + 4 * 19,
PTC0 = 0x2000 + 4 * 0,
PTC1 = 0x2000 + 4 * 1,
PTC2 = 0x2000 + 4 * 2,
PTC3 = 0x2000 + 4 * 3,
PTC4 = 0x2000 + 4 * 4,
PTC5 = 0x2000 + 4 * 5,
PTC6 = 0x2000 + 4 * 6,
PTC7 = 0x2000 + 4 * 7,
PTC8 = 0x2000 + 4 * 8,
PTC9 = 0x2000 + 4 * 9,
PTC10 = 0x2000 + 4 * 10,
PTC11 = 0x2000 + 4 * 11,
PTD0 = 0x3000 + 4 * 0,
PTD1 = 0x3000 + 4 * 1,
PTD2 = 0x3000 + 4 * 2,
PTD3 = 0x3000 + 4 * 3,
PTD4 = 0x3000 + 4 * 4,
PTD5 = 0x3000 + 4 * 5,
PTD6 = 0x3000 + 4 * 6,
PTD7 = 0x3000 + 4 * 7,
PTE0 = 0x4000 + 4 * 0,
PTE1 = 0x4000 + 4 * 1,
};
// Assemble a pin number programmatically
Pin pin(Port port, unsigned index) {
return (Pin)(port + index * 4);
}
protected:
bool testMemoryAccess();
// Low-level flash interface
bool ftfl_busyWait();
bool ftfl_launchCommand();
bool ftfl_setFlexRAMFunction(uint8_t controlCode);
bool ftfl_programSection(uint32_t address, uint32_t numLWords);
bool ftfl_handleCommandStatus(const char *cmdSpecificError = 0);
};