I know there's not a great demand for I2C slave, but as proof of concept, I added slave code to i2c.c and i2c.h (maple ide v0.0.12). see code here
http://pastebin.com/QdcwjgN4
http://pastebin.com/QTm6aHig
Code is not industrial strength, only hobbyist strength with several TODOs. Code is interrupt driven and uses arduino-like event handlers. Setup would be
i2c_slave_enable(I2C2, I2CID, 0); // 100KHz
i2c_attachSlaveRxEvent(I2C2,receiveEvent);
i2c_attachSlaveTxEvent(I2C2,requestEvent);
with events handlers
void receiveEvent(int howMany)
{
if (i2c_slave_available(I2C2)) x = i2c_slave_read(I2C2);
}
void requestEvent()
{
uint8 data[32];
x++;
data[0] = x;
i2c_slave_write(I2C2,data,1); // send back to master
}
Though code sort of supports both maple I2C interfaces, the i2c.c code needs additional work to replicate some of the data structures into each interface, if you really want to run two I2C interfaces at once.
I've only tested at 100KHz from an arduino Wire I2C master. Seems to work with single and multiple byte transfers.
I observed SDA/CLK with USB scope, and enabled I2C_DEBUG so I could print out the event "crumbs" and also printed out I2C regs with
void i2c_dump(){
int i;
unsigned int *p = (unsigned int *)0x40005800; // i2c2 c1 is 5400
for (i=0; i<9; i++){
SerialUSB.println(p[i],HEX);
}
}
Only trick was that reference manual failed to mention that you need to touch CR1 after slave transmit done (AF raised).
Next I might try DMA, though I'm tempted to wait on next generation F4, e.g., Maple II or Arduino Due.