Skip to content

Commit cfb76af

Browse files
committed
Initial Commit
1 parent 061c4b5 commit cfb76af

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+3584
-1
lines changed

.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
*.py[cod]
22

3+
# Private settings
4+
private_settings.py
5+
6+
# Eclipse Project Files
7+
.cproject
8+
.project
9+
.pydevproject
10+
311
# C extensions
412
*.so
513

@@ -34,3 +42,4 @@ nosetests.xml
3442
.mr.developer.cfg
3543
.project
3644
.pydevproject
45+
*.bak

README.md

+154-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,157 @@
11
pyOCD
22
=====
3+
pyOCD is an Open Source python library or programming and debugging
4+
ARM Cortex-M microcontrollers using CMSIS-DAP.
35

4-
Open source python library for programming and debugging ARM Cortex-M microcontrollers using CMSIS-DAP
6+
You can use the following interfaces:
7+
8+
1. From a python interpretor:
9+
* halt, step, resume execution
10+
* read/write memory
11+
* read/write block memory
12+
* read-write core register
13+
* set/remove hardware breakpoints
14+
* flash new binary
15+
* reset
16+
2. From a GDB client, you have all the features provided by gdb:
17+
* load a .elf file
18+
* read/write memory
19+
* read/write core register
20+
* set/remove hardware breakpoints
21+
* high level stepping
22+
* ...
23+
24+
Dependencies
25+
------------
26+
pyOCD relies on external libraries:
27+
28+
* Windows: [pyWinUSB](https://github.com/rene-aguirre/pywinusb):
29+
30+
```
31+
$ cd /path-to-pywinusb/
32+
$ python setup.py install
33+
```
34+
35+
* Linux: [pyUSB](https://github.com/walac/pyusb):
36+
37+
```
38+
$ sudo apt-get install python libusb-1.0-0-dev
39+
$ cd /path-to-pyusb/
40+
$ sudo python setup.py install
41+
```
42+
43+
* Mac:
44+
So far Mac OS X is not supported
45+
46+
47+
Installation
48+
------------
49+
```
50+
$ cd /path-to-pyOCD/
51+
$ python setup.py install
52+
```
53+
54+
Examples
55+
--------
56+
### Tests
57+
A series of tests are on the test directory:
58+
* basic_test.py: simple test that checks:
59+
* read/write core registers
60+
* read/write memory
61+
* stop/resume/step the execution
62+
* reset the target
63+
* flash a binary
64+
* gdb_test.py: launch a gdbserver
65+
66+
### Hello World example
67+
```python
68+
from pyOCD.board import MbedBoard
69+
70+
import logging
71+
logging.basicConfig(level=logging.INFO)
72+
73+
board = MbedBoard.chooseBoard()
74+
75+
target = board.target
76+
flash = board.flash
77+
target.resume()
78+
target.halt()
79+
80+
print "pc: 0x%X" % target.readCoreRegister("pc")
81+
pc: 0xA64
82+
83+
target.step()
84+
print "pc: 0x%X" % target.readCoreRegister("pc")
85+
pc: 0xA30
86+
87+
target.step()
88+
print "pc: 0x%X" % target.readCoreRegister("pc")
89+
pc: 0xA32
90+
91+
flash.flashBinary("binaries/l1_lpc1768.bin")
92+
print "pc: 0x%X" % target.readCoreRegister("pc")
93+
pc: 0x10000000
94+
95+
target.reset()
96+
target.halt()
97+
print "pc: 0x%X" % target.readCoreRegister("pc")
98+
pc: 0xAAC
99+
100+
board.uninit()
101+
```
102+
103+
###GDB server example
104+
Python:
105+
```python
106+
from pyOCD.gdbserver import GDBServer
107+
from pyOCD.board import MbedBoard
108+
109+
import logging
110+
logging.basicConfig(level=logging.INFO)
111+
112+
board = MbedBoard.chooseBoard()
113+
114+
# start gdbserver
115+
gdb = GDBServer(board, 3333)
116+
```
117+
gdb server:
118+
```
119+
arm-none-eabi-gdb basic.elf
120+
121+
<gdb> target remote localhost:3333
122+
<gdb> load
123+
<gdb> continue
124+
125+
```
126+
127+
Architecture
128+
------------
129+
130+
### Interface
131+
An interface does the link between the target and the computer.
132+
This module contains basic functionalities to write and read data to and from
133+
an interface. You can inherit from ```Interface``` and overwrite ```read()```, ```write()```,...
134+
135+
Then declare your interface in ```INTERFACE``` (in ```pyOCD.interface.__init__.py```)
136+
137+
### Target
138+
A target defines basic functionalities such as ```step```, ```resume```, ```halt```, ```readMemory```,...
139+
You can inherit from Target to implement your own methods.
140+
141+
Then declare your target in TARGET (in ```pyOCD.target.__init__.py```)
142+
143+
### Transport
144+
Defines the transport used to communicate. In particular, you can find CMSIS-DAP.
145+
Implements methods such as ```memWriteAP```, ```memReadAP```, ```writeDP```, ```readDP```, ...
146+
147+
You can inherit from ```Transport``` and implement your own methods.
148+
Then declare your transport in ```TRANSPORT``` (in ```pyOCD.transport.__init__.py```)
149+
150+
### Flash
151+
Contains flash algorithm in order to flash a new binary into the target.
152+
153+
### gdbserver
154+
Start a GDB server. The server listens on a specific port. You can then
155+
connect a GDB client to it and debug/program the target
156+
157+
Then you can debug a board which is composed by an interface, a target, a transport and a flash

__init__.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
mbed CMSIS-DAP debugger
3+
Copyright (c) 2006-2013 ARM Limited
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
"""

binaries/l1_kl25z.bin

1.86 KB
Binary file not shown.

binaries/l1_lpc11u24.bin

3.74 KB
Binary file not shown.

binaries/l1_lpc1768.bin

4.04 KB
Binary file not shown.

binaries/l1_lpc800.bin

2.53 KB
Binary file not shown.

elf_files/lpc11u24_l1_gcc_arm.elf

140 KB
Binary file not shown.

elf_files/lpc1768_l1_gcc_arm.elf

151 KB
Binary file not shown.

pyOCD/__init__.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
mbed CMSIS-DAP debugger
3+
Copyright (c) 2006-2013 ARM Limited
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
"""

pyOCD/board/__init__.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""
2+
mbed CMSIS-DAP debugger
3+
Copyright (c) 2006-2013 ARM Limited
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
"""
17+
18+
from mbed_board import MbedBoard

pyOCD/board/board.py

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
"""
2+
mbed CMSIS-DAP debugger
3+
Copyright (c) 2006-2013 ARM Limited
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
"""
17+
18+
from pyOCD.target import TARGET
19+
from pyOCD.transport import TRANSPORT
20+
from pyOCD.interface import INTERFACE
21+
from pyOCD.flash import FLASH
22+
23+
import logging
24+
25+
class Board():
26+
"""
27+
This class associates a target, a flash, a transport and an interface
28+
to create a board
29+
"""
30+
def __init__(self, target, flash, interface, transport = "cmsis_dap"):
31+
if isinstance(interface, str) == False:
32+
self.interface = interface
33+
else:
34+
self.interface = INTERFACE[interface].chooseInterface(INTERFACE[interface])
35+
self.transport = TRANSPORT[transport](self.interface)
36+
self.target = TARGET[target](self.transport)
37+
self.flash = FLASH[flash](self.target)
38+
return
39+
40+
def init(self):
41+
"""
42+
Initialize the board: interface, transport and target
43+
"""
44+
logging.debug("init board %s", self)
45+
self.interface.init()
46+
self.transport.init()
47+
self.target.init()
48+
49+
def uninit(self):
50+
"""
51+
Uninitialize the board: inetrface, transport and target.
52+
This function resets the target
53+
"""
54+
logging.debug("uninit board %s", self)
55+
self.target.resume()
56+
self.transport.uninit()
57+
self.interface.close()
58+
59+
def getInfo(self):
60+
return self.interface.getInfo()

0 commit comments

Comments
 (0)