Page 2 of 2

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

Posted: Thu Mar 18, 2021 12:30 pm
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

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

Posted: Thu Mar 18, 2021 1:35 pm
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;

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

Posted: Thu Mar 18, 2021 1:37 pm
by Giovanni
Hi,

Moving this to "bug reports".

Giovanni

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

Posted: Sat Apr 09, 2022 9:11 am
by Giovanni
Hi,

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

Giovanni

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

Posted: Tue Apr 26, 2022 9:29 am
by Giovanni
Closing.