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

[RMT] single shot transmit is continuous. #2115

Closed
Tnze opened this issue Sep 8, 2024 · 3 comments · Fixed by #2463
Closed

[RMT] single shot transmit is continuous. #2115

Tnze opened this issue Sep 8, 2024 · 3 comments · Fixed by #2463
Assignees
Labels
bug Something isn't working peripheral:rmt RMT peripheral
Milestone

Comments

@Tnze
Copy link

Tnze commented Sep 8, 2024

My testing code is basically same as the RMT example , but remove the final PulseCode::default() from data. And some logging and delay are added.

It turns out that as long as I remove the final PulseCode::default(), the wait() never returned.

#![no_std]
#![no_main]

use esp_backtrace as _;
use esp_hal::{
    clock::ClockControl,
    delay::Delay,
    gpio::Io,
    peripherals::Peripherals,
    prelude::*,
    rmt::{PulseCode, Rmt, TxChannel, TxChannelConfig, TxChannelCreator},
    system::SystemControl,
};

extern crate alloc;
use core::mem::MaybeUninit;

#[global_allocator]
static ALLOCATOR: esp_alloc::EspHeap = esp_alloc::EspHeap::empty();

fn init_heap() {
    const HEAP_SIZE: usize = 32 * 1024;
    static mut HEAP: MaybeUninit<[u8; HEAP_SIZE]> = MaybeUninit::uninit();

    unsafe {
        ALLOCATOR.init(HEAP.as_mut_ptr() as *mut u8, HEAP_SIZE);
    }
}

#[entry]
fn main() -> ! {
    let peripherals = Peripherals::take();
    let system = SystemControl::new(peripherals.SYSTEM);

    let clocks = ClockControl::max(system.clock_control).freeze();
    let delay = Delay::new(&clocks);
    init_heap();

    esp_println::logger::init_logger_from_env();

    let timg0 = esp_hal::timer::timg::TimerGroup::new(peripherals.TIMG0, &clocks);
    let _init = esp_wifi::initialize(
        esp_wifi::EspWifiInitFor::Ble,
        timg0.timer0,
        esp_hal::rng::Rng::new(peripherals.RNG),
        peripherals.RADIO_CLK,
        &clocks,
    )
    .unwrap();

    let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);

    let rmt = Rmt::new(peripherals.RMT, 32.MHz(), &clocks).unwrap();

    let tx_config = TxChannelConfig {
        clk_divider: 255,
        ..TxChannelConfig::default()
    };
    let mut channel = rmt.channel0.configure(io.pins.gpio0, tx_config).unwrap();

    let mut data = [PulseCode {
        level1: true,
        length1: 200,
        level2: false,
        length2: 50,
    }; 20];

    data[data.len() - 2] = PulseCode {
        level1: true,
        length1: 3000,
        level2: false,
        length2: 500,
    };
    // data[data.len() - 1] = PulseCode::default();

    delay.delay(5.secs());
    loop {
        log::info!("Hello world!");
        let transaction = channel.transmit(&data);
        channel = transaction.wait().unwrap();
        delay.delay_millis(500);
    }
}
@github-project-automation github-project-automation bot moved this to Todo in esp-rs Sep 8, 2024
@SergioGasquez SergioGasquez added the peripheral:rmt RMT peripheral label Sep 9, 2024
@bjoernQ
Copy link
Contributor

bjoernQ commented Sep 9, 2024

We probably should check there is a transmission end-marker when starting a one-shot transmission

@Tnze
Copy link
Author

Tnze commented Sep 9, 2024

You mean the last element is a terminal marker?

@bjoernQ
Copy link
Contributor

bjoernQ commented Sep 9, 2024

You mean the last element is a terminal marker?

Yes - from the TRM

The minimum value for the period is zero (0) and is interpreted as a transmission end-marker

@MabezDev MabezDev added the bug Something isn't working label Sep 9, 2024
@tom-borcin tom-borcin added this to the 0.22.0 milestone Oct 7, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in esp-rs Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working peripheral:rmt RMT peripheral
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants