9names / bl602-rust-example

A simple example showcasing what's working in the bl602-hal
MIT License
7 stars 2 forks source link

Problems following the readme #1

Open EdJoPaTo opened 3 years ago

EdJoPaTo commented 3 years ago

When following the readme I can not program the bl602.

cargo blflash --port /dev/ttyUSB0 ends up in a bunch of rust-lld: error: undefined symbol: <something>. I suspect I might not have something installed which is required for building there.

Output Compiling bl602-rust-example v0.1.0 (/home/edjopato/git/pine/bl602-rust-example) error: linking with `rust-lld` failed: exit code: 1 | = note: "rust-lld" "-flavor" "gnu" "-L" "/home/edjopato/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/riscv32imac-unknown-none-elf/lib" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/bl602_rust_example-2c5807f90e5d5a09.19rzuhug5jgffkt4.rcgu.o" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/bl602_rust_example-2c5807f90e5d5a09.1bagfflw3iymmsl1.rcgu.o" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/bl602_rust_example-2c5807f90e5d5a09.1c2xza23b52988e1.rcgu.o" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/bl602_rust_example-2c5807f90e5d5a09.1s82tq9z5yffh9w3.rcgu.o" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/bl602_rust_example-2c5807f90e5d5a09.1umrxqjyuwpb9tmu.rcgu.o" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/bl602_rust_example-2c5807f90e5d5a09.212u42na95mlm36j.rcgu.o" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/bl602_rust_example-2c5807f90e5d5a09.2e7hgu7twroaveb1.rcgu.o" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/bl602_rust_example-2c5807f90e5d5a09.2m989adu15p6i8fc.rcgu.o" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/bl602_rust_example-2c5807f90e5d5a09.2t1pty9y7i51cega.rcgu.o" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/bl602_rust_example-2c5807f90e5d5a09.3g56zditx5qedan.rcgu.o" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/bl602_rust_example-2c5807f90e5d5a09.3vzvdip2stbq37g7.rcgu.o" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/bl602_rust_example-2c5807f90e5d5a09.41pzrc0lmerfsgqr.rcgu.o" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/bl602_rust_example-2c5807f90e5d5a09.483xdn0c5fkd3w3r.rcgu.o" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/bl602_rust_example-2c5807f90e5d5a09.4ayc8jyioig2cl8r.rcgu.o" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/bl602_rust_example-2c5807f90e5d5a09.4j1pfyaprjqod1nd.rcgu.o" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/bl602_rust_example-2c5807f90e5d5a09.4ko2iqxfc87akhct.rcgu.o" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/bl602_rust_example-2c5807f90e5d5a09.4rt7c5zsld64czhl.rcgu.o" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/bl602_rust_example-2c5807f90e5d5a09.52s0f98d4bsyla2t.rcgu.o" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/bl602_rust_example-2c5807f90e5d5a09.55hteh3izcd0w6yx.rcgu.o" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/bl602_rust_example-2c5807f90e5d5a09.9m4mtrr4234z9w4.rcgu.o" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/bl602_rust_example-2c5807f90e5d5a09.c9dtk4c6kzopwy6.rcgu.o" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/bl602_rust_example-2c5807f90e5d5a09.mpv7t0ckrh72903.rcgu.o" "-o" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/bl602_rust_example-2c5807f90e5d5a09" "--gc-sections" "-L" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps" "-L" "/home/edjopato/git/pine/bl602-rust-example/target/debug/deps" "-L" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/build/bl602-rust-example-7e85585145c875d2/out" "-L" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/build/riscv-9417f4984cfd2398/out" "-L" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/build/riscv-rt-eb206a37a3506ab2/out" "-L" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/build/riscv-rt-eb206a37a3506ab2/out" "-L" "/home/edjopato/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/riscv32imac-unknown-none-elf/lib" "-Bstatic" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libriscv_rt-f894b1c28319eca3.rlib" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libr0-3bddc3009785bc51.rlib" "--start-group" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libpanic_halt-6c25fb084d56260a.rlib" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libbl602_hal-e05e5cf62ac57337.rlib" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libembedded_time-c01ec075b066ef34.rlib" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libnum-5fa3ed64c096ec6d.rlib" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libnum_iter-7f4ac91d196edd92.rlib" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libnum_rational-911f7e942a3425aa.rlib" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libnum_integer-c371862d9a657de6.rlib" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libnum_complex-f197e1bdbb85422a.rlib" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libnum_traits-25f41c1789ee1297.rlib" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libembedded_hal-ad33db3098802071.rlib" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libnb-d18bf94afae8128e.rlib" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libbl602_pac-ed9cda13cfd47903.rlib" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libriscv-fc8e3be9fc8cc1b5.rlib" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libbit_field-e2bcb677dea1b3b8.rlib" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libbare_metal-08115285c3d30b9f.rlib" "/home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libvcell-20d459121750863b.rlib" "/home/edjopato/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/riscv32imac-unknown-none-elf/lib/librustc_std_workspace_core-62f575e3ae6178b4.rlib" "/home/edjopato/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/riscv32imac-unknown-none-elf/lib/libcore-4c7d2a9096081455.rlib" "--end-group" "/home/edjopato/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/riscv32imac-unknown-none-elf/lib/libcompiler_builtins-d5745c1f152f4617.rlib" "-Bdynamic" = note: rust-lld: error: undefined symbol: _max_hart_id >>> referenced by asm.S:55 >>> riscv-rt.o:(.init+0x5A) in archive /home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libriscv_rt-f894b1c28319eca3.rlib >>> referenced by asm.S:55 >>> riscv-rt.o:(.init+0x5E) in archive /home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libriscv_rt-f894b1c28319eca3.rlib rust-lld: error: undefined symbol: _stack_start >>> referenced by asm.S:55 >>> riscv-rt.o:(.init+0x6A) in archive /home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libriscv_rt-f894b1c28319eca3.rlib rust-lld: error: undefined symbol: _hart_stack_size >>> referenced by asm.S:56 >>> riscv-rt.o:(.init+0x72) in archive /home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libriscv_rt-f894b1c28319eca3.rlib >>> referenced by asm.S:56 >>> riscv-rt.o:(.init+0x76) in archive /home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libriscv_rt-f894b1c28319eca3.rlib rust-lld: error: undefined symbol: _mp_hook >>> referenced by lib.rs:378 (/home/edjopato/.cargo/registry/src/github.com-1ecc6299db9ec823/riscv-rt-0.8.0/src/lib.rs:378) >>> riscv_rt-f894b1c28319eca3.riscv_rt.3cs0sfv7-cgu.3.rcgu.o:(_start_rust) in archive /home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libriscv_rt-f894b1c28319eca3.rlib rust-lld: error: undefined symbol: __pre_init >>> referenced by lib.rs:379 (/home/edjopato/.cargo/registry/src/github.com-1ecc6299db9ec823/riscv-rt-0.8.0/src/lib.rs:379) >>> riscv_rt-f894b1c28319eca3.riscv_rt.3cs0sfv7-cgu.3.rcgu.o:(_start_rust) in archive /home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libriscv_rt-f894b1c28319eca3.rlib rust-lld: error: undefined symbol: _sbss >>> referenced by lib.rs:381 (/home/edjopato/.cargo/registry/src/github.com-1ecc6299db9ec823/riscv-rt-0.8.0/src/lib.rs:381) >>> riscv_rt-f894b1c28319eca3.riscv_rt.3cs0sfv7-cgu.3.rcgu.o:(_start_rust) in archive /home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libriscv_rt-f894b1c28319eca3.rlib >>> referenced by lib.rs:381 (/home/edjopato/.cargo/registry/src/github.com-1ecc6299db9ec823/riscv-rt-0.8.0/src/lib.rs:381) >>> riscv_rt-f894b1c28319eca3.riscv_rt.3cs0sfv7-cgu.3.rcgu.o:(_start_rust) in archive /home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libriscv_rt-f894b1c28319eca3.rlib rust-lld: error: undefined symbol: _ebss >>> referenced by lib.rs:381 (/home/edjopato/.cargo/registry/src/github.com-1ecc6299db9ec823/riscv-rt-0.8.0/src/lib.rs:381) >>> riscv_rt-f894b1c28319eca3.riscv_rt.3cs0sfv7-cgu.3.rcgu.o:(_start_rust) in archive /home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libriscv_rt-f894b1c28319eca3.rlib >>> referenced by lib.rs:381 (/home/edjopato/.cargo/registry/src/github.com-1ecc6299db9ec823/riscv-rt-0.8.0/src/lib.rs:381) >>> riscv_rt-f894b1c28319eca3.riscv_rt.3cs0sfv7-cgu.3.rcgu.o:(_start_rust) in archive /home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libriscv_rt-f894b1c28319eca3.rlib rust-lld: error: undefined symbol: _sdata >>> referenced by lib.rs:382 (/home/edjopato/.cargo/registry/src/github.com-1ecc6299db9ec823/riscv-rt-0.8.0/src/lib.rs:382) >>> riscv_rt-f894b1c28319eca3.riscv_rt.3cs0sfv7-cgu.3.rcgu.o:(_start_rust) in archive /home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libriscv_rt-f894b1c28319eca3.rlib >>> referenced by lib.rs:382 (/home/edjopato/.cargo/registry/src/github.com-1ecc6299db9ec823/riscv-rt-0.8.0/src/lib.rs:382) >>> riscv_rt-f894b1c28319eca3.riscv_rt.3cs0sfv7-cgu.3.rcgu.o:(_start_rust) in archive /home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libriscv_rt-f894b1c28319eca3.rlib rust-lld: error: undefined symbol: _sidata >>> referenced by lib.rs:382 (/home/edjopato/.cargo/registry/src/github.com-1ecc6299db9ec823/riscv-rt-0.8.0/src/lib.rs:382) >>> riscv_rt-f894b1c28319eca3.riscv_rt.3cs0sfv7-cgu.3.rcgu.o:(_start_rust) in archive /home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libriscv_rt-f894b1c28319eca3.rlib >>> referenced by lib.rs:382 (/home/edjopato/.cargo/registry/src/github.com-1ecc6299db9ec823/riscv-rt-0.8.0/src/lib.rs:382) >>> riscv_rt-f894b1c28319eca3.riscv_rt.3cs0sfv7-cgu.3.rcgu.o:(_start_rust) in archive /home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libriscv_rt-f894b1c28319eca3.rlib rust-lld: error: undefined symbol: _setup_interrupts >>> referenced by lib.rs:387 (/home/edjopato/.cargo/registry/src/github.com-1ecc6299db9ec823/riscv-rt-0.8.0/src/lib.rs:387) >>> riscv_rt-f894b1c28319eca3.riscv_rt.3cs0sfv7-cgu.3.rcgu.o:(_start_rust) in archive /home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libriscv_rt-f894b1c28319eca3.rlib rust-lld: error: undefined symbol: ExceptionHandler >>> referenced by lib.rs:430 (/home/edjopato/.cargo/registry/src/github.com-1ecc6299db9ec823/riscv-rt-0.8.0/src/lib.rs:430) >>> riscv_rt-f894b1c28319eca3.riscv_rt.3cs0sfv7-cgu.3.rcgu.o:(_start_trap_rust) in archive /home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libriscv_rt-f894b1c28319eca3.rlib rust-lld: error: undefined symbol: DefaultHandler >>> referenced by lib.rs:441 (/home/edjopato/.cargo/registry/src/github.com-1ecc6299db9ec823/riscv-rt-0.8.0/src/lib.rs:441) >>> riscv_rt-f894b1c28319eca3.riscv_rt.3cs0sfv7-cgu.3.rcgu.o:(_start_trap_rust) in archive /home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libriscv_rt-f894b1c28319eca3.rlib >>> referenced by lib.rs:436 (/home/edjopato/.cargo/registry/src/github.com-1ecc6299db9ec823/riscv-rt-0.8.0/src/lib.rs:436) >>> riscv_rt-f894b1c28319eca3.riscv_rt.3cs0sfv7-cgu.3.rcgu.o:(_start_trap_rust) in archive /home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libriscv_rt-f894b1c28319eca3.rlib rust-lld: error: undefined symbol: UserSoft >>> referenced by riscv_rt.3cs0sfv7-cgu.3 >>> riscv_rt-f894b1c28319eca3.riscv_rt.3cs0sfv7-cgu.3.rcgu.o:(__INTERRUPTS) in archive /home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libriscv_rt-f894b1c28319eca3.rlib rust-lld: error: undefined symbol: SupervisorSoft >>> referenced by riscv_rt.3cs0sfv7-cgu.3 >>> riscv_rt-f894b1c28319eca3.riscv_rt.3cs0sfv7-cgu.3.rcgu.o:(__INTERRUPTS) in archive /home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libriscv_rt-f894b1c28319eca3.rlib rust-lld: error: undefined symbol: MachineSoft >>> referenced by riscv_rt.3cs0sfv7-cgu.3 >>> riscv_rt-f894b1c28319eca3.riscv_rt.3cs0sfv7-cgu.3.rcgu.o:(__INTERRUPTS) in archive /home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libriscv_rt-f894b1c28319eca3.rlib rust-lld: error: undefined symbol: UserTimer >>> referenced by riscv_rt.3cs0sfv7-cgu.3 >>> riscv_rt-f894b1c28319eca3.riscv_rt.3cs0sfv7-cgu.3.rcgu.o:(__INTERRUPTS) in archive /home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libriscv_rt-f894b1c28319eca3.rlib rust-lld: error: undefined symbol: SupervisorTimer >>> referenced by riscv_rt.3cs0sfv7-cgu.3 >>> riscv_rt-f894b1c28319eca3.riscv_rt.3cs0sfv7-cgu.3.rcgu.o:(__INTERRUPTS) in archive /home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libriscv_rt-f894b1c28319eca3.rlib rust-lld: error: undefined symbol: MachineTimer >>> referenced by riscv_rt.3cs0sfv7-cgu.3 >>> riscv_rt-f894b1c28319eca3.riscv_rt.3cs0sfv7-cgu.3.rcgu.o:(__INTERRUPTS) in archive /home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libriscv_rt-f894b1c28319eca3.rlib rust-lld: error: undefined symbol: UserExternal >>> referenced by riscv_rt.3cs0sfv7-cgu.3 >>> riscv_rt-f894b1c28319eca3.riscv_rt.3cs0sfv7-cgu.3.rcgu.o:(__INTERRUPTS) in archive /home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libriscv_rt-f894b1c28319eca3.rlib rust-lld: error: undefined symbol: SupervisorExternal >>> referenced by riscv_rt.3cs0sfv7-cgu.3 >>> riscv_rt-f894b1c28319eca3.riscv_rt.3cs0sfv7-cgu.3.rcgu.o:(__INTERRUPTS) in archive /home/edjopato/git/pine/bl602-rust-example/target/riscv32imac-unknown-none-elf/debug/deps/libriscv_rt-f894b1c28319eca3.rlib rust-lld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors) error: aborting due to previous error error: could not compile `bl602-rust-example` To learn more, run the command again with --verbose.

When I use cargo build everything works. Which is interesting to me.

Switching runner in .cargo/config.toml to runner = "blflash flash --port /dev/ttyUSB0" I can simply use cargo run. (Currently openocd is still mentioned in the runner, this might be something overlooked when creating this example?) Programming the BL602 that way works fine according to blflash.

Then opening minicom or other serial port thingies do not result in any activity (Pressed EN / Reset multiple times).

Any ideas what might be wrong here and how to improve the example to get these problems out of the way for others? And thanks for the example showcasing the bl602-hal usage!

9names commented 3 years ago

Thanks for the feedback, and sorry I didn't notice it for so long. The issues here are due to cargo-blflash targeting a different toolchain than this project. I changed it part-way though implementing this, and for whatever reason it kept working on existing builds even though it should have broken.

I'm going to change this project back to using the riscv32imac-unknown-none-elf target until I can get cargo-blflash updated with the correct target.

9names commented 3 years ago

I've committed the necessary changes to get everything working properly again. There's an issue at the moment with one of blflash's dependencies if you try to cargo install it. It works fine if you build it and manually install it, or if you manually install the binaries to your .cargo/bin folder.

Anyway - If you get a chance to test this, I'd appreciate hearing how it goes. Thanks again!

bjoernQ commented 3 years ago

First of all thanks for this - it's the only example I could find that doesn't use JTAG (and I don't own an JTAG adapter currently - just ordered one)

I tried this with a DT-BL10 but unfortunately I get the same results as the thread-opener. I can built and flash it (with blflash) but nothing happens on the GPIO or on the serial port.

I tried the C samples from the Pine64 port of the original C SDK and those work fine.

I tried a recent Rust nightly and the current stable one - always the same. I have really no idea what is going wrong for me.

If you have any idea or did anything special I'd be happy to try that. Beside that I'm waiting for my JTAG adapter and maybe that might help me to investigate this

9names commented 3 years ago

That's no good, but thanks for speaking up. Which OS are you running? My batch of PineNuts and eval boards just turned up, so I'm also going to try running it on some fresh hardware in case it's not a host-computer problem.

bjoernQ commented 3 years ago

I tried it on Windows 10. On OSX I cannot get blflash to work but since I'm sure blflash is working fine I will try to flash the binary built on OSX via my Windows box. I can also try WSL/Ubuntu later today

bjoernQ commented 3 years ago

Quick update: I was able to test the binary built on OSX with the same results unfortunately

9names commented 3 years ago

I've bumped the hal dependency as that was causing some build issues. Tested the produced binary against dt-bl10 devkit, pine nut and pine bl602 evb on Ubuntu 20.04 and Windows 10, working fine I have noticed that if I use the reset button on the pine-nut programmer, it doesn't work any more. I have to unplug -> replug the USB. This is not the case for DT-BL10 or Pine EVB. There is some problems obtaining cargo-blflash at the moment due to a dependency issue, but you don't have to worry about it if blflash is already working for you

bjoernQ commented 3 years ago

Thanks for all your efforts. The serial stuff is still not working for me - it apparently crashes quite early - so I removed everything from main.rs and just toggle GPIO5 - and that is working now 🎉

So I finally managed to get Blinky working - I guess I can work my way from that now.

Again - thanks a lot for your support on this - it's been a long time since I was so much happy about a blinking LED

9names commented 3 years ago

Glad to hear you got something going! You might have some luck doing release builds - I'm planning on changing the readme to recommend that. I'd love to have more feedback on crash/panic, but it's tough to print useful info when the serial code is what is causing the problem.

bjoernQ commented 3 years ago

I'll keep you posted when I find out something - probably the JTAG adapter I ordered will improve my debug experience a lot

from a simple first test it seems to crash as early as it executes this

    let clocks = Strict::new()
        .use_pll(40_000_000u32.Hz())
        .sys_clk(SysclkFreq::Pll160Mhz)
        .uart_clk(UART_PLL_FREQ.Hz())
        .freeze(&mut parts.clk_cfg);
bjoernQ commented 3 years ago

Update: Big step forward!

As soon as I change

.sys_clk(SysclkFreq::Pll160Mhz)

to

.sys_clk(SysclkFreq::Rc32Mhz)

it works ... using any of the SysclkFreq::PllXXX variants it crashes immediately at that point

9names commented 3 years ago

Yeah, so it's likely that it's in the clock init code I wrote. Doesn't explain why it works for me and not for you though :(

I could change it so that the clocks are only reconfigured if they're not already correct - since the ROM bootloader will init the external oscillator and PLL based on the config values (40mhz external, 160mhz PLL). For most users that would skip it for everything except switching from bootloader to code - which pretty much only happens when you're debugging at the moment.

We'll want to have better clock control for low power modes though. Having a path where it does nothing will only make it more surprising when it fails.

9names commented 3 years ago

Could you upload a release and a debug build with the code as it is in the repo? If it's something about the way it's built, I could use that info to help debug it

bjoernQ commented 3 years ago

Really strange it works for you but not for me - I attached the generated binaries for debug and release here. Hope it helps

build.zip

9names commented 3 years ago

Practically the same as my binaries, works on my board Will have to wait until you have a debugger to discover where it's going wrong.

We've got a matrix chat room specifically for Rust on BL602 at https://app.element.io/#/room/#bl602-rust:matrix.org It's very quiet at the moment, but I'm hoping that more people will join in the effort as it becomes more accessible

bjoernQ commented 3 years ago

I was able to track my problem down to the call to glb_set_system_clk_pll from freeze - but there is a lot going on so I guess I really have to wait for the JTAG adapter which should arrive during the first week of April hopefully.

I also ordered a couple more BL602 modules since it seems like a problem specific to this board - while it would be certainly good to figure out how to fix it for this board since it might not be the only chip with this problem. But unfortunately those modules will take a long time to get delivered

I also hope that Rust on BL602 will attract a lot of devs - it's really nice and there is hope to have blob free Wifi and BLE support some day if Pine's NutCracker challenge is successful - and even with some blobs it would be awesome

9names commented 3 years ago

The most likely cause is hbn_set_root_clk_sel_pll() in that function, which switches the core clock to use the PLL. Possible causes that I've thought of:

So really, the best options in front of me are

bjoernQ commented 3 years ago

I guess I understand it so far and I also think moving that function to RAM would be the best option.

I also tried to use a function in RAM and it doesn't work for me, too. Seems that https://github.com/rust-embedded/riscv-rt/blob/47ece5f5163a2e38ce5e4685b5d3145713d7954a/src/lib.rs#L382 doesn't work

Indeed at runtime I see that a RAM function has an address in RAM but at that address it's all zero. Also global static mut variables don't get initialized.

I tried to make sense of this and tried to look at the value of _sidata but that seems to be garbage - not something pointing into the flash.

bjoernQ commented 3 years ago

Oh - _sidata is a pointer not an address - so the value looks fine - still don't know what is going wrong there

bjoernQ commented 3 years ago

Ok so ...

Do you know if there is some kind of MMU on this chip which needs to be configured to make ITCM writable?

bjoernQ commented 3 years ago

Now I found the original problem running the code on my board:

https://github.com/sipeed/bl602-hal/blob/6d2209b14d95badd3e0116cc3a2f56f03e20aad3/src/clock.rs#L476

No matter how long I delay and how high I set the timeout ... it never returns Ok - since the caller just unwraps it crashs. Apparently I can just return Ok(()) and my code runs without crashing - that's certainly not really a solution and I really wonder why that is happening with my board.

Tomorrow I will look into the C examples and see if they actually configure the clock and if they do I will check if and why it is working on my board.

9names commented 3 years ago

Chip doesn't have an MMU, and ITCM is just regular SRAM that can be used by one of the flash caching units, so it should be writable. I tried changing the linker file (memory.x) so that everything is placed in ITCM, and everything is still working, so at least the stack functions in this state, so I'm not sure why you're seeing this behavior.

With regard to static data init: cortex-rt moved their r0 init code to assembly to avoid issues with pointer accesses getting optimized away. I modified it slightly to do volatile reads of the source address and it worked - I should get back to that + check pointer provenance while I'm at it. I started a port of r0 to riscv asm, but I'm not good at that and I've been distracted by writing a flash loader (so we can use probe-rs to flash the board).

bjoernQ commented 3 years ago

Ok I guess this proves that I got an faulty cursed chip. I can write parts of ITCM but not the lower 16k ... together with the other problems I was facing I will have to wait until my orders arrive.

Thanks for your support and sorry for the noise.

Being able to use probe-rs would be awesome by the way.

KenjutsuGH commented 3 years ago

I'm having a similar problem as the OP.

cargo install blflash fails to build

cargo blflash --port /dev/tty.wchusbserialfa13140

fails with error: no such subcommand: 'blflash'

I downloaded blflash and built it.

Where must I copy the compiled blflash binary? I copied it to bl602-rust-example/.cargo/bin and bl602-rust-example, but still cargo blflash --port /dev/tty.wchusbserialfa13140 fails with error: no such subcommand: 'blflash'

I'm using a BL10 board with rustc 1.54.0-nightly (4de757209 2021-05-01) under macOS 10.13.6

9names commented 3 years ago

You need to install cargo-blflash to be able to run cargo blflash

KenjutsuGH commented 3 years ago

Thank you for the reply

cargo install cargo-blflash fails with a lot of errors. The first one being:

error[E0576]: cannot find method or associated constant `BITS` in trait `IsNumber`
   --> /Users/aaaaaa/.cargo/registry/src/github.com-1ecc6299db9ec823/bitvec-0.21.0/src/ptr/single.rs:606:36
9names commented 3 years ago

Yeah, there was a clash with the name BITS earlier in the year, it took some time to resolve https://github.com/bitvecto-rs/bitvec/issues/105 I managed to build blflash cloning https://github.com/spacemeowx2/blflash and bumping the version of of funty to 1.2.0 If that works for you, can you make a PR against the blflash repo?

KenjutsuGH commented 3 years ago

I cloned blflash and did a cargo build which completed without any errors. I then copied blflash to my bl602-rust-example folder.

I executed cargo build which completed without any errors. I then proceeded to flash with: ./blflash flash target/riscv32imac-unknown-none-elf/debug/bl602-rust-example --port /dev/tty.wchusbserialfa13140 --initial-baud-rate 230400 --baud-rate 230400

and got the LED blinking with serial output :-)