HPS I2C Protocol

All communication is initiated by the host (I2C controller) and consists of either a single write (START_WRITE...STOP), or a write_read (START_WRITE...START_READ...STOP) operation.

All multi-byte values are big-endian.

The first byte written by the host is the command byte:

BITNAMEDESCRIPTION
7-XCMDCommand is either 1 or 2 bits
X-0PARAMETERParameter is 7 or 6 bits

CMD

ValueFUNCTION
00Write memory.
1Register Access.
01Unused

Write memory

6 bit Parameter specifies the memory bank, followed by a 32 bit start address, and then the data.

Memory banks

NumberBank
0MCU flashWritable in stage0
1FPGA gatewareWritable in stage1
2SOC ROMWritable in stage1

Register access

7 bit Parameter specifies the register number. The host either requests data from the register (write_read operation), or data to be written to the register follows the command (write operation).

RegisterAccessStageDescriptionLength
0ROAllMagic number2
1ROStage0Hardware version2
2ROAllSystem status2
3WOAllSystem commands2
4RO---Application version (unused)2
5ROAllMemory bank available2
6ROAllError2
7RWApplEnabled features2
8ROApplFeature 02
9ROApplFeature 12
10ROStage1/ApplFirmware version (high)2
11ROStage1/ApplFirmware version (low)2
12ROApplFPGA boot count2
13ROApplFPGA loop count2
14ROApplFPGA ROM version2
15ROApplSPI flash status bits2
16RO---(unused)2
17RO---(unused)2
18ROApplCamera configuration2
19WOApplStart camera test2
20RWOneTimeInitOption bytes configuration2
21ROApplPart IDs20
22ROStage1/ApplPrevious crash message256
23ROApplFPGA crash message256

Registers numbered 100 and over are reserved for debugging and development use and are not documented here.

Register 0: Magic number

0x9df2

Register 1: Hardware version

This register is only valid while stage0 is running. At other times, it reads zero.

The high byte describes the hardware version, only 0x01 is used.

The low byte describes the stage0 firmware version.

ValueMeaning
0x01Early prototyping version
0x02The stage0/stage1 boundary was moved
0x03The MP key is used for verification
0x04Launch1 now does signature check. AVERIFY and ANONVER status bits gone.
0x05Reserved for developer versions built from source.

Register 2: System status

BITNAMEDESCRIPTION
15
14
13ONE_TIME_INITWhether the one_time_init binary is running
12STAGE0_PERM_LOCKEDWhether stage0 has been made permanently read-only
11STAGE0_LOCKEDWhether stage0 has been made read-only
10CMDINPROGRESSA command is in-progress.
9APPLREADYApplication is running, and features may be enabled.
8STAGE1Stage 1 has been launched, and is now running.
7
6
5WPOFFWrite protect pin off.
4WPONWrite protect pin on.
3STAGE0Stage 0 is running.
2DEPRECATED1
1FAULTSystem has an unrecoverable fault.
0OKSystem is operational.

Register 3: System commands

BITNAMEDESCRIPTION
15ERASE_STAGE0Erase stage0 (one_time_init)
14WRITE_TEST_DATAWrite SPI flash test data
13
12
11
10
9
8
7
6
5
4ERASE_SPIFLASHErase SPI flash (FPGA bitstream and application)
3ERASE_STAGE1Erase RW region of MCU flash (stage1)
2LAUNCHAPPLaunch application (from stage1)
1LAUNCH1Launch stage1 (from stage0)
0RESETReset module to stage0

Register 5: Memory bank available

Bit N is set if memory bank N is available for a Memory Write request. The host should poll this register before issuing a Memory Write command.

Register 6: Error

If an unrecoverable error has occurred (indicated by the FAULT bit in the system status register), then the error register contains a value that identifies the first error that occurred.

See rust/mcu_common/src/errors.rs for the mapping from values to error names and descriptions.

Register 7: Enabled features

BITNAMEDESCRIPTION
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1FEATURE1Enable feature 1
0FEATURE0Enable feature 0

Registers 8-9: Feature N

BITSNAMEDESCRIPTION
15USABLEThe feature result is valid to use.
14-8COUNTWrapping result counter.
7-0RESULTSigned 8 bit score

Register 18: Camera configuration

BITNAMEDESCRIPTION
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1ROTATIONRotation bit 1
0ROTATIONRotation bit 0

Supported rotations:

VALUEROTATIONDESCRIPTION
0UPRIGHTNo rotation required
1CLOCKWISEImage needs 90 clockwise rotation
2
3

Register 21: Part IDs

The Part IDs register consists of multiple 32 bit words as follows:

BYTE_OFFSETNAMEDESCRIPTION
0MCU_IDSee RM0444 section 40.10.1
4FPGA_IDNot yet implemented. Reserved for future use
8CAMERA_IDCamera part ID
12SPI_FLASH_MNSPI flash manufacturer
16SPI_FLASH_PISPI flash part ID

Boot sequence

From the perspective of the host, there are 3 boot stages: stage0, stage1 and ‘Application’ (Appl). Stage1 and the application are a single binary with two different stages.

Provided no firmware updates are required, the HPS can be started by sending a LAUNCH1 command to stage0, then once stage1 starts, by sending a LAUNCHAPP command.

Firmware updates

A boot sequence with firmware updates can be performed as follows:

  • Reset, power cycle, or otherwise ensure that stage0 is running.
  • Erase MCU RW flash region.
  • Write new stage1/application into MCU RW flash region.
  • Issue RESET command
  • Issue LAUNCH1 command
  • Erase SPI flash.
  • Write FPGA bitstream and application into SPI flash.
  • Issue LAUNCHAPP command
  • Operate as per normal (e.g. enable a feature)