This repo contains two labs written by Samuel Tardieu to learn the Rust programming language :
tp-rust-VM/ is a project where we created a simple Virtual Machine in Rust. This VM has 16 virtual registers and a virtual memory of 4096 bytes. It is able to perform some basics operations such as move_if, store, load, loadimm and sub. By combining these simple operations, it is possible to process more complexe instructions such as push, pop, mult, fact and others.
- The VM code is located in
src/machine.rs - Test files are located in
tests/:
tests/assignment.rsis the easiest test file,
tests/basic_operations.rsis more challenging,
tests/complex_execution.rsis the most difficult test file.
To be 100% functional, the VM must pass all the tests.
Below are the commands to test the VM :
$ cargo build
$ cargo test --test assignment
$ cargo test --test basic_operations
$ cargo test --test complex_executionThe goal of the lab tp-led-matrix/ is to program the STM32L475 board (Arm Cortex-M4) from scratch and display visual elements on a led matrix. You can find more info about this board in the reference manuel.
Description of the Rust files:
src/contains all the source of the led matrix and the peripherals configuration.image.rsdefines structures which represent an individual RBG pixel and the whole 8x8 image made of pixels.gamma.rsprovides the require gamma correction of the led matrix.matrix.rsdefines the necessary functions to handle correctly the led matrix and associates the GPIOs to the right led matrix's pins.main.rsset up correctly the STM32L475 board. It uses the cratestm32l4xx_halto set up the clocks, the usart, the gpios, etc.
First, you need to download the corresponding target (microcontroller STM32L475VGT6 which contains a Cortex-M4F core) so that Rust can cross-compile for it.
$ rustup target add thumbv7em-none-eabihfThe project has been set to build the code automatically for this target (configured in .cargo/config.toml).
[build]
target = "thumbv7em-none-eabihf" # Cortex-M4F/M7FIt is now possible to build the code for the right target :
# Debug mode
$ cargo build
# release mode
$ cargo build --release(For your information, we used the linker script provided by the cortex-m-rt crate and we defined the memory regions in memory.x).
You then must ensure that you have either one of arm-none-eabi-gdb or gdb-multiarch installed on your system. If this is not the case, install it before proceeding.
Open a dedicated terminal and launch :
$ JLinkGDBServer -device STM32L475VGFinally, when the board is connected, run the program:
$ cargo run
To understand what really happens under the hood, you will see the following line in .cargo/config.toml:
runner = "arm-none-eabi-gdb -q -x jlink.gdb"It executes the jlink.gdb script when you type cargo run:
target extended-remote :2331
load
mon reset
c