% CROSS_CONTAINER_OPTS="--platform linux/amd64" cross build --target arm-unknown-linux-gnueabihf —release
The application panicked (crashed).
Message: byte index 1 is not a char boundary; it is inside '—' (bytes 0..3) of `—release`
Location: /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/str/mod.rs:659
//// % cargo run --bin raspico
#![no_std]
#![no_main]
use embassy_executor::Spawner;
use embassy_rp::gpio::{Level, Output};
use {defmt_rtt as _, panic_probe as _};
mod routine;
use routine::DispData;
#[embassy_executor::main]
async fn main(_spawner: Spawner){
let p = embassy_rp::init(Default::default());
let mut r1 = Output::new(p.PIN_2, Level::High);
let mut r2 = Output::new(p.PIN_5, Level::High);
let mut g1 = Output::new(p.PIN_3, Level::High);
let mut g2 = Output::new(p.PIN_8, Level::High);
let mut b1 = Output::new(p.PIN_4, Level::High);
let mut b2 = Output::new(p.PIN_9, Level::High);
let mut a = Output::new(p.PIN_10, Level::Low);
let mut b = Output::new(p.PIN_16, Level::Low);
let mut c = Output::new(p.PIN_18, Level::Low);
let mut d = Output::new(p.PIN_20, Level::Low);
let _e = Output::new(p.PIN_22, Level::Low);
let mut clk = Output::new(p.PIN_11, Level::Low);
let mut lat = Output::new(p.PIN_12, Level::High);
let mut oe = Output::new(p.PIN_13, Level::High);
let a_array:[u8;16]=[0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1];
let b_array:[u8;16]=[0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1];
let c_array:[u8;16]=[0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1];
let d_array:[u8;16]=[0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1];
let mut disp_data = DispData {
_array64:[0;64],
array4d:[[[[0;64];32];3];2],};
let new_disp_data = disp_data.new();
loop {for i in 0..16{// row numberif a_array[i]==0{
a.set_low();}else{
a.set_high();};if b_array[i]==0{
b.set_low();}else{
b.set_high();};if c_array[i]==0{
c.set_low();}else{
c.set_high();};if d_array[i]==0{
d.set_low();}else{
d.set_high();};for b in 0..15{// shading
lat.set_high();for k in 0..64{// column data
clk.set_low();//if new_disp_data.array4d[0][2][i][k]> b {
r1.set_high();}else{
r1.set_low();}if new_disp_data.array4d[0][2][16+ i][k]> b {
r2.set_high();}else{
r2.set_low();}if new_disp_data.array4d[0][1][i][k]> b {
g1.set_high();}else{
g1.set_low();}if new_disp_data.array4d[0][1][16+ i][k]> b {
g2.set_high();}else{
g2.set_low();}if new_disp_data.array4d[0][0][i][k]> b {
b1.set_high();}else{
b1.set_low();}if new_disp_data.array4d[0][0][16+ i][k]> b {
b2.set_high();}else{
b2.set_low();}
clk.set_high();}
oe.set_high();
lat.set_low();
oe.set_low();}}}}
<routine.rs>
表示データの作成をするだけ、
static ARRAY64:[u8;64]=[0,1,1,2,3,5,8,13,13,8,5,3,2,1,1,0,0,1,1,2,3,5,8,13,13,8,5,3,2,1,1,0,0,1,1,2,3,5,8,13,13,8,5,3,2,1,1,0,0,1,1,2,3,5,8,13,13,8,5,3,2,1,1,0,];
pub struct DispData {
pub _array64:[u8;64],
pub array4d:[[[[u8;64];32];3];2],}
impl DispData {
pub fn new(&mut self)-> Self {
let mut dis_data = DispData {
_array64: ARRAY64,
array4d:[[[[0;64];32];3];2],};for j in 0..3{for i in 0..32{
dis_data.array4d[0][j][i]= ARRAY64;}}
dis_data
}}
//// original from https://qiita.com/Kumassy/items/fec47952d70b5073b1b7//// [dependencies]// tokio = { version = "1.42", features = ["full"] }
use std::{thread, time};
use tokio::time::{sleep, Duration};
async fn hello()-> String {
let one_sec = time::Duration::from_millis(1000);// in case of async application, it looks better to use tokio::time crate// delay_for : before tokio 0.2sleep(Duration::from_millis(1000)).await;
thread::sleep(one_sec);"hello, async fn".to_string()}// tokio: to support async runtime
#[tokio::main]// the async keyword of the fn main() is necessary
async fn main(){// excute sysnc function and wait completion
let greeting: String =hello().await;
println!("{}", greeting);// new task create(spawn)// return the type Result//
let handle = tokio::spawn(async {sleep(Duration::from_millis(1000)).await;"spawn thread elapsed one second".to_string()});// define async block//
let world = async {
let one_sec = time::Duration::from_millis(1000);
thread::sleep(one_sec);
println!("hello, async block");};// rcv spwan thread return
let result: String = handle.await.unwrap();
println!("{}", result);// async block call and wait
world.await;// wait to avoid main thread terminate before spawn task completesleep(Duration::from_millis(1500)).await;}
やっていること、
① async fn hello()での非同期処理
② asyncブロック(let world)での非同期処理
③ async非同期タスク(tokio::spawn)からの戻り値(let result: String)の取得
<実行結果>
hello, async fn
spawn thread elapsed one second
hello, async block
複数箇所に時間待ちを入れているので、その時間待ちが入って出力されます
let one_sec = time::Duration::from_millis(1000);
sleep(Duration::from_millis(1000)).await;
//! This build script copies the `memory.x` file from the crate root into
//! a directory where the linker can always find it at build time.
//! For many projects this is optional, as the linker always searches the
//! project root directory -- wherever `Cargo.toml` is. However, if you
//! are using a workspace or have a more complicated build setup, this
//! build script becomes required. Additionally, by requesting that
//! Cargo re-run the build script whenever `memory.x` is changed,
//! updating `memory.x` ensures a rebuild of the application with the
//! new memory settings.