Having the memory handling done for you might be easier
Still too much boilerplate needed in rust (unwrap, unsafe to name a few), and secret handshakes with the hardware the novice would not know what are they and where is it coming from (apb2enr, set bit, etc.)
With 6.1, however, there is something fundamentally different. For the first time in Linux's history, in addition to C, you'll be able to use another language, Rust, for kernel development.
Why? As Wedson Almeida Filho of Google's Android Team said, "We feel that Rust is now ready to join C as a practical language for implementing the kernel. It can help us reduce the number of potential bugs and security vulnerabilities in privileged code while playing nicely with the core kernel and preserving its performance characteristics."
Specifically, as Alex Gaynor and Geoffrey Thomas explained at the 2019 Linux Security Summit, almost two-thirds of Linux kernel security holes [PDF] come from memory safety issues. And where do they originate? Inherent weaknesses in C and C++. Rust, on the other hand, dodges these issues by using far safer application programming interfaces (APIs). Rust is simply safer than C.
Recently, the US National Security Agency (NSA), which is in charge of securing code as well as breaking it, suggested that one of the best things you can do for your program's security is to use memory-safe languages such as Rust instead of C.
Here is nice startup code for novice. This is a code example for LED blinking.
It is written in Rust language for STM32 bluepill arduino board.Code: [Select]// std and main are not available for bare metal software
#![no_std]
#![no_main]
extern crate stm32f1;
extern crate panic_halt;
extern crate cortex_m_rt;
use cortex_m_rt::entry;
use stm32f1::stm32f103;
// use `main` as the entry point of this application
#[entry]
fn main() -> ! {
// get handles to the hardware
let peripherals = stm32f103::Peripherals::take().unwrap();
let gpioc = &peripherals.GPIOC;
let rcc = &peripherals.RCC;
// enable the GPIO clock for IO port C
rcc.apb2enr.write(|w| w.iopcen().set_bit());
gpioc.crh.write(|w| unsafe{
w.mode13().bits(0b11);
w.cnf13().bits(0b00)
});
loop{
gpioc.bsrr.write(|w| w.bs13().set_bit());
cortex_m::asm::delay(2000000);
gpioc.brr.write(|w| w.br13().set_bit());
cortex_m::asm::delay(2000000);
}
}
You can find more details on how to compile it and upload into microcontroller here:
https://jonathanklimt.de/electronics/programming/embedded-rust/rust-STM32F103-blink/
As you can see, it is very easy, you can play with it and extend its functionality. That way you can learn programming for microcontrollers.
It feels a bit like everybody needs to show how knowledgeable they are by bringing far to complex stuff to the table for a beginner.
Like Rick Law wrote this is about getting started with microcontrollers and for that Arduino based on the ATmega328 is the simplest one can get.
Forget faster or dual core or wifi connectivity or what ever programming language out there and just follow your already chosen path with the UNO. In time and when you feel like it, it is always an option to step up to something faster or more complex with a more "mature" IDE if needed.
Recall the OP's question is "Getting started with microcontrollers."
Given the ecosystem Arduino has, information and example are readily available - possibly exceeding competing ecosystems by many folds. That made the Arduino ecosystem a prime choice for "getting started".
Once one got started, one can always switch to more feature filled, stronger, or more powerful systems. For the getting started phase, the easiest and simplest (in getting going and in getting additional info/help) is probably the most suitable.
It feels a bit like everybody needs to show how knowledgeable they are by bringing far to complex stuff to the table for a beginner.
Like Rick Law wrote this is about getting started with microcontrollers and for that Arduino based on the ATmega328 is the simplest one can get.
Forget faster or dual core or wifi connectivity or what ever programming language out there and just follow your already chosen path with the UNO. In time and when you feel like it, it is always an option to step up to something faster or more complex with a more "mature" IDE if needed.
...
I have ordered the Arduino Uno R3 and when i get it I will get started with IDE 2.3.2 and ask questions from there. Often too many choices is a bad thing.
I have ordered the Arduino Uno R3 and when i get it I will get started with IDE 2.3.2 and ask questions from there. Often too many choices is a bad thing.
Heck, I’m not a beginner and I have no clue what most of that code does!
// std and main are not available for bare metal software
#![no_std]
#![no_main]
extern crate stm32f1;
extern crate panic_halt;
extern crate cortex_m_rt;
use cortex_m_rt::entry;
use stm32f1::stm32f103;
#[entry]
fn main() -> ! {
...
}
// get handles to the hardware
let peripherals = stm32f103::Peripherals::take().unwrap();
let gpioc = &peripherals.GPIOC;
let rcc = &peripherals.RCC;
// enable the GPIO clock for IO port C
rcc.apb2enr.write(|w| w.iopcen().set_bit());
gpioc.crh.write(|w| unsafe{
w.mode13().bits(0b11);
w.cnf13().bits(0b00)
});
loop{
gpioc.bsrr.write(|w| w.bs13().set_bit());
cortex_m::asm::delay(2000000);
gpioc.brr.write(|w| w.br13().set_bit());
cortex_m::asm::delay(2000000);
}
Are you kidding? Common dude, the code is pretty clean.
Are you kidding? Common dude, the code is pretty clean.
Sure I can read it but it looks cluttered with all the objects needed to do a simple thing. A bit like java with all the dot extensions to call a simple thing.
Like "cortex_m::asm::delay(2000000);" when in C with your own function "delay(2000000);" is enough. But here you need to select the top class, sub class and then the function you want to use.
And "safe" is just a word. Nothing is really safe. Mistakes are easily made even for experienced programmers and the "safe" flies out of the window.
loop{
gpioc.bsrr.write(|w| w.bs13().set_bit());
cortex_m::asm::delay(2000000);
gpioc.bsrr.write(|w| w.bs13().set_bit());
cortex_m::asm::delay(2000000);
}
what is better readable?
Yep it is much the same. The main processor is the ATmega328P and that is what is needed.
The bonus on this one is the 16U2 MCU they use for the communication with the PC. So yes you can save yourself some money.
It states 100% compatibility.
Even 2 dollar nano's bought on Aliexpress have the bootloader. Not sure if you can still get them for 2 dollar though. Have not looked at AVR (ATmega and ATtiny) boards for quite some time.
Yep it is much the same. The main processor is the ATmega328P and that is what is needed.
The bonus on this one is the 16U2 MCU they use for the communication with the PC. So yes you can save yourself some money.Thanks. From some of the posts I had understood that the Arduino includes some kind of boot firmware or something like that which makes it work with the IDE on the computer and I want to make sure this will also work. If it works exactly the same then I will get it but if I need to tinker with it before I even get started then I would rather pay $10 more and save myself the trouble.
Thanks. From some of the posts I had understood that the Arduino includes some kind of boot firmware or something like that which makes it work with the IDE on the computer and I want to make sure this will also work. If it works exactly the same then I will get it but if I need to tinker with it before I even get started then I would rather pay $10 more and save myself the trouble.
Heck, I’m not a beginner and I have no clue what most of that code does!
Are you kidding? Common dude, the code is pretty clean.
It may scary for you just because it uses some new syntax which is not familiar for you, but that can be learned within several hours.
Just look, the structure is very transparent:
…
There is even no need to know Rust to read the code and say what it does, it self explaining...
The only thing which may be not obvious are these manipulations for GPIO port configuration. But this is not Rust specific thing, this is MCU specific details, which will be the same for any language. You're needs to read MCU datasheet in order to learn it.