Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RTIC framework STM32H7 program #501

Open
userdai1 opened this issue Jun 29, 2024 · 0 comments
Open

RTIC framework STM32H7 program #501

userdai1 opened this issue Jun 29, 2024 · 0 comments

Comments

@userdai1
Copy link

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) -> ! {}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant