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

Add RNG driver #36

Merged
merged 1 commit into from
Oct 2, 2024
Merged

Add RNG driver #36

merged 1 commit into from
Oct 2, 2024

Conversation

andelf
Copy link
Collaborator

@andelf andelf commented Oct 1, 2024

This pull request includes the following changes:

  1. Update hpm-metapac to the latest version
  2. Add RNG (Random Number Generator) driver with implementation of rand_core traits:
    • next_u32
    • next_u64
    • fill_bytes

Notes on RNG Implementation:

  • Async RNG driver implementation is currently not feasible due to hardware design limitations.

Possible Issues:

The RNG interrupt functionality appears to be non-functional due to the following reasons:

  • Lack of a FIFO-ready signal (FUFMOD usage unclear)
  • Absence of explicit interrupt flags
  • Subsequent interrupts after the initial one fail to trigger

Further investigation and potential workarounds for these issues may be needed in future updates.

@andelf andelf requested a review from HaoboGu October 1, 2024 16:30
@andelf
Copy link
Collaborator Author

andelf commented Oct 1, 2024

Demo:

use rand_core::RngCore;
use {defmt_rtt as _, hpm_hal as hal};

#[embassy_executor::main(entry = "hpm_hal::entry")]
async fn main(_spawner: embassy_executor::Spawner) -> ! {
    let p = hal::init(Default::default());

    let mut rng = hal::rng::Rng::new(p.RNG).unwrap();
    let mut buf = [0u8; 20];

    loop {
        rng.fill_bytes(&mut buf);

        defmt::println!("buf: {:?}", buf);
    }
}

#[panic_handler]
fn panic(info: &core::panic::PanicInfo) -> ! {
    defmt::panic!("{}", defmt::Debug2Format(info));
}

Copy link
Contributor

@HaoboGu HaoboGu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@andelf andelf merged commit 6f2e51f into master Oct 2, 2024
1 check passed
@andelf andelf deleted the feat/rng branch October 2, 2024 02:39
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

Successfully merging this pull request may close these issues.

2 participants