Skip to content

consider code sample for embedded and wasm wgs #350

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

Closed
sophiajt opened this issue Nov 19, 2018 · 8 comments
Closed

consider code sample for embedded and wasm wgs #350

sophiajt opened this issue Nov 19, 2018 · 8 comments
Assignees
Labels
A-Content The written content on the website.

Comments

@sophiajt
Copy link

We have a great precedent with Command Line and Networking: you jump in, and within a few seconds you see your first examples of how easy it is to use Rust in these domains. Would it be possible to have a similar feel for WASM and embedded? This way each of the four sections feels like "Rust is awesome in each of these topics. Look how easy this is!"

@ashleygwilliams ashleygwilliams added question A-Content The written content on the website. labels Nov 20, 2018
@ashleygwilliams ashleygwilliams changed the title Two Build It In Rust sections need quick code samples consider code sample for embedded and wasm wgs Nov 20, 2018
@aturon
Copy link
Member

aturon commented Nov 29, 2018

cc @japaric @fitzgen @jamesmunns

@aturon aturon added this to the end-of-year milestone Nov 29, 2018
@aturon
Copy link
Member

aturon commented Nov 29, 2018

Scheduled for end of year milestone; not blocking the edition rollout.

@fitzgen
Copy link
Member

fitzgen commented Nov 29, 2018

So we had originally discussed embedding webassembly.studio in the wasm page, but decided not to because our target audience for the website was supposed to be CTOs and not hackers, so getting too technical didn't really make sense. Have we changed our target audience such that we should revisit that decision?

@ashleygwilliams
Copy link
Member

we haven't. i personally don't think this needs to happen- but it was an ask. if there's a good small sample we can consider adding it, but i dont think this is something that must happen.

@aturon
Copy link
Member

aturon commented Nov 29, 2018

@fitzgen the web site is intended to address both audiences. Please take a look at some of the other WG pages to get a sense for what we've done there. If there's something of similar scope for wasm, let's go for it. But if not, no big deal.

@jamesmunns
Copy link
Member

For the embedded WG, I would suggest one of the examples from https://docs.rust-embedded.org/book/start/registers.html, in particular I'm fond of this example, while a bit long, is a pretty good "full, standalone example":

#![no_std]
#![no_main]

extern crate panic_halt; // panic handler

use cortex_m_rt::entry;
use tm4c123x_hal as hal;
use tm4c123x_hal::prelude::*;
use tm4c123x_hal::serial::{NewlineMode, Serial};
use tm4c123x_hal::sysctl;

#[entry]
fn main() -> ! {
    let p = hal::Peripherals::take().unwrap();
    let cp = hal::CorePeripherals::take().unwrap();

    // Wrap up the SYSCTL struct into an object with a higher-layer API
    let mut sc = p.SYSCTL.constrain();
    // Pick our oscillation settings
    sc.clock_setup.oscillator = sysctl::Oscillator::Main(
        sysctl::CrystalFrequency::_16mhz,
        sysctl::SystemClock::UsePll(sysctl::PllOutputFrequency::_80_00mhz),
    );
    // Configure the PLL with those settings
    let clocks = sc.clock_setup.freeze();

    // Wrap up the GPIO_PORTA struct into an object with a higher-layer API.
    // Note it needs to borrow `sc.power_control` so it can power up the GPIO
    // peripheral automatically.
    let mut porta = p.GPIO_PORTA.split(&sc.power_control);

    // Activate the UART.
    let uart = Serial::uart0(
        p.UART0,
        // The transmit pin
        porta
            .pa1
            .into_af_push_pull::<hal::gpio::AF1>(&mut porta.control),
        // The receive pin
        porta
            .pa0
            .into_af_push_pull::<hal::gpio::AF1>(&mut porta.control),
        // No RTS or CTS required
        (),
        (),
        // The baud rate
        115200_u32.bps(),
        // Output handling
        NewlineMode::SwapLFtoCRLF,
        // We need the clock rates to calculate the baud rate divisors
        &clocks,
        // We need this to power up the UART peripheral
        &sc.power_control,
    );

    loop {
        writeln!(uart, "Hello, World!\r\n").unwrap();
    }
}

@jamesmunns
Copy link
Member

@therealprof suggested this blinky light example, which would be easier to trim down to size:

https://github.com/therealprof/stm32f042-hal/blob/master/examples/blinky_delay.rs

@XAMPPRocky
Copy link
Member

I'm going to close this as a duplicate of #838, as I think we should consider adding these as part of addressing that issue, if someone wants to make a PR adding either to the website feel free!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Content The written content on the website.
Projects
None yet
Development

No branches or pull requests

7 participants