I2C lockup stm32f4discovery

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
drgowen
Posts: 12
Joined: Tue Aug 27, 2013 3:28 pm

I2C lockup stm32f4discovery

Post by drgowen »

Hi

Are there known problems with the i2c driver for stm32f4? I am raeding an MPU6050, checking for new data, and it works fine for about 20 seconds, and then a lockup occurs in i2cMasterTransmitTimeout despite the specification of a 50ms timeout - reboot then required.

hal.console->println("acq");
i2cAcquireBus(&I2CD2);
hal.console->println("rd");
rdymsg = i2cMasterTransmitTimeout(&I2CD2, addr, &reg, 1, data, len, MS2ST(timeout));
hal.console->println("rl");
i2cReleaseBus(&I2CD2);
hal.console->println("rlc");

After a while, a transaction only gets to "rd" and then stops.

Best
Gareth
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: I2C lockup stm32f4discovery

Post by Giovanni »

Hi,

Does it stop inside the i2cMasterTransmitTimeout() function? also, do you have debug options enabled? if so, is anything caught by an assertion?

Giovanni
drgowen
Posts: 12
Joined: Tue Aug 27, 2013 3:28 pm

Re: I2C lockup stm32f4discovery

Post by drgowen »

Yes its crashing in master timeout. I don't have debug enabled... cant get openocd working. Will try printing out the asserts.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: I2C lockup stm32f4discovery

Post by Giovanni »

drgowen wrote:Yes its crashing in master timeout. I don't have debug enabled... cant get openocd working. Will try printing out the asserts.


Try ChibiStudio, it includes everything is required.

Giovanni
drgowen
Posts: 12
Joined: Tue Aug 27, 2013 3:28 pm

Re: I2C lockup stm32f4discovery

Post by drgowen »

OK, I just had to reconfig pins to enable jtag.

It's getting stuck in unhandled_exception() - I cant see any way to get a stack trace and work out the cause of the exception.

There's also nothing shown in the eclipse console that would indicate the cause.

Best
Gareth
Attachments
Untitled.png
Untitled.png (283.4 KiB) Viewed 6941 times
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: I2C lockup stm32f4discovery

Post by Giovanni »

Hi,

It could be something not directly related like a stack overflow. Does the error happen always at the same time or randomly?

When an error is caught by an asserion then the system stops in port_halt() and the global pointer dbg_panic_msg points to a description string.

Giovanni
drgowen
Posts: 12
Joined: Tue Aug 27, 2013 3:28 pm

Re: I2C lockup stm32f4discovery

Post by drgowen »

It happens at the same time.

I've just tried doubling the stack size (using THD_WA_SIZE) but no effect - my code isn't being called in a recursive fashion, just a loop to check register values.

There is only one thread [afaik] - so the exception is definitely happening in the i2c master transmit function....

Best
Gareth
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: I2C lockup stm32f4discovery

Post by Giovanni »

You have 4 stacks there:
- main thread stack
- your thread stack
- idle thread stack (unlikely)
- IRQ stack

You you have complex code in the main() function or into some interrupt handler?

If not, increase a counter each time you do the transfer and see in which iteration it happens, then stop just before and step into the function.

Giovanni
drgowen
Posts: 12
Joined: Tue Aug 27, 2013 3:28 pm

Re: I2C lockup stm32f4discovery

Post by drgowen »

Thanks for your time again Giovanni.

It appears the bug was actually elsewhere, but the print statements weren't outputting to the USB quickly enough leaving me to erroneously believe it was in the i2c handler.

Sorry
Gareth
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: I2C lockup stm32f4discovery

Post by Giovanni »

NP, I am glad it's fixed.

Giovanni
Post Reply