diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2013-04-06 11:31:05 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2013-04-06 11:31:05 +0000 |
commit | 03fab93a8b8809ac405e83349579fbfa8adfb7f0 (patch) | |
tree | 2a7f1b6d8e9b0a3f63caf63a3bf9063b67ed5e87 | |
parent | 44a4c3aacb6bc9ea440ca4a74cb3d568051f1317 (diff) | |
download | ChibiOS-03fab93a8b8809ac405e83349579fbfa8adfb7f0.tar.gz ChibiOS-03fab93a8b8809ac405e83349579fbfa8adfb7f0.tar.bz2 ChibiOS-03fab93a8b8809ac405e83349579fbfa8adfb7f0.zip |
STM32 I2Cv2 driver now working correctly.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5548 35acf78f-673a-0410-8e92-d51de3d6d3f4
-rw-r--r-- | os/hal/platforms/STM32/I2Cv2/i2c_lld.c | 36 | ||||
-rw-r--r-- | testhal/STM32F37x/I2C/Makefile | 2 | ||||
-rw-r--r-- | testhal/STM32F37x/I2C/main.c | 1 |
3 files changed, 19 insertions, 20 deletions
diff --git a/os/hal/platforms/STM32/I2Cv2/i2c_lld.c b/os/hal/platforms/STM32/I2Cv2/i2c_lld.c index dd20758cc..3a6c8f7f8 100644 --- a/os/hal/platforms/STM32/I2Cv2/i2c_lld.c +++ b/os/hal/platforms/STM32/I2Cv2/i2c_lld.c @@ -624,6 +624,15 @@ msg_t i2c_lld_master_receive_timeout(I2CDriver *i2cp, i2caddr_t addr, /* Releases the lock from high level driver.*/
chSysUnlock();
+ /* Waits until BUSY flag is reset and the STOP from the previous operation
+ is completed, alternatively for a timeout condition.*/
+ while (dp->ISR & I2C_ISR_BUSY) {
+ chSysLock();
+ if ((timeout != TIME_INFINITE) && !chVTIsArmedI(&vt))
+ return RDY_TIMEOUT;
+ chSysUnlock();
+ }
+
/* Adjust slave address (master mode) for 7-bit address mode */
if ((i2cp->config->cr2 & I2C_CR2_ADD10) == 0)
addr_cr2 = (addr_cr2 & 0x7f) << 1;
@@ -643,15 +652,6 @@ msg_t i2c_lld_master_receive_timeout(I2CDriver *i2cp, i2caddr_t addr, /* Enable RX DMA */
dmaStreamEnable(i2cp->dmarx);
- /* Waits until BUSY flag is reset and the STOP from the previous operation
- is completed, alternatively for a timeout condition.*/
- while (dp->ISR & I2C_ISR_BUSY) {
- chSysLock();
- if ((timeout != TIME_INFINITE) && !chVTIsArmedI(&vt))
- return RDY_TIMEOUT;
- chSysUnlock();
- }
-
/* This lock will be released in high level driver.*/
chSysLock();
@@ -719,6 +719,15 @@ msg_t i2c_lld_master_transmit_timeout(I2CDriver *i2cp, i2caddr_t addr, /* Releases the lock from high level driver.*/
chSysUnlock();
+ /* Waits until BUSY flag is reset and the STOP from the previous operation
+ is completed, alternatively for a timeout condition.*/
+ while (dp->ISR & I2C_ISR_BUSY) {
+ chSysLock();
+ if ((timeout != TIME_INFINITE) && !chVTIsArmedI(&vt))
+ return RDY_TIMEOUT;
+ chSysUnlock();
+ }
+
/* Adjust slave address (master mode) for 7-bit address mode */
if ((i2cp->config->cr2 & I2C_CR2_ADD10) == 0)
addr_cr2 = (addr_cr2 & 0x7f) << 1;
@@ -743,15 +752,6 @@ msg_t i2c_lld_master_transmit_timeout(I2CDriver *i2cp, i2caddr_t addr, /* Enable TX DMA */
dmaStreamEnable(i2cp->dmatx);
- /* Waits until BUSY flag is reset and the STOP from the previous operation
- is completed, alternatively for a timeout condition.*/
- while (dp->ISR & I2C_ISR_BUSY) {
- chSysLock();
- if ((timeout != TIME_INFINITE) && !chVTIsArmedI(&vt))
- return RDY_TIMEOUT;
- chSysUnlock();
- }
-
/* This lock will be released in high level driver.*/
chSysLock();
diff --git a/testhal/STM32F37x/I2C/Makefile b/testhal/STM32F37x/I2C/Makefile index 0090b317a..782a3b3d7 100644 --- a/testhal/STM32F37x/I2C/Makefile +++ b/testhal/STM32F37x/I2C/Makefile @@ -5,7 +5,7 @@ # Compiler options here.
ifeq ($(USE_OPT),)
- USE_OPT = -O0 -ggdb -fomit-frame-pointer -falign-functions=16
+ USE_OPT = -O2 -ggdb -fomit-frame-pointer -falign-functions=16
endif
# C specific options here (added to USE_OPT).
diff --git a/testhal/STM32F37x/I2C/main.c b/testhal/STM32F37x/I2C/main.c index 46f190f2a..fc0e4e2ab 100644 --- a/testhal/STM32F37x/I2C/main.c +++ b/testhal/STM32F37x/I2C/main.c @@ -98,7 +98,6 @@ int main(void) { if (msg != RDY_OK)
palTogglePad(GPIOC, GPIOC_LED3);
for (i = 0; i < 256; i++) {
- chThdSleepMilliseconds(2);
msg = i2cMasterReceiveTimeout(&I2CD2, 0x52,
data, sizeof(data), TIME_INFINITE);
if (msg != RDY_OK)
|