Skip to content

Commit

Permalink
Merge #509
Browse files Browse the repository at this point in the history
509: Add static IP address as a build feature r=ryan-summers a=svrotter

In some cases it might be advantageous to set a static IP address for Stabilizer e.g. if it is used in an embedded environment that doesn't support DHCP or troubleshooting problems with DHCP negotiation.
This PR add this functionality as a build feature.

Co-authored-by: Sven Rotter <s.rotter@tu-berlin.de>
  • Loading branch information
bors[bot] and svrotter authored Feb 15, 2022
2 parents 36ef71e + 4805272 commit 02a791d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Added

* Optional specification of a static IP address ([#509](https://github.com/quartiq/stabilizer/pull/509))
* Telemetry ([#341](https://github.com/quartiq/stabilizer/pull/341))
* Logging via RTT (real time tracing) over SWD/JTAG instead of semihosting
for fast and low-overhead debugging ([#393](https://github.com/quartiq/stabilizer/pull/393) [#391](https://github.com/quartiq/stabilizer/pull/391) [#358](https://github.com/quartiq/stabilizer/pull/358))
Expand Down
2 changes: 2 additions & 0 deletions book/src/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Stabilizer supports 10Base-T or 100Base-T with Auto MDI-X.
Stabilizer uses DHCP to obtain its network configuration information. Ensure there is a
properly configured DHCP server running on the network segment that Stabilizer is
connected to.
Alternatively, a static IP can be enforced in the firmware build command by specifying
the environmental variable `STATIC_IP` analogous to how a specific broker IP is set.

> **Note:** If Stabilizer is connected directly to an Ubuntu system (for example using a USB-Ethernet dongle)
you can set the IPv4 settings of this Ethernet connection in the Ubuntu network settings to
Expand Down
17 changes: 10 additions & 7 deletions src/hardware/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,17 +695,18 @@ pub fn setup(

unsafe { ethernet::enable_interrupt() };

// Configure IP address according to DHCP socket availability
let ip_addrs: smoltcp::wire::IpAddress = option_env!("STATIC_IP")
.unwrap_or("0.0.0.0")
.parse()
.unwrap();

// Note(unwrap): The hardware configuration function is only allowed to be called once.
// Unwrapping is intended to panic if called again to prevent re-use of global memory.
let store =
cortex_m::singleton!(: NetStorage = NetStorage::default()).unwrap();

store.ip_addrs[0] = smoltcp::wire::IpCidr::new(
smoltcp::wire::IpAddress::Ipv4(
smoltcp::wire::Ipv4Address::UNSPECIFIED,
),
0,
);
store.ip_addrs[0] = smoltcp::wire::IpCidr::new(ip_addrs, 24);

let mut routes =
smoltcp::iface::Routes::new(&mut store.routes_cache[..]);
Expand All @@ -726,7 +727,9 @@ pub fn setup(
.routes(routes)
.finalize();

interface.add_socket(smoltcp::socket::Dhcpv4Socket::new());
if ip_addrs.is_unspecified() {
interface.add_socket(smoltcp::socket::Dhcpv4Socket::new());
}

for storage in store.tcp_socket_storage[..].iter_mut() {
let tcp_socket = {
Expand Down

0 comments on commit 02a791d

Please sign in to comment.