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

Added DAC, low-power, alternate clocks, interrupts module. Added seri… #166

Closed
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
a96369e
Added DAC, low-power, alternate clocks, interrupts module. Added seri…
David-OConnor Nov 4, 2020
0dff4f5
Moved new timer features to f303 only
David-OConnor Nov 4, 2020
f6f7689
Restructured pwm-related timer features to not break families that do…
David-OConnor Nov 5, 2020
bd9acfc
Sync rtc Clippy-related code with upstream
David-OConnor Nov 5, 2020
6711cc3
Clippy
David-OConnor Nov 5, 2020
2a2cb34
Filled in missing information in interrupt_ module. Renamed to exti. …
David-OConnor Nov 6, 2020
813565b
0.5.1 release
David-OConnor Nov 30, 2020
c285c55
Change name for v
David-OConnor Nov 30, 2020
fed0a2b
merge
David-OConnor Dec 10, 2020
25aad85
Synced with upstream
David-OConnor Dec 11, 2020
4e82eca
tweak wakeup interrupt fn for rtc
David-OConnor Dec 26, 2020
ac189db
tweaks to RTC wakeup
David-OConnor Jan 2, 2021
7d4177b
Added RTC alarm
David-OConnor Jan 2, 2021
0ed734b
Fixed some typos
David-OConnor Jan 2, 2021
b8423da
Re-flowed RTC wakeup to allow you to enter MS directly
David-OConnor Jan 2, 2021
4872108
more reflow of rtc wakeup calc
David-OConnor Jan 2, 2021
8f177bb
update set_update_interval too
David-OConnor Jan 2, 2021
50ffd54
Share code between set and chagne WU interval for RTC
David-OConnor Jan 3, 2021
1b846ed
RTC sleep time now uses seconds
David-OConnor Jan 3, 2021
3c03e63
Added HSE and LSI support to RTC
David-OConnor Jan 3, 2021
1b31ae2
Tweaks to rtc sleep time
David-OConnor Jan 3, 2021
bd3f567
Fix RTC wakeup interval for non-LSE src
David-OConnor Jan 3, 2021
c5ae430
stop and standby modes now re-enable HSE, adn re-select input source
David-OConnor Jan 3, 2021
6c7a99e
Aded way to set period > 1s in GP timers
David-OConnor Jan 3, 2021
be5837a
Raise error if arr or psc out of bounds on set period
David-OConnor Jan 4, 2021
809ea02
Set flash latency before setting up clocks; should now work at higher…
David-OConnor Jan 4, 2021
c627c5a
Reverted split of timers into original form, while keeping PWM featur…
David-OConnor Jan 6, 2021
4824a0f
release 0.6.1
David-OConnor Jan 8, 2021
915f76d
Tweaked RTC module. Merged some features with that in l4xx-hal
David-OConnor Jan 8, 2021
093caae
Partially included some code from f1's I2c
David-OConnor Jan 10, 2021
861ea79
Attempting to adopt f1 i2c
David-OConnor Jan 10, 2021
dbba3ad
Changed input_freq dynamics, and calculate it for HSI
David-OConnor Jan 11, 2021
71aa011
Tweaks to timer
David-OConnor Jan 13, 2021
5326a51
Tweaks to clocks and timers
David-OConnor Jan 17, 2021
e6e69f8
Fixed repeating starts in i2c
David-OConnor Jan 18, 2021
2ad084c
Apply H7 style I2Cto read and write too, correcting problems
David-OConnor Jan 19, 2021
6ac3a83
Tweaks
David-OConnor Feb 15, 2021
129cc9f
tweaks
David-OConnor Mar 4, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/stm32f3xx-hal.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 18 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ name = "stm32f3xx-hal"
readme = "README.md"
repository = "https://github.com/stm32-rs/stm32f3xx-hal"
documentation = "https://docs.rs/stm32f3xx-hal"
version = "0.6.0"
version = "0.6.1"
exclude = [
"codegen",
".markdownlint.yml"
Expand All @@ -25,11 +25,12 @@ targets = ["thumbv7em-none-eabihf"]

[dependencies]
cfg-if = "1.0"
cortex-m = "0.6"
cortex-m-rt = "0.6"
cortex-m = "0.7.1"
cortex-m-rt = "0.6.13"
embedded-dma = "0.1"
embedded-hal = "0.2"
embedded-hal = "0.2.4"
nb = "0.1"
num-traits = { version = "0.2.11", default-features = false, features=["libm"] } # For sqrt in timers
paste = "1"
rtcc = "0.2"
stm32f3 = "0.12"
Expand All @@ -43,6 +44,10 @@ optional = true
version = "0.2"
features = ["const-fn"]

[dependencies.cast]
version = "0.2.3"
default-features = false

[dependencies.stm32-usbd]
version = "0.5"
optional = true
Expand All @@ -65,7 +70,7 @@ defmt-rtt = "0.1.0"
defmt-test = "0.1.0"

[features]
default = ["unproven"]
default = ["unproven", "rt"]
unproven = ["embedded-hal/unproven"]
device-selected = []
direct-call-deprecated = []
Expand Down Expand Up @@ -119,6 +124,10 @@ debug = true
lto = true
opt-level = "s"

[[example]]
name = "clocks"
required-features = ["stm32f303xc"]

[[example]]
name = "pwm"
required-features = ["stm32f303xc"]
Expand All @@ -139,6 +148,10 @@ required-features = ["stm32f303"]
name = "can"
required-features = ["rt", "can", "stm32f303"]

[[example]]
name = "serial"
required-features = ["stm32f303"]

[[example]]
name = "serial_dma"
required-features = ["stm32f303"]
Expand Down
61 changes: 61 additions & 0 deletions examples/clocks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//! Example of using a number of timer channels in PWM mode.
//! Target board: STM32F3DISCOVERY
#![no_std]
#![no_main]

use panic_semihosting as _;

use stm32f3xx_hal::{clocks, pac};

use cortex_m_rt::entry;

use cortex_m_semihosting::hprintln;

#[entry]
fn main() -> ! {
// Get our peripherals
let mut dp = pac::Peripherals::take().unwrap();

// Initialize to 48Mhz sys clock, and 24Mhz peripheral clocks. Settings don't take
// effect until we run the `setup` method below.
let mut clocks = clocks::Clocks::default();

// Setting HSE bypass, to save power and free up a pin, if using a compatible oscillator.
clocks.hse_bypass = true;

// We'll set the system clock frequency to 72 Mhz, while keeping a 48Mhz USB
// frequency. We do this by increasing the PLL multiplier from it's default of
// 6×, to 9×, and increasing the amount we divide by for the USB clock.
clocks.pll_mul = clocks::PllMul::Mul9;
clocks.usb_pre = clocks::UsbPrescaler::Div1_5;

// Some further functionality examples:

// If you wish to use the internal (HSI) oscillator:
// clocks.input_src = clocks::InputSrc::Hsi;

// Setting the HCLK (AHB) prescaler:
// clocks.hclk_prescaler = clocks::HclkPrescaler::Div2;

// Setting the APB1 peripheral clock prescaler:
// clocks.apb1_prescaler = clocks::ApbPrescaler::Div1;

// The `setup` method validates our clock speeds, and if validated, writes
// to the clock registers.
if clocks.setup(&mut dp.RCC, &mut dp.FLASH).is_err() {
hprintln!("Unable to configure clocks due to a speed error.").ok();
};

// Display the calculated speeds.
hprintln!("Speeds: {:#?}", clocks.calc_speeds()).ok();

// Existing modules expect an `rcc::Clocks` struct to be passed, to use
// speeds during configuration. We can make one using the `make_rcc_clocks` method.
// `rcc.rs` clock config we pass to other fns that need the speeds.
let _rcc_clocks = clocks.make_rcc_clocks();

// Eg, we could use it in the commented-out line below, in a timer, spi etc.
// let i2c = I2c::i2c1(dp.I2C1, (scl, sda), 100.khz(), rcc_clocks, &mut rcc.apb1);

loop {}
}
47 changes: 47 additions & 0 deletions examples/serial.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//! Example of transmitting data over serial interface using UART.
//! For this to work, the PA9 and PA10 pins must be connected.
//! Target board: STM32F3DISCOVERY

#![no_std]
#![no_main]

use panic_semihosting as _;

use cortex_m_rt::entry;
use stm32f3xx_hal::{pac, prelude::*, serial::Serial};

#[entry]
fn main() -> ! {
let dp = pac::Peripherals::take().unwrap();

let mut flash = dp.FLASH.constrain();
let mut rcc = dp.RCC.constrain();
let clocks = rcc.cfgr.freeze(&mut flash.acr);

let mut gpioa = dp.GPIOA.split(&mut rcc.ahb);

// Setup UART pins.
let uart_pins = (
gpioa.pa9.into_af7(&mut gpioa.moder, &mut gpioa.afrh),
gpioa.pa10.into_af7(&mut gpioa.moder, &mut gpioa.afrh),
);

let serial = Serial::usart1(dp.USART1, uart_pins, 9600.bps(), clocks, &mut rcc.apb2);
let (mut tx, mut rx) = serial.split();

loop {
// Send a single byte.
let single_byte_to_send = 8;
tx.write(single_byte_to_send).ok();

// Send multiple bytes over the U[S]ART pins.
let data_to_send = [2, 3, 4, 5];
tx.bwrite_all(&data_to_send).ok();

// Send a string
// tx.write_str("Don't panic.");

// Receive multiple bytes as an array.
let _data_recieved = rx.read();
}
}
10 changes: 8 additions & 2 deletions src/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ macro_rules! adc_hal {
crate::panic!("Clock already enabled with a different setting");
}
this_adc.set_align(Align::default());
this_adc.calibrate();
this_adc.calibrate(); // todo: Cal causes freeze! TS commented out.
// ADEN bit cannot be set during ADCAL=1
// and 4 ADC clock cycle after the ADCAL
// bit is cleared by hardware
Expand Down Expand Up @@ -413,7 +413,13 @@ macro_rules! adc_hal {
///
/// This is based on the MAX_ADVREGEN_STARTUP_US of the device.
fn wait_advregen_startup(&self) {
asm::delay((MAX_ADVREGEN_STARTUP_US * 1_000_000) / self.clocks.sysclk().0);
// Prevents crashes. Not sure why / when it started showing up.
// https://github.com/rust-embedded/cortex-m/pull/328
let mut delay = (MAX_ADVREGEN_STARTUP_US * 1_000_000) / self.clocks.sysclk().0;
if delay < 2 {
delay = 2;
}
asm::delay(delay);
}

/// busy ADC read
Expand Down
Loading