|
1 | 1 | # Neotron-BMC |
2 | | -Firmware for the Neotron Board Management Controller |
| 2 | + |
| 3 | +Firmware for the Neotron Board Management Controller (NBMC). |
| 4 | + |
| 5 | +## Introduction |
| 6 | + |
| 7 | +The NMBC is an always-on microcontroller used on Neotron systems. It has very low idle power consumption, allowing it to remain powered up at all times. This lets it listen to button events from the Power and Reset buttons, and control the system LEDs, main `~RESET` signal and turn the main 5V Power Rail on and off. This lets your Neotron system have smart 'ATX PC' style features like a soft power button, and it also ensures that all power rails come up before the system is taken out of reset. |
| 8 | + |
| 9 | +The NBMC appears to the main Neotron system processor as an Expansion Device. As such it sits on the SPI bus as a peripheral device, with a dedicated Chip Select line and a dedicated IRQ line. It provides to the system: |
| 10 | + |
| 11 | +* an extra I²C bus, |
| 12 | +* a four-wire UART, |
| 13 | +* two PS/2 ports (one for keyboard, one for a mouse), |
| 14 | +* two analog inputs for monitoring for the 3.3V and 5.0V rails, |
| 15 | +* two GPIO inputs for a power button and a reset button, and |
| 16 | +* three GPIO outputs - nominally used for |
| 17 | + * the main DC/DC enable signal, |
| 18 | + * the power LED, and |
| 19 | + * a status LED. |
| 20 | + |
| 21 | +## Hardware Interface |
| 22 | + |
| 23 | +The NBMC firmware is designed to run on an ST Micro STM32F0 (STM32F031K6T6) microcontroller |
| 24 | + |
| 25 | +* 32-bit Arm Cortex-M0+ Core |
| 26 | +* 3.3V I/O (5V tolerant) |
| 27 | +* 32 KiB Flash |
| 28 | +* 4 KiB SRAM |
| 29 | +* LQFP-32 package (0.8mm pitch) |
| 30 | + |
| 31 | + |
| 32 | +| Pin | Name | Signal | Function | |
| 33 | +| :--- | :--- | :---------- | :------------------------------------------- | |
| 34 | +| 02 | PF0 | BUTTON_nPWR | Power Button Input (active low) | |
| 35 | +| 03 | PF1 | HOST_nRST | Reset Output to reset the rest of the system | |
| 36 | +| 06 | PA0 | MON_3V3 | 3.3V rail monitor Input (1.65V nominal) | |
| 37 | +| 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 | |
| 40 | +| 10 | PA4 | SPI1_nCS | SPI Chip Select Input (active low) | |
| 41 | +| 11 | PA5 | SPI1_SCK | SPI Clock Input | |
| 42 | +| 12 | PA6 | SPI1_CIPO | SPI Data Output | |
| 43 | +| 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 | |
| 46 | +| 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 | |
| 49 | +| 21 | PA11 | USART1_CTS | UART Clear-to-Send Output | |
| 50 | +| 22 | PA12 | USART1_RTS | UART Ready-to-Receive Input | |
| 51 | +| 23 | PA13 | SWDIO | SWD Progamming Data Input | |
| 52 | +| 24 | PA14 | SWCLK | SWD Programming Clock Input | |
| 53 | +| 25 | PA15 | PS2_CLK0 | Keyboard Clock Input | |
| 54 | +| 26 | PB3 | PS2_CLK1 | Mouse Clock Input | |
| 55 | +| 27 | PB4 | PS2_DAT0 | Keyboard Data Input | |
| 56 | +| 28 | PB5 | PS2_DAT1 | Mouse Data Input | |
| 57 | +| 29 | PB6 | USART1_TX | UART Transmit Output | |
| 58 | +| 30 | PB7 | USART1_RX | UART Receive Input | |
| 59 | + |
| 60 | +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). |
| 61 | + |
| 62 | +This design should also be pin-compatible with the following SoCs (although this firmware may need changes): |
| 63 | + |
| 64 | +* STM32F042K4Tx |
| 65 | +* STM32F042K6Tx |
| 66 | +* STM32L071KBTx |
| 67 | +* STM32L071KZTx |
| 68 | +* STM32L072KZTx |
| 69 | +* STM32L081KZTx |
| 70 | +* STM32L082KZTx |
| 71 | + |
| 72 | +Note that not all STM32 pins are 5V-tolerant, and the PS/2 protocol is a 5V open-collector system, so ensure that whichever part you pick has 5V-tolerant pins (marked `FT` or `FTt` in the datasheet) for the PS/2 signals. All of the parts above _should_ be OK, but they haven't been tested. Let us know if you try one! |
| 73 | + |
| 74 | +## Communications Protocol - SPI Frames |
| 75 | + |
| 76 | +The SPI interface runs in SPI mode 0 (clock line idles low, data sampled on rising edge) at up to 16 MHz (TBD). It uses frames made up of 8-bit words. |
| 77 | + |
| 78 | +To communicate with the NBMC, first take the Chip Select line (`SPI1_nCS`) low, then send the appropriate number of bytes. SPI is a full-duplex system, but in this system only one side is actually transferring useful data at any time. |
| 79 | + |
| 80 | +Once the appropriate number of bytes have been exchange, the Chip Select line must be raised for at least XXX microseconds, before another transfer is started. |
| 81 | + |
| 82 | +``` |
| 83 | ++-----+-------------...-------------+----------------...---------------+ |
| 84 | +| CMD | CLEN | Command Bytes 0..n | PADDING | Controller Out, Peripheral In (COPI) |
| 85 | ++-----+------+------...-------------+-----+------+---------...---------+ |
| 86 | +| PADDING | RSP | RLEN | Response Bytes 0..n | Controller In, Peripheral Out (CIPO) |
| 87 | ++----------------...----------------+-----+------+---------...---------+ |
| 88 | +``` |
| 89 | + |
| 90 | +The `CMD` byte is a command, given in the Table of Commands below. `RSP` is a response byte, given in the Table of Responses below. |
| 91 | + |
| 92 | +Taking the Chip Select line low activates an Interrupt Routine. You must leave XXX microseconds (TBD) before starting the transfer in order to give the routine time to start. The various CMD bytes either read or write various registers in RAM. Once the Chip Select is raised, the system goes into its background processing, reading from the registers to set system outputs, and writing to registers based on system inputs. |
| 93 | + |
| 94 | +## Communications Protocol - Commands and Responses |
| 95 | + |
| 96 | +### Table of Commands |
| 97 | + |
| 98 | +| Command Byte | Name | |
| 99 | +| ------------ | ----- | |
| 100 | +| 0x00 | PING | |
| 101 | +| 0x01 | READ | |
| 102 | +| 0x02 | WRITE | |
| 103 | + |
| 104 | +### Table of Responses |
| 105 | + |
| 106 | +| Response Byte | Name | |
| 107 | +| ------------- | --------------- | |
| 108 | +| 0x80 | OK | |
| 109 | +| 0x81 | Unknown Command | |
| 110 | +| 0xFF | Busy | |
| 111 | + |
| 112 | +### PING Command |
| 113 | + |
| 114 | +This command just checks the NBMC is awake. There is no payload. A OK response is sent in return. |
| 115 | + |
| 116 | +### READ Command |
| 117 | + |
| 118 | +This command reads from an address in the NBMC. The payload is the 8-bit register address, followed by the 8-bit number of bytes to read. The `CLEN` must therefore be two. |
| 119 | + |
| 120 | +### WRITE Command |
| 121 | + |
| 122 | +This command writes to an address in the NBMC. The payload is the 8-bit register address, followed by the 8-bit number of bytes to write, followed by the bytes themselves (up to 253). The `CLEN` must therefore be 2 + the number of bytes written. |
| 123 | + |
| 124 | +### Table of Registers |
| 125 | + |
| 126 | +| Address | Name | Type | Contains | Length | |
| 127 | +| ------- | ------------------------------------- | ----- | -------------------------------------------------------- | ------ | |
| 128 | +| 0x00 | Firmware Version | RO | The NBMC firmware version, as a null-padded UTF-8 string | 64 | |
| 129 | +| 0x01 | Hardware Version | RO | The NBMC firmware version, as a null-padded UTF-8 string | 64 | |
| 130 | +| 0x02 | Interrupt Status | R/W1C | Which interrupts are currently active, as a bitmask. | 2 | |
| 131 | +| 0x02 | Interrupt Control | R/W | Which interrupts are currently enabled, as a bitmask. | 2 | |
| 132 | +| 0x10 | UART Receive/Transmit Buffer | FIFO | Data received over the UART | max 64 | |
| 133 | +| 0x11 | UART FIFO Control | R/W | Settings for the UART FIFO | 1 | |
| 134 | +| 0x12 | UART Control | R/W | ... | 1 | |
| 135 | +| 0x13 | UART Status | R/W | ... | 1 | |
| 136 | +| 0x14 | UART Baud Rate | R/W | ... | 4 | |
| 137 | +| 0x20 | PS/2 Keyboard Receive/Transmit Buffer | FIFO | ... | max 16 | |
| 138 | +| 0x22 | PS/2 Keyboard Control | R/W | ... | 1 | |
| 139 | +| 0x23 | PS/2 Keyboard Status | R/W1C | ... | 1 | |
| 140 | +| 0x30 | PS/2 Mouse Receive/Transmit Buffer | FIFO | ... | max 16 | |
| 141 | +| 0x32 | PS/2 Mouse Control | R/W | ... | 1 | |
| 142 | +| 0x33 | PS/2 Mouse Status | R/W1C | ... | 1 | |
| 143 | +| 0x40 | LED Control | R/W | ... | 1 | |
| 144 | +| 0x41 | Button Status | RO | ... | 1 | |
| 145 | + |
| 146 | +The register types are: |
| 147 | + |
| 148 | +* `RO` - read only register, where writes will return an error |
| 149 | +* `R/W` - read/write register |
| 150 | +* `R/W1C` - when writing a 1 bit clears that bit position and a 0 bit is ignored, reads are as normal. |
| 151 | +* `FIFO` - a first-in, first-out buffer |
| 152 | + |
| 153 | +## Build Requirements |
| 154 | + |
| 155 | +1. rustup and Rust |
| 156 | + - see https://www.rust-lang.org |
| 157 | +2. The `thumbv6m-none-eabi` target |
| 158 | + - run `rustup target add thumbv6m-none-eabi` |
| 159 | +3. `probe-run` |
| 160 | + - run `cargo install probe-run` from your `$HOME` dir (not this folder!) |
| 161 | +4. `flip-link` |
| 162 | + - run `cargo install flip-link` from your `$HOME` dir (not this folder!) |
| 163 | + |
| 164 | +Then to build and flash, connect a probe supported by probe-rs (such as a SEGGER J-Link, or an ST-Link) and run: |
| 165 | + |
| 166 | +``` |
| 167 | +$ cargo run --bin neotron-bmc --release |
| 168 | +``` |
| 169 | + |
| 170 | +## Licence |
| 171 | + |
| 172 | +This code is licenced under the GNU Public Licence version 3. See: |
| 173 | + |
| 174 | +* [The LICENSE file](./LICENSE) |
| 175 | +* [The GPL Website](http://www.gnu.org/licenses/gpl-3.0.html) |
| 176 | + |
| 177 | +Our intent behind picking this licence is that you must ensure anyone who receives a programmed Neotron BMC processor, also receives: |
| 178 | + |
| 179 | +* A note stating that the firmware is licenced under the GPL v3, and |
| 180 | +* Access to Complete and Corresponding Source Code (e.g. in the form of the URL of this repository, or the source repository the firmware was built from if not this one). |
| 181 | + |
| 182 | +For the avoidance of doubt, it is not our intention to: |
| 183 | + |
| 184 | +* prevent you from selling PCBs containing a programmed Neotron BMC processor, or |
| 185 | +* prevent you from making changes to the Neotron BMC source code. |
| 186 | + |
| 187 | +It is however our intention to ensure that anyone who sells or distributes this firmware (or products that contain it): |
| 188 | + |
| 189 | +* provides proper attribution, and |
| 190 | +* gives the customers/recipients access to the source code, including any changes that were made. |
| 191 | + |
| 192 | +Note that this firmware image incorporates a number of third-party modules. You should review the output of `cargo tree` and ensure that any licence terms for those modules are upheld. You should also be aware that this application was based on the Knurling Template at https://github.com/knurling-rs/app-template. |
0 commit comments