Skip to main content
nileswan documentation
Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

MCU firmware protocol

This page documents protocols used to communicate with the on-board STM32 MCU via SPI.

Bootloader protocol

This is the default mode after resetting with BOOT0 pulled high.

For details on this protocol, please refer to the ST Application note AN4286.

Native mode

This is the default mode after resetting with BOOT0 pulled low.

To initiate a transaction, send a 16-bit little endian value (two bytes) declaring the command ID (in bits 0-6) and parameter (bits 7-15, values 0-511).

Every packet except “Switch to mode” has a response. The response always consists of the length (two bytes) and the data.

0x00 - Echo

Test command. The parameter is the number of bytes to echo, followed by the bytes to echo.

0x01 - MCU: Switch to mode

The parameter is the ID of the mode of communication to use going forward:

  • 0x00 - command mode
  • 0x01 - EEPROM emulation mode
  • 0x02 - RTC S-3511A emulation mode
  • 0x03 - CDC output mode (transferred SPI bytes are output via USB CDC)
  • 0xFF - standby mode (requires reset to respond to SPI again)

0x02 - SPI: Set maximum frequency

The parameter is the maximum SPI transfer frequency that the MCU should be configured for (clock/pin speeds):

  • 0x00 - 384 KHz
  • 0x01 - 6 MHz
  • 0x02 - 24 MHz

The response is 1 on success, 0 on failure.

So far, speeds faster than 384 KHz have been tested with the exception of commands with large (> 2-4 bytes) input parameter buffers.

0x03 - MCU: Get unique ID

The response is the unique ID of the chip.

0x10 - EEPROM: Set emulation mode

Set the size of the emulated EEPROM:

  • 0x00 - no EEPROM
  • 0x01 - M93LC06
  • 0x02 - M93LC46 compatible
  • 0x03 - M93LC56 compatible
  • 0x04 - M93LC66 compatible
  • 0x05 - M93LC76 compatible
  • 0x06 - M93LC86 compatible

The response is 1 on success, 0 on failure.

0x11 - EEPROM: Erase all data

The response is empty.

0x12 - EEPROM: Read data

The parameter is the number of words to read; the following word is the offset.

The response is the bytes read.

0x13 - EEPROM: Write data

The parameter is the number of words to write; the following word is the offset, then the words to write.

The response is empty.

0x14 - RTC: Send command

The parameter is the packet type to send to the emulated S-3511A, followed by the relevant bytes.

The response is the data returned by the emulated S-3511A.

0x15 - EEPROM: Get emulation mode

The response is 1 byte - the EEPROM emulation mode.

0x16 - MCU: Set save ID

The parameter specifies the save ID location:

  • 0x01: SRAM2 (if the save ID depends on data stored in SRAM2, such as EEPROM),
  • 0x02: RTC backup domain (if it doesn’t),
  • 0x03: both.

The command is followed by four bytes of the save ID.

The save ID 0xFFFFFFFF is reserved and means “no save is stored”.

The response is 1 on success, 0 on failure.

0x17 - MCU: Get save ID

The parameter specifies the save ID location.

The response is four bytes of the save ID.

0x40 - USB: CDC: Read

The parameter is the maximum number of bytes to read. The value 0 is treated as 512 bytes.

The response is the data read from the CDC.

0x41 - USB: CDC: Write

The parameter is the number of bytes to write. The value 0 is treated as 512 bytes.

The response is two bytes in size and is the number of bytes successfully written.

0x42 - USB: HID: Write

The parameter is the length of the packet.

The data sent is two bytes - the result of a keypad scan.

The response is zero bytes in size.

0x43 - USB: CDC: Available

The response is the number of bytes that can be read from the CDC.

0x44 - USB: CDC: Clear

Clears the write and read buffers, removing any unread data.

No parameter, no response data.

0x50 - Accelerometer enable

If the parameter is 1 the accelerometer is powered up and is polled at 100 Hz. If the parameter is 0 it is powered down and polling is stopped.

A one byte response is given, 1 if the operation was successful and the accelerometer is present and 0 for the opposite.

0x51 - Accelerometer read

Returns three signed 16-bit words representing the measured acceleration on three axis X, Y and Z.


Plane representing Swan as held when playing horizontally.

Coordinate system is the local coordinate system of the accelerometer. -Z is equivalent to the normal of the plane.

               ^ +Y
              /
     ________/________
+X  /       /        /
<----------0        /
  /        |       /
 /_________|______/
           |
           v +Z

The accelerometer is configured work in a range of +/- 2 g with 10 bit fractional precision. This means that when the console is resting the accelerometer will read a vector of magnitude 1024 the direction opposite to Earth’s gravitational pull. E.g. if the console sits on the side with the EXT port a value of approximately (1024, 0, 0) will be read. See also: https://en.wikipedia.org/wiki/Accelerometer#Physical_principles and the datasheet of the used MXC400xXC series accelerometer.


### 0x7F - Reserved

Reserved to distinguish 0xFF bytes from commands.