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

Combine samd11 and samd21 into common/thumbv6m using feature flags #424

Merged
merged 2 commits into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion boards/arduino_mkr1000/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use hal::time::Hertz;
use hal::sercom::{PadPin, UART5};

pub use hal::common::*;
pub use hal::samd21::*;

pub use hal::target_device as pac;

use gpio::{Floating, Input, PfD, Port};
Expand Down
2 changes: 1 addition & 1 deletion boards/arduino_mkrvidor4000/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use hal::prelude::*;
use hal::*;

pub use hal::common::*;
pub use hal::samd21::*;

pub use hal::target_device as pac;

use gpio::{Floating, Input, Port};
Expand Down
2 changes: 1 addition & 1 deletion boards/arduino_mkrzero/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use hal::prelude::*;
use hal::*;

pub use hal::common::*;
pub use hal::samd21::*;

pub use hal::target_device as pac;

use gpio::{Floating, Input, Port};
Expand Down
2 changes: 1 addition & 1 deletion boards/arduino_nano33iot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use hal::sercom::{I2CMaster4, PadPin, SPIMaster1, UART5};
use hal::time::Hertz;

pub use hal::common::*;
pub use hal::samd21::*;

pub use hal::target_device as pac;

#[cfg(feature = "usb")]
Expand Down
2 changes: 1 addition & 1 deletion boards/circuit_playground_express/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use hal::prelude::*;
use hal::*;

pub use hal::common::*;
pub use hal::samd21::*;

pub use hal::target_device as pac;

use gpio::{Floating, Input, Output, Port, PushPull};
Expand Down
2 changes: 1 addition & 1 deletion boards/feather_m0/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use hal::prelude::*;
use hal::*;

pub use hal::common::*;
pub use hal::samd21::*;

pub use hal::target_device as pac;

use gpio::{Floating, Input, PfC, Port};
Expand Down
2 changes: 1 addition & 1 deletion boards/gemma_m0/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use hal::prelude::*;
use hal::*;

pub use hal::common::*;
pub use hal::samd21::*;

pub use hal::target_device as pac;

use gpio::{Floating, Input, PfD, Port};
Expand Down
2 changes: 1 addition & 1 deletion boards/itsybitsy_m0/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use hal::prelude::*;
use hal::*;

pub use hal::common::*;
pub use hal::samd21::*;

pub use hal::target_device as pac;

use gpio::{Floating, Input, PfC, Port};
Expand Down
2 changes: 1 addition & 1 deletion boards/metro_m0/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use hal::prelude::*;
use hal::*;

pub use hal::common::*;
pub use hal::samd21::*;

pub use hal::target_device as pac;

use hal::clock::GenericClockController;
Expand Down
2 changes: 1 addition & 1 deletion boards/samd11_bare/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use hal::prelude::*;
use hal::*;

pub use hal::common::*;
pub use hal::samd11::*;

pub use hal::target_device as pac;

use gpio::{Floating, Input, PfC, Port};
Expand Down
2 changes: 1 addition & 1 deletion boards/samd21_mini/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub use cortex_m_rt::entry;
extern crate atsamd_hal as hal;

pub use hal::common::*;
pub use hal::samd21::*;

pub use hal::target_device as pac;

use hal::prelude::*;
Expand Down
2 changes: 1 addition & 1 deletion boards/serpente/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use hal::prelude::*;
use hal::*;

pub use hal::common::*;
pub use hal::samd21::*;

pub use hal::target_device as pac;

use gpio::{Floating, Input, PfC, Port};
Expand Down
2 changes: 1 addition & 1 deletion boards/sodaq_one/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use hal::prelude::*;
use hal::*;

pub use hal::common::*;
pub use hal::samd21::*;

pub use hal::target_device as pac;

use gpio::{Floating, Input, Port};
Expand Down
2 changes: 1 addition & 1 deletion boards/sodaq_sara_aff/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use hal::prelude::*;
use hal::*;

pub use hal::common::*;
pub use hal::samd21::*;

pub use hal::target_device as pac;

use gpio::{Floating, Input, PfD, Port};
Expand Down
2 changes: 1 addition & 1 deletion boards/trinket_m0/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use hal::prelude::*;
use hal::*;

pub use hal::common::*;
pub use hal::samd21::*;

pub use hal::target_device as pac;

use gpio::{self, *};
Expand Down
2 changes: 1 addition & 1 deletion boards/wio_lite_mg126/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use hal::prelude::*;
use hal::*;

pub use hal::common::*;
pub use hal::samd21::*;

pub use hal::target_device as pac;

use gpio::{self, *};
Expand Down
2 changes: 1 addition & 1 deletion boards/xiao_m0/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub extern crate atsamd_hal as hal;
pub use cortex_m_rt::entry;

pub use hal::common::*;
pub use hal::samd21::*;

pub use hal::target_device as pac;

use hal::prelude::*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! NVM Software Calibration Area Mapping
// See 10.3.2 NVM Software Calibration Area Mapping, page 46
// For samd11, see 9.5 NVM Software Calibration Area Mapping, page 24
// For samd21, see 10.3.2 NVM Software Calibration Area Mapping, page 46

use core::ptr;

Expand Down Expand Up @@ -53,5 +54,8 @@ pub fn usb_transp_cal() -> u8 {

/// USB TRIM calibration value. Should be written to USB PADCAL register.
pub fn usb_trim_cal() -> u8 {
cal_with_errata(4, 23, 7, 7, 3) as u8
#[cfg(feature = "samd11")]
return cal_with_errata(4, 23, 7, 7, 5) as u8;
#[cfg(feature = "samd21")]
return cal_with_errata(4, 23, 7, 7, 3) as u8;
}
35 changes: 34 additions & 1 deletion hal/src/samd21/clock.rs → hal/src/common/thumbv6m/clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ impl State {
src: ClockSource,
improve_duty_cycle: bool,
) {
// validate the divisor factor based on gclk ID (see 15.8.5)
// validate the divisor factor based on gclk ID (samd21 see 15.8.5, for samd11
// see 14.8.5)
let mut divisor_invalid = false;
if gclk == GCLK1 {
if divider as u32 >= 2_u32.pow(16) {
Expand Down Expand Up @@ -160,6 +161,7 @@ impl GenericClockController {
let mut state = State { gclk };

set_flash_to_half_auto_wait_state(nvmctrl);
#[cfg(feature = "samd21")]
set_flash_manual_write(nvmctrl);
enable_gclk_apb(pm);
if use_external_crystal {
Expand Down Expand Up @@ -222,6 +224,7 @@ impl GenericClockController {
let mut state = State { gclk };

// No wait states needed <= 24 MHz @ 3.3v (ref. 37.12 NVM characteristics)
#[cfg(feature = "samd21")]
set_flash_manual_write(nvmctrl);
enable_gclk_apb(pm);

Expand Down Expand Up @@ -386,6 +389,30 @@ impl GenericClockController {
}
}

// samd11
#[cfg(feature = "samd11")]
clock_generator!(
(tcc0, Tcc0Clock, TCC0),
(tc1_tc2, Tc1Tc2Clock, TC1_TC2),
(sercom0_core, Sercom0CoreClock, SERCOM0_CORE),
(sercom1_core, Sercom1CoreClock, SERCOM1_CORE),
(sercom2_core, Sercom2CoreClock, SERCOM2_CORE),
(rtc, RtcClock, RTC),
(adc, AdcClock, ADC),
(wdt, WdtClock, WDT),
(eic, EicClock, EIC),
(evsys0, Evsys0Clock, EVSYS_0),
(evsys1, Evsys1Clock, EVSYS_1),
(evsys2, Evsys2Clock, EVSYS_2),
(evsys3, Evsys3Clock, EVSYS_3),
(evsys4, Evsys4Clock, EVSYS_4),
(evsys5, Evsys5Clock, EVSYS_5),
(ac_ana, AcAnaClock, AC_ANA),
(ac_dig, AcDigClock, AC_DIG),
(dac, DacClock, DAC),
);
// samd21
#[cfg(feature = "samd21")]
clock_generator!(
(tcc0_tcc1, Tcc0Tcc1Clock, TCC0_TCC1),
(tcc2_tc3, Tcc2Tc3Clock, TCC2_TC3),
Expand Down Expand Up @@ -433,6 +460,7 @@ fn set_flash_to_half_auto_wait_state(nvmctrl: &mut NVMCTRL) {
}

/// Prevent automatic writes to flash by pointers to flash area
#[cfg(feature = "samd21")]
fn set_flash_manual_write(nvmctrl: &mut NVMCTRL) {
nvmctrl.ctrlb.modify(|_, w| w.manw().set_bit());
}
Expand Down Expand Up @@ -544,6 +572,10 @@ fn configure_and_enable_dfll48m(sysctrl: &mut SYSCTRL, use_external_crystal: boo

// usb correction is not set due to instability issues around
// USB bus resets. TODO(twitchyliquid64): Maybe switch to OSC8M?
//
// TODO usb correction (still active for samd11??)
#[cfg(feature = "samd11")]
w.usbcrm().set_bit();

// bypass coarse lock (have calibration data)
w.bplckc().set_bit()
Expand All @@ -555,6 +587,7 @@ fn configure_and_enable_dfll48m(sysctrl: &mut SYSCTRL, use_external_crystal: boo
// and finally enable it!
sysctrl.dfllctrl.modify(|_, w| w.enable().set_bit());

#[cfg(feature = "samd21")]
if use_external_crystal {
// wait for lock
while sysctrl.pclksr.read().dflllckc().bit_is_clear()
Expand Down
8 changes: 8 additions & 0 deletions hal/src/common/thumbv6m/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ pub use reset_cause::*;
mod serial_number;
pub use serial_number::*;

pub mod calibration;
pub mod clock;
pub mod timer;

#[cfg(feature = "unproven")]
pub mod adc;

Expand All @@ -15,4 +19,8 @@ pub mod pwm;
#[cfg(feature = "unproven")]
pub mod watchdog;

#[cfg(feature = "usb")]
#[cfg(feature = "samd21")]
pub mod usb;

pub(crate) mod sercom;
14 changes: 14 additions & 0 deletions hal/src/samd21/timer.rs → hal/src/common/thumbv6m/timer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
//! Working with timer counter hardware
#[cfg(feature = "samd11")]
use crate::target_device::tc1::COUNT16;
#[cfg(feature = "samd21")]
use crate::target_device::tc3::COUNT16;
#[allow(unused)]
#[cfg(feature = "samd11")]
use crate::target_device::{PM, TC1};
#[allow(unused)]
#[cfg(feature = "samd21")]
use crate::target_device::{PM, TC3, TC4, TC5};
use crate::timer_params::TimerParams;
use hal::timer::{CountDown, Periodic};
Expand Down Expand Up @@ -168,6 +175,13 @@ impl TimerCounter<$TC>
}
}

// samd11
#[cfg(feature = "samd11")]
tc! {
TimerCounter1: (TC1, tc1_, Tc1Tc2Clock),
}
// samd21
#[cfg(feature = "samd21")]
tc! {
TimerCounter3: (TC3, tc3_, Tcc2Tc3Clock),
TimerCounter4: (TC4, tc4_, Tc4Tc5Clock),
Expand Down
File renamed without changes.
File renamed without changes.
10 changes: 0 additions & 10 deletions hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,6 @@ macro_rules! dbgprint {
pub mod common;
pub use self::common::*;

#[cfg(feature = "samd11")]
pub mod samd11;
#[cfg(feature = "samd11")]
pub use self::samd11::*;

#[cfg(feature = "samd21")]
pub mod samd21;
#[cfg(feature = "samd21")]
pub use self::samd21::*;

// The following modules are included purely for backward compatibility reasons.
// Whenever major breaking changes are made to the HAL next, these modules
// should be removed.
Expand Down
57 changes: 0 additions & 57 deletions hal/src/samd11/calibration.rs

This file was deleted.

Loading