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

avoid stack overflow from power_on calling hard_reset #1

Merged
merged 1 commit into from
Oct 5, 2023
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: 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