* [2 - Guessing Game Tutorial](https://doc.rust-lang.org/book/second-edition/ch02-00-guessing-game-tutorial.html), and
*[2 - Guessing Game Tutorial](https://doc.rust-lang.org/book/second-edition/ch02-00-guessing-game-tutorial.html), and
* [3 - Common Programming Concepts](https://doc.rust-lang.org/book/second-edition/ch03-00-common-programming-concepts.html).
*[3 - Common Programming Concepts](https://doc.rust-lang.org/book/second-edition/ch03-00-common-programming-concepts.html).
* Assignment 1
* Assignment 1
Extend the guessing game application such to give an error message on ill formated input,(use the Restult::Err type). Add a counter to the number of tries and write the number of tries for each iteration and on "winning".
Extend the guessing game application such to give an error message on ill formated input,(use the Restult::Err type). Add a counter to the number of tries and write the number of tries for each iteration and on "winning".
Make a github account (if you don't have it). Make a github project whith your code, along with a README.md for usage instructions.
Make a github account (if you don't have it). Make a github project whith your code, along with a README.md for usage instructions.
Prepare to present your development for the next seminar.
Prepare to present your development for the next seminar.
2. Basic Programming
2. Basic Programming
* Preparetion
* Preparetion
Solve and be prepared to present Assignment 1.
Solve and be prepared to present Assignment 1.
* Topic
* Topic
Using the Rust ownership model.
Using the Rust ownership model.
Data structures, structs, enums, String (relation to slices) etc. Containers, Vec, and HashSets/Maps. Iterators. Using the Rust module system. Handling errors.
Data structures, structs, enums, String (relation to slices) etc. Containers, Vec, and HashSets/Maps. Iterators. Using the Rust module system. Handling errors.
We will cover the Rust book [Rustbook Second Edition](https://doc.rust-lang.org/book/second-edition.html) sections
We will cover the Rust book [Rustbook Second Edition](https://doc.rust-lang.org/book/second-edition.html) sections
a. Extend the guessing game with a tuple holding `(u32, String)`, store each input `(counter, guess)` in a vector. Iterate (`for`) to print the history at exiting.
a. Extend the guessing game with a tuple holding `(u32, String)`, store each input `(counter, guess)` in a vector. Iterate (`for`) to print the history at exiting.
b. Instead of vector use a 'HashMap', with a key `u32` and a value `String`. Again iterate (`for`) to print the history at exiting. (Explain the result.)
b. Instead of vector use a 'HashMap', with a key `u32` and a value `String`. Again iterate (`for`) to print the history at exiting. (Explain the result.)
c. Break out the line input into a function returning a `Result<Ok<u32>>, Err<String>>`. In case of a parsing error prepend the `Err<String>` with the text `"in parsing u32, "`.
c. Break out the line input into a function returning a `Result<Ok<u32>>, Err<String>>`. In case of a parsing error prepend the `Err<String>` with the text `"in parsing u32, "`.
d. Optional, find a way to print the `HashMap` in a sorted way.
d. Optional, find a way to print the `HashMap` in a sorted way.
Make three new branches (`2a, 2b, 2c`) whith your code, along with a README.md for usage instructions, and expected behavior.
Make three new branches (`2a, 2b, 2c`) whith your code, along with a README.md for usage instructions, and expected behavior.
*During development you may want to limit the number of tries so you can test without having to bother with answering correctly (the game gets boring after a while.)*
*During development you may want to limit the number of tries so you can test without having to bother with answering correctly (the game gets boring after a while.)*
Prepare to present your development for the next seminar.
Prepare to present your development for the next seminar.
3. The Rust Memory Model Revisited
3. The Rust Memory Model Revisited
* Preparation
* Preparation
Finish Assignment 2.
Finish Assignment 2.
* Topic
* Topic
In deapth discussion of underlying theory, linear types (relation to functional programming). The *Affine* type system of Rust, requirements on the programmer, and guarantees offered by the compiler. Lifetimes, of stack allocated and global variables. Relation to C++ `unique pointers`.
In deapth discussion of underlying theory, linear types (relation to functional programming). The *Affine* type system of Rust, requirements on the programmer, and guarantees offered by the compiler. Lifetimes, of stack allocated and global variables. Relation to C++ `unique pointers`.
* Assignment
* Assignment
a. Recall the D0013E course lab2/4, where you decrypted an message in assembler (lab2) and C (lab 4). Now, let's re-implement the lab in Rust (base your development on group number [1's](www.sm.luth.se/csee/courses/smd/D0013E/labs/lab1underlag/grupp_01.lab1_underlag.s ) lab assignment).
a. Recall the D0013E course lab2/4, where you decrypted an message in assembler (lab2) and C (lab 4). Now, let's re-implement the lab in Rust (base your development on group number [1's](www.sm.luth.se/csee/courses/smd/D0013E/labs/lab1underlag/grupp_01.lab1_underlag.s ) lab assignment).
You have to be careful about the signed/unsigned operations and use `wrapping` arithmetics to avoid panics due to unsigned *carry* and signed *overflow*.
You have to be careful about the signed/unsigned operations and use `wrapping` arithmetics to avoid panics due to unsigned *carry* and signed *overflow*.
Use borrowed array slices as arguments to `decode`.
Use borrowed array slices as arguments to `decode`.
The `seed`, `abc`,`coded` and `plain` should be stack allocated. The decoded string should be printed when decryption is finished.
The `seed`, `abc`,`coded` and `plain` should be stack allocated. The decoded string should be printed when decryption is finished.
b. Make the `seed`, `abc`,`coded` and `plain` heap allocated. Accessing those will require some `unsafe` code. (Keep the unsafe blocks as local as possible.)
b. Make the `seed`, `abc`,`coded` and `plain` heap allocated. Accessing those will require some `unsafe` code. (Keep the unsafe blocks as local as possible.)
c. Safety analysis. Provoke the implementation, by omitting the `'\0'` (null termintation). Observe the result and motivate the behavior in terms of your understanding of the Rust memory model. Under which circumpstances do you consider 3a and 3b to have same/different memory safety.
c. Safety analysis. Provoke the implementation, by omitting the `'\0'` (null termintation). Observe the result and motivate the behavior in terms of your understanding of the Rust memory model. Under which circumpstances do you consider 3a and 3b to have same/different memory safety.
Update your git with two new branches (`3a, 3b`), and update docmentation to cover usage and analysis (`3c`).
Update your git with two new branches (`3a, 3b`), and update docmentation to cover usage and analysis (`3c`).
4. Cortex-M, are we embedded yet
4. Cortex-M, are we embedded yet
* Prepration
* Prepration
Finish assignment 3. Bring a USB mini cable.
Finish assignment 3. Bring a USB mini cable.
* Topic
* Topic
Embedded programming in Rust.
Embedded programming in Rust.
* xargo for building non-`std` (bare metal) systems
* xargo for building non-`std` (bare metal) systems
* [cortex-m-quickstart]
* [cortex-m-quickstart]
* [cortex-m]
* [cortex-m]
* ([bluepill/nucleo] crates)
* ([bluepill/nucleo] crates)
* Building and debugging your first application.
* Building and debugging your first application.
* Assignment
* Assignment
a. Backport assignment `3b` to your choosen target. Use semihosting in order to `write` the resulting string to the host. You may need to use `--release` for decoding the long (`coded`) message, as being deeply recursive unoptimized code may run out of stack memory.
a. Backport assignment `3b` to your choosen target. Use semihosting in order to `write` the resulting string to the host. You may need to use `--release` for decoding the long (`coded`) message, as being deeply recursive unoptimized code may run out of stack memory.
b. Discuss from a memory safety perspective the outcome.
b. Discuss from a memory safety perspective the outcome.
c. Compare for the short message (`abc`), the number of cycles required for `decode` in `--dev` vs. `--release`. As a comparison my straightforword C implementation took 2200 cycles in best optimized mode using `gcc` (-o3), while my (transation) to Rust code took 1780 cycles. (Both executed on a bluepill board at 8MHz with flash memory wait states).
c. Compare for the short message (`abc`), the number of cycles required for `decode` in `--dev` vs. `--release`. As a comparison my straightforword C implementation took 2200 cycles in best optimized mode using `gcc` (-o3), while my (transation) to Rust code took 1780 cycles. (Both executed on a bluepill board at 8MHz with flash memory wait states).
Make a new git for your embedded development. Make three branches (`3a, 3b, 3c`) with updated documentation according to the above.
Make a new git for your embedded development. Make three branches (`3a, 3b, 3c`) with updated documentation according to the above.
5. Advanced Rust Concepts
5. Advanced Rust Concepts
* Prepration
* Prepration
Bring a USB mini cable and your dev board. Be prepared to present the progress on assignment 3.
Bring a USB mini cable and your dev board. Be prepared to present the progress on assignment 3.
* Topic
* Topic
Advanced Rust features, trait system and closures.
Advanced Rust features, trait system and closures.
* [10 - Generic Types, Traits, and Lifetimes](https://doc.rust-lang.org/book/second-edition/ch10-00-generics.html), and
* [10 - Generic Types, Traits, and Lifetimes](https://doc.rust-lang.org/book/second-edition/ch10-00-generics.html), and
* [13 - Functional Language Features in Rust](https://doc.rust-lang.org/book/second-edition/ch13-00-functional-features.html).
* [13 - Functional Language Features in Rust](https://doc.rust-lang.org/book/second-edition/ch13-00-functional-features.html).
* Assignment
* Assignment
Continue working on assignment 3.
Continue working on assignment 3.
6. Memory Safe Concrreny
6. Memory Safe Concrreny
* Preparation
* Preparation
* Finish lab 3 and be prepared to show your solution.
* Finish lab 3 and be prepared to show your solution.
* Topic
* Topic
* UnsafeCell, and synchronization in the RTFM model.
* UnsafeCell, and synchronization in the RTFM model.
* Requirements for Stack Resource Policy (SRP) based single-core scheduling.
* Requirements for Stack Resource Policy (SRP) based single-core scheduling.
* [cortex-m-rtfm](https://github.com/japaric/cortex-m-rtfm) The RTFM-core (task and resource model) in Rust for the Cortex-M family
* [cortex-m-rtfm](https://github.com/japaric/cortex-m-rtfm) The RTFM-core (task and resource model) in Rust for the Cortex-M family