From b8caf078bbd1e52226ceb0f0877102844f021ae0 Mon Sep 17 00:00:00 2001 From: Amit Aryeh Levy Date: Wed, 23 Oct 2024 02:02:16 -0700 Subject: [PATCH 1/3] stm32f412gdisco: use PLL@100MHz --- boards/stm32f412gdiscovery/src/main.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/boards/stm32f412gdiscovery/src/main.rs b/boards/stm32f412gdiscovery/src/main.rs index 2d8c75520f..b297c63522 100644 --- a/boards/stm32f412gdiscovery/src/main.rs +++ b/boards/stm32f412gdiscovery/src/main.rs @@ -27,6 +27,7 @@ use kernel::{create_capability, debug, static_init}; use stm32f412g::chip_specs::Stm32f412Specs; use stm32f412g::clocks::hsi::HSI_FREQUENCY_MHZ; use stm32f412g::interrupt_service::Stm32f412gDefaultPeripherals; +use stm32f412g::rcc::PllSource; /// Support routines for debugging I/O. pub mod io; @@ -179,6 +180,7 @@ unsafe fn set_pin_primary_functions( syscfg: &stm32f412g::syscfg::Syscfg, i2c1: &stm32f412g::i2c::I2C, gpio_ports: &'static stm32f412g::gpio::GpioPorts<'static>, + system_frequency: usize, ) { use kernel::hil::gpio::Configure; use stm32f412g::gpio::{AlternateFunction, Mode, PinId, PortId}; @@ -269,7 +271,7 @@ unsafe fn set_pin_primary_functions( }); i2c1.enable_clock(); - i2c1.set_speed(stm32f412g::i2c::I2CSpeed::Speed100k, 16); + i2c1.set_speed(stm32f412g::i2c::I2CSpeed::Speed400k, system_frequency); // FT6206 interrupt gpio_ports.get_pin(PinId::PG05).map(|pin| { @@ -414,6 +416,14 @@ unsafe fn start() -> ( ); peripherals.init(); + + let _ = clocks.set_ahb_prescaler(stm32f412g::rcc::AHBPrescaler::DivideBy1); + let _ = clocks.set_apb1_prescaler(stm32f412g::rcc::APBPrescaler::DivideBy4); + let _ = clocks.set_apb2_prescaler(stm32f412g::rcc::APBPrescaler::DivideBy2); + let _ = clocks.set_pll_frequency_mhz(PllSource::HSI, 100); + let _ = clocks.pll.enable(); + let _ = clocks.set_sys_clock_source(stm32f412g::rcc::SysClockSource::PLL); + let base_peripherals = &peripherals.stm32f4; setup_peripherals( &base_peripherals.tim2, @@ -421,8 +431,12 @@ unsafe fn start() -> ( &peripherals.trng, ); - // We use the default HSI 16Mhz clock - set_pin_primary_functions(syscfg, &base_peripherals.i2c1, &base_peripherals.gpio_ports); + set_pin_primary_functions( + syscfg, + &base_peripherals.i2c1, + &base_peripherals.gpio_ports, + clocks.get_apb1_frequency_mhz(), + ); setup_dma( dma1, @@ -653,7 +667,7 @@ unsafe fn start() -> ( tft, Some(tft), ) - .finalize(components::screen_component_static!(57600)); + .finalize(components::screen_component_static!(1024)); let touch = components::touch::MultiTouchComponent::new( board_kernel, From ad60c3a6f48e18583282510d3d290736c737b1a3 Mon Sep 17 00:00:00 2001 From: Amit Aryeh Levy Date: Fri, 25 Oct 2024 12:07:52 -0700 Subject: [PATCH 2/3] screen driver: fix error in copy length reporting If the target kernel buffer is smaller than the userspace buffer this commit correctly reports the amount of data _actually_ copied rather than the amount attempted from the user. --- capsules/extra/src/screen.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/capsules/extra/src/screen.rs b/capsules/extra/src/screen.rs index 6e14ad0d7c..d0d5bb1a84 100644 --- a/capsules/extra/src/screen.rs +++ b/capsules/extra/src/screen.rs @@ -353,17 +353,19 @@ impl<'a> Screen<'a> { .get_readonly_processbuffer(ro_allow::SHARED) .and_then(|shared| { shared.enter(|s| { + let mut count = 0; let mut chunks = s.chunks(buffer_size); if let Some(chunk) = chunks.nth(chunk_number) { for (i, byte) in chunk.iter().enumerate() { if pos < len { buffer[i] = byte.get(); - pos += 1 + count += 1; + pos += 1; } else { break; } } - app.write_len - initial_pos + count } else { // stop writing 0 From c35c1ece0843dc9f8481360a07c964c265e67673 Mon Sep 17 00:00:00 2001 From: Amit Levy Date: Fri, 25 Oct 2024 15:32:45 -0700 Subject: [PATCH 3/3] stm32f412g-disco: rename clock parameter Co-authored-by: Leon Schuermann --- boards/stm32f412gdiscovery/src/main.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/boards/stm32f412gdiscovery/src/main.rs b/boards/stm32f412gdiscovery/src/main.rs index b297c63522..fb65e79df3 100644 --- a/boards/stm32f412gdiscovery/src/main.rs +++ b/boards/stm32f412gdiscovery/src/main.rs @@ -180,7 +180,7 @@ unsafe fn set_pin_primary_functions( syscfg: &stm32f412g::syscfg::Syscfg, i2c1: &stm32f412g::i2c::I2C, gpio_ports: &'static stm32f412g::gpio::GpioPorts<'static>, - system_frequency: usize, + peripheral_clock_frequency: usize, ) { use kernel::hil::gpio::Configure; use stm32f412g::gpio::{AlternateFunction, Mode, PinId, PortId}; @@ -271,7 +271,10 @@ unsafe fn set_pin_primary_functions( }); i2c1.enable_clock(); - i2c1.set_speed(stm32f412g::i2c::I2CSpeed::Speed400k, system_frequency); + i2c1.set_speed( + stm32f412g::i2c::I2CSpeed::Speed400k, + peripheral_clock_frequency, + ); // FT6206 interrupt gpio_ports.get_pin(PinId::PG05).map(|pin| {