Skip to content

Commit

Permalink
avoid stack overflow from power_on calling hard_reset
Browse files Browse the repository at this point in the history
  • Loading branch information
diekleinekuh authored and diekleinekuh committed Oct 5, 2023
1 parent 16c8c23 commit 38aba12
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 30 deletions.
2 changes: 2 additions & 0 deletions ublox-cellular/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ where
self.network.at_tx.reset()?;
if self.power_on().is_err() {
self.hard_reset()?;
self.power_on()?;
}

self.power_state = PowerState::On;
Expand Down Expand Up @@ -612,6 +613,7 @@ where
// as well as consecutive AT timeouts and do a hard reset.
Err(crate::network::Error::Generic(GenericError::Timeout)) => {
self.hard_reset()?;
self.power_on()?;
Err(Error::Generic(GenericError::Timeout))
}
result => result.map_err(Error::from),
Expand Down
54 changes: 24 additions & 30 deletions ublox-cellular/src/power.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ where

if self.soft_reset(true).is_err() {
self.hard_reset()?;
self.power_on()?;
}

Ok(())
Expand Down Expand Up @@ -133,8 +134,6 @@ where

self.power_state = PowerState::Off;

self.power_on()?;

Ok(())
}

Expand All @@ -147,38 +146,33 @@ where

if self.power_state()? != PowerState::On {
trace!("Powering modem on.");
match self.config.pwr_pin {
if let Some(ref mut pwr) = self.config.pwr_pin {
// Apply Low pulse on PWR_ON for 50 microseconds to power on
Some(ref mut pwr) => {
pwr.set_low().ok();
self.network
.status
.timer
.start(50.micros())
.map_err(from_clock)?;
nb::block!(self.network.status.timer.wait()).map_err(from_clock)?;
pwr.set_low().ok();
self.network
.status
.timer
.start(50.micros())
.map_err(from_clock)?;
nb::block!(self.network.status.timer.wait()).map_err(from_clock)?;

pwr.set_high().ok();
self.network
.status
.timer
.start(1.secs())
.map_err(from_clock)?;
nb::block!(self.network.status.timer.wait()).map_err(from_clock)?;
pwr.set_high().ok();
self.network
.status
.timer
.start(1.secs())
.map_err(from_clock)?;
nb::block!(self.network.status.timer.wait()).map_err(from_clock)?;

if let Err(e) = self.wait_power_state(PowerState::On, 25.secs()) {
error!("Failed to power on modem");
return Err(e);
} else {
trace!("Modem powered on");
}
}
_ => {
// Software restart
if self.soft_reset(false).is_err() {
self.hard_reset()?;
}
if let Err(e) = self.wait_power_state(PowerState::On, 25.secs()) {
error!("Failed to power on modem");
return Err(e);
} else {
trace!("Modem powered on");
}
} else {
error!("Cannot power on modem, pin disabled");
return Err(Error::Generic(GenericError::Timeout));
}
} else {
debug!("module is already on");
Expand Down

0 comments on commit 38aba12

Please sign in to comment.