blflash icon indicating copy to clipboard operation
blflash copied to clipboard

auto trigger bootlaoder and flash with ft232rl

Open ntn888 opened this issue 2 years ago • 15 comments

i'm not sure on this, but i think the bootloader checks the uart for comm. if so:

the bootloader trigger could be automated by using a ft232rl module (very compact) in bitbang mode. just like how openOCD uses in one of it's mode.

ft232rl API: https://ftdichip.com/Documents/AppNotes/AN_232R-01_Bit_Bang_Mode_Available_For_FT232R_and_Ft245R http://www.ftdichip.com/Support/Documents/ProgramGuides/D2XX_Programmer's_Guide(FT_000071).pdf

i think the challenge will be to fiddle the single pin(tx) by inspecting the image...

i've seen a method where RPi is used: https://lupyuen.github.io/articles/auto but this is more compact...

any thoughts?

ntn888 avatar Feb 20 '22 11:02 ntn888

Do you mean this:

https://github.com/spacemeowx2/blflash/blob/aae6a9b2c3fdfa0f73f1a697f05d7ac4a62aa200/blflash/src/connection.rs#L78-L100

spacemeowx2 avatar Feb 20 '22 15:02 spacemeowx2

yes,

ntn888 avatar Feb 20 '22 16:02 ntn888

but the ftdi bridge has only 1 usb, how do yo connect to the bl602?

ntn888 avatar Feb 20 '22 16:02 ntn888

pinout? pinout

ntn888 avatar Feb 20 '22 16:02 ntn888

oh the tx0, rx0 pins are on the breakout... this is easier than I thought, same code to flash... just different bridge!! kudos for impl. the auto-reset!! :+1:

~/Downloads/blflash-linux-amd64 flash blink.bin --port /dev/ttyUSB0                   

[INFO  blflash::flasher] Start connection...
[TRACE blflash::flasher] 5ms send count 55
[TRACE blflash::flasher] handshake sent elapsed 7.924643ms
[TRACE blflash::connection] read_response err: [3c, 4b]
[TRACE blflash::connection] read_response err: [42, 42]
[TRACE blflash::connection] read_response err: [28, a8]
[TRACE blflash::connection] read_response err: [f0, f0]
[TRACE blflash::connection] read_response err: [7c, e1]
[DEBUG blflash::flasher] Retry 1
[TRACE blflash::flasher] 5ms send count 55
[TRACE blflash::flasher] handshake sent elapsed 7.632275ms
[TRACE blflash::connection] read_response err: [71, ca]
[TRACE blflash::connection] read_response err: [2c, 5b]
[TRACE blflash::connection] read_response err: [51, c0]
[TRACE blflash::connection] read_response err: [c1, 60]
[TRACE blflash::connection] read_response err: [c3, 64]
[DEBUG blflash::flasher] Retry 2
[TRACE blflash::flasher] 5ms send count 55
[TRACE blflash::flasher] handshake sent elapsed 7.643651ms
[TRACE blflash::connection] read_response err: [f8, c1]
[TRACE blflash::connection] read_response err: [c0, 51]
[TRACE blflash::connection] read_response err: [51, 40]
[TRACE blflash::connection] read_response err: [59, 28]
[TRACE blflash::connection] read_response err: [e0, c1]
[DEBUG blflash::flasher] Retry 3
[TRACE blflash::flasher] 5ms send count 55
[TRACE blflash::flasher] handshake sent elapsed 7.543551ms
[TRACE blflash::connection] read_response err: [c0, c9]
[TRACE blflash::connection] read_response err: [e0, e8]
[TRACE blflash::connection] read_response err: [c1, 41]
[TRACE blflash::connection] read_response err: [c1, 64]
[TRACE blflash::connection] read_response err: [ea, c0]
[DEBUG blflash::flasher] Retry 4
[TRACE blflash::flasher] 5ms send count 55
[TRACE blflash::flasher] handshake sent elapsed 7.72075ms
[TRACE blflash::connection] read_response err: [43, fa]
[TRACE blflash::connection] read_response err: [c0, f8]
[TRACE blflash::connection] read_response err: [f9, 60]
[TRACE blflash::connection] read_response err: [a0, e9]
[TRACE blflash::connection] read_response err: [f8, b0]
[DEBUG blflash::flasher] Retry 5
[TRACE blflash::flasher] 5ms send count 55
[TRACE blflash::flasher] handshake sent elapsed 7.620683ms
[TRACE blflash::connection] read_response err: [40, d8]
[DEBUG blflash::flasher] Retry 6
[TRACE blflash::flasher] 5ms send count 55
[TRACE blflash::flasher] handshake sent elapsed 6.585363ms
[DEBUG blflash::flasher] Retry 7
[TRACE blflash::flasher] 5ms send count 55
[TRACE blflash::flasher] handshake sent elapsed 6.299506ms
[DEBUG blflash::flasher] Retry 8
[TRACE blflash::flasher] 5ms send count 55
[TRACE blflash::flasher] handshake sent elapsed 5.966381ms
[DEBUG blflash::flasher] Retry 9
[TRACE blflash::flasher] 5ms send count 55
[TRACE blflash::flasher] handshake sent elapsed 6.070779ms
[DEBUG blflash::flasher] Retry 10
Error: Failed to connect to the device

/dev/ttyUSB0 is ft232rl ?? is right? how do i make the connections?

ntn888 avatar Feb 20 '22 16:02 ntn888

DTR -> EN RTS -> D8 is right?

ntn888 avatar Feb 20 '22 16:02 ntn888

could you please add instructions on how to do this in Readme? many thanks

ntn888 avatar Feb 20 '22 17:02 ntn888

hi, it doesnt even program through the ftdi, even if i manually press the button? i get the same error!

ntn888 avatar Feb 20 '22 22:02 ntn888

okay success!

i had to desolder out the onboard usb ic...

ntn888 avatar Feb 21 '22 02:02 ntn888

actually it was already in bootloadre mode (but can flash). i think the following change is necessary:

 pub fn reset_to_flash(&mut self) -> Result<(), Error> {

        self.serial
            .reconfigure(&|setup: &mut dyn SerialPortSettings| setup.set_flow_control(RTSCTS))?;
        self.serial.set_rts(true)?;
        sleep(Duration::from_millis(50));
        self.serial.set_dtr(true)?;
        sleep(Duration::from_millis(50));
        self.serial.set_dtr(false)?;
        sleep(Duration::from_millis(50));
        self.serial.set_rts(false)?;
        sleep(Duration::from_millis(50));
        self.serial
            .reconfigure(&|setup: &mut dyn SerialPortSettings| setup.set_flow_control(FlowNone))?;

        Ok(())
    }

pls have a look; I dont know Rust...

ntn888 avatar Feb 21 '22 03:02 ntn888

my bad, the signals are correctly working... checked it with the probe... maybe the buttons on the board bl-dt10 need to be removed...

ntn888 avatar Feb 21 '22 07:02 ntn888

D8 is active low, need to reverse...

ntn888 avatar Feb 21 '22 08:02 ntn888

Screenshot from 2022-02-21 19-05-16

ntn888 avatar Feb 21 '22 08:02 ntn888

    pub fn reset(&mut self) -> Result<(), Error> {
        self.serial.set_rts(true)?;
        sleep(Duration::from_millis(50));
        self.serial.set_dtr(true)?;
        sleep(Duration::from_millis(50));
        self.serial.set_dtr(false)?;
        sleep(Duration::from_millis(50));

        Ok(())
    }

    pub fn reset_to_flash(&mut self) -> Result<(), Error> {
        self.serial.set_rts(false)?;
        sleep(Duration::from_millis(50));
        self.serial.set_dtr(true)?;
        sleep(Duration::from_millis(50));
        self.serial.set_dtr(false)?;
        sleep(Duration::from_millis(50));
        self.serial.set_rts(false)?;
        sleep(Duration::from_millis(50));

        Ok(())
    }

~/blflash/target/debug/blflash flash blink.bin --port /dev/ttyUSB0
[INFO  blflash::flasher] Start connection...
[TRACE blflash::flasher] 5ms send count 55
[TRACE blflash::flasher] handshake sent elapsed 4.895562ms
[INFO  blflash::flasher] Connection Succeed
[INFO  blflash] Bootrom version: 1
[TRACE blflash] Boot info: BootInfo { len: 14, bootrom_version: 1, otp_info: [0, 0, 0, 0, 3, 0, 0, 0, 57, 1f, c3, 5, b9, 18, 19, 0] }
[INFO  blflash::flasher] Sending eflash_loader...
[INFO  blflash::flasher] Finished 3.00971273s 9.50KiB/s
[TRACE blflash::flasher] 5ms send count 500
[TRACE blflash::flasher] handshake sent elapsed 12.170592ms
[INFO  blflash::flasher] Entered eflash_loader
[INFO  blflash::flasher] Skip segment addr: 0 size: 47504 sha256 matches
[INFO  blflash::flasher] Skip segment addr: e000 size: 272 sha256 matches
[INFO  blflash::flasher] Skip segment addr: f000 size: 272 sha256 matches
[INFO  blflash::flasher] Skip segment addr: 10000 size: 86496 sha256 matches
[INFO  blflash::flasher] Skip segment addr: 1f8000 size: 5671 sha256 matches
[INFO  blflash] Success

ntn888 avatar Feb 21 '22 08:02 ntn888

There's a discussion here about BL command-line flashing, wonder if it might be helpful...

https://bbs.bouffalolab.com/d/132-cli-firmware-update-via-openocd-on-bl702

Or perhaps we could ask around on the Pine64 #nutcracker channel on Matrix, Telegram, Discord or IRC...

https://wiki.pine64.org/wiki/Main_Page#Chat_Platforms

lupyuen avatar Jul 16 '22 09:07 lupyuen