Skip to content

Commit e7646b8

Browse files
committed
WIP. Testing GDB packet parsing.
1 parent 0c99894 commit e7646b8

File tree

2 files changed

+37
-28
lines changed

2 files changed

+37
-28
lines changed

gdb.py

+33-28
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
3636
conn.close()
3737
38-
3938
"""
4039

4140
testbuf = (
@@ -61,15 +60,35 @@
6160

6261
class gdb(object):
6362

64-
def __init__(self, port):
65-
self.port = port # gdb listening port
63+
def __init__(self, cpu):
64+
self.cpu = cpu
65+
self.port = 3333 # gdb listening port
6666
self.rx_state = self.wait4_start # receive packet state
6767
self.rx_cs = [] # receive packet checksum
6868
self.rx_data = [] # receive packet data
6969

70+
def rx_ack(self):
71+
print('ack')
72+
73+
def rx_nak(self):
74+
print('nak')
75+
76+
def rx_cmd(self, cmd):
77+
print('%s' % cmd)
78+
79+
def csum_good(self, data, cs):
80+
csum = 0
81+
for c in data:
82+
csum += ord(c)
83+
return int(cs, 16) == csum % 256
84+
7085
def wait4_start(self, c):
7186
"""wait for the packet start delimiter"""
72-
if c == '$':
87+
if c == '+':
88+
self.rx_ack()
89+
elif c == '-':
90+
self.rx_nak()
91+
elif c == '$':
7392
# get the packet data
7493
self.rx_data = []
7594
self.rx_state = self.wait4_end
@@ -82,7 +101,7 @@ def wait4_end(self, c):
82101
if c == '#':
83102
# get the checksum
84103
self.rx_cs = []
85-
self.rx_state == self.wait4_checksum
104+
self.rx_state = self.wait4_checksum
86105
else:
87106
# accumulate the packet data
88107
self.rx_data.append(c)
@@ -95,34 +114,20 @@ def wait4_checksum(self, c):
95114
# we have the checksum
96115
cs = ''.join(self.rx_cs)
97116
data = ''.join(self.rx_data)
98-
# TODO process the checksum
99-
self.ui.put('data: %s cs %s' % (data, cs))
100-
self.rx_state == self.wait4_start
101-
102-
def wait4_ack(self, c):
103-
"""wait for an acknowledgement"""
104-
if c == '+':
105-
# ack TODO clear the packet
106-
pass
107-
elif c == '-':
108-
# nack TODO retransmit
109-
pass
110-
else:
111-
# what is this?
112-
pass
117+
if self.csum_good(data, cs):
118+
self.rx_cmd(data)
119+
else:
120+
# TODO: bad checksum - send a nak
121+
pass
122+
self.rx_state = self.wait4_start
113123

114124
def rx(self, buf):
115125
"""receive a buffer of characters"""
116126
for c in buf:
117127
self.rx_state(c)
118128

119-
120-
121-
#-----------------------------------------------------------------------------
122-
123-
def main():
124-
print testbuf
125-
126-
main()
129+
def run(self, ui, args):
130+
"""run the gdb server"""
131+
self.rx(testbuf)
127132

128133
#-----------------------------------------------------------------------------

target/mb997c.py

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import gpio
1515
import i2c
1616
import rtt
17+
import gdb
1718

1819
import vendor.st.st as vendor
1920
import vendor.st.flash as flash_driver
@@ -105,6 +106,8 @@ def __init__(self, ui, dbgio):
105106
# setup the rtt client
106107
ram = self.device.sram
107108
self.rtt = rtt.rtt(self.cpu, mem.region('ram', ram.address, ram.size))
109+
# setup the gdb server
110+
self.gdb = gdb.gdb(self.cpu)
108111

109112
self.menu_root = (
110113
('cpu', self.cpu.menu, 'cpu functions'),
@@ -113,6 +116,7 @@ def __init__(self, ui, dbgio):
113116
('debugger', self.dbgio.menu, 'debugger functions'),
114117
('exit', self.cmd_exit),
115118
('flash', self.flash.menu, 'flash functions'),
119+
('gdb', self.gdb.run),
116120
('go', self.cpu.cmd_go),
117121
('gpio', self.gpio.menu, 'gpio functions'),
118122
('halt', self.cpu.cmd_halt),

0 commit comments

Comments
 (0)