Skip to content

Commit 6428256

Browse files
authored
Merge pull request #10 from Neotron-Compute/bugfix/testing-on-pico-050-pcb
Bugfix/testing on pico 050 pcb
2 parents 4922a3d + 01e4afe commit 6428256

4 files changed

Lines changed: 120 additions & 28 deletions

File tree

.github/workflows/build.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Build
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout
10+
uses: actions/checkout@v1
11+
with:
12+
submodules: true
13+
- name: Add Target
14+
run: rustup target add thumbv6m-none-eabi
15+
- name: Install flip-link
16+
run: cd / && cargo install flip-link
17+
- name: Build
18+
run: cargo build --verbose --target=thumbv6m-none-eabi

.github/workflows/format.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Format
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
check:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v1
10+
- name: Add Tool
11+
run: rustup component add rustfmt
12+
- name: Check Format
13+
run: cargo fmt -- --check

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ The NBMC firmware is designed to run on an ST Micro STM32F0 (STM32F031K6T6) micr
3535
| 03 | PF1 | HOST_nRST | Reset Output to reset the rest of the system |
3636
| 06 | PA0 | MON_3V3 | 3.3V rail monitor Input (1.65V nominal) |
3737
| 07 | PA1 | MON_5V | 5.0V rail monitor Input (1.65V nominal) |
38-
| 08 | PA2 | LED0 | PWM output for first Status LED |
39-
| 09 | PA3 | LED1 | PWM output for second Status LED |
38+
| 08 | PA2 | nSYS_RESET | System Reset Output (active low) |
39+
| 09 | PA3 | DC_ON | PSU Enable Output (active high) |
4040
| 10 | PA4 | SPI1_nCS | SPI Chip Select Input (active low) |
4141
| 11 | PA5 | SPI1_SCK | SPI Clock Input |
4242
| 12 | PA6 | SPI1_CIPO | SPI Data Output |
4343
| 13 | PA7 | SPI1_COPI | SPI Data Input |
44-
| 14 | PB0 | BUTTON_nRST | Reset Button Input (active low) |
45-
| 15 | PB1 | DC_ON | PSU Enable Output |
44+
| 14 | PB0 | LED0 | Output for Power LED |
45+
| 15 | PB1 | LED1 | Output for Status LED |
4646
| 18 | PA8 | IRQ_nHOST | Interrupt Output to the Host (active low) |
47-
| 19 | PA9 | I2C1_SCL | I²C Clock |
48-
| 20 | PA10 | I2C1_SDA | I²C Data |
47+
| 19 | PA9 | USART1_TX | UART Transmit Output |
48+
| 20 | PA10 | USART1_RX | UART Receive Input |
4949
| 21 | PA11 | USART1_CTS | UART Clear-to-Send Output |
5050
| 22 | PA12 | USART1_RTS | UART Ready-to-Receive Input |
5151
| 23 | PA13 | SWDIO | SWD Progamming Data Input |
@@ -54,8 +54,8 @@ The NBMC firmware is designed to run on an ST Micro STM32F0 (STM32F031K6T6) micr
5454
| 26 | PB3 | PS2_CLK1 | Mouse Clock Input |
5555
| 27 | PB4 | PS2_DAT0 | Keyboard Data Input |
5656
| 28 | PB5 | PS2_DAT1 | Mouse Data Input |
57-
| 29 | PB6 | USART1_TX | UART Transmit Output |
58-
| 30 | PB7 | USART1_RX | UART Receive Input |
57+
| 29 | PB6 | I2C1_SCL | I²C Clock |
58+
| 30 | PB7 | I2C1_SDA | I²C Data |
5959

6060
Note that in the above table, the UART signals are wired as _Data Terminal Equipment (DTE)_ (i.e. like a PC, not like a Modem).
6161

src/main.rs

Lines changed: 81 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,103 @@ use stm32f0xx_hal as hal;
88

99
static VERSION: &'static str = include_str!(concat!(env!("OUT_DIR"), "/version.txt"));
1010

11-
const MODE_0: spi::Mode = spi::Mode {
12-
polarity: spi::Polarity::IdleLow,
13-
phase: spi::Phase::CaptureOnFirstTransition,
14-
};
11+
/// Holds all the I/O pins in our system
12+
#[allow(unused)]
13+
struct Pins {
14+
// spi_clk: hal::gpio::gpioa::PA5<hal::gpio::Alternate<hal::gpio::AF0>>,
15+
// spi_cipo: hal::gpio::gpioa::PA6<hal::gpio::Alternate<hal::gpio::AF0>>,
16+
// spi_copi: hal::gpio::gpioa::PA7<hal::gpio::Alternate<hal::gpio::AF0>>,
17+
// i2c_scl: hal::gpio::gpiob::PB6<hal::gpio::Alternate<hal::gpio::AF4>>,
18+
// i2c_sda: hal::gpio::gpiob::PB7<hal::gpio::Alternate<hal::gpio::AF4>>,
19+
uart_tx: hal::gpio::gpioa::PA9<hal::gpio::Alternate<hal::gpio::AF1>>,
20+
uart_rx: hal::gpio::gpioa::PA10<hal::gpio::Alternate<hal::gpio::AF1>>,
21+
uart_cts: hal::gpio::gpioa::PA11<hal::gpio::Alternate<hal::gpio::AF1>>,
22+
uart_rts: hal::gpio::gpioa::PA12<hal::gpio::Alternate<hal::gpio::AF1>>,
23+
led_power: hal::gpio::gpiob::PB0<hal::gpio::Output<hal::gpio::PushPull>>,
24+
led_status: hal::gpio::gpiob::PB1<hal::gpio::Output<hal::gpio::PushPull>>,
25+
}
1526

1627
#[cortex_m_rt::entry]
1728
fn main() -> ! {
1829
defmt::info!("Neotron BMC version {:?} booting", VERSION);
1930

2031
let p = pac::Peripherals::take().unwrap();
2132

33+
// Configure the clocks.
34+
// We have no external crystal, and instead run from the High Speed Internal Oscillator.
2235
let mut flash = p.FLASH;
23-
let mut rcc = p.RCC.configure().freeze(&mut flash);
36+
let mut rcc = p
37+
.RCC
38+
.configure()
39+
.hclk(48.mhz())
40+
.pclk(48.mhz())
41+
.sysclk(48.mhz())
42+
.freeze(&mut flash);
43+
44+
defmt::info!("Clocks are clocked");
2445

2546
let gpioa = p.GPIOA.split(&mut rcc);
2647
let gpiob = p.GPIOB.split(&mut rcc);
2748

28-
let (sck, miso, mosi, scl, sda, tx, rx) = cortex_m::interrupt::free(move |cs| {
29-
(
49+
let mut pins: Pins = cortex_m::interrupt::free(move |cs| {
50+
Pins {
3051
// SPI pins
31-
gpioa.pa5.into_alternate_af0(cs),
32-
gpioa.pa6.into_alternate_af0(cs),
33-
gpioa.pa7.into_alternate_af0(cs),
52+
// spi_clk: gpioa.pa5.into_alternate_af0(cs),
53+
// spi_cipo: gpioa.pa6.into_alternate_af0(cs),
54+
// spi_copi: gpioa.pa7.into_alternate_af0(cs),
3455
// I²C pins
35-
gpioa.pa9.into_alternate_af4(cs),
36-
gpioa.pa10.into_alternate_af4(cs),
56+
// i2c_scl: gpiob.pb6.into_alternate_af4(cs),
57+
// i2c_sda: gpiob.pb7.into_alternate_af4(cs),
3758
// USART pins
38-
gpiob.pb6.into_alternate_af0(cs),
39-
gpiob.pb7.into_alternate_af0(cs),
40-
)
59+
uart_tx: gpioa.pa9.into_alternate_af1(cs),
60+
uart_rx: gpioa.pa10.into_alternate_af1(cs),
61+
uart_cts: gpioa.pa11.into_alternate_af1(cs),
62+
uart_rts: gpioa.pa12.into_alternate_af1(cs),
63+
// LED pins
64+
led_power: gpiob.pb0.into_push_pull_output(cs),
65+
led_status: gpiob.pb1.into_push_pull_output(cs),
66+
}
4167
});
4268

43-
// Configure SPI with 1MHz rate
44-
let spi = spi::Spi::spi1(p.SPI1, (sck, miso, mosi), MODE_0, 1.mhz(), &mut rcc);
45-
let serial = serial::Serial::usart1(p.USART1, (tx, rx), 115_200.bps(), &mut rcc);
46-
let i2c = i2c::I2c::i2c1(p.I2C1, (scl, sda), 100.khz(), &mut rcc);
69+
// // Configure UART. Pick some default baud rate - we can change it later
70+
let mut serial = serial::Serial::usart1(
71+
p.USART1,
72+
(pins.uart_tx, pins.uart_rx),
73+
115_200.bps(),
74+
&mut rcc,
75+
);
76+
77+
use core::fmt::Write;
78+
79+
loop {
80+
serial.write_str("Hello, world!\r\n").unwrap();
81+
82+
defmt::info!("Off Off");
83+
84+
pins.led_power.set_low().unwrap();
85+
pins.led_status.set_low().unwrap();
86+
87+
cortex_m::asm::delay(6_000_000);
88+
89+
defmt::info!("Off On");
90+
91+
pins.led_power.set_low().unwrap();
92+
pins.led_status.set_high().unwrap();
93+
94+
cortex_m::asm::delay(6_000_000);
95+
96+
defmt::info!("On Off");
97+
98+
pins.led_power.set_high().unwrap();
99+
pins.led_status.set_low().unwrap();
100+
101+
cortex_m::asm::delay(6_000_000);
102+
103+
defmt::info!("On On");
104+
105+
pins.led_power.set_high().unwrap();
106+
pins.led_status.set_high().unwrap();
47107

48-
neotron_bmc::exit()
108+
cortex_m::asm::delay(6_000_000);
109+
}
49110
}

0 commit comments

Comments
 (0)