ASF4 TWI Master RTOS Driver Issue

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've been working on this bug for a few days now, and it seems that the root cause is likely how the ASF4 RTOS TWI Driver (doesn't) handle things.

 

In order to do a read from an I2C device with an internal address, you must first Write the Address, then Read the data, as two separate operations.  The problem happens when there is a delay between the write operation and this line of the read operation:

 

hri_twi_write_CR_reg(dev->hw, TWI_CR_START | ((msg->len == 1) ? TWI_CR_STOP : 0));

If a delay occurs, the read operation fails to clock, which locks up the mutex, which puts the task in permanent suspension.

 

In my case the delay came in the form of a context switch happening right after the write operation.

 

I did notice that the listed version of the driver is "1", but I can't figure out where any sort of ASF4 changelog is posted to see if a newer version might exist that's fixed this.

 

Does anyone know WHY this delay causes the read to fail?  I haven't found anything about it in the data sheet.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I should also add that the proper way to do this (which is entirely unimplemented in the current TWI RTOS driver) is to do a single read operation with the I2C device's internal address programmed into the IADR and the size of this address programmed into the MMR.  I've hacked together a re-write of the ASF driver to accomplish this and it seems to be working pretty well.  More testing (and code cleanup) is needed to see if this issue is resolved though. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yeah, this driver is hot garbage, even for a beta.