-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdebugging-hook.patch
More file actions
199 lines (186 loc) · 6.97 KB
/
Copy pathdebugging-hook.patch
File metadata and controls
199 lines (186 loc) · 6.97 KB
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
diff --git a/extmod/modwebrepl.c b/extmod/modwebrepl.c
index 9d09f65a3..7ce7c3d78 100644
--- a/extmod/modwebrepl.c
+++ b/extmod/modwebrepl.c
@@ -173,9 +173,36 @@ static void handle_op(mp_obj_webrepl_t *self) {
}
}
+volatile int check_debug = 0;
+void receive_debugger_file() {
+ char buf[512];
+ volatile int len = 0;
+ __asm volatile ("bkpt");
+ mp_obj_t open_args[2] = {
+ mp_obj_new_str(buf, len),
+ MP_OBJ_NEW_QSTR(MP_QSTR_wb)
+ };
+ mp_obj_t file = mp_builtin_open(2, open_args, (mp_map_t *)&mp_const_empty_map);
+ while(len > 0){
+ __asm volatile ("bkpt");
+ if(len == 0){
+ break;
+ }
+ int err;
+ mp_uint_t res = mp_stream_write_exactly(file, buf, len, &err);
+ if (err != 0 || res != len) {
+ assert(0);
+ }
+ }
+ mp_stream_close(file);
+}
+
static mp_uint_t _webrepl_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode);
static mp_uint_t webrepl_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) {
+ if(check_debug){
+ receive_debugger_file();
+ }
mp_uint_t out_sz;
do {
out_sz = _webrepl_read(self_in, buf, size, errcode);
diff --git a/ports/rp2/mphalport.c b/ports/rp2/mphalport.c
index 1641eadb7..d1490d6c8 100644
--- a/ports/rp2/mphalport.c
+++ b/ports/rp2/mphalport.c
@@ -129,6 +129,8 @@ uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) {
return ret;
}
+volatile int debugging = 0;
+
// Receive single character
int mp_hal_stdin_rx_chr(void) {
for (;;) {
@@ -146,10 +148,16 @@ int mp_hal_stdin_rx_chr(void) {
return dupterm_c;
}
#endif
+ if(debugging & 1) {
+ __asm volatile ("bkpt");
+ }
mp_event_wait_indefinite();
}
}
+STATIC uint8_t stdout_ringbuf_array[512];
+ringbuf_t stdout_ringbuf = { stdout_ringbuf_array, sizeof(stdout_ringbuf_array) };
+
// Send string of given length
mp_uint_t mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
mp_uint_t ret = len;
@@ -158,8 +166,16 @@ mp_uint_t mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
mp_uart_write_strn(str, len);
did_write = true;
#endif
+ for (size_t i = 0; (debugging & 2) && i < len; i++) {
+ if(ringbuf_free(&stdout_ringbuf)){
+ ringbuf_put(&stdout_ringbuf, str[i]);
+ }
+ if(( debugging & 2) && !ringbuf_free(&stdout_ringbuf)){
+ __asm volatile ("bkpt");
+ }
+ }
#if MICROPY_HW_USB_CDC
if (tud_cdc_connected()) {
diff --git a/ports/rp2/mphalport.c b/ports/rp2/mphalport.c
index d1490d6c8..c3b9158ad 100644
--- a/ports/rp2/mphalport.c
+++ b/ports/rp2/mphalport.c
@@ -155,7 +155,7 @@ int mp_hal_stdin_rx_chr(void) {
}
}
-STATIC uint8_t stdout_ringbuf_array[512];
+static uint8_t stdout_ringbuf_array[512];
ringbuf_t stdout_ringbuf = { stdout_ringbuf_array, sizeof(stdout_ringbuf_array) };
// Send string of given length
diff --git a/lib/cyw43-driversrc/cyw43_ctrl.c b/lib/cyw43-driversrc/cyw43_ctrl.c
index a9db363..34e2e27 100644
--- a/lib/cyw43-driversrc/cyw43_ctrl.c
+++ b/lib/cyw43-driversrc/cyw43_ctrl.c
@@ -447,6 +447,7 @@ int cyw43_ioctl(cyw43_t *self, uint32_t cmd, size_t len, uint8_t *buf, uint32_t
return ret;
}
+extern volatile int debugging;
int cyw43_send_ethernet(cyw43_t *self, int itf, size_t len, const void *buf, bool is_pbuf) {
CYW43_THREAD_ENTER;
int ret = cyw43_ensure_up(self);
@@ -454,6 +455,10 @@ int cyw43_send_ethernet(cyw43_t *self, int itf, size_t len, const void *buf, boo
CYW43_THREAD_EXIT;
return ret;
}
+ if ( debugging & 8 ) {
+ __asm volatile (".global cyw43_eth_output_hook");
+ __asm volatile ("cyw43_eth_output_hook: bkpt");
+ }
ret = cyw43_ll_send_ethernet(&self->cyw43_ll, itf, len, buf, is_pbuf);
CYW43_THREAD_EXIT;
@@ -776,6 +781,10 @@ int cyw43_bluetooth_hci_read(uint8_t *buf, uint32_t max_size, uint32_t *len) {
return ret;
}
ret = cyw43_btbus_read(buf, max_size, len);
+ if (*len != 0 && (debugging & 16) && ((debugging & 64) || !(*len >= 9 && buf[3] == 0x04 && buf[4] == 0x0e && (buf[7] == 0x17 || buf[7] == 0x18) && buf[8] == 0x20))) {
+ __asm volatile (".global cyw43_bt_input_hook");
+ __asm volatile ("cyw43_bt_input_hook: bkpt");
+ }
if (ret) {
CYW43_PRINTF("cyw43_bluetooth_hci_read: failed to read from shared bus\n");
return ret;
@@ -790,6 +799,10 @@ int cyw43_bluetooth_hci_write(uint8_t *buf, size_t len) {
if (ret) {
return ret;
}
+ if ((debugging & 32) && ((debugging & 64) || !(len >= 6 && buf[3] == 0x01 && (buf[4] == 0x17 || buf[4] == 0x18) && buf[5] == 0x20))) {
+ __asm volatile (".global cyw43_bt_output_hook");
+ __asm volatile ("cyw43_bt_output_hook: bkpt");
+ }
ret = cyw43_btbus_write(buf, len);
if (ret) {
CYW43_PRINTF("cyw43_bluetooth_hci_write: failed to write to shared bus\n");
diff --git a/lib/cyw43-driversrc/cyw43_lwip.c b/lib/cyw43-driversrc/cyw43_lwip.c
index be043f4..0950035 100644
--- a/lib/cyw43-driversrc/cyw43_lwip.c
+++ b/lib/cyw43-driversrc/cyw43_lwip.c
@@ -84,6 +84,7 @@ static void cyw43_ethernet_trace(cyw43_t *self, struct netif *netif, size_t len,
}
#endif
+extern volatile int debugging;
static err_t cyw43_netif_output(struct netif *netif, struct pbuf *p) {
cyw43_t *self = netif->state;
#if CYW43_NETUTILS
@@ -265,8 +266,12 @@ void cyw43_cb_tcpip_deinit(cyw43_t *self, int itf) {
void cyw43_cb_process_ethernet(void *cb_data, int itf, size_t len, const uint8_t *buf) {
cyw43_t *self = cb_data;
struct netif *netif = &self->netif[itf];
+ if ( debugging & 4 ) {
+ __asm volatile (".global cyw43_eth_input_hook");
+ __asm volatile ("cyw43_eth_input_hook: bkpt");
+ }
#if CYW43_NETUTILS
if (self->trace_flags) {
cyw43_ethernet_trace(self, netif, len, buf, NETUTILS_TRACE_NEWLINE);
diff --git a/lib/cyw43-driversrc/cyw43_ctrl.c b/lib/cyw43-driversrc/cyw43_ctrl.c
index 34e2e27..a459635 100644
--- a/lib/cyw43-driversrc/cyw43_ctrl.c
+++ b/lib/cyw43-driversrc/cyw43_ctrl.c
@@ -455,10 +455,6 @@ int cyw43_send_ethernet(cyw43_t *self, int itf, size_t len, const void *buf, boo
CYW43_THREAD_EXIT;
return ret;
}
- if ( debugging & 8 ) {
- __asm volatile (".global cyw43_eth_output_hook");
- __asm volatile ("cyw43_eth_output_hook: bkpt");
- }
ret = cyw43_ll_send_ethernet(&self->cyw43_ll, itf, len, buf, is_pbuf);
CYW43_THREAD_EXIT;
diff --git a/lib/cyw43-driversrc/cyw43_lwip.c b/lib/cyw43-driversrc/cyw43_lwip.c
index 0950035..87ea70b 100644
--- a/lib/cyw43-driversrc/cyw43_lwip.c
+++ b/lib/cyw43-driversrc/cyw43_lwip.c
@@ -92,6 +92,10 @@ static err_t cyw43_netif_output(struct netif *netif, struct pbuf *p) {
cyw43_ethernet_trace(self, netif, (size_t)-1, p, NETUTILS_TRACE_IS_TX | NETUTILS_TRACE_NEWLINE);
}
#endif
+ if ( debugging & 8 ) {
+ __asm volatile (".global cyw43_eth_output_hook");
+ __asm volatile ("cyw43_eth_output_hook: bkpt");
+ }
int itf = netif->name[1] - '0';
int ret = cyw43_send_ethernet(self, itf, p->tot_len, (void *)p, true);
if (ret) {