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

Add static IP address as a build feature #509

Merged
merged 4 commits into from
Feb 15, 2022
Merged
Changes from 3 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
17 changes: 10 additions & 7 deletions src/hardware/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,17 +688,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 @@ -719,7 +720,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());
ryan-summers marked this conversation as resolved.
Show resolved Hide resolved
}

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