sftool_lib/sf32lb52/
ram_command.rs1use crate::Result;
2use crate::common::ram_command::{CommandConfig, RamOps};
3use crate::common::sifli_debug::{SifliDebug, SifliUartCommand};
4use crate::sf32lb52::SF32LB52Tool;
5
6pub use crate::common::ram_command::{Command, DownloadStub, RamCommand, Response};
8
9impl RamCommand for SF32LB52Tool {
10 fn command(&mut self, cmd: Command) -> Result<Response> {
11 let cmd_string = self.format_command(&cmd);
12 RamOps::send_command_and_wait_response(
13 &mut self.port,
14 cmd,
15 &cmd_string,
16 self.base.memory_type.as_str(),
17 )
18 }
19
20 fn send_data(&mut self, data: &[u8]) -> Result<Response> {
21 let config = CommandConfig {
22 compat_mode: self.base.compat,
23 ..Default::default()
24 };
25 RamOps::send_data_and_wait_response(&mut self.port, data, &config)
26 }
27
28 fn format_command(&self, cmd: &Command) -> String {
29 match cmd {
30 Command::EraseAll { address } => {
31 format!("burn_erase_all_factory 0x{address:08x}\r")
32 }
33 _ => cmd.to_string(),
34 }
35 }
36}
37
38impl DownloadStub for SF32LB52Tool {
39 fn download_stub(&mut self) -> Result<()> {
40 self.attempt_connect()?;
42 self.download_stub_impl()?;
43
44 std::thread::sleep(std::time::Duration::from_millis(100));
45 self.port.clear(serialport::ClearBuffer::All)?;
46 self.debug_command(SifliUartCommand::Exit)?;
47
48 if self.base.memory_type == "sd" {
50 RamOps::wait_for_shell_prompt(
52 &mut self.port,
53 b"sd0 OPEN success",
54 5000, 1, )
57 } else {
58 RamOps::wait_for_shell_prompt(
60 &mut self.port,
61 b"msh >",
62 200, 5, )
65 }
66 }
67}