@@ -8,42 +8,103 @@ use stm32f0xx_hal as hal;
88
99static 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]
1728fn 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