I am trying to get my Arduino MKRZero to work in Rust. I successfully blinked the LED, and my next step was to copy the global data from text to data.
I have the following linker variables:
Rust
extern {
static __StackTop: u32;
static mut __etext: u32;
static mut __data_start__: u32;
static mut __data_end__: u32;
static mut __bss_start__: u32;
static mut __bss_end__: u32;
}
WITH
extern uint32_t __etext;
extern uint32_t __data_start__;
extern uint32_t __data_end__;
extern uint32_t __bss_start__;
extern uint32_t __bss_end__;
extern uint32_t __StackTop;
To shorten the long history, rust code
let mut pSrc: *mut u32;
pSrc = &mut __etext;
causes execution to stop, i.e. LED does not blink. Commenting out this line and moving on to the code that zeros the BSS segment
let mut pDest: *mut u32;
pDest = &mut __bss_start__;
makes blinker code work fine. As far as I can see, getting the address of the __etextlinker variable pauses execution, but getting the address __bss_start__is fine.
In version C there is no problem:
uint32_t *pSrc, *pDest;
pSrc = &__etext;
pDest = &__data_start__;
// <fill pDest with pSrc>
for (pDest = &__bss_start__; pDest < &__bss_end__; pDest++)
{
*pDest = 0;
}
( , ). arm-none-eabi-gcc Rust LLVM JSON, LLVM:
{
"llvm-target" : "thumbv6m-none-eabi",
"data-layout" : "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64",
"linker" : "arm-none-eabi-gcc",
"pre-link-args" : [ "-nostartfiles", "-Tlayout.ld" ],
"target-endian" : "little",
"target-pointer-width": "32",
"arch" : "arm",
"os" : "none",
"executables" : true
}
build.sh , , .
clang --target=thumbv6m-none-eabi -S -emit-llvm empty.c -o empty.ll
C , Rust . src/main.rs:38.
arm-none-eabi-objdump -Cd 1) C, 2) Rust 3) Rust . , , .
, LLVM C GCC, , - , C Rust C. MKRZero, , , - SAMD21 .