the blinking led in the code is just a visual indicator to show the program has started to run
this bit below deals with setting up the function that handles the tmc2209-uart crate and uses it properly:-
use tmc2209_uart::{Gconf, MicrostepResolution, Tmc2209};
//#[cfg(feature = "blocking")]
pub fn basic_motor_control<U, E>(uart: U) -> Result<(), tmc2209_uart::Error<E>>
where
U: embedded_io::Read<Error = E> + embedded_io::Write<Error = E>,
{
let mut driver = Tmc2209::new(uart, 0);
info!("starting motor control");
let mut gconf = Gconf::new();
gconf.set_pdn_disable(true);
driver.write_register::<Gconf>(&mut gconf)?;
info!("uart mode enabled");
if !driver.is_connected() {
info!("driver is not connected");
return Err(tmc2209_uart::Error::NoResponse);
} else {
info!("driver is connected");
}
driver.clear_gstat()?;
info!("gstat cleared");
driver.set_microsteps(MicrostepResolution::M64)?;
info!("microstep set 64");
driver.set_interpolation(true)?;
info!("mstep intpol set true");
driver.set_velocity(4000)?;
info!("motor velocity set 4000");
let status = driver.drv_status()?;
info!("driver status checked");
if status.ot() {
driver.stop()?;
driver.set_enabled(false)?;
}
if status.otpw() {
info!("Warning motor temperature is high");
}
driver.stop()?;
info!("driver is stopped");
Ok(())
}
and this is my rp235x-hal setup:-
#![no_std]
#![no_main]
use panic_probe as _;
use defmt::info;
use defmt_rtt as _;
use rp235x_hal::{self as hal, Clock};
use hal::fugit::RateExtU32;
//use hal::gpio;
use hal::uart::{DataBits, StopBits, UartConfig}; //, ValidatedPinRx, ValidatedPinTx};
use embedded_hal::delay::DelayNs;
use embedded_hal::digital::OutputPin;
pub mod tmc2209_test;
#[unsafe(link_section = ".start_block")]
#[used]
pub static IMAGE_DEF: hal::block::ImageDef = hal::block::ImageDef::secure_exe();
const XTAL_FREQ_HZ: u32 = 12_000_000u32;
#[hal::entry]
fn main() -> ! {
let mut pac = hal::pac::Peripherals::take().unwrap();
let mut watchdog = hal::Watchdog::new(pac.WATCHDOG);
let clocks = hal::clocks::init_clocks_and_plls(
XTAL_FREQ_HZ,
pac.XOSC,
pac.CLOCKS,
pac.PLL_SYS,
pac.PLL_USB,
&mut pac.RESETS,
&mut watchdog,
)
.unwrap();
let mut timer = hal::Timer::new_timer0(pac.TIMER0, &mut pac.RESETS, &clocks);
let sio = hal::Sio::new(pac.SIO);
let pins = hal::gpio::Pins::new(
pac.IO_BANK0,
pac.PADS_BANK0,
sio.gpio_bank0,
&mut pac.RESETS,
);
let mut led_pin = pins.gpio25.into_push_pull_output();
led_pin.set_high().unwrap();
info!("led on");
timer.delay_ms(500);
led_pin.set_low().unwrap();
info!("led off");
timer.delay_ms(500);
{
let uart1_pins = (pins.gpio8.into_function(), pins.gpio9.into_function());
let mut uart1 = hal::uart::UartPeripheral::new(pac.UART1, uart1_pins, &mut pac.RESETS)
.enable(
UartConfig::new(115200.Hz(), DataBits::Eight, None, StopBits::One),
clocks.peripheral_clock.freq(),
)
.unwrap();
uart1.set_fifos(true);
tmc2209_test::basic_motor_control(uart1).unwrap();
}
loop {
info!("finished program");
timer.delay_ms(1000);
}
}
#[unsafe(link_section = ".bi_entries")]
#[used]
pub static PICOTOOL_ENTRIES: [hal::binary_info::EntryAddr; 5] = [
hal::binary_info::rp_cargo_bin_name!(),
hal::binary_info::rp_cargo_version!(),
hal::binary_info::rp_program_description!(c"Blinky Example"),
hal::binary_info::rp_cargo_homepage_url!(),
hal::binary_info::rp_program_build_attribute!(),
];