Skip to content

Commit

Permalink
Dummy handler to receive the I2CSlaveAddr when don't match the IPMBAddr
Browse files Browse the repository at this point in the history
When repeatedly upgrading and downgrading the openMMC via ipmitool, it
crashes sporadically at Chip_I2C_SlaveStateHandler. This happens because
for some motive, when calling startMasterXfer() sometimes an interrupt
occurs for the I2C0 peripheral, and the Chip_I2C_SlaveStateHandler is
called, dispatching  the handling to the callback registered for
I2C_SLAVE_GENERAL. But, this callback is not configured, resulting in a
invalid memory access.

It is not clear why this interrupt is generated for an I2C slave address
other than the expected IPMB address obtained by get_ipmb_addr(), but
this should be properly handled and not lead to a crash.

Fixes #160.
  • Loading branch information
gustavosr8 committed Mar 21, 2024
1 parent 3e0d9e7 commit 80a81f5
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions port/ucontroller/nxp/lpc17xx/lpc17_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ void vI2CConfig( I2C_ID_T id, uint32_t speed )

static TaskHandle_t slave_task_id;
I2C_XFER_T slave_cfg;
I2C_XFER_T slave_dummy;
uint8_t recv_msg[i2cMAX_MSG_LENGTH];
uint8_t recv_msg_dummy[i2cMAX_MSG_LENGTH];
uint8_t recv_bytes;

uint8_t xI2CSlaveReceive( I2C_ID_T id, uint8_t * rx_buff, uint8_t buff_len, uint32_t timeout )
Expand Down Expand Up @@ -138,6 +140,13 @@ static void I2C_Slave_Event(I2C_ID_T id, I2C_EVENT_T event)
}
}

/*
* This stub functions is called when the received I2C Slave Address doesn't match the
* expected IPMB address. This seems to be necessary because the lpcopen library tries
* to handle the I2C Slave configuration for I2C_SLAVE_GENERAL even if it's not configured,
* thus dereferencing an invalid unitialized pointer generating a HardFault.
*/
static void I2C_Dummy_Event(I2C_ID_T id, I2C_EVENT_T event){}

void vI2CSlaveSetup ( I2C_ID_T id, uint8_t slave_addr )
{
Expand All @@ -149,6 +158,13 @@ void vI2CSlaveSetup ( I2C_ID_T id, uint8_t slave_addr )
slave_cfg.rxBuff = &recv_msg[0];
slave_cfg.rxSz = (sizeof(recv_msg)/sizeof(recv_msg[0]));
Chip_I2C_SlaveSetup( id, I2C_SLAVE_0, &slave_cfg, I2C_Slave_Event, SLAVE_MASK);

slave_dummy.slaveAddr = 0;
slave_dummy.txBuff = NULL;
slave_dummy.txSz = 0;
slave_dummy.rxBuff = recv_msg_dummy;
slave_dummy.rxSz =(sizeof(recv_msg_dummy)/sizeof(recv_msg_dummy[0]));
Chip_I2C_SlaveSetup( id, I2C_SLAVE_GENERAL, &slave_dummy, I2C_Dummy_Event, SLAVE_MASK);
}

int xI2CMasterWriteRead(I2C_ID_T id, uint8_t addr, const uint8_t *tx_buff, int tx_len, uint8_t *rx_buff, int rx_len)
Expand Down

0 comments on commit 80a81f5

Please sign in to comment.