Revision db6bd9f8
| modules/NUCLEO-L476RG/board.h | ||
|---|---|---|
| 461 | 461 |
* PB5 - ARD_D4 (analog). |
| 462 | 462 |
* PB6 - ARD_D10 (analog). |
| 463 | 463 |
* PB7 - PIN7 (analog). |
| 464 |
* PB8 - ARD_D15 (analog).
|
|
| 465 |
* PB9 - ARD_D14 (analog).
|
|
| 464 |
* PB8 - ARD_D15 (alternate 4).
|
|
| 465 |
* PB9 - ARD_D14 (alternate 4).
|
|
| 466 | 466 |
* PB10 - ARD_D6 (analog). |
| 467 | 467 |
* PB11 - PIN11 (analog). |
| 468 | 468 |
* PB12 - PIN12 (analog). |
| ... | ... | |
| 478 | 478 |
PIN_MODE_ANALOG(GPIOB_ARD_D4) | \ |
| 479 | 479 |
PIN_MODE_ANALOG(GPIOB_ARD_D10) | \ |
| 480 | 480 |
PIN_MODE_ANALOG(GPIOB_PIN7) | \ |
| 481 |
PIN_MODE_ANALOG(GPIOB_ARD_D15) | \
|
|
| 482 |
PIN_MODE_ANALOG(GPIOB_ARD_D14) | \
|
|
| 481 |
PIN_MODE_ALTERNATE(GPIOB_ARD_D15) | \
|
|
| 482 |
PIN_MODE_ALTERNATE(GPIOB_ARD_D14) | \
|
|
| 483 | 483 |
PIN_MODE_ANALOG(GPIOB_ARD_D6) | \ |
| 484 | 484 |
PIN_MODE_ANALOG(GPIOB_PIN11) | \ |
| 485 | 485 |
PIN_MODE_ANALOG(GPIOB_PIN12) | \ |
| ... | ... | |
| 494 | 494 |
PIN_OTYPE_PUSHPULL(GPIOB_ARD_D4) | \ |
| 495 | 495 |
PIN_OTYPE_PUSHPULL(GPIOB_ARD_D10) | \ |
| 496 | 496 |
PIN_OTYPE_PUSHPULL(GPIOB_PIN7) | \ |
| 497 |
PIN_OTYPE_PUSHPULL(GPIOB_ARD_D15) | \
|
|
| 498 |
PIN_OTYPE_PUSHPULL(GPIOB_ARD_D14) | \
|
|
| 497 |
PIN_OTYPE_OPENDRAIN(GPIOB_ARD_D15) | \
|
|
| 498 |
PIN_OTYPE_OPENDRAIN(GPIOB_ARD_D14) | \
|
|
| 499 | 499 |
PIN_OTYPE_PUSHPULL(GPIOB_ARD_D6) | \ |
| 500 | 500 |
PIN_OTYPE_PUSHPULL(GPIOB_PIN11) | \ |
| 501 | 501 |
PIN_OTYPE_PUSHPULL(GPIOB_PIN12) | \ |
| ... | ... | |
| 558 | 558 |
PIN_AFIO_AF(GPIOB_ARD_D4, 0U) | \ |
| 559 | 559 |
PIN_AFIO_AF(GPIOB_ARD_D10, 0U) | \ |
| 560 | 560 |
PIN_AFIO_AF(GPIOB_PIN7, 0U)) |
| 561 |
#define VAL_GPIOB_AFRH (PIN_AFIO_AF(GPIOB_ARD_D15, 0U) | \
|
|
| 562 |
PIN_AFIO_AF(GPIOB_ARD_D14, 0U) | \
|
|
| 561 |
#define VAL_GPIOB_AFRH (PIN_AFIO_AF(GPIOB_ARD_D15, 4U) | \
|
|
| 562 |
PIN_AFIO_AF(GPIOB_ARD_D14, 4U) | \
|
|
| 563 | 563 |
PIN_AFIO_AF(GPIOB_ARD_D6, 0U) | \ |
| 564 | 564 |
PIN_AFIO_AF(GPIOB_PIN11, 0U) | \ |
| 565 | 565 |
PIN_AFIO_AF(GPIOB_PIN12, 0U) | \ |
| modules/NUCLEO-L476RG/mcuconf.h | ||
|---|---|---|
| 181 | 181 |
/* |
| 182 | 182 |
* I2C driver system settings. |
| 183 | 183 |
*/ |
| 184 |
#define STM32_I2C_USE_I2C1 FALSE
|
|
| 184 |
#define STM32_I2C_USE_I2C1 TRUE
|
|
| 185 | 185 |
#define STM32_I2C_USE_I2C2 FALSE |
| 186 |
#define STM32_I2C_USE_I2C3 TRUE
|
|
| 186 |
#define STM32_I2C_USE_I2C3 FALSE
|
|
| 187 | 187 |
#define STM32_I2C_BUSY_TIMEOUT 50 |
| 188 | 188 |
#define STM32_I2C_I2C1_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 7) |
| 189 | 189 |
#define STM32_I2C_I2C1_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 6) |
| modules/NUCLEO-L476RG/module.c | ||
|---|---|---|
| 49 | 49 |
/* CR1 */ 0, |
| 50 | 50 |
}; |
| 51 | 51 |
|
| 52 |
#if (BOARD_MPU6050_CONNECTED == true) |
|
| 53 |
|
|
| 54 |
I2CConfig moduleHalI2c3Config = {
|
|
| 55 |
/* timing reg */ 0, // configured later in MODULE_INIT_PERIPHERY_IF_MPU6050() hook |
|
| 52 |
I2CConfig moduleHalI2cConfig = {
|
|
| 53 |
/* timing reg */ 0, // configured later in MODULE_INIT_PERIPHERY_IF hook |
|
| 56 | 54 |
/* CR1 */ 0, |
| 57 | 55 |
/* CR2 */ 0, |
| 58 | 56 |
}; |
| 59 | 57 |
|
| 60 |
#endif /* (BOARD_MPU6050_CONNECTED == true) */ |
|
| 61 |
|
|
| 62 | 58 |
/** @} */ |
| 63 | 59 |
|
| 64 | 60 |
/*===========================================================================*/ |
| ... | ... | |
| 140 | 136 |
#if (BOARD_MPU6050_CONNECTED == true) |
| 141 | 137 |
|
| 142 | 138 |
MPU6050Driver moduleLldMpu6050 = {
|
| 143 |
/* I2C Driver */ &MODULE_HAL_I2C3,
|
|
| 139 |
/* I2C Driver */ &MODULE_HAL_I2C, |
|
| 144 | 140 |
/* I²C address */ MPU6050_LLD_I2C_ADDR_FIXED, |
| 145 | 141 |
}; |
| 146 | 142 |
|
| modules/NUCLEO-L476RG/module.h | ||
|---|---|---|
| 64 | 64 |
*/ |
| 65 | 65 |
#define MODULE_HAL_RTC RTCD1 |
| 66 | 66 |
|
| 67 |
#if (BOARD_MPU6050_CONNECTED == true) || defined(__DOXYGEN__) |
|
| 68 |
|
|
| 69 | 67 |
/** |
| 70 |
* @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).
|
|
| 68 |
* @brief Default I2C interface for the NUCLEO I/O.
|
|
| 71 | 69 |
*/ |
| 72 |
#define MODULE_HAL_I2C3 I2CD3
|
|
| 70 |
#define MODULE_HAL_I2C I2CD1
|
|
| 73 | 71 |
|
| 74 | 72 |
/** |
| 75 |
* @brief Configuration for the I2C driver #3.
|
|
| 73 |
* @brief Configuration for the I2C driver #1.
|
|
| 76 | 74 |
*/ |
| 77 |
extern I2CConfig moduleHalI2c3Config; |
|
| 78 |
|
|
| 79 |
#endif /* (BOARD_MPU6050_CONNECTED == true) */ |
|
| 75 |
extern I2CConfig moduleHalI2cConfig; |
|
| 80 | 76 |
|
| 81 | 77 |
/** @} */ |
| 82 | 78 |
|
| ... | ... | |
| 151 | 147 |
#define MODULE_INIT_PERIPHERY_IF() { \
|
| 152 | 148 |
/* serial driver */ \ |
| 153 | 149 |
sdStart(&MODULE_HAL_PROGIF, &moduleHalProgIfConfig); \ |
| 154 |
/* MPU6050 demo */ \ |
|
| 155 |
MODULE_INIT_PERIPHERY_IF_MPU6050(); \ |
|
| 150 |
/* I2C */ \ |
|
| 151 |
uint32_t i2c_freq = 1000000; /* maximum I2C frequency supported for this MCU */ \ |
|
| 152 |
MODULE_INIT_PERIPHERY_IF_MPU6050(i2c_freq); \ |
|
| 153 |
if (i2c_freq == 100000) /* standard-mode @ 100 kHz */ { \
|
|
| 154 |
moduleHalI2cConfig.timingr = 0x10909CEC; /* obtained via STM32CubeMX with STM32_I2CxCLK = 80 MHz */ \ |
|
| 155 |
} else if (i2c_freq == 400000) /* fast-mode @ 400 kHz */ { \
|
|
| 156 |
moduleHalI2cConfig.timingr = 0x00702991; /* obtained via STM32CubeMX with STM32_I2CxCLK = 80 MHz */ \ |
|
| 157 |
} else if (i2c_freq == 1000000) /* fast-mode-plus @ 10000 kHz */ { \
|
|
| 158 |
moduleHalI2cConfig.timingr = 0x00300F33; /* obtained via STM32CubeMX with STM32_I2CxCLK = 80 MHz */ \ |
|
| 159 |
} else { \
|
|
| 160 |
aosDbgAssertMsg(false, "I2C frequency not supported"); \ |
|
| 161 |
} \ |
|
| 162 |
i2cStart(&MODULE_HAL_I2C, &moduleHalI2cConfig); \ |
|
| 156 | 163 |
} |
| 157 | 164 |
#if (BOARD_MPU6050_CONNECTED == true) |
| 158 |
#define MODULE_INIT_PERIPHERY_IF_MPU6050() { \
|
|
| 159 |
/* maximum I2C frequency is 1MHz for this MCU */ \ |
|
| 160 |
uint32_t i2c3_freq = 1000000; \ |
|
| 161 |
/* find minimum amon all devices connected to this bus */ \ |
|
| 162 |
i2c3_freq = (MPU6050_LLD_I2C_MAXFREQUENCY < i2c3_freq) ? MPU6050_LLD_I2C_MAXFREQUENCY : i2c3_freq; \ |
|
| 163 |
/* calculate PRESC (prescaler): \ |
|
| 164 |
* target is 1/(I2CXCLK * (PRESC + 1)) = 125ns \ |
|
| 165 |
*/ \ |
|
| 166 |
moduleHalI2c3Config.timingr = ((uint8_t)((0.000000125f * STM32_I2C3CLK) - 1)) << I2C_TIMINGR_PRESC_Pos; \ |
|
| 167 |
/* SCL shall be low half of the time. */ \ |
|
| 168 |
moduleHalI2c3Config.timingr |= ((uint8_t)((1.f / i2c3_freq / 2 / 0.000000125f) - 1)) << I2C_TIMINGR_SCLL_Pos; \ |
|
| 169 |
/* SCL shall be high half the time of low or slightly longer. */ \ |
|
| 170 |
moduleHalI2c3Config.timingr |= (uint8_t)(ceilf(((moduleHalI2c3Config.timingr & I2C_TIMINGR_SCLL_Msk) >> I2C_TIMINGR_SCLL_Pos) / 2.f)) << I2C_TIMINGR_SCLH_Pos; \ |
|
| 171 |
/* SDA shall be delayed 1/10 of SCL low, or shorter */ \ |
|
| 172 |
moduleHalI2c3Config.timingr |= (uint8_t)(((moduleHalI2c3Config.timingr & I2C_TIMINGR_SCLL_Msk) >> I2C_TIMINGR_SCLL_Pos) * 0.1f) << I2C_TIMINGR_SDADEL_Pos; \ |
|
| 173 |
/* SCL shall be delyed twice as long as SDA, but longer than 0. */ \ |
|
| 174 |
moduleHalI2c3Config.timingr |= ((((moduleHalI2c3Config.timingr & I2C_TIMINGR_SDADEL_Msk) >> I2C_TIMINGR_SDADEL_Pos) * 2) + 1) << I2C_TIMINGR_SCLDEL_Pos; \ |
|
| 175 |
/* now we can start the I2C driver */ \ |
|
| 176 |
chSysLock(); \ |
|
| 177 |
palSetLineMode(LINE_ARD_A4, PAL_MODE_ALTERNATE(4)); \ |
|
| 178 |
palSetLineMode(LINE_ARD_A5, PAL_MODE_ALTERNATE(4)); \ |
|
| 179 |
chSysUnlock(); \ |
|
| 180 |
i2cStart(&MODULE_HAL_I2C3, &moduleHalI2c3Config); \ |
|
| 181 |
} |
|
| 182 |
#else /* (BOARD_MPU6050_CONNECTED == true) */ |
|
| 183 |
#define MODULE_INIT_PERIPHERY_IF_MPU6050() {}
|
|
| 184 |
#endif /* (BOARD_MPU6050_CONNECTED == true) */ |
|
| 165 |
#define MODULE_INIT_PERIPHERY_IF_MPU6050(freq) {freq = (MPU6050_LLD_I2C_MAXFREQUENCY < freq) ? MPU6050_LLD_I2C_MAXFREQUENCY : freq;}
|
|
| 166 |
#else |
|
| 167 |
#define MODULE_INIT_PERIPHERY_IF_MPU6050(freq) {}
|
|
| 168 |
#endif |
|
| 185 | 169 |
|
| 186 | 170 |
/** |
| 187 | 171 |
* @brief Periphery communication interface deinitialization hook. |
| 188 | 172 |
*/ |
| 189 | 173 |
#define MODULE_SHUTDOWN_PERIPHERY_IF() { \
|
| 174 |
/* I2C */ \ |
|
| 175 |
i2cStop(&MODULE_HAL_I2C); \ |
|
| 190 | 176 |
/* don't stop the serial driver so messages can still be printed */ \ |
| 191 | 177 |
} |
| 192 | 178 |
|
| modules/NUCLEO-L476RG/test/MPU6050/module_test_MPU6050.c | ||
|---|---|---|
| 44 | 44 |
/* timeout */ MICROSECONDS_PER_SECOND, |
| 45 | 45 |
}; |
| 46 | 46 |
|
| 47 |
static AOS_TEST(_test, "MPU6050", "Accelerometer & Gyroscope", moduleTestMpu6050ShellCb, aosTestMpu6050Func, &_data); |
|
| 47 |
static AOS_TEST(_test, "MPU-6050", "Accelerometer & Gyroscope", moduleTestMpu6050ShellCb, aosTestMpu6050Func, &_data);
|
|
| 48 | 48 |
|
| 49 | 49 |
/******************************************************************************/ |
| 50 | 50 |
/* LOCAL FUNCTIONS */ |
| periphery-lld/AMiRo-LLD | ||
|---|---|---|
| 1 |
Subproject commit 99ca7610753617020954f4c3abcf72c7ecf63f6a |
|
| 1 |
Subproject commit ed9a1bf53c3145e845296a606332dc10ee72ca76 |
|
| test/periphery-lld/MPU6050_v1/aos_test_MPU6050.c | ||
|---|---|---|
| 47 | 47 |
|
| 48 | 48 |
aos_testresult_t aosTestMpu6050Func(BaseSequentialStream* stream, const aos_test_t* test) |
| 49 | 49 |
{
|
| 50 |
aos_testresult_t result; |
|
| 51 |
|
|
| 52 |
uint8_t data[1] = {0};
|
|
| 53 |
int32_t status; |
|
| 50 |
aos_testresult_t result; |
|
| 51 |
uint8_t data[1] = {0};
|
|
| 52 |
int32_t status; |
|
| 54 | 53 |
|
| 55 | 54 |
aosTestResultInit(&result); |
| 56 | 55 |
|
| 57 |
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); |
|
| 58 |
if (status == APAL_STATUS_OK && data[0] == MPU6050_I_AM) {
|
|
| 59 |
aosTestPassed(stream, &result); |
|
| 60 |
} else {
|
|
| 61 |
aosTestFailedMsg(stream, &result, "0x%08X | 0x%02X\n", status, data[0]); |
|
| 62 |
} |
|
| 56 |
chprintf(stream, "read device name...\n"); |
|
| 57 |
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); |
|
| 58 |
if (status == APAL_STATUS_OK && data[0] == MPU6050_LLD_WHO_AM_I) {
|
|
| 59 |
aosTestPassed(stream, &result); |
|
| 60 |
} else {
|
|
| 61 |
aosTestFailedMsg(stream, &result, "0x%08X | 0x%02X\n", status, data[0]); |
|
| 62 |
} |
|
| 63 | 63 |
|
| 64 | 64 |
return result; |
| 65 | 65 |
} |
Also available in: Unified diff