So far I have avoided anything to do with Rust. Mostly I just don't want to add yet another language to the dozen or so I regularly work with.
But as a brief aside, where does Rust fit in the C and C++ world? C++ is a mess. My take is that if you are doing embedded work, you will avoid C++ like the plague and use C. Rust offers the potential for using a language with object oriented features in an embedded project. Just the fact that the linux kernel developers have now started using Rust for some things says something. That aside, Rust is a new language with modern features, while C++ has always been a kludge at best (the old "nail six legs on a dog to create an octopus joke").
So I clone the "template" project:
cd /u1/Projects/rp2040 git clone --depth=1 [email protected]:rp-rs/rp2040-project-template.git ln -s rp2040-project-template rust cd rustI bravely try "cargo build", but it fails, in particular it mentions that "thumbv6m-none-eabi" target is not installed. The "lesson" I am following tells me to do "rustup target add thumbv6m-none-eabi" to get that. So, let's try the other way of doing things.
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shIt warns me that I have an existing rust installed and asks if I want to continue. I say no, and do this:
su dnf erase rust cargo exit curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shI am doing this as user "tom" and it tells me it will put stuff in /home/tom/.rustup and /home/tom/.cargo and that it will modify my .bashrc to add .cargo/bin to my path.
Now I am back to the instructions in the "lesson", I do this:
cd /home/tom rustup target add thumbv6m-none-eabi cargo install flip-link cargo install probe-run cargo install elf2uf2-rs --lockedThese all pull in and even compile quite a lot. But without any errors.
cd /u1/Projects/rp2040/rust cargo buildIt all goes just fine. When done, the result is an elf file:
/u1/Projects/rp2040/rust/target/thumbv6m-none-eabi/debug -rwxr-xr-x 2 tom tom 2291980 Aug 12 14:17 rp2040-project-template
Pretty big, eh?
So in one terminal I run:
openocd -f interface/cmsis-dap.cfg -c "adapter speed 5000" -f target/rp2040.cfgIn another I run:
cd /u1/Projects/rp2040/rust arm-none-eabi-gdb -q -ex "target extended-remote :3333" target/thumbv6m-none-eabi/debug/rp2040-project-templateOnce I see the "(gdb) " prompt, I do:
(gdb) load Loading section .boot2, size 0x100 lma 0x10000000 Loading section .vector_table, size 0xc0 lma 0x10000100 Loading section .text, size 0x2338 lma 0x100001c0 Loading section .rodata, size 0x6c0 lma 0x10002500 Loading section .data, size 0x38 lma 0x10002bc0 Start address 0x100001c0, load size 11248 Transfer rate: 11 KB/sec, 2249 bytes/write. (gdb) continue Continuing.And indeed the LED on my target board begins blinking
Tom's electronics pages / [email protected]