Skip to content

Commit dd942c7

Browse files
committed
Remove shell support
1 parent 186facd commit dd942c7

File tree

2 files changed

+31
-539
lines changed

2 files changed

+31
-539
lines changed

application/src/main.rs

Lines changed: 31 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ mod control;
88
mod dfu;
99
mod storage;
1010
mod usbserial;
11-
mod shell;
1211
mod ctlpins;
1312
mod powermeter;
1413
mod filter;
@@ -32,7 +31,6 @@ mod app {
3231
dma::{config::DmaConfig, PeripheralToMemory, Stream0, StreamsTuple, Transfer},
3332
pac::{ADC1, DMA2},
3433
};
35-
use core::fmt::Write;
3634

3735
use heapless::spsc::{Consumer, Producer, Queue};
3836
use usb_device::{class_prelude::*, prelude::*};
@@ -42,7 +40,6 @@ mod app {
4240
use crate::{control::ControlClass, dfu::{get_serial_str, new_dfu_bootloader, DFUBootloaderRuntime}};
4341
use crate::storage::*;
4442
use crate::usbserial::*;
45-
use crate::shell;
4643
use crate::ctlpins;
4744
use crate::powermeter::*;
4845
use crate::version;
@@ -60,8 +57,7 @@ mod app {
6057
struct Shared {
6158
timer: timer::CounterMs<pac::TIM2>,
6259
usb_dev: UsbDevice<'static, UsbBusType>,
63-
shell: shell::ShellType,
64-
shell_status: shell::ShellStatus,
60+
usb_serial: USBSerialType,
6561
dfu: DFUBootloaderRuntime,
6662
ctl: ControlClass,
6763

@@ -199,11 +195,11 @@ mod app {
199195
}
200196
/* I tried creating a 2nd serial port which only works on STM32F412 , 411 has not enough
201197
endpoints, but it didn't work well, the library probably needs some debugging */
202-
let mut serial1 = new_usb_serial! (unsafe { USB_BUS.as_ref().unwrap() });
198+
let mut usb_serial = new_usb_serial! (unsafe { USB_BUS.as_ref().unwrap() });
203199
let dfu = new_dfu_bootloader(unsafe { USB_BUS.as_ref().unwrap() });
204200
let ctl = ControlClass::new(unsafe { USB_BUS.as_ref().unwrap() });
205201

206-
serial1.reset();
202+
usb_serial.reset();
207203

208204
let usb_dev = UsbDeviceBuilder::new(
209205
unsafe { USB_BUS.as_ref().unwrap() },
@@ -221,11 +217,6 @@ mod app {
221217
.max_packet_size_0(64).unwrap()
222218
.build();
223219

224-
let shell = shell::new(serial1);
225-
let shell_status = shell::ShellStatus{
226-
monitor_enabled: false,
227-
meter_enabled: false,
228-
console_mode: true,};
229220

230221

231222
let (to_dut_serial, to_dut_serial_consumer) = ctx.local.q_to_dut.split();
@@ -237,8 +228,7 @@ mod app {
237228
Shared {
238229
timer,
239230
usb_dev,
240-
shell,
241-
shell_status,
231+
usb_serial,
242232
dfu,
243233
ctl,
244234
led_tx,
@@ -266,21 +256,18 @@ mod app {
266256
)
267257
}
268258

269-
#[task(binds = USART1, priority=1, local = [usart_rx, to_host_serial], shared = [shell_status, led_rx])]
259+
#[task(binds = USART1, priority=1, local = [usart_rx, to_host_serial], shared = [led_rx])]
270260
fn usart_task(cx: usart_task::Context){
271261
let usart_rx = cx.local.usart_rx;
272-
let shell_status = cx.shared.shell_status;
273-
let led_rx = cx.shared.led_rx;
262+
let mut led_rx = cx.shared.led_rx;
274263
let to_host_serial = cx.local.to_host_serial;
275264

276-
(shell_status, led_rx).lock(|shell_status, led_rx| {
265+
led_rx.lock(|led_rx| {
277266
while usart_rx.is_rx_not_empty() {
278267
led_rx.set_low();
279268
match usart_rx.read() {
280269
Ok(b) => {
281-
if shell_status.console_mode || shell_status.monitor_enabled {
282-
to_host_serial.enqueue(b).ok(); // this could over-run but it's ok the only solution would be a bigger buffer
283-
}
270+
to_host_serial.enqueue(b).ok(); // this could over-run but it's ok the only solution would be a bigger buffer
284271
},
285272
Err(_e) => {
286273
break;
@@ -296,21 +283,15 @@ mod app {
296283
}
297284
}
298285

299-
#[task(local=[to_host_serial_consumer], shared=[shell, shell_status, power_meter])]
286+
#[task(local=[to_host_serial_consumer], shared=[usb_serial])]
300287
fn console_monitor_task(mut cx: console_monitor_task::Context) {
301-
use arrform::ArrForm;
302-
303288
let to_host_serial_consumer = cx.local.to_host_serial_consumer;
304-
let shell = &mut cx.shared.shell;
305-
let shell_status = &mut cx.shared.shell_status;
306-
let power_meter = &mut cx.shared.power_meter;
289+
let usb_serial = &mut cx.shared.usb_serial;
307290

308-
// if the DUT has sent data over the uart, we send it to the host now
309-
// at this point we can incercept and add additional info like power readings
291+
// Forward data from physical serial port to USB serial port
310292
if to_host_serial_consumer.len() > 0 {
311-
(shell, shell_status, power_meter).lock(|shell, shell_status, power_meter| {
312-
let serial1 = shell.get_serial_mut();
313-
let mut buf = [0u8; DUT_BUF_SIZE+32];
293+
usb_serial.lock(|usb_serial| {
294+
let mut buf = [0u8; DUT_BUF_SIZE];
314295
let mut count = 0;
315296
loop {
316297
match to_host_serial_consumer.dequeue() {
@@ -320,91 +301,53 @@ mod app {
320301
if count >= buf.len() {
321302
break;
322303
}
323-
// check if we need to add power readings after the line break
324-
if shell_status.meter_enabled && c == 0x0d {
325-
let mut af = ArrForm::<64>::new();
326-
power_meter.write_trace(&mut af);
327-
328-
for p in af.as_bytes() {
329-
buf[count] = *p;
330-
count += 1;
331-
}
332-
}
333304
},
334305
None => {
335306
break;
336307
}
337308
}
338309
}
339-
if count>0 {
340-
serial1.write(&buf[..count]).ok();
310+
if count > 0 {
311+
usb_serial.write(&buf[..count]).ok();
341312
}
342313
});
343314
}
344315
}
345316

346-
#[task(binds = OTG_FS, shared = [usb_dev, shell, shell_status, dfu, ctl, led_cmd, storage, ctl_pins, power_meter, config], local=[esc_cnt:u8 = 0, to_dut_serial])]
317+
#[task(binds = OTG_FS, shared = [usb_dev, usb_serial, dfu, ctl, led_cmd, storage, ctl_pins, power_meter, config], local=[to_dut_serial])]
347318
fn usb_task(mut cx: usb_task::Context) {
348319
let usb_dev = &mut cx.shared.usb_dev;
349-
let shell = &mut cx.shared.shell;
350-
let shell_status = &mut cx.shared.shell_status;
320+
let usb_serial = &mut cx.shared.usb_serial;
351321
let dfu = &mut cx.shared.dfu;
352322
let ctl = &mut cx.shared.ctl;
353323
let led_cmd = &mut cx.shared.led_cmd;
354324
let storage = &mut cx.shared.storage;
355325
let to_dut_serial = cx.local.to_dut_serial;
356326

357-
let esc_cnt = cx.local.esc_cnt;
358327
let ctl_pins = &mut cx.shared.ctl_pins;
359328
let power_meter = &mut cx.shared.power_meter;
360329
let config = &mut cx.shared.config;
361330

362-
(usb_dev, dfu, ctl, shell, shell_status, led_cmd, storage, ctl_pins, power_meter, config).lock(
363-
|usb_dev, dfu, ctl, shell, shell_status, led_cmd, storage, ctl_pins, power_meter, config| {
364-
let serial1 = shell.get_serial_mut();
365-
366-
if !usb_dev.poll(&mut [serial1, dfu, ctl]) {
331+
(usb_dev, usb_serial, dfu, ctl, led_cmd, storage, ctl_pins, power_meter, config).lock(
332+
|usb_dev, usb_serial, dfu, ctl, _led_cmd, storage, ctl_pins, power_meter, config| {
333+
if !usb_dev.poll(&mut [usb_serial, dfu, ctl]) {
367334
return;
368335
}
369336

370337
ctl.post_poll(config, ctl_pins, storage, power_meter);
371338

372-
let available_to_dut = to_dut_serial.capacity()-to_dut_serial.len();
373-
374-
let mut send_to_dut = |buf: &[u8]|{
375-
for b in buf {
376-
to_dut_serial.enqueue(*b).ok();
377-
}
378-
return
379-
};
380-
381-
if shell_status.console_mode {
382-
// if in console mode, send all data to the DUT, only read from the USB serial port as much as we can send to the DUT
339+
// Forward USB serial data to physical serial port
340+
let available_to_dut = to_dut_serial.capacity() - to_dut_serial.len();
341+
if available_to_dut > 0 {
383342
let mut buf = [0u8; DUT_BUF_SIZE];
384-
match serial1.read(&mut buf[..available_to_dut]) {
343+
match usb_serial.read(&mut buf[..available_to_dut]) {
385344
Ok(count) => {
386-
send_to_dut(&buf[..count]);
387-
388-
for c in &buf[..count] {
389-
if *c == 0x02 { // CTRL+B
390-
*esc_cnt = *esc_cnt + 1;
391-
if *esc_cnt == 5 {
392-
shell_status.console_mode = false;
393-
shell_status.monitor_enabled = false;
394-
shell.write_str("\r\nExiting console mode\r\n").ok();
395-
shell.write_str(shell::SHELL_PROMPT).ok();
396-
*esc_cnt = 0;
397-
}
398-
} else {
399-
*esc_cnt = 0;
400-
}
345+
for b in &buf[..count] {
346+
to_dut_serial.enqueue(*b).ok();
401347
}
402348
},
403-
Err(_e) => {
404-
}
349+
Err(_e) => {}
405350
}
406-
} else {
407-
shell::handle_shell_commands(shell, shell_status, led_cmd, storage, ctl_pins, &mut send_to_dut, power_meter, config);
408351
}
409352
});
410353
}
@@ -472,46 +415,23 @@ mod app {
472415

473416

474417
// Background task, runs whenever no other tasks are running
475-
#[idle(local=[to_dut_serial_consumer, usart_tx], shared=[led_tx, shell_status])]
418+
#[idle(local=[to_dut_serial_consumer, usart_tx], shared=[led_tx])]
476419
fn idle(mut ctx: idle::Context) -> ! {
477-
// the source of this queue is the send command from the shell
420+
// Forward data from USB serial to physical serial port
478421
let to_dut_serial_consumer = &mut ctx.local.to_dut_serial_consumer;
479-
let shell_status = &mut ctx.shared.shell_status;
480422

481423
loop {
482424
// Go to sleep, wake up on interrupt
483-
let mut escaped = false;
484425
cortex_m::asm::wfi();
485426

486-
// NOTE: this can probably be moved to its own software task
487427
// Is there any data to be sent to the device under test over USART?
488428
if to_dut_serial_consumer.len() == 0 {
489429
continue;
490430
}
491-
let should_escape = shell_status.lock(|shell_status| !shell_status.console_mode);
492431
loop {
493432
match to_dut_serial_consumer.dequeue() {
494433
Some(c) => {
495-
// in console mode we should not handle escape characters.
496-
// this would be arguably better implemented in the shell send function
497-
// but this allows for the \w wait command to delay and not block other
498-
// tasts
499-
let mut final_c:u8 = c;
500-
if should_escape {
501-
if escaped == false && c == 0x5c { // backslash
502-
escaped = true;
503-
continue;
504-
}
505-
506-
if escaped == true {
507-
escaped = false;
508-
final_c = match escaped_char(c) {
509-
Some(c) => c,
510-
None => continue,
511-
}
512-
}
513-
}
514-
434+
// Transparent forwarding - no escape character processing
515435
let usart_tx = &mut ctx.local.usart_tx;
516436
let led_tx = &mut ctx.shared.led_tx;
517437
led_tx.lock(|led_tx| led_tx.set_low());
@@ -522,7 +442,7 @@ mod app {
522442
}
523443
}
524444

525-
usart_tx.write(final_c).ok();
445+
usart_tx.write(c).ok();
526446

527447
},
528448
None => {
@@ -533,22 +453,6 @@ mod app {
533453
}
534454
}
535455

536-
fn escaped_char(c:u8) -> Option<u8> {
537-
538-
match c {
539-
0x5c => { Some(0x5c) }, // \\
540-
0x6e => { Some(0x0a) }, // \n
541-
0x72 => { Some(0x0d) }, // \r
542-
0x74 => { Some(0x09) }, // \t
543-
0x61 => { Some(0x07) }, // \a alert
544-
0x62 => { Some(0x08) }, // \b backspace
545-
0x65 => { Some(0x1b) }, // \e escape character
546-
0x63 => { Some(0x03) }, // \c // CTRL+C
547-
0x64 => { Some(0x04) }, // \d CTRL+D
548-
0x77 => { cortex_m::asm::delay(50*1000*1000); None },// \w WAIT DELAY
549-
_ => Some(c)
550-
}
551-
}
552456

553457

554458
}

0 commit comments

Comments
 (0)