I recently decided i wanted to try using Rust for embedded programming rather than C, and only have a Teensy 3.6 board available for learning this process. I am fairly new to Rust so this has already been a massive learning curve, plus the inner workings of CPUs have always been elusive until now. There are not many tutorials / help forum posts relating to the teensy 3.6, and those that are available are multiple years old.
I have spent a few weeks on following these tutorials and writing code that I thought should work, however after uploading my code, nothing happens. The current goal is just to get the onboard LED to turn on so I know my code is running correctly. I tried writing the code from scratch following a tutorial I found online which never worked, and I recently found out about svd2rust crates for accessing peripherals.
I am now attempting to write the same program to turn on the onboard LED, but using the K66 PAC. This has made a bit more sense to me, however the program still seems to fail. My current code using the PAC is below.
#![no_std]
#![no_main]
// allows us to define our entry point for the program
use cortex_m_rt::entry;
use k66;
// defines panic behaviour so we dont have to
extern crate panic_halt;
// our entry point main function, it loops infinitely
#[entry]
fn main() -> ! {
// first extract the peripherals for the processor
let k66_periph = k66::Peripherals::take().unwrap();
// first we need to disable the watchdog timer.
// to do this we need the unlock and stctrlh register addresses
let wd = k66_periph.WDOG;
// unlock the watchdog
wd.unlock.write(|w| unsafe { w.wdogunlock().bits(0xC520) });
wd.unlock.write(|w| unsafe { w.wdogunlock().bits(0xD928) });
// now its unlocked, disable the watchdog
wd.stctrlh.write(|w| w.wdogen().clear_bit());
// next enable clock gate for portc
let sim = k66_periph.SIM;
// enable portc
sim.scgc5.write(|w| w.portc().set_bit());
// next we set pin 13 to gpio mode
let portc = k66_periph.PORTC;
// set pin 13 to run in gpio mode
portc.pcr5.write(|w| w.mux()._001());
// next we write to the pin
let pin13 = k66_periph.GPIOC;
pin13.pdor.write(|w| w.pdo5()._1());
loop{}
}
for reference, the onboard LED is connected to Port C on bit 6, and requires a logic high output on the pin in order to be illuminated. I have also setup the memory.x file for the cortex-m-rt crate and am targeting the correct target (thumbv7em-none-eabihf). finally, the processor on the board is the MK66FX1M0VMD18 for reference. I have been attempting this for weeks and any help will be greatly appreciated.