commit db6bd9f855ec7e35156e021297f6dfa9c1c1be8f
Author: Thomas Schöpping <tschoepp@cit-ec.uni-bielefeld.de>
Date:   Tue Jun 23 16:58:50 2020 +0200

    AMiRo-LLD updated and MPU-6050 test reworked (for NUCLEO-L476RG module).

diff --git a/modules/NUCLEO-L476RG/board.h b/modules/NUCLEO-L476RG/board.h
index b3f88bd..e8bafe6 100644
--- a/modules/NUCLEO-L476RG/board.h
+++ b/modules/NUCLEO-L476RG/board.h
@@ -461,8 +461,8 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
  * PB5  - ARD_D4                    (analog).
  * PB6  - ARD_D10                   (analog).
  * PB7  - PIN7                      (analog).
- * PB8  - ARD_D15                   (analog).
- * PB9  - ARD_D14                   (analog).
+ * PB8  - ARD_D15                   (alternate 4).
+ * PB9  - ARD_D14                   (alternate 4).
  * PB10 - ARD_D6                    (analog).
  * PB11 - PIN11                     (analog).
  * PB12 - PIN12                     (analog).
@@ -478,8 +478,8 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
                                      PIN_MODE_ANALOG(GPIOB_ARD_D4) |        \
                                      PIN_MODE_ANALOG(GPIOB_ARD_D10) |       \
                                      PIN_MODE_ANALOG(GPIOB_PIN7) |          \
-                                     PIN_MODE_ANALOG(GPIOB_ARD_D15) |       \
-                                     PIN_MODE_ANALOG(GPIOB_ARD_D14) |       \
+                                     PIN_MODE_ALTERNATE(GPIOB_ARD_D15) |    \
+                                     PIN_MODE_ALTERNATE(GPIOB_ARD_D14) |    \
                                      PIN_MODE_ANALOG(GPIOB_ARD_D6) |        \
                                      PIN_MODE_ANALOG(GPIOB_PIN11) |         \
                                      PIN_MODE_ANALOG(GPIOB_PIN12) |         \
@@ -494,8 +494,8 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
                                      PIN_OTYPE_PUSHPULL(GPIOB_ARD_D4) |     \
                                      PIN_OTYPE_PUSHPULL(GPIOB_ARD_D10) |    \
                                      PIN_OTYPE_PUSHPULL(GPIOB_PIN7) |       \
-                                     PIN_OTYPE_PUSHPULL(GPIOB_ARD_D15) |    \
-                                     PIN_OTYPE_PUSHPULL(GPIOB_ARD_D14) |    \
+                                     PIN_OTYPE_OPENDRAIN(GPIOB_ARD_D15) |   \
+                                     PIN_OTYPE_OPENDRAIN(GPIOB_ARD_D14) |   \
                                      PIN_OTYPE_PUSHPULL(GPIOB_ARD_D6) |     \
                                      PIN_OTYPE_PUSHPULL(GPIOB_PIN11) |      \
                                      PIN_OTYPE_PUSHPULL(GPIOB_PIN12) |      \
@@ -558,8 +558,8 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
                                      PIN_AFIO_AF(GPIOB_ARD_D4, 0U) |        \
                                      PIN_AFIO_AF(GPIOB_ARD_D10, 0U) |       \
                                      PIN_AFIO_AF(GPIOB_PIN7, 0U))
-#define VAL_GPIOB_AFRH              (PIN_AFIO_AF(GPIOB_ARD_D15, 0U) |       \
-                                     PIN_AFIO_AF(GPIOB_ARD_D14, 0U) |       \
+#define VAL_GPIOB_AFRH              (PIN_AFIO_AF(GPIOB_ARD_D15, 4U) |       \
+                                     PIN_AFIO_AF(GPIOB_ARD_D14, 4U) |       \
                                      PIN_AFIO_AF(GPIOB_ARD_D6, 0U) |        \
                                      PIN_AFIO_AF(GPIOB_PIN11, 0U) |         \
                                      PIN_AFIO_AF(GPIOB_PIN12, 0U) |         \
diff --git a/modules/NUCLEO-L476RG/mcuconf.h b/modules/NUCLEO-L476RG/mcuconf.h
index 582ca31..07a9331 100644
--- a/modules/NUCLEO-L476RG/mcuconf.h
+++ b/modules/NUCLEO-L476RG/mcuconf.h
@@ -181,9 +181,9 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 /*
  * I2C driver system settings.
  */
-#define STM32_I2C_USE_I2C1                  FALSE
+#define STM32_I2C_USE_I2C1                  TRUE
 #define STM32_I2C_USE_I2C2                  FALSE
-#define STM32_I2C_USE_I2C3                  TRUE
+#define STM32_I2C_USE_I2C3                  FALSE
 #define STM32_I2C_BUSY_TIMEOUT              50
 #define STM32_I2C_I2C1_RX_DMA_STREAM        STM32_DMA_STREAM_ID(1, 7)
 #define STM32_I2C_I2C1_TX_DMA_STREAM        STM32_DMA_STREAM_ID(1, 6)
diff --git a/modules/NUCLEO-L476RG/module.c b/modules/NUCLEO-L476RG/module.c
index 8b9dff8..d503465 100644
--- a/modules/NUCLEO-L476RG/module.c
+++ b/modules/NUCLEO-L476RG/module.c
@@ -49,16 +49,12 @@ SerialConfig moduleHalProgIfConfig = {
   /* CR1      */ 0,
 };
 
-#if (BOARD_MPU6050_CONNECTED == true)
-
-I2CConfig moduleHalI2c3Config = {
-  /* timing reg */ 0, // configured later in MODULE_INIT_PERIPHERY_IF_MPU6050() hook
+I2CConfig moduleHalI2cConfig = {
+  /* timing reg */ 0, // configured later in MODULE_INIT_PERIPHERY_IF hook
   /* CR1        */ 0,
   /* CR2        */ 0,
 };
 
-#endif /* (BOARD_MPU6050_CONNECTED == true) */
-
 /** @} */
 
 /*===========================================================================*/
@@ -140,7 +136,7 @@ ButtonDriver moduleLldUserButton = {
 #if (BOARD_MPU6050_CONNECTED == true)
 
 MPU6050Driver moduleLldMpu6050 = {
-  /* I2C Driver       */ &MODULE_HAL_I2C3,
+  /* I2C Driver       */ &MODULE_HAL_I2C,
   /* I²C address      */ MPU6050_LLD_I2C_ADDR_FIXED,
 };
 
diff --git a/modules/NUCLEO-L476RG/module.h b/modules/NUCLEO-L476RG/module.h
index 52e891b..e53d27d 100644
--- a/modules/NUCLEO-L476RG/module.h
+++ b/modules/NUCLEO-L476RG/module.h
@@ -64,19 +64,15 @@ extern SerialConfig moduleHalProgIfConfig;
  */
 #define MODULE_HAL_RTC                          RTCD1
 
-#if (BOARD_MPU6050_CONNECTED == true) || defined(__DOXYGEN__)
-
 /**
- * @brief   I2C driver to access multiplexer, proximity sensors 5 to 8, power monitors for VSYS4.2, VIO 5.0 and VDD, EEPROM, touch sensor, and fuel gauge (front battery).
+ * @brief   Default I2C interface for the NUCLEO I/O.
  */
-#define MODULE_HAL_I2C3                         I2CD3
+#define MODULE_HAL_I2C                          I2CD1
 
 /**
- * @brief   Configuration for the I2C driver #3.
+ * @brief   Configuration for the I2C driver #1.
  */
-extern I2CConfig moduleHalI2c3Config;
-
-#endif /* (BOARD_MPU6050_CONNECTED == true) */
+extern I2CConfig moduleHalI2cConfig;
 
 /** @} */
 
@@ -151,42 +147,32 @@ extern ROMCONST char* moduleShellPrompt;
 #define MODULE_INIT_PERIPHERY_IF() {                                          \
   /* serial driver */                                                         \
   sdStart(&MODULE_HAL_PROGIF, &moduleHalProgIfConfig);                        \
-  /* MPU6050 demo */                                                          \
-  MODULE_INIT_PERIPHERY_IF_MPU6050();                                         \
+  /* I2C */                                                                   \
+  uint32_t i2c_freq = 1000000; /* maximum I2C frequency supported for this MCU */ \
+  MODULE_INIT_PERIPHERY_IF_MPU6050(i2c_freq);                                 \
+  if (i2c_freq == 100000) /* standard-mode @ 100 kHz */ {                     \
+    moduleHalI2cConfig.timingr = 0x10909CEC; /* obtained via STM32CubeMX with STM32_I2CxCLK = 80 MHz */ \
+  } else if (i2c_freq == 400000) /* fast-mode @ 400 kHz */ {                  \
+    moduleHalI2cConfig.timingr = 0x00702991; /* obtained via STM32CubeMX with STM32_I2CxCLK = 80 MHz */ \
+  } else if (i2c_freq == 1000000) /* fast-mode-plus @ 10000 kHz */ {          \
+    moduleHalI2cConfig.timingr = 0x00300F33; /* obtained via STM32CubeMX with STM32_I2CxCLK = 80 MHz */ \
+  } else {                                                                    \
+    aosDbgAssertMsg(false, "I2C frequency not supported");                    \
+  }                                                                           \
+  i2cStart(&MODULE_HAL_I2C, &moduleHalI2cConfig);                             \
 }
 #if (BOARD_MPU6050_CONNECTED == true)
-  #define MODULE_INIT_PERIPHERY_IF_MPU6050() {                                \
-    /* maximum I2C frequency is 1MHz for this MCU */                          \
-    uint32_t i2c3_freq = 1000000;                                             \
-    /* find minimum amon all devices connected to this bus */                 \
-    i2c3_freq = (MPU6050_LLD_I2C_MAXFREQUENCY < i2c3_freq) ? MPU6050_LLD_I2C_MAXFREQUENCY : i2c3_freq;  \
-    /* calculate PRESC (prescaler):                                           \
-     *   target is 1/(I2CXCLK * (PRESC + 1)) = 125ns                          \
-     */                                                                       \
-    moduleHalI2c3Config.timingr = ((uint8_t)((0.000000125f * STM32_I2C3CLK) - 1)) << I2C_TIMINGR_PRESC_Pos; \
-    /* SCL shall be low half of the time. */                                  \
-    moduleHalI2c3Config.timingr |= ((uint8_t)((1.f / i2c3_freq / 2 / 0.000000125f) - 1)) << I2C_TIMINGR_SCLL_Pos; \
-    /* SCL shall be high half the time of low or slightly longer. */          \
-    moduleHalI2c3Config.timingr |= (uint8_t)(ceilf(((moduleHalI2c3Config.timingr & I2C_TIMINGR_SCLL_Msk) >> I2C_TIMINGR_SCLL_Pos) / 2.f)) << I2C_TIMINGR_SCLH_Pos;  \
-    /* SDA shall be delayed 1/10 of SCL low, or shorter */                    \
-    moduleHalI2c3Config.timingr |= (uint8_t)(((moduleHalI2c3Config.timingr & I2C_TIMINGR_SCLL_Msk) >> I2C_TIMINGR_SCLL_Pos) * 0.1f) << I2C_TIMINGR_SDADEL_Pos;  \
-    /* SCL shall be delyed twice as long as SDA, but longer than 0. */        \
-    moduleHalI2c3Config.timingr |= ((((moduleHalI2c3Config.timingr & I2C_TIMINGR_SDADEL_Msk) >> I2C_TIMINGR_SDADEL_Pos) * 2) + 1) << I2C_TIMINGR_SCLDEL_Pos;  \
-    /* now we can start the I2C driver */                                     \
-    chSysLock();                                                              \
-    palSetLineMode(LINE_ARD_A4, PAL_MODE_ALTERNATE(4));                       \
-    palSetLineMode(LINE_ARD_A5, PAL_MODE_ALTERNATE(4));                       \
-    chSysUnlock();                                                            \
-    i2cStart(&MODULE_HAL_I2C3, &moduleHalI2c3Config);                         \
-  }
-#else /* (BOARD_MPU6050_CONNECTED == true) */
-  #define MODULE_INIT_PERIPHERY_IF_MPU6050() {}
-#endif /* (BOARD_MPU6050_CONNECTED == true) */
+  #define MODULE_INIT_PERIPHERY_IF_MPU6050(freq) {freq = (MPU6050_LLD_I2C_MAXFREQUENCY < freq) ? MPU6050_LLD_I2C_MAXFREQUENCY : freq;}
+#else
+  #define MODULE_INIT_PERIPHERY_IF_MPU6050(freq) {}
+#endif
 
 /**
  * @brief   Periphery communication interface deinitialization hook.
  */
 #define MODULE_SHUTDOWN_PERIPHERY_IF() {                                      \
+  /* I2C */                                                                   \
+  i2cStop(&MODULE_HAL_I2C);                                                   \
   /* don't stop the serial driver so messages can still be printed */         \
 }
 
diff --git a/modules/NUCLEO-L476RG/test/MPU6050/module_test_MPU6050.c b/modules/NUCLEO-L476RG/test/MPU6050/module_test_MPU6050.c
index 950bdca..ba7ad72 100644
--- a/modules/NUCLEO-L476RG/test/MPU6050/module_test_MPU6050.c
+++ b/modules/NUCLEO-L476RG/test/MPU6050/module_test_MPU6050.c
@@ -44,7 +44,7 @@ static aos_test_mpu6050data_t _data = {
   /* timeout  */ MICROSECONDS_PER_SECOND,
 };
 
-static AOS_TEST(_test, "MPU6050", "Accelerometer & Gyroscope", moduleTestMpu6050ShellCb, aosTestMpu6050Func, &_data);
+static AOS_TEST(_test, "MPU-6050", "Accelerometer & Gyroscope", moduleTestMpu6050ShellCb, aosTestMpu6050Func, &_data);
 
 /******************************************************************************/
 /* LOCAL FUNCTIONS                                                            */
diff --git a/periphery-lld/AMiRo-LLD b/periphery-lld/AMiRo-LLD
index 99ca761..ed9a1bf 160000
--- a/periphery-lld/AMiRo-LLD
+++ b/periphery-lld/AMiRo-LLD
@@ -1 +1 @@
-Subproject commit 99ca7610753617020954f4c3abcf72c7ecf63f6a
+Subproject commit ed9a1bf53c3145e845296a606332dc10ee72ca76
diff --git a/test/periphery-lld/MPU6050_v1/aos_test_MPU6050.c b/test/periphery-lld/MPU6050_v1/aos_test_MPU6050.c
index 443b769..3a0bffd 100644
--- a/test/periphery-lld/MPU6050_v1/aos_test_MPU6050.c
+++ b/test/periphery-lld/MPU6050_v1/aos_test_MPU6050.c
@@ -47,19 +47,19 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 aos_testresult_t aosTestMpu6050Func(BaseSequentialStream* stream, const aos_test_t* test)
 {
-    aos_testresult_t result;
-
-    uint8_t data[1] = {0};
-    int32_t status;
+  aos_testresult_t result;
+  uint8_t data[1] = {0};
+  int32_t status;
 
   aosTestResultInit(&result);
 
-    status = mpu6050_lld_read_register(((aos_test_mpu6050data_t*)test->data)->mpu, MPU6050_LLD_WHO_AM_I, data, 1, ((aos_test_mpu6050data_t*)test->data)->timeout);
-    if (status == APAL_STATUS_OK && data[0] == MPU6050_I_AM) {
-      aosTestPassed(stream, &result);
-    } else {
-      aosTestFailedMsg(stream, &result, "0x%08X | 0x%02X\n", status, data[0]);
-    }
+  chprintf(stream, "read device name...\n");
+  status = mpu6050_lld_read_register(((aos_test_mpu6050data_t*)test->data)->mpu, MPU6050_LLD_REGISTER_WHO_AM_I, data, 1, ((aos_test_mpu6050data_t*)test->data)->timeout);
+  if (status == APAL_STATUS_OK && data[0] == MPU6050_LLD_WHO_AM_I) {
+    aosTestPassed(stream, &result);
+  } else {
+    aosTestFailedMsg(stream, &result, "0x%08X | 0x%02X\n", status, data[0]);
+  }
 
   return result;
 }
