sftool_lib/sf32lb56/
ram_command.rs1use crate::Result;
2use crate::common::ram_command::{CommandConfig, RamOps, is_sd_memory};
3use crate::common::serial_io::{for_tool, sleep_with_cancel};
4use crate::common::sifli_debug::{SifliDebug, SifliUartCommand};
5use crate::sf32lb56::SF32LB56Tool;
6
7pub use crate::common::ram_command::{Command, DownloadStub, RamCommand, Response};
9
10impl RamCommand for SF32LB56Tool {
11 fn command(&mut self, cmd: Command) -> Result<Response> {
12 let cmd_string = self.format_command(&cmd);
13 let memory_type = self.base.memory_type.clone();
14 let mut io = for_tool(self);
15 RamOps::send_command_and_wait_response(&mut io, cmd, &cmd_string, memory_type.as_str())
16 }
17
18 fn send_data(&mut self, data: &[u8]) -> Result<Response> {
19 let config = CommandConfig {
20 compat_mode: self.base.compat,
21 ..Default::default()
22 };
23 let mut io = for_tool(self);
24 RamOps::send_data_and_wait_response(&mut io, data, &config)
25 }
26}
27
28impl DownloadStub for SF32LB56Tool {
29 fn download_stub(&mut self) -> Result<()> {
30 self.attempt_connect()?;
32 self.download_stub_impl()?;
33
34 sleep_with_cancel(
35 &self.base.cancel_token,
36 std::time::Duration::from_millis(100),
37 )?;
38 {
39 let mut io = for_tool(self);
40 io.clear(serialport::ClearBuffer::All)?;
41 }
42 self.debug_command(SifliUartCommand::Exit)?;
43
44 let is_sd = is_sd_memory(&self.base.memory_type);
46 let mut io = for_tool(self);
47 if is_sd {
48 RamOps::wait_for_shell_prompt(
50 &mut io,
51 b"sd0 OPEN success",
52 1000, 5, )
55 } else {
56 RamOps::wait_for_shell_prompt(
58 &mut io, b"msh >", 200, 5, )
61 }
62 }
63}