reboot after 5 times error code without powercycle
This commit is contained in:
@@ -6,7 +6,7 @@ use crate::hal::peripherals::CAN1;
|
||||
use canapi::id::{plant_id, IDENTIFY_CMD_OFFSET, MOISTURE_DATA_OFFSET};
|
||||
use canapi::SensorSlot;
|
||||
use ch32_hal::adc::{Adc, SampleTime, ADC_MAX};
|
||||
use ch32_hal::can;
|
||||
use ch32_hal::{pac};
|
||||
use ch32_hal::can::{Can, CanFifo, CanFilter, CanFrame, CanMode};
|
||||
use ch32_hal::gpio::{Flex, Level, Output, Pull, Speed};
|
||||
use ch32_hal::mode::NonBlocking;
|
||||
@@ -52,7 +52,9 @@ async fn main(spawner: Spawner) {
|
||||
ch32_hal::pac::AFIO.pcfr1().write(|w| w.set_can1_rm(2));
|
||||
|
||||
unsafe {
|
||||
static mut HEAP_SPACE: [u8; 4096] = [0; 4096]; // 4 KiB heap, adjust as needed
|
||||
#[allow(static_mut_refs)]
|
||||
static mut HEAP_SPACE: [u8; 4096] = [0; 4096]; // 4 KiB heap
|
||||
#[allow(static_mut_refs)]
|
||||
HEAP.init(HEAP_SPACE.as_ptr() as usize, HEAP_SPACE.len());
|
||||
}
|
||||
|
||||
@@ -232,7 +234,7 @@ async fn main(spawner: Spawner) {
|
||||
// Create ADC on ADC1 and use PA1 as analog input (Threshold/Trigger)
|
||||
let adc = Adc::new(p.ADC1, Default::default());
|
||||
let ain = p.PA1;
|
||||
let config = can::can::Config::default();
|
||||
let config = Default::default();
|
||||
let can: Can<CAN1, NonBlocking> = Can::new_nb(
|
||||
p.CAN1,
|
||||
p.PB8,
|
||||
@@ -293,7 +295,7 @@ async fn detect_stable_pin(pin: &mut Flex<'static>) -> Option<bool> {
|
||||
}
|
||||
}
|
||||
async fn blink_error_loop(info_led: &mut Output<'static>, warn_led: &mut Output<'static>, c_i: u8, c_w: u8) -> ! {
|
||||
loop {
|
||||
for _loop_count in 0..5 {
|
||||
// code: 1-4 for PB4..PB7, 5 for PB3 (A/B), 7 for CAN address collision
|
||||
for _ in 0..c_i {
|
||||
info_led.set_high();
|
||||
@@ -310,6 +312,25 @@ async fn blink_error_loop(info_led: &mut Output<'static>, warn_led: &mut Output<
|
||||
// Pause between sequences
|
||||
Timer::after_millis(400).await;
|
||||
}
|
||||
|
||||
for _ in 0..5 {
|
||||
info_led.set_high();
|
||||
Timer::after_millis(50).await;
|
||||
info_led.set_low();
|
||||
Timer::after_millis(50).await;
|
||||
warn_led.set_high();
|
||||
Timer::after_millis(50).await;
|
||||
warn_led.set_low();
|
||||
Timer::after_millis(50).await;
|
||||
}
|
||||
|
||||
pac::PFIC.cfgr().modify(|w| {
|
||||
w.set_resetsys(true);
|
||||
w.set_keycode(pac::pfic::vals::Keycode::KEY3); // KEY3 is 0xBEEF, the System Reset key
|
||||
});
|
||||
loop{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#[task]
|
||||
|
||||
Reference in New Issue
Block a user