summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchemicstry <chemicstry@gmail.com>2022-06-06 17:05:37 +0300
committerchemicstry <chemicstry@gmail.com>2022-06-06 17:12:52 +0300
commitb0ffd9a1cc6ae19f4698f704df037e5dd6f5fb97 (patch)
tree0cdf0c6d11b34b3172ee4bbeb5380020d87ebb47
parent34673f52c9c23179f0274726a5aa1877dd554df0 (diff)
downloadembassy-b0ffd9a1cc6ae19f4698f704df037e5dd6f5fb97.zip
Fix AF pullup configuration for GPIOv1
-rw-r--r--embassy-stm32/src/gpio.rs27
1 files changed, 19 insertions, 8 deletions
diff --git a/embassy-stm32/src/gpio.rs b/embassy-stm32/src/gpio.rs
index b6982e91..f7a5da0a 100644
--- a/embassy-stm32/src/gpio.rs
+++ b/embassy-stm32/src/gpio.rs
@@ -424,9 +424,14 @@ pub(crate) mod sealed {
}
}
+ #[inline]
+ unsafe fn set_as_af(&self, af_num: u8, af_type: AFType) {
+ self.set_as_af_pull(af_num, af_type, Pull::None);
+ }
+
#[cfg(gpio_v1)]
#[inline]
- unsafe fn set_as_af(&self, _af_num: u8, af_type: AFType) {
+ unsafe fn set_as_af_pull(&self, _af_num: u8, af_type: AFType, pull: Pull) {
// F1 uses the AFIO register for remapping.
// For now, this is not implemented, so af_num is ignored
// _af_num should be zero here, since it is not set by stm32-data
@@ -435,9 +440,21 @@ pub(crate) mod sealed {
let crlh = if n < 8 { 0 } else { 1 };
match af_type {
AFType::Input => {
+ let cnf = match pull {
+ Pull::Up => {
+ r.bsrr().write(|w| w.set_bs(n, true));
+ vals::CnfIn::PULL
+ }
+ Pull::Down => {
+ r.bsrr().write(|w| w.set_br(n, true));
+ vals::CnfIn::PULL
+ }
+ Pull::None => vals::CnfIn::FLOATING,
+ };
+
r.cr(crlh).modify(|w| {
w.set_mode(n % 8, vals::Mode::INPUT);
- w.set_cnf_in(n % 8, vals::CnfIn::FLOATING);
+ w.set_cnf_in(n % 8, cnf);
});
}
AFType::OutputPushPull => {
@@ -457,12 +474,6 @@ pub(crate) mod sealed {
#[cfg(gpio_v2)]
#[inline]
- unsafe fn set_as_af(&self, af_num: u8, af_type: AFType) {
- self.set_as_af_pull(af_num, af_type, Pull::None);
- }
-
- #[cfg(gpio_v2)]
- #[inline]
unsafe fn set_as_af_pull(&self, af_num: u8, af_type: AFType, pull: Pull) {
let pin = self._pin() as usize;
let block = self.block();