sftool_lib/sf32lb56/
ram_command.rs

1use crate::Result;
2use crate::common::ram_command::{CommandConfig, RamOps};
3use crate::common::sifli_debug::{SifliDebug, SifliUartCommand};
4use crate::sf32lb56::SF32LB56Tool;
5
6// 重新导出公共类型
7pub use crate::common::ram_command::{Command, DownloadStub, RamCommand, Response};
8
9impl RamCommand for SF32LB56Tool {
10    fn command(&mut self, cmd: Command) -> Result<Response> {
11        RamOps::send_command_and_wait_response(&mut self.port, cmd, self.base.memory_type.as_str())
12    }
13
14    fn send_data(&mut self, data: &[u8]) -> Result<Response> {
15        let config = CommandConfig {
16            compat_mode: self.base.compat,
17            ..Default::default()
18        };
19        RamOps::send_data_and_wait_response(&mut self.port, data, &config)
20    }
21}
22
23impl DownloadStub for SF32LB56Tool {
24    fn download_stub(&mut self) -> Result<()> {
25        // Use SifliTool trait methods
26        self.attempt_connect()?;
27        self.download_stub_impl()?;
28
29        std::thread::sleep(std::time::Duration::from_millis(100));
30        self.port.clear(serialport::ClearBuffer::All)?;
31        self.debug_command(SifliUartCommand::Exit)?;
32
33        // 根据memory_type选择不同的等待条件
34        if self.base.memory_type == "sd" {
35            // SD卡模式:等待 "sd0 OPEN success",超时5秒
36            RamOps::wait_for_shell_prompt(
37                &mut self.port,
38                b"sd0 OPEN success",
39                1000, // 1秒间隔
40                5,    // 最多重试5次 (总计5秒)
41            )
42        } else {
43            // 非SD模式:等待shell提示符 "msh >"
44            RamOps::wait_for_shell_prompt(
45                &mut self.port,
46                b"msh >",
47                200, // 200ms间隔
48                5,   // 最多重试5次
49            )
50        }
51    }
52}