I2C on OLIMEX-STM32-LCD (STM32F103ZE) Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: I2C on OLIMEX-STM32-LCD (STM32F103ZE)

Post by Giovanni »

Hi,

The field "thread" has to be NULL this is intentional, it is the osalThreadSuspendTimeoutS() function that writes in it. If it hangs it is because the thread is not resumed after suspending itself.

Giovanni
Tuxford
Posts: 26
Joined: Fri Nov 06, 2020 3:28 pm
Has thanked: 4 times
Been thanked: 4 times

Re: I2C on OLIMEX-STM32-LCD (STM32F103ZE)

Post by Tuxford »

Found the problem. It doesn't work with DMA. I made some small fix related to disabling DMA and it works. I suppose DMA isn't configured properly.

Giovanni, I think it has sense to add those changes to repo.

Code: Select all

diff --git a/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.c b/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.c
index 57ee6db..10d29cc 100644
--- a/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.c
+++ b/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.c
@@ -941,7 +941,9 @@ msg_t i2c_lld_master_receive_timeout(I2CDriver *i2cp, i2caddr_t addr,
     /* If the system time went outside the allowed window then a timeout
        condition is returned.*/
     if (!osalTimeIsInRangeX(osalOsGetSystemTimeX(), start, end)) {
+#if STM32_I2C_USE_DMA^M
       dmaStreamDisable(i2cp->dmarx);
+#endif^M
       return MSG_TIMEOUT;
     }
 
@@ -955,7 +957,9 @@ msg_t i2c_lld_master_receive_timeout(I2CDriver *i2cp, i2caddr_t addr,
   /* Waits for the operation completion or a timeout.*/
   msg = osalThreadSuspendTimeoutS(&i2cp->thread, timeout);
   if (msg != MSG_OK) {
+#if STM32_I2C_USE_DMA^M
     dmaStreamDisable(i2cp->dmarx);
+#endif^M
   }
 
   return msg;
@@ -1041,8 +1045,10 @@ msg_t i2c_lld_master_transmit_timeout(I2CDriver *i2cp, i2caddr_t addr,
     /* If the system time went outside the allowed window then a timeout
        condition is returned.*/
     if (!osalTimeIsInRangeX(osalOsGetSystemTimeX(), start, end)) {
+#if STM32_I2C_USE_DMA^M
       dmaStreamDisable(i2cp->dmatx);
       dmaStreamDisable(i2cp->dmarx);
+#endif^M
       return MSG_TIMEOUT;
     }
 
@@ -1056,8 +1062,10 @@ msg_t i2c_lld_master_transmit_timeout(I2CDriver *i2cp, i2caddr_t addr,
   /* Waits for the operation completion or a timeout.*/
   msg = osalThreadSuspendTimeoutS(&i2cp->thread, timeout);
   if (msg != MSG_OK) {
+#if STM32_I2C_USE_DMA^M
     dmaStreamDisable(i2cp->dmatx);
     dmaStreamDisable(i2cp->dmarx);
+#endif^M
rluchyshyn@rluchyshynHP:~/Src/VVG/chibios_commercial/os/hal/ports/STM32/LLD/I2Cv1$ git diff hal_i2c_lld.c > hal_i2c_lld^C
rluchyshyn@rluchyshynHP:~/Src/VVG/chibios_commercial/os/hal/ports/STM32/LLD/I2Cv1$ Giovanni^C
rluchyshyn@rluchyshynHP:~/Src/VVG/chibios_commercial/os/hal/ports/STM32/LLD/I2Cv1$
rluchyshyn@rluchyshynHP:~/Src/VVG/chibios_commercial$
rluchyshyn@rluchyshynHP:~/Src/VVG/chibios_commercial$ git diff hal_i2^C
rluchyshyn@rluchyshynHP:~/Src/VVG/chibios_commercial$ git diff os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.c
diff --git a/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.c b/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.c
index 57ee6db..10d29cc 100644
--- a/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.c
+++ b/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.c
@@ -941,7 +941,9 @@ msg_t i2c_lld_master_receive_timeout(I2CDriver *i2cp, i2caddr_t addr,
     /* If the system time went outside the allowed window then a timeout
        condition is returned.*/
     if (!osalTimeIsInRangeX(osalOsGetSystemTimeX(), start, end)) {
+#if STM32_I2C_USE_DMA^M
       dmaStreamDisable(i2cp->dmarx);
+#endif^M
       return MSG_TIMEOUT;
     }
 
@@ -955,7 +957,9 @@ msg_t i2c_lld_master_receive_timeout(I2CDriver *i2cp, i2caddr_t addr,
   /* Waits for the operation completion or a timeout.*/
   msg = osalThreadSuspendTimeoutS(&i2cp->thread, timeout);
   if (msg != MSG_OK) {
+#if STM32_I2C_USE_DMA^M
     dmaStreamDisable(i2cp->dmarx);
+#endif^M
   }
 
   return msg;
@@ -1041,8 +1045,10 @@ msg_t i2c_lld_master_transmit_timeout(I2CDriver *i2cp, i2caddr_t addr,
     /* If the system time went outside the allowed window then a timeout
        condition is returned.*/
     if (!osalTimeIsInRangeX(osalOsGetSystemTimeX(), start, end)) {
+#if STM32_I2C_USE_DMA^M
       dmaStreamDisable(i2cp->dmatx);
       dmaStreamDisable(i2cp->dmarx);
+#endif^M
       return MSG_TIMEOUT;
     }
 
@@ -1056,8 +1062,10 @@ msg_t i2c_lld_master_transmit_timeout(I2CDriver *i2cp, i2caddr_t addr,
   /* Waits for the operation completion or a timeout.*/
   msg = osalThreadSuspendTimeoutS(&i2cp->thread, timeout);
   if (msg != MSG_OK) {
+#if STM32_I2C_USE_DMA^M
     dmaStreamDisable(i2cp->dmatx);
     dmaStreamDisable(i2cp->dmarx);
+#endif^M
rluchyshyn@rluchyshynHP:~/Src/VVG/chibios_commercial$ git diff os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.c > hal_i2c_lld.patch
rluchyshyn@rluchyshynHP:~/Src/VVG/chibios_commercial$
cat hal_i2c_lld.patch
diff --git a/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.c b/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.c
index 57ee6db..10d29cc 100644
--- a/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.c
+++ b/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.c
@@ -941,7 +941,9 @@ msg_t i2c_lld_master_receive_timeout(I2CDriver *i2cp, i2caddr_t addr,
     /* If the system time went outside the allowed window then a timeout
        condition is returned.*/
     if (!osalTimeIsInRangeX(osalOsGetSystemTimeX(), start, end)) {
+#if STM32_I2C_USE_DMA
       dmaStreamDisable(i2cp->dmarx);
+#endif
       return MSG_TIMEOUT;
     }
 
@@ -955,7 +957,9 @@ msg_t i2c_lld_master_receive_timeout(I2CDriver *i2cp, i2caddr_t addr,
   /* Waits for the operation completion or a timeout.*/
   msg = osalThreadSuspendTimeoutS(&i2cp->thread, timeout);
   if (msg != MSG_OK) {
+#if STM32_I2C_USE_DMA
     dmaStreamDisable(i2cp->dmarx);
+#endif
   }
 
   return msg;
@@ -1041,8 +1045,10 @@ msg_t i2c_lld_master_transmit_timeout(I2CDriver *i2cp, i2caddr_t addr,
     /* If the system time went outside the allowed window then a timeout
        condition is returned.*/
     if (!osalTimeIsInRangeX(osalOsGetSystemTimeX(), start, end)) {
+#if STM32_I2C_USE_DMA
       dmaStreamDisable(i2cp->dmatx);
       dmaStreamDisable(i2cp->dmarx);
+#endif
       return MSG_TIMEOUT;
     }
 
@@ -1056,8 +1062,10 @@ msg_t i2c_lld_master_transmit_timeout(I2CDriver *i2cp, i2caddr_t addr,
   /* Waits for the operation completion or a timeout.*/
   msg = osalThreadSuspendTimeoutS(&i2cp->thread, timeout);
   if (msg != MSG_OK) {
+#if STM32_I2C_USE_DMA
     dmaStreamDisable(i2cp->dmatx);
     dmaStreamDisable(i2cp->dmarx);
+#endif
   }
 
   return msg;
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: I2C on OLIMEX-STM32-LCD (STM32F103ZE)

Post by Giovanni »

Hi,

Moving this to "bug reports".

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

Re: I2C on OLIMEX-STM32-LCD (STM32F103ZE)

Post by Giovanni »

Hi,

In I2Cv1 there is no STM32_I2C_USE_DMA, are we talking about a customized driver?

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

Re: I2C on OLIMEX-STM32-LCD (STM32F103ZE)

Post by Giovanni »

Closing.
Post Reply