stm32-rs / stm32h7xx-hal

Peripheral access API for STM32H7 series microcontrollers
BSD Zero Clause License
209 stars 99 forks source link

RTIC framework STM32H7 program #501

Open userdai1 opened 4 days ago

userdai1 commented 4 days ago

In the process of program initialization, the serial port received a lot of data, sometimes the program will not enter the idle function, now using the watchdog restart to solve, there is no way to solve this problem from the root, the following is the serial port and dma initialization part

let serial3 = match dp.UART4.serial( (tx_pin, rx_pin), config, clock.peripheral.UART4, &clock.clocks, ) { Ok(t) => t, Err(e) => { let = er_list.push(7); SCB::sys_reset(); //重启 } }; let (tx, mut serial_rx) = serial3.split(); serial_rx.listen();

    let short_buffer: &'static mut [u8; BUF_SIZE] = {
        let buf: &mut [core::mem::MaybeUninit<u8>; BUF_SIZE] =
            unsafe { core::mem::transmute(&mut crate::SHORT_BUFFER) };
        for (_i, value) in buf.iter_mut().enumerate() {
            unsafe {
                value.as_mut_ptr().write(0);
            }
        }
        // unsafe { core::mem::transmute(buf) }
        unsafe { crate::SHORT_BUFFER.assume_init_mut() }
    };

    let streams = StreamsTuple::new(dp.DMA1, clock.peripheral.DMA1);
    let dma_config = DmaConfig::default()
        // .transfer_complete_interrupt(true)
        .memory_increment(true);
    let mut rx = Transfer::init(streams.1, serial_rx, short_buffer, None, dma_config);
    rx.start(|serialrx| {
        //该闭包在启用流后立即运行
        //通过设置USART_CR3中的DMAT位来启用DMA rx缓冲区
        //注册
        serialrx.enable_dma_rx();
    });

The program continues to execute with this interrupt:

[task(binds = UART4, shared = [rx,m_rtu_v1,is_m_rtu_c1,er_list,m_rtu_s_a1,msg_list], priority = 2)]

    fn monitor_serial_port1(cx: monitor_serial_port1::Context);

The idle function cannot be entered because the idle function contains the execution part of a loop:

[idle(local = [DI1,DI2,DI3,DI4,DI5,DI6,DI7,DI8,DI9,DI10,DI11,DI12,DI13,DI14,DI15,DI16,DI17,DI18,DI19,DI20,DI21,DI22,WDI] , shared = [STM32LORAconfig,eeprom_wc,is_m_rtu_c1,is_m_rtu_c2,w_v_list,gnm1_2_list,gnm3_4_list,adc1,voltage1,voltage2,voltage3,voltage4,voltage5,voltage6,voltage7,voltage8,er_list,i2c,DODATA,AI_MODE,gxhjsq_list,spi,cs,read_bufferAI1,read_bufferAI2,read_bufferAO,calibrate_mode,tx5])]

fn idle(mut c: idle::Context) -> ! {}