Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bobmcwhirter/6fbf19d2f436ef1dd3912392ef58340c to your computer and use it in GitHub Desktop.
Save bobmcwhirter/6fbf19d2f436ef1dd3912392ef58340c to your computer and use it in GitHub Desktop.
#![no_std]
#![no_main]
mod esp;
mod at_parser;
//use cortex_m;
//use embedded_hal::digital::v2::OutputPin;
use cortex_m_rt::entry;
use generic_array::{arr, GenericArray};
use heapless::Vec;
use panic_rtt_target as _;
use rtt_target::{rprintln, rtt_init_print};
use bbqueue::{
BBBuffer,
ConstBBBuffer,
};
use esp::{
ESPBuffers,
ESP,
};
use generic_array::typenum::{
U1,
U1024,
};
use nucleo_f401re::hal as hal;
use nucleo_f401re::{
hal::{
gpio::Edge,
prelude::*,
serial::{
config::{Config, Parity, StopBits},
Event, NoRx, NoTx, Rx, Serial, Tx,
},
timer::{
Timer,
}
},
pac,
Button, Led,
};
//use drogue_esp8266::socket::SocketSet;
use rtic::{
app,
cyccnt::{Instant, U32Ext},
};
type UsartTx = Tx<pac::USART6>;
type UsartRx = Rx<pac::USART6>;
#[app(device = nucleo_f401re::pac, peripherals = true, monotonic = rtic::cyccnt::CYCCNT)]
const APP: () = {
struct Resources {
//TX: TX,
//RX: RX,
ESP: ESP<UsartTx, UsartRx, U1, U1024, U1024>,
ESP_TIMER: Timer<pac::TIM3>,
}
#[init()]
fn init(mut ctx: init::Context) -> init::LateResources {
rtt_init_print!();
rprintln!("startup");
let device: nucleo_f401re::pac::Peripherals = ctx.device;
// Enable the clock for the SYSCFG
device.RCC.apb2enr.modify(|_, w| w.syscfgen().enabled());
// Setup the system clock
let rcc = device.RCC.constrain();
let clocks = rcc.cfgr.sysclk(84.mhz()).freeze();
let mut timer = Timer::tim3(
device.TIM3,
1u32.hz(),
clocks,
);
timer.listen(hal::timer::Event::TimeOut);
//let mut afio = device.AFIO.constrain(&mut rcc.apb2);
let gpioa = device.GPIOA.split();
let gpiob = device.GPIOB.split();
let gpioc = device.GPIOC.split();
// SERIAL pins for USART 1
let tx_pin = gpioa.pa11.into_alternate_af8();
//let rx = gpiob.pb7.into_floating_input();
let rx_pin = gpioa.pa12.into_alternate_af8();
// ch_pd
let mut en = gpioc.pc10.into_push_pull_output();
// rst
let mut reset = gpioc.pc12.into_push_pull_output();
//en.set_low().unwrap();
en.set_low().unwrap();
reset.set_low().unwrap();
en.set_high().unwrap();
reset.set_high().unwrap();
let mut serial = Serial::usart6(
device.USART6,
(tx_pin, rx_pin),
Config {
baudrate: 115_200.bps(),
parity: Parity::ParityNone,
stopbits: StopBits::STOP1,
..Default::default()
},
clocks,
)
.unwrap();
serial.listen(Event::Rxne);
let (tx, rx) = serial.split();
static ESP_BUFFERS: ESPBuffers<U1024, U1024> = [
(
BBBuffer(ConstBBBuffer::new()),
BBBuffer(ConstBBBuffer::new())
)
];
let esp = ESP::new(tx, rx, &ESP_BUFFERS);
rprintln!("running app via RTIC");
init::LateResources {
ESP: esp,
ESP_TIMER: timer,
}
}
#[task(binds = USART6, priority = 2, resources = [ESP])]
fn USART6(ctx: USART6::Context) {
ctx.resources.ESP.interrupt();
}
#[task(binds = TIM3, priority = 1, resources = [ESP, ESP_TIMER])]
fn esp_timer(mut ctx: esp_timer::Context) {
ctx.resources.ESP.lock( |esp| {
esp.service()
} );
ctx.resources.ESP_TIMER.clear_interrupt(hal::timer::Event::TimeOut);
}
#[idle]
fn idle(ctx: idle::Context) -> ! {
loop {
continue;
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment