From 63a904ae93e17b1f4bb7eacacc63212ca1ac289c Mon Sep 17 00:00:00 2001 From: Barabas Raffai Date: Sat, 28 Oct 2023 11:46:32 +0100 Subject: [PATCH 1/6] Add rust firmware --- fw/{ => c}/.clang-tidy | 0 fw/{ => c}/.idea/.gitignore | 0 fw/{ => c}/.idea/.name | 0 fw/{ => c}/.idea/discord.xml | 0 fw/{ => c}/.idea/fw.iml | 0 fw/{ => c}/.idea/inspectionProfiles/Project_Default.xml | 0 fw/{ => c}/.idea/misc.xml | 0 fw/{ => c}/.idea/modules.xml | 0 fw/{ => c}/.idea/vcs.xml | 0 fw/{ => c}/CMakeLists.txt | 0 fw/{ => c}/TC-crush.cmake | 0 fw/{ => c}/binary/crush-blinky.data | 0 fw/{ => c}/crush.ld | 0 fw/{ => c}/hal.c | 0 fw/{ => c}/hal.h | 0 fw/{ => c}/main.c | 0 fw/{ => c}/start.S | 0 fw/{ => c}/start.c | 0 fw/rust/.gitignore | 1 + fw/rust/Cargo.lock | 7 +++++++ fw/rust/Cargo.toml | 8 ++++++++ fw/rust/src/main.rs | 5 +++++ 22 files changed, 21 insertions(+) rename fw/{ => c}/.clang-tidy (100%) rename fw/{ => c}/.idea/.gitignore (100%) rename fw/{ => c}/.idea/.name (100%) rename fw/{ => c}/.idea/discord.xml (100%) rename fw/{ => c}/.idea/fw.iml (100%) rename fw/{ => c}/.idea/inspectionProfiles/Project_Default.xml (100%) rename fw/{ => c}/.idea/misc.xml (100%) rename fw/{ => c}/.idea/modules.xml (100%) rename fw/{ => c}/.idea/vcs.xml (100%) rename fw/{ => c}/CMakeLists.txt (100%) rename fw/{ => c}/TC-crush.cmake (100%) rename fw/{ => c}/binary/crush-blinky.data (100%) rename fw/{ => c}/crush.ld (100%) rename fw/{ => c}/hal.c (100%) rename fw/{ => c}/hal.h (100%) rename fw/{ => c}/main.c (100%) rename fw/{ => c}/start.S (100%) rename fw/{ => c}/start.c (100%) create mode 100644 fw/rust/.gitignore create mode 100644 fw/rust/Cargo.lock create mode 100644 fw/rust/Cargo.toml create mode 100644 fw/rust/src/main.rs diff --git a/fw/.clang-tidy b/fw/c/.clang-tidy similarity index 100% rename from fw/.clang-tidy rename to fw/c/.clang-tidy diff --git a/fw/.idea/.gitignore b/fw/c/.idea/.gitignore similarity index 100% rename from fw/.idea/.gitignore rename to fw/c/.idea/.gitignore diff --git a/fw/.idea/.name b/fw/c/.idea/.name similarity index 100% rename from fw/.idea/.name rename to fw/c/.idea/.name diff --git a/fw/.idea/discord.xml b/fw/c/.idea/discord.xml similarity index 100% rename from fw/.idea/discord.xml rename to fw/c/.idea/discord.xml diff --git a/fw/.idea/fw.iml b/fw/c/.idea/fw.iml similarity index 100% rename from fw/.idea/fw.iml rename to fw/c/.idea/fw.iml diff --git a/fw/.idea/inspectionProfiles/Project_Default.xml b/fw/c/.idea/inspectionProfiles/Project_Default.xml similarity index 100% rename from fw/.idea/inspectionProfiles/Project_Default.xml rename to fw/c/.idea/inspectionProfiles/Project_Default.xml diff --git a/fw/.idea/misc.xml b/fw/c/.idea/misc.xml similarity index 100% rename from fw/.idea/misc.xml rename to fw/c/.idea/misc.xml diff --git a/fw/.idea/modules.xml b/fw/c/.idea/modules.xml similarity index 100% rename from fw/.idea/modules.xml rename to fw/c/.idea/modules.xml diff --git a/fw/.idea/vcs.xml b/fw/c/.idea/vcs.xml similarity index 100% rename from fw/.idea/vcs.xml rename to fw/c/.idea/vcs.xml diff --git a/fw/CMakeLists.txt b/fw/c/CMakeLists.txt similarity index 100% rename from fw/CMakeLists.txt rename to fw/c/CMakeLists.txt diff --git a/fw/TC-crush.cmake b/fw/c/TC-crush.cmake similarity index 100% rename from fw/TC-crush.cmake rename to fw/c/TC-crush.cmake diff --git a/fw/binary/crush-blinky.data b/fw/c/binary/crush-blinky.data similarity index 100% rename from fw/binary/crush-blinky.data rename to fw/c/binary/crush-blinky.data diff --git a/fw/crush.ld b/fw/c/crush.ld similarity index 100% rename from fw/crush.ld rename to fw/c/crush.ld diff --git a/fw/hal.c b/fw/c/hal.c similarity index 100% rename from fw/hal.c rename to fw/c/hal.c diff --git a/fw/hal.h b/fw/c/hal.h similarity index 100% rename from fw/hal.h rename to fw/c/hal.h diff --git a/fw/main.c b/fw/c/main.c similarity index 100% rename from fw/main.c rename to fw/c/main.c diff --git a/fw/start.S b/fw/c/start.S similarity index 100% rename from fw/start.S rename to fw/c/start.S diff --git a/fw/start.c b/fw/c/start.c similarity index 100% rename from fw/start.c rename to fw/c/start.c diff --git a/fw/rust/.gitignore b/fw/rust/.gitignore new file mode 100644 index 0000000..eb5a316 --- /dev/null +++ b/fw/rust/.gitignore @@ -0,0 +1 @@ +target diff --git a/fw/rust/Cargo.lock b/fw/rust/Cargo.lock new file mode 100644 index 0000000..f255837 --- /dev/null +++ b/fw/rust/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "crush_blinky" +version = "0.1.0" diff --git a/fw/rust/Cargo.toml b/fw/rust/Cargo.toml new file mode 100644 index 0000000..3fe87a0 --- /dev/null +++ b/fw/rust/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "crush_blinky" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/fw/rust/src/main.rs b/fw/rust/src/main.rs new file mode 100644 index 0000000..38a9397 --- /dev/null +++ b/fw/rust/src/main.rs @@ -0,0 +1,5 @@ +#![] + +fn main() { + println!("Hello, world!"); +} From 4c31669ca175fd0ee7f050ba45521096c982f27b Mon Sep 17 00:00:00 2001 From: Barabas Raffai Date: Sat, 28 Oct 2023 16:22:32 +0100 Subject: [PATCH 2/6] WIP set up rust --- fw/c/.idea/vcs.xml | 1 + fw/rust/.cargo/config.toml | 5 +++++ fw/rust/crush.ld | 20 ++++++++++++++++++++ fw/rust/src/hal.rs | 35 +++++++++++++++++++++++++++++++++++ fw/rust/src/main.rs | 17 ++++++++++++++--- fw/rust/src/start.S | 7 +++++++ fw/rust/src/start.rs | 16 ++++++++++++++++ 7 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 fw/rust/.cargo/config.toml create mode 100644 fw/rust/crush.ld create mode 100644 fw/rust/src/hal.rs create mode 100644 fw/rust/src/start.S create mode 100644 fw/rust/src/start.rs diff --git a/fw/c/.idea/vcs.xml b/fw/c/.idea/vcs.xml index 6c0b863..64713b8 100644 --- a/fw/c/.idea/vcs.xml +++ b/fw/c/.idea/vcs.xml @@ -1,6 +1,7 @@ + \ No newline at end of file diff --git a/fw/rust/.cargo/config.toml b/fw/rust/.cargo/config.toml new file mode 100644 index 0000000..2c5d626 --- /dev/null +++ b/fw/rust/.cargo/config.toml @@ -0,0 +1,5 @@ +[build] +target = "riscv32i-unknown-none-elf" + +[target.riscv32i-unknown-none-elf] +rustflags = ["-C", "link-arg=-Tcrush.ld"] \ No newline at end of file diff --git a/fw/rust/crush.ld b/fw/rust/crush.ld new file mode 100644 index 0000000..df2a7c9 --- /dev/null +++ b/fw/rust/crush.ld @@ -0,0 +1,20 @@ +OUTPUT_ARCH( "riscv" ) +ENTRY(start) + +MEMORY +{ + mem (rwx): ORIGIN = 0x10000000, LENGTH = 0x800 * 4 +} + +SECTIONS +{ + .mem : { + KEEP(*(.start)); + *(.text .text.*); + *(.rodata .rodata.*); + *(.bss .bss.*); + *(.data .data.*); + } > mem +} + +stack_start = ORIGIN(mem) + LENGTH(mem); diff --git a/fw/rust/src/hal.rs b/fw/rust/src/hal.rs new file mode 100644 index 0000000..02c0418 --- /dev/null +++ b/fw/rust/src/hal.rs @@ -0,0 +1,35 @@ +use core::arch::asm; + +fn delay() { + for i in 0..100_000 { + unsafe { + asm!("nop"); + } + } +} + +const GPIO_BASE_ADDRESS: *mut u32 = 0x40000000 as *mut u32; + +const fn bit_mask(i: u32) -> u32 { + 1 << i +} + +fn get_button() -> bool { + unsafe { + return (GPIO_BASE_ADDRESS.read_volatile() & bit_mask(8)) != 0; + } +} + +fn set_led_on(index: u32, led_on: bool) { + if led_on { + unsafe { + let value = GPIO_BASE_ADDRESS.read_volatile(); + GPIO_BASE_ADDRESS.write_volatile(value | bit_mask(index)); + } + } else { + unsafe { + let value = GPIO_BASE_ADDRESS.read_volatile(); + GPIO_BASE_ADDRESS.write_volatile(value & !bit_mask(index)); + } + } +} diff --git a/fw/rust/src/main.rs b/fw/rust/src/main.rs index 38a9397..b731dbf 100644 --- a/fw/rust/src/main.rs +++ b/fw/rust/src/main.rs @@ -1,5 +1,16 @@ -#![] +#![no_main] +#![no_std] -fn main() { - println!("Hello, world!"); +use core::panic::PanicInfo; + +mod hal; +mod start; + +#[panic_handler] +fn panic(_panic: &PanicInfo) -> ! { + loop {} +} + +pub fn main() -> ! { + loop {} } diff --git a/fw/rust/src/start.S b/fw/rust/src/start.S new file mode 100644 index 0000000..ccd27e1 --- /dev/null +++ b/fw/rust/src/start.S @@ -0,0 +1,7 @@ +.section .start +.global start +start: + // Load stack_start defined by the linker file to the stack pointer + la sp, stack_start + // Call c_start to do the rest of the initialisation + call c_start diff --git a/fw/rust/src/start.rs b/fw/rust/src/start.rs new file mode 100644 index 0000000..ff19b61 --- /dev/null +++ b/fw/rust/src/start.rs @@ -0,0 +1,16 @@ +//! Start-up code for hardware initialisation. + +// FIXME: import bss addresses from linker script + +use crate::main; +use core::arch::global_asm; + +global_asm!(include_str!("start.S")); + +#[no_mangle] +// FIXME: should this be unsafe? +pub extern "C" fn c_start() -> ! { + // FIXME: bss init + + main(); +} From 324e6bc3530080735a4c15f41d80be83a5fa0013 Mon Sep 17 00:00:00 2001 From: Barabas Raffai Date: Sat, 28 Oct 2023 18:01:07 +0100 Subject: [PATCH 3/6] Fix rust linker script --- fw/c/.idea/cmake.xml | 8 ++++ fw/rust/.idea/discord.xml | 7 +++ fw/rust/.idea/workspace.xml | 94 +++++++++++++++++++++++++++++++++++++ fw/rust/crush.ld | 21 +++++++-- fw/rust/src/start.S | 2 +- 5 files changed, 127 insertions(+), 5 deletions(-) create mode 100644 fw/c/.idea/cmake.xml create mode 100644 fw/rust/.idea/discord.xml create mode 100644 fw/rust/.idea/workspace.xml diff --git a/fw/c/.idea/cmake.xml b/fw/c/.idea/cmake.xml new file mode 100644 index 0000000..e300a94 --- /dev/null +++ b/fw/c/.idea/cmake.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/fw/rust/.idea/discord.xml b/fw/rust/.idea/discord.xml new file mode 100644 index 0000000..30bab2a --- /dev/null +++ b/fw/rust/.idea/discord.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/fw/rust/.idea/workspace.xml b/fw/rust/.idea/workspace.xml new file mode 100644 index 0000000..f03cb37 --- /dev/null +++ b/fw/rust/.idea/workspace.xml @@ -0,0 +1,94 @@ + + + + + { + "useNewFormat": true +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1698507639029 + + + + + + \ No newline at end of file diff --git a/fw/rust/crush.ld b/fw/rust/crush.ld index df2a7c9..d879ea3 100644 --- a/fw/rust/crush.ld +++ b/fw/rust/crush.ld @@ -9,12 +9,25 @@ MEMORY SECTIONS { .mem : { - KEEP(*(.start)); + . = ALIGN(4); + /* FIXME: must use ".init" due to possible bug in rust: + * https://github.com/rust-lang/rust/issues/117323 + */ + KEEP(*(.init)); *(.text .text.*); - *(.rodata .rodata.*); - *(.bss .bss.*); + *(.rodata .rodata*); + . = ALIGN(4); *(.data .data.*); } > mem + + .bss (NOLOAD) : { + . = ALIGN(4); + bss_start = .; + *(.bss .bss.*); + . = ALIGN(4); + bss_end = .; + } > mem + + stack_start = ORIGIN(mem) + LENGTH(mem); } -stack_start = ORIGIN(mem) + LENGTH(mem); diff --git a/fw/rust/src/start.S b/fw/rust/src/start.S index ccd27e1..a6bf701 100644 --- a/fw/rust/src/start.S +++ b/fw/rust/src/start.S @@ -1,4 +1,4 @@ -.section .start +.section .init .global start start: // Load stack_start defined by the linker file to the stack pointer From 4a15820bac0f316bf4d559c18e9511f7eb5785e3 Mon Sep 17 00:00:00 2001 From: Barabas Raffai Date: Sat, 28 Oct 2023 18:27:22 +0100 Subject: [PATCH 4/6] set up end-to-end build for rust --- fw/rust/.idea/discord.xml | 2 +- fw/rust/.idea/vcs.xml | 6 +++ fw/rust/.idea/workspace.xml | 15 +++++-- fw/rust/bin/crush-blinky.bin | Bin 0 -> 1220 bytes fw/rust/bin/crush-blinky.data | 78 ++++++++++++++++++++++++++++++++++ fw/rust/build.sh | 2 + fw/rust/src/hal.rs | 8 ++-- fw/rust/src/main.rs | 10 ++++- 8 files changed, 112 insertions(+), 9 deletions(-) create mode 100644 fw/rust/.idea/vcs.xml create mode 100755 fw/rust/bin/crush-blinky.bin create mode 100644 fw/rust/bin/crush-blinky.data create mode 100755 fw/rust/build.sh diff --git a/fw/rust/.idea/discord.xml b/fw/rust/.idea/discord.xml index 30bab2a..d8e9561 100644 --- a/fw/rust/.idea/discord.xml +++ b/fw/rust/.idea/discord.xml @@ -1,7 +1,7 @@ - \ No newline at end of file diff --git a/fw/rust/.idea/vcs.xml b/fw/rust/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/fw/rust/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/fw/rust/.idea/workspace.xml b/fw/rust/.idea/workspace.xml index f03cb37..b5170fa 100644 --- a/fw/rust/.idea/workspace.xml +++ b/fw/rust/.idea/workspace.xml @@ -15,7 +15,12 @@ - + + + + + + - + + diff --git a/fw/rust/bin/crush-blinky.bin b/fw/rust/bin/crush-blinky.bin new file mode 100755 index 0000000000000000000000000000000000000000..05495e0e96d0b9576e026e46d592b92cc4403525 GIT binary patch literal 1220 zcmY*Y&ubGw82x5XXcx4-n{qCn@cx|Tp{Q!5&dWm zZee_;GE?MAA~n;c#kRm$K2wP<*~vWl$(G5b>nhbHH5*Wsa>yB)c=L)%2c+h7z9?Ol zdfoSi0@&8mCeFiI)q@+Sn1>xHNhOe<3V?ASO3(XIKF)DvoU+q><|laHqNF&u+~4E= z&3>*U7p#bPbG{y@!H7HZa%vXbGzZ|PnM+GBUspCqJdgQoJ2|B6R-dwWcj!NkLY%17 zlrzHFy%138ope~MofHBba+>#SV5zyl@_T#^`ee&yEh-a?>U798b7Rq2?$WO?yS0zn z298Q}9ktVAy>g7{Vebqu69zNIm_rLOQeI&64u1Mc+>6G{Q??Ae4EA_qJl5i%9#YpE zb%qwyxjWKsVSQXzz6V~@cVKFb*eUi{`hIZ7tjBE^4Y#gkL$BW}Qt4rIU)nFIH?%mc z#ZICgjOlfO5!cwpW450X!vCixYUcyjPTyBl-#o7iaJ0a~9&3OfM_$RwzrHZI!gv5$ zH4kvn-qzYRKN-dCB79Ih3f-+~QivH3ePO@vV(#-g{BLl-`S3k^(agV^{!{hf{Rwm1 zJ9_l7(=KnSRG;?x8}prZuci_hKfd?6)9&9^Gdy0lI_;z1%IlNSqu<$L3|@{c6;xtK z<8f-JYr$`e&s7u5r)AF19U7hbe!y9K#g%z0@;CC?`x#;0OR>Q3K&1sRhSZU<5zaB= z)N7^rwUtVyR!6ZMil0X}i3a)lTWK`P8=DQUQT6I;>#Gf~QpRt4y|Lz1UzBUBmFhO- zY>IQTKr3LZCp>?-OyZRg*Cs5Ta2c`BXJP1|=a2K!XamIVZ~)&$v>e)Z#JH!zq*rJO S9e;x9xiAbLMDYcV^Y;htS{x$) literal 0 HcmV?d00001 diff --git a/fw/rust/bin/crush-blinky.data b/fw/rust/bin/crush-blinky.data new file mode 100644 index 0000000..6de9ffa --- /dev/null +++ b/fw/rust/bin/crush-blinky.data @@ -0,0 +1,78 @@ +@00000000 +17210000 13010100 97000000 E780C02B +130101FE 232E1100 13050000 2322A100 +37850100 1305056A 2324A100 03254100 +83258100 97000000 E780001D 2326A100 +2328B100 6F004000 1305C100 97000000 +E7808019 232CB100 232AA100 03254101 +631A0500 6F004000 8320C101 13010102 +67800000 13000000 6FF01FFD 130101FF +93050500 2324B100 2326B100 1305F001 +636EB500 6F004000 83258100 13051000 +3315B500 13010101 67800000 37050010 +13050542 B7050010 1386C540 93053002 +97000000 E780802F 731000C0 130101FE +232E1100 37050040 2328A100 232AA100 +03250500 232CA100 03258101 2326A100 +13058000 97000000 E78080F8 93050500 +0325C100 3375B500 3335A000 8320C101 +13010102 67800000 130101FB 23261104 +2328A100 232AA100 A30DB100 639E0504 +6F004000 03250101 B7050040 2324B100 +2328B102 232AB102 83A50500 232CB102 +83258103 2326B100 232EB100 97000000 +E78000F2 83258100 13060500 0325C100 +1346F6FF 3375C500 2322B104 2324A104 +23A0A500 6F004005 03250101 B7050040 +2320B100 2322B102 2324B102 83A50500 +2326B102 8325C102 2322B100 2320B102 +97000000 E780C0EC 83250100 13060500 +03254100 3365C500 232EB102 2320A104 +23A0A500 6F004000 8320C104 13010105 +67800000 130101FF 23261100 2324A100 +97000000 E7808002 8320C100 13010101 +67800000 130101FF 2324A100 2326B100 +13010101 67800000 130101FD 23261102 +93050500 2328B100 232EB100 13854500 +2322B102 2324A102 03A50500 83A54500 +634AB500 6F004000 13050000 232AA100 +6F004004 03250101 03250500 2324A100 +2320A102 93051000 2326B100 97000000 +E780C003 83260101 83258100 13060500 +0325C100 23A0C600 232CB100 232AA100 +6F004000 03254101 83258101 8320C102 +13010103 67800000 130101FF 2322A100 +2324B100 2326B100 3305B500 13010101 +67800000 97000000 E780C001 731000C0 +130101FF 2326A100 6F004000 6F000000 +130101FF 23261100 13050000 2305A100 +6F004000 0345A100 1345F5FF 13751500 +2305A100 97000000 E78080DC 2322A100 +A305A100 8345A100 13050000 97000000 +E780C0DF 83254100 13051000 97000000 +E780C0DE 97000000 E780C0CD 6FF09FFB +67800000 B7F54DC9 93856570 2326B500 +B7B56D2F 9385A572 2324B500 B7553D82 +9385B532 2322B500 B7555202 9385F5F7 +2320B500 67800000 130101FE 232E1100 +37060010 13064644 2324C100 37060010 +13064644 2326C100 232AA100 2328B100 +13051000 230CA100 13058100 97000000 +E78040F2 731000C0 130101FD 23261102 +2322A102 2324B102 13054102 2326A100 +13051000 2328A100 232E0100 37050010 +13054544 232AA100 232C0100 1305C100 +93050600 97000000 E78040F8 731000C0 +7372632F 68616C2E 72730000 00040010 +0A000000 0E000000 05000000 00000000 +61747465 6D707420 746F2073 68696674 +206C6566 74207769 7468206F 76657266 +6C6F7700 40030010 00000000 01000000 +44030010 10000000 00000000 017A5200 +017C0101 1B0C0200 10000000 18000000 +D0FEFFFF 04000000 00000000 10000000 +2C000000 C0FEFFFF 34000000 00000000 +14000000 40000000 E0FEFFFF 40000000 +00440E20 44810100 14000000 58000000 +08FFFFFF 48000000 00440E30 44810100 +00000000 diff --git a/fw/rust/build.sh b/fw/rust/build.sh new file mode 100755 index 0000000..784b372 --- /dev/null +++ b/fw/rust/build.sh @@ -0,0 +1,2 @@ +cargo objcopy -- -O binary bin/crush-blinky.bin +objcopy -I binary --verilog-data-width 4 -O verilog bin/crush-blinky.bin bin/crush-blinky.data diff --git a/fw/rust/src/hal.rs b/fw/rust/src/hal.rs index 02c0418..5400aa8 100644 --- a/fw/rust/src/hal.rs +++ b/fw/rust/src/hal.rs @@ -1,7 +1,7 @@ use core::arch::asm; -fn delay() { - for i in 0..100_000 { +pub(crate) fn delay() { + for _ in 0..100_000 { unsafe { asm!("nop"); } @@ -14,13 +14,13 @@ const fn bit_mask(i: u32) -> u32 { 1 << i } -fn get_button() -> bool { +pub(crate) fn get_button() -> bool { unsafe { return (GPIO_BASE_ADDRESS.read_volatile() & bit_mask(8)) != 0; } } -fn set_led_on(index: u32, led_on: bool) { +pub(crate) fn set_led_on(index: u32, led_on: bool) { if led_on { unsafe { let value = GPIO_BASE_ADDRESS.read_volatile(); diff --git a/fw/rust/src/main.rs b/fw/rust/src/main.rs index b731dbf..6e417ac 100644 --- a/fw/rust/src/main.rs +++ b/fw/rust/src/main.rs @@ -12,5 +12,13 @@ fn panic(_panic: &PanicInfo) -> ! { } pub fn main() -> ! { - loop {} + let mut blinky_led_on = false; + loop { + blinky_led_on = !blinky_led_on; + + let is_pressed = hal::get_button(); + hal::set_led_on(0, blinky_led_on); + hal::set_led_on(1, is_pressed); + hal::delay(); + } } From db45fb90632ca814818bde540ab2b0ff1383b50f Mon Sep 17 00:00:00 2001 From: Barabas Raffai Date: Sat, 28 Oct 2023 18:49:51 +0100 Subject: [PATCH 5/6] set up top sim with rust --- crush.core | 2 +- fw/rust/.idea/.gitignore | 8 +++ fw/rust/.idea/modules.xml | 8 +++ fw/rust/.idea/rust.iml | 11 ++++ fw/rust/.idea/workspace.xml | 103 ------------------------------- fw/rust/bin/crush-blinky.bin | Bin 1220 -> 0 bytes fw/rust/bin/crush-blinky.data | 78 ----------------------- fw/rust/binary/crush-blinky.bin | Bin 0 -> 1220 bytes fw/rust/binary/crush-blinky.data | 78 +++++++++++++++++++++++ fw/rust/build.sh | 4 +- fw/rust/src/hal.rs | 2 +- rtl/soc/memory_infer.v | 2 +- 12 files changed, 110 insertions(+), 186 deletions(-) create mode 100644 fw/rust/.idea/.gitignore create mode 100644 fw/rust/.idea/modules.xml create mode 100644 fw/rust/.idea/rust.iml delete mode 100644 fw/rust/.idea/workspace.xml delete mode 100755 fw/rust/bin/crush-blinky.bin delete mode 100644 fw/rust/bin/crush-blinky.data create mode 100755 fw/rust/binary/crush-blinky.bin create mode 100644 fw/rust/binary/crush-blinky.data diff --git a/crush.core b/crush.core index 1776347..32fe3e6 100644 --- a/crush.core +++ b/crush.core @@ -19,7 +19,7 @@ filesets: - rtl/soc/memory_ice40_spram.v - rtl/soc/top.v - rtl/soc/gpio.v - - fw/binary/crush-blinky.data: + - fw/rust/binary/crush-blinky.data: file_type: user copyto: fw.data file_type: verilogSource diff --git a/fw/rust/.idea/.gitignore b/fw/rust/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/fw/rust/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/fw/rust/.idea/modules.xml b/fw/rust/.idea/modules.xml new file mode 100644 index 0000000..8e518a5 --- /dev/null +++ b/fw/rust/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/fw/rust/.idea/rust.iml b/fw/rust/.idea/rust.iml new file mode 100644 index 0000000..c254557 --- /dev/null +++ b/fw/rust/.idea/rust.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/fw/rust/.idea/workspace.xml b/fw/rust/.idea/workspace.xml deleted file mode 100644 index b5170fa..0000000 --- a/fw/rust/.idea/workspace.xml +++ /dev/null @@ -1,103 +0,0 @@ - - - - - { - "useNewFormat": true -} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1698507639029 - - - - - - \ No newline at end of file diff --git a/fw/rust/bin/crush-blinky.bin b/fw/rust/bin/crush-blinky.bin deleted file mode 100755 index 05495e0e96d0b9576e026e46d592b92cc4403525..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1220 zcmY*Y&ubGw82x5XXcx4-n{qCn@cx|Tp{Q!5&dWm zZee_;GE?MAA~n;c#kRm$K2wP<*~vWl$(G5b>nhbHH5*Wsa>yB)c=L)%2c+h7z9?Ol zdfoSi0@&8mCeFiI)q@+Sn1>xHNhOe<3V?ASO3(XIKF)DvoU+q><|laHqNF&u+~4E= z&3>*U7p#bPbG{y@!H7HZa%vXbGzZ|PnM+GBUspCqJdgQoJ2|B6R-dwWcj!NkLY%17 zlrzHFy%138ope~MofHBba+>#SV5zyl@_T#^`ee&yEh-a?>U798b7Rq2?$WO?yS0zn z298Q}9ktVAy>g7{Vebqu69zNIm_rLOQeI&64u1Mc+>6G{Q??Ae4EA_qJl5i%9#YpE zb%qwyxjWKsVSQXzz6V~@cVKFb*eUi{`hIZ7tjBE^4Y#gkL$BW}Qt4rIU)nFIH?%mc z#ZICgjOlfO5!cwpW450X!vCixYUcyjPTyBl-#o7iaJ0a~9&3OfM_$RwzrHZI!gv5$ zH4kvn-qzYRKN-dCB79Ih3f-+~QivH3ePO@vV(#-g{BLl-`S3k^(agV^{!{hf{Rwm1 zJ9_l7(=KnSRG;?x8}prZuci_hKfd?6)9&9^Gdy0lI_;z1%IlNSqu<$L3|@{c6;xtK z<8f-JYr$`e&s7u5r)AF19U7hbe!y9K#g%z0@;CC?`x#;0OR>Q3K&1sRhSZU<5zaB= z)N7^rwUtVyR!6ZMil0X}i3a)lTWK`P8=DQUQT6I;>#Gf~QpRt4y|Lz1UzBUBmFhO- zY>IQTKr3LZCp>?-OyZRg*Cs5Ta2c`BXJP1|=a2K!XamIVZ~)&$v>e)Z#JH!zq*rJO S9e;x9xiAbLMDYcV^Y;htS{x$) diff --git a/fw/rust/bin/crush-blinky.data b/fw/rust/bin/crush-blinky.data deleted file mode 100644 index 6de9ffa..0000000 --- a/fw/rust/bin/crush-blinky.data +++ /dev/null @@ -1,78 +0,0 @@ -@00000000 -17210000 13010100 97000000 E780C02B -130101FE 232E1100 13050000 2322A100 -37850100 1305056A 2324A100 03254100 -83258100 97000000 E780001D 2326A100 -2328B100 6F004000 1305C100 97000000 -E7808019 232CB100 232AA100 03254101 -631A0500 6F004000 8320C101 13010102 -67800000 13000000 6FF01FFD 130101FF -93050500 2324B100 2326B100 1305F001 -636EB500 6F004000 83258100 13051000 -3315B500 13010101 67800000 37050010 -13050542 B7050010 1386C540 93053002 -97000000 E780802F 731000C0 130101FE -232E1100 37050040 2328A100 232AA100 -03250500 232CA100 03258101 2326A100 -13058000 97000000 E78080F8 93050500 -0325C100 3375B500 3335A000 8320C101 -13010102 67800000 130101FB 23261104 -2328A100 232AA100 A30DB100 639E0504 -6F004000 03250101 B7050040 2324B100 -2328B102 232AB102 83A50500 232CB102 -83258103 2326B100 232EB100 97000000 -E78000F2 83258100 13060500 0325C100 -1346F6FF 3375C500 2322B104 2324A104 -23A0A500 6F004005 03250101 B7050040 -2320B100 2322B102 2324B102 83A50500 -2326B102 8325C102 2322B100 2320B102 -97000000 E780C0EC 83250100 13060500 -03254100 3365C500 232EB102 2320A104 -23A0A500 6F004000 8320C104 13010105 -67800000 130101FF 23261100 2324A100 -97000000 E7808002 8320C100 13010101 -67800000 130101FF 2324A100 2326B100 -13010101 67800000 130101FD 23261102 -93050500 2328B100 232EB100 13854500 -2322B102 2324A102 03A50500 83A54500 -634AB500 6F004000 13050000 232AA100 -6F004004 03250101 03250500 2324A100 -2320A102 93051000 2326B100 97000000 -E780C003 83260101 83258100 13060500 -0325C100 23A0C600 232CB100 232AA100 -6F004000 03254101 83258101 8320C102 -13010103 67800000 130101FF 2322A100 -2324B100 2326B100 3305B500 13010101 -67800000 97000000 E780C001 731000C0 -130101FF 2326A100 6F004000 6F000000 -130101FF 23261100 13050000 2305A100 -6F004000 0345A100 1345F5FF 13751500 -2305A100 97000000 E78080DC 2322A100 -A305A100 8345A100 13050000 97000000 -E780C0DF 83254100 13051000 97000000 -E780C0DE 97000000 E780C0CD 6FF09FFB -67800000 B7F54DC9 93856570 2326B500 -B7B56D2F 9385A572 2324B500 B7553D82 -9385B532 2322B500 B7555202 9385F5F7 -2320B500 67800000 130101FE 232E1100 -37060010 13064644 2324C100 37060010 -13064644 2326C100 232AA100 2328B100 -13051000 230CA100 13058100 97000000 -E78040F2 731000C0 130101FD 23261102 -2322A102 2324B102 13054102 2326A100 -13051000 2328A100 232E0100 37050010 -13054544 232AA100 232C0100 1305C100 -93050600 97000000 E78040F8 731000C0 -7372632F 68616C2E 72730000 00040010 -0A000000 0E000000 05000000 00000000 -61747465 6D707420 746F2073 68696674 -206C6566 74207769 7468206F 76657266 -6C6F7700 40030010 00000000 01000000 -44030010 10000000 00000000 017A5200 -017C0101 1B0C0200 10000000 18000000 -D0FEFFFF 04000000 00000000 10000000 -2C000000 C0FEFFFF 34000000 00000000 -14000000 40000000 E0FEFFFF 40000000 -00440E20 44810100 14000000 58000000 -08FFFFFF 48000000 00440E30 44810100 -00000000 diff --git a/fw/rust/binary/crush-blinky.bin b/fw/rust/binary/crush-blinky.bin new file mode 100755 index 0000000000000000000000000000000000000000..5acaffe6b238abf9dba5c91cf256bdc1ec3e7881 GIT binary patch literal 1220 zcmY*Y&ubGw82x5X*h`R3vcB3B4{Lqy*j zjhh&ssoVs)l1NQ;(RWCtx@4yd6r`IbkFKdqm(+Af74nfY81BEUvLUG%oi9pPq+Soa zfdH=cw1Km5PUYbGDdtgIN?;>D69VHvl%DnDe4OLTB;_aj%uVpVc}YoE%KN+Azi#<$ zIcFKpv$Z7c4S6HaSJU98IRHP)T$+OUy0S6kdCX_q=>g@p`jo%Zq5n7vaiTI4&Jbtk zd`P9Y(qXN3S_p9PHSg)rQZu0y^!Oa~>88zER4yF)bjY5$iTEsc@n@9Z`T$=;N2R)s z>hxHz9ASFcI|a;?!OSq`z(S0a7aF~LKZ3L{m<7t0ftSM`Z-mEM9QYx%-|!h)^c@<% zEUb@w<$C~^_zsNMh@E1OrSAuK%zE5b(QxZpHuMI)B9$J-_oZtEenX4HTI@9ZU`($I zjHJen&)&0xj1d2NqBU0yNEg{9!2ifBq_vPWc27aHlIK(Cl(h}YCxlLW}v;` zx5ekGG3GOTcmAQ#sqY7zb*;FvV8!)~e6IbRFz=Gph<@9YJO|Il(I9{HE!XSijm^4OuXwf9wUxTJUdC^Gt-k72o|mgD>y>S~i@m%- zp!pc<3C~|Fk$5S@)iFyaTte*gSrj?w`QyAS+Iz%qa{%83G#_mrG45$$+*@c09e;wU O6GhR3I6lX5{{8@oKpQ&% literal 0 HcmV?d00001 diff --git a/fw/rust/binary/crush-blinky.data b/fw/rust/binary/crush-blinky.data new file mode 100644 index 0000000..15432dc --- /dev/null +++ b/fw/rust/binary/crush-blinky.data @@ -0,0 +1,78 @@ +@00000000 +17210000 13010100 97000000 E780802B +130101FE 232E1100 13050000 2322A100 +1305A000 2324A100 03254100 83258100 +97000000 E780001D 2326A100 2328B100 +6F004000 1305C100 97000000 E7808019 +232CB100 232AA100 03254101 631A0500 +6F004000 8320C101 13010102 67800000 +13000000 6FF01FFD 130101FF 93050500 +2324B100 2326B100 1305F001 636EB500 +6F004000 83258100 13051000 3315B500 +13010101 67800000 37050010 13050542 +B7050010 13868540 93053002 97000000 +E780802F 731000C0 130101FE 232E1100 +37050040 2328A100 232AA100 03250500 +232CA100 03258101 2326A100 13058000 +97000000 E78080F8 93050500 0325C100 +3375B500 3335A000 8320C101 13010102 +67800000 130101FB 23261104 2328A100 +232AA100 A30DB100 639E0504 6F004000 +03250101 B7050040 2324B100 2328B102 +232AB102 83A50500 232CB102 83258103 +2326B100 232EB100 97000000 E78000F2 +83258100 13060500 0325C100 1346F6FF +3375C500 2322B104 2324A104 23A0A500 +6F004005 03250101 B7050040 2320B100 +2322B102 2324B102 83A50500 2326B102 +8325C102 2322B100 2320B102 97000000 +E780C0EC 83250100 13060500 03254100 +3365C500 232EB102 2320A104 23A0A500 +6F004000 8320C104 13010105 67800000 +130101FF 23261100 2324A100 97000000 +E7808002 8320C100 13010101 67800000 +130101FF 2324A100 2326B100 13010101 +67800000 130101FD 23261102 93050500 +2328B100 232EB100 13854500 2322B102 +2324A102 03A50500 83A54500 634AB500 +6F004000 13050000 232AA100 6F004004 +03250101 03250500 2324A100 2320A102 +93051000 2326B100 97000000 E780C003 +83260101 83258100 13060500 0325C100 +23A0C600 232CB100 232AA100 6F004000 +03254101 83258101 8320C102 13010103 +67800000 130101FF 2322A100 2324B100 +2326B100 3305B500 13010101 67800000 +97000000 E780C001 731000C0 130101FF +2326A100 6F004000 6F000000 130101FF +23261100 13050000 2305A100 6F004000 +0345A100 1345F5FF 13751500 2305A100 +97000000 E78080DC 2322A100 A305A100 +8345A100 13050000 97000000 E780C0DF +83254100 13051000 97000000 E780C0DE +97000000 E78000CE 6FF09FFB 67800000 +B7F54DC9 93856570 2326B500 B7B56D2F +9385A572 2324B500 B7553D82 9385B532 +2322B500 B7555202 9385F5F7 2320B500 +67800000 130101FE 232E1100 37060010 +13064644 2324C100 37060010 13064644 +2326C100 232AA100 2328B100 13051000 +230CA100 13058100 97000000 E78040F2 +731000C0 130101FD 23261102 2322A102 +2324B102 13054102 2326A100 13051000 +2328A100 232E0100 37050010 13054544 +232AA100 232C0100 1305C100 93050600 +97000000 E78040F8 731000C0 7372632F +68616C2E 72730000 FC030010 0A000000 +0E000000 05000000 00000000 00000000 +61747465 6D707420 746F2073 68696674 +206C6566 74207769 7468206F 76657266 +6C6F7700 3C030010 00000000 01000000 +40030010 10000000 00000000 017A5200 +017C0101 1B0C0200 10000000 18000000 +CCFEFFFF 04000000 00000000 10000000 +2C000000 BCFEFFFF 34000000 00000000 +14000000 40000000 DCFEFFFF 40000000 +00440E20 44810100 14000000 58000000 +04FFFFFF 48000000 00440E30 44810100 +00000000 diff --git a/fw/rust/build.sh b/fw/rust/build.sh index 784b372..fb98303 100755 --- a/fw/rust/build.sh +++ b/fw/rust/build.sh @@ -1,2 +1,2 @@ -cargo objcopy -- -O binary bin/crush-blinky.bin -objcopy -I binary --verilog-data-width 4 -O verilog bin/crush-blinky.bin bin/crush-blinky.data +cargo objcopy -- -O binary binary/crush-blinky.bin +objcopy -I binary --verilog-data-width 4 -O verilog binary/crush-blinky.bin binary/crush-blinky.data diff --git a/fw/rust/src/hal.rs b/fw/rust/src/hal.rs index 5400aa8..83601c3 100644 --- a/fw/rust/src/hal.rs +++ b/fw/rust/src/hal.rs @@ -1,7 +1,7 @@ use core::arch::asm; pub(crate) fn delay() { - for _ in 0..100_000 { + for _ in 0..10 { unsafe { asm!("nop"); } diff --git a/rtl/soc/memory_infer.v b/rtl/soc/memory_infer.v index 164ec6e..f580531 100644 --- a/rtl/soc/memory_infer.v +++ b/rtl/soc/memory_infer.v @@ -29,7 +29,7 @@ module memory_infer #( reg [31:0] data; assign dat_o = ack_o ? data : 32'hzzzz_zzzz; - wire addressed = (adr_i >= BASE_ADDRESS) & (adr_i < BASE_ADDRESS + SIZE); + wire addressed = (adr_i >= BASE_ADDRESS) & (adr_i < BASE_ADDRESS + 4 * SIZE); // depending on the size, some address bits are not going to be used // verilator lint_off UNUSEDSIGNAL From 9daee4c0f8774576feb7d7a35a51bab2457898ba Mon Sep 17 00:00:00 2001 From: Barabas Raffai Date: Sat, 28 Oct 2023 18:55:15 +0100 Subject: [PATCH 6/6] fix up rust timing --- fw/rust/binary/crush-blinky.bin | Bin 1220 -> 1220 bytes fw/rust/binary/crush-blinky.data | 142 +++++++++++++++---------------- fw/rust/src/hal.rs | 2 +- 3 files changed, 72 insertions(+), 72 deletions(-) diff --git a/fw/rust/binary/crush-blinky.bin b/fw/rust/binary/crush-blinky.bin index 5acaffe6b238abf9dba5c91cf256bdc1ec3e7881..c6101f9e3465a099b322ade182ae2fbb6f6495fa 100755 GIT binary patch delta 153 zcmX@Yd4y9#T#l0}=>ftf)7$YEdvVwcH*Eb@#OCKs{@>mK;` l|Gx=H0tiHa*a3(i0L4HwgA1R6OCuv#JOaq&n7oli7yzr;AHDzp delta 153 zcmX@Yd4y9%T#B*xZ_yX%>l z7|u<$VZI>vhnYcu3#fq)h=J-D7$!@yX!F_tML`@!Aa$Rf{pW^y5mu