proveskit / circuitpy_flight_software

Flight software for the PROVES Kit.
MIT License
2 stars 4 forks source link

Communication Bus Init Order #24

Open Mikefly123 opened 1 month ago

Mikefly123 commented 1 month ago

Potential Issue

In the legacy configuration of the code all of the communication buses initialized in a single try / except statement. See the example from the as flown flight software on Pleiades - Squared:

        # Define SPI,I2C,UART | paasing I2C1 to BigData
        try:
            self.i2c0  = busio.I2C(board.SCL0,board.SDA0,timeout=5)
            self.spi0   = busio.SPI(board.SPI0_SCK,board.SPI0_MOSI,board.SPI0_MISO)
            self.i2c1  = busio.I2C(board.SCL1,board.SDA1,timeout=5,frequency=100000)
            self.spi1   = busio.SPI(board.SPI1_SCK,board.SPI1_MOSI,board.SPI1_MISO)
            self.uart  = busio.UART(board.TX,board.RX,baudrate=self.urate)
        except Exception as e:
            self.debug_print("ERROR INITIALIZING BUSSES: " + ''.join(traceback.format_exception(e)))

The problem with this scheme is that if an error is thrown during the self.i2c0 initialization it will block all subsequent initializations from taking place. The SPI0 bus is a critical part of the satellite because that is the only way the microcontroller communicates with the radio. On Yearling-2 and Pleiades - Squared we had both the PCA Face Power Driver and TCA I2C Multiplexer on I2C0, if either of these devices suffered a latch up that bricked that bus it is possible that it would block the initialization of the SPI bus that communicates with the radio.

Test Case

I think we should have someone go and short the I2C0 SDA and SCL lines together and to GND to see if that kind of failure would actually stop an orderly initialization of the satellite buses.

Mikefly123 commented 1 month ago

Updated Code Implementation

This new implementation available on the circuit-python-cleanup branch that splits all of the initializations into separate try/except statements.

        """
        Intializing Communication Buses
        """
        try:
            self.i2c0 = busio.I2C(board.I2C0_SCL, board.I2C0_SDA)
            self.hardware["I2C0"] = True

        except Exception as e:
            self.error_print(
                "ERROR INITIALIZING I2C0: " + "".join(traceback.format_exception(e))
            )

        try:
            self.spi0 = busio.SPI(board.SPI0_SCK, board.SPI0_MOSI, board.SPI0_MISO)
            self.hardware["SPI0"] = True

        except Exception as e:
            self.error_print(
                "ERROR INITIALIZING SPI0: " + "".join(traceback.format_exception(e))
            )

        try:
            self.i2c1 = busio.I2C(board.I2C1_SCL, board.I2C1_SDA, frequency=100000)
            self.hardware["I2C1"] = True

        except Exception as e:
            self.error_print(
                "ERROR INITIALIZING I2C1: " + "".join(traceback.format_exception(e))
            )

        try:
            self.uart = busio.UART(board.TX, board.RX, baudrate=self.urate)
            self.hardware["UART"] = True

        except Exception as e:
            self.error_print(
                "ERROR INITIALIZING UART: " + "".join(traceback.format_exception(e))
            )