diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/board.h b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/board.h index 352dd0a461..bd9d57c3c0 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/board.h +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/board.h @@ -335,12 +335,12 @@ PIN_PUPDR_FLOATING(GPIOA_AN4) | \ PIN_PUPDR_FLOATING(GPIOA_AN1) | \ PIN_PUPDR_FLOATING(GPIOA_AN3) | \ - PIN_PUPDR_FLOATING(GPIOA_FLASH_HOLD) | \ + PIN_PUPDR_PULLDOWN(GPIOA_FLASH_HOLD) | \ PIN_PUPDR_FLOATING(GPIOA_TX4) | \ PIN_PUPDR_FLOATING(GPIOA_RX4) | \ PIN_PUPDR_FLOATING(GPIOA_OTG_FS_DM) | \ PIN_PUPDR_FLOATING(GPIOA_OTG_FS_DP) | \ - PIN_PUPDR_PULLDOWN(GPIOA_FLASH_CS) | \ + PIN_PUPDR_FLOATING(GPIOA_FLASH_CS) | \ PIN_PUPDR_FLOATING(GPIOA_INT4) | \ PIN_PUPDR_FLOATING(GPIOA_GPIO1)) #define VAL_GPIOA_ODR (PIN_ODR_LOW(GPIOA_PA0) | \ @@ -351,12 +351,12 @@ PIN_ODR_LOW(GPIOA_AN4) | \ PIN_ODR_LOW(GPIOA_AN1) | \ PIN_ODR_LOW(GPIOA_AN3) | \ - PIN_ODR_HIGH(GPIOA_FLASH_HOLD) | \ + PIN_ODR_LOW(GPIOA_FLASH_HOLD) | \ PIN_ODR_LOW(GPIOA_TX4) | \ PIN_ODR_LOW(GPIOA_RX4) | \ PIN_ODR_HIGH(GPIOA_OTG_FS_DM) | \ PIN_ODR_HIGH(GPIOA_OTG_FS_DP) | \ - PIN_ODR_LOW(GPIOA_FLASH_CS) | \ + PIN_ODR_HIGH(GPIOA_FLASH_CS) | \ PIN_ODR_LOW(GPIOA_INT4) | \ PIN_ODR_LOW(GPIOA_GPIO1)) #define VAL_GPIOA_AFRL (PIN_AFIO_AF(GPIOA_PA0, 0U) | \ diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO144_F746ZG/board.h b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO144_F746ZG/board.h index aa8c93835c..12c40e93c8 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO144_F746ZG/board.h +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO144_F746ZG/board.h @@ -678,8 +678,8 @@ PIN_MODE_INPUT(GPIOB_ZIO_D22) | \ PIN_MODE_INPUT(GPIOB_ZIO_D26) | \ PIN_MODE_OUTPUT(GPIOB_LED2) | \ - PIN_MODE_INPUT(GPIOB_ARD_D15) | \ - PIN_MODE_INPUT(GPIOB_ARD_D14) | \ + PIN_MODE_ALTERNATE(GPIOB_I2C1_SCL) | \ + PIN_MODE_ALTERNATE(GPIOB_I2C1_SDA) | \ PIN_MODE_INPUT(GPIOB_ZIO_D36) | \ PIN_MODE_INPUT(GPIOB_ZIO_D35) | \ PIN_MODE_INPUT(GPIOB_ZIO_D19) | \ @@ -694,8 +694,8 @@ PIN_OTYPE_PUSHPULL(GPIOB_ZIO_D22) | \ PIN_OTYPE_PUSHPULL(GPIOB_ZIO_D26) | \ PIN_OTYPE_PUSHPULL(GPIOB_LED2) | \ - PIN_OTYPE_PUSHPULL(GPIOB_ARD_D15) | \ - PIN_OTYPE_PUSHPULL(GPIOB_ARD_D14) | \ + PIN_OTYPE_OPENDRAIN(GPIOB_I2C1_SCL) | \ + PIN_OTYPE_OPENDRAIN(GPIOB_I2C1_SDA) | \ PIN_OTYPE_PUSHPULL(GPIOB_ZIO_D36) | \ PIN_OTYPE_PUSHPULL(GPIOB_ZIO_D35) | \ PIN_OTYPE_PUSHPULL(GPIOB_ZIO_D19) | \ @@ -710,8 +710,8 @@ PIN_OSPEED_HIGH(GPIOB_ZIO_D22) | \ PIN_OSPEED_HIGH(GPIOB_ZIO_D26) | \ PIN_OSPEED_HIGH(GPIOB_LED2) | \ - PIN_OSPEED_HIGH(GPIOB_ARD_D15) | \ - PIN_OSPEED_HIGH(GPIOB_ARD_D14) | \ + PIN_OSPEED_HIGH(GPIOB_I2C1_SCL) | \ + PIN_OSPEED_HIGH(GPIOB_I2C1_SDA) | \ PIN_OSPEED_HIGH(GPIOB_ZIO_D36) | \ PIN_OSPEED_HIGH(GPIOB_ZIO_D35) | \ PIN_OSPEED_HIGH(GPIOB_ZIO_D19) | \ @@ -726,8 +726,8 @@ PIN_PUPDR_PULLUP(GPIOB_ZIO_D22) | \ PIN_PUPDR_PULLUP(GPIOB_ZIO_D26) | \ PIN_PUPDR_FLOATING(GPIOB_LED2) | \ - PIN_PUPDR_PULLUP(GPIOB_ARD_D15) | \ - PIN_PUPDR_PULLUP(GPIOB_ARD_D14) | \ + PIN_PUPDR_FLOATING(GPIOB_I2C1_SCL) | \ + PIN_PUPDR_FLOATING(GPIOB_I2C1_SDA) | \ PIN_PUPDR_PULLUP(GPIOB_ZIO_D36) | \ PIN_PUPDR_PULLUP(GPIOB_ZIO_D35) | \ PIN_PUPDR_PULLUP(GPIOB_ZIO_D19) | \ @@ -742,8 +742,8 @@ PIN_ODR_HIGH(GPIOB_ZIO_D22) | \ PIN_ODR_HIGH(GPIOB_ZIO_D26) | \ PIN_ODR_LOW(GPIOB_LED2) | \ - PIN_ODR_HIGH(GPIOB_ARD_D15) | \ - PIN_ODR_HIGH(GPIOB_ARD_D14) | \ + PIN_ODR_LOW(GPIOB_I2C1_SCL) | \ + PIN_ODR_LOW(GPIOB_I2C1_SDA) | \ PIN_ODR_HIGH(GPIOB_ZIO_D36) | \ PIN_ODR_HIGH(GPIOB_ZIO_D35) | \ PIN_ODR_HIGH(GPIOB_ZIO_D19) | \ @@ -758,8 +758,8 @@ PIN_AFIO_AF(GPIOB_ZIO_D22, 0U) | \ PIN_AFIO_AF(GPIOB_ZIO_D26, 0U) | \ PIN_AFIO_AF(GPIOB_LED2, 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_I2C1_SCL, 4U) | \ + PIN_AFIO_AF(GPIOB_I2C1_SDA, 4U) | \ PIN_AFIO_AF(GPIOB_ZIO_D36, 0U) | \ PIN_AFIO_AF(GPIOB_ZIO_D35, 0U) | \ PIN_AFIO_AF(GPIOB_ZIO_D19, 0U) | \ diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO144_F746ZG/nanoCLR/mcuconf.h b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO144_F746ZG/nanoCLR/mcuconf.h index b04c01bbaf..f15910f965 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO144_F746ZG/nanoCLR/mcuconf.h +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO144_F746ZG/nanoCLR/mcuconf.h @@ -81,7 +81,7 @@ #define STM32_CK48MSEL STM32_CK48MSEL_PLL #define STM32_SDMMCSEL STM32_SDMMCSEL_SYSCLK #define STM32_SRAM2_NOCACHE FALSE - + /* * ADC driver system settings. */ @@ -172,8 +172,8 @@ /* * I2C driver system settings. */ -#define STM32_I2C_USE_I2C1 FALSE -#define STM32_I2C_USE_I2C2 FALSE +#define STM32_I2C_USE_I2C1 TRUE +#define STM32_I2C_USE_I2C2 TRUE #define STM32_I2C_USE_I2C3 FALSE #define STM32_I2C_USE_I2C4 FALSE #define STM32_I2C_BUSY_TIMEOUT 50 diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_Windows_Devices_I2C_I2cDevice.cpp b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_Windows_Devices_I2C_I2cDevice.cpp index 41ebb1d656..6e1233b663 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_Windows_Devices_I2C_I2cDevice.cpp +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_Windows_Devices_I2C_I2cDevice.cpp @@ -1,14 +1,7 @@ -//----------------------------------------------------------------------------- // -// ** WARNING! ** -// This file was generated automatically by a tool. -// Re-running the tool will overwrite this file. -// You should copy this file to a custom location -// before adding any customization in the copy to -// prevent loss of your changes when the tool is -// re-run. +// Copyright (c) 2017 The nanoFramework project contributors +// See LICENSE file in the project root for full license information. // -//----------------------------------------------------------------------------- #include #include @@ -71,6 +64,10 @@ nfI2CConfig Library_win_dev_i2c_native_Windows_Devices_I2c_I2cDevice::GetConfig( #if STM32_I2C_USE_I2C3 case 3 : _drv = &I2CD3; break; +#endif +#if STM32_I2C_USE_I2C4 + case 4 : _drv = &I2CD4; + break; #endif } @@ -78,9 +75,19 @@ nfI2CConfig Library_win_dev_i2c_native_Windows_Devices_I2c_I2cDevice::GetConfig( nfI2CConfig cfg = { { +#ifdef STM32F4xx_MCUCONF OPMODE_I2C, busSpeed == I2cBusSpeed_StandardMode ? 100000U : 400000U, busSpeed == I2cBusSpeed_StandardMode ? STD_DUTY_CYCLE : FAST_DUTY_CYCLE_2 +#endif +#ifdef STM32F7xx_MCUCONF + // Standard mode : 100 KHz, Rise time 120 ns, Fall time 25 ns, 54MHz clock source + // Fast mode : 400 KHz, Rise time 120 ns, Fall time 25 ns, 54MHz clock source + // Timing register value calculated by STM32 CubeMx + busSpeed == I2cBusSpeed_StandardMode ? 0x80201721 : 0x00B01B59, + 0, + 0 +#endif }, _drv, (uint16_t)slaveAddress @@ -122,7 +129,7 @@ HRESULT Library_win_dev_i2c_native_Windows_Devices_I2c_I2cDevice::NativeTransmit // get bus index // this is coded with a multiplication, need to perform and int division to get the number // see the comments in the SpiDevice() constructor in managed code for details - uint8_t bus = (uint8_t)(pThis[ FIELD___i2cBus ].NumericByRef().s4 / 1000); + uint8_t bus = (uint8_t)(pThis[ FIELD___deviceId ].NumericByRef().s4 / 1000); // Get a complete low-level SPI configuration, depending on user's managed parameters nfI2CConfig cfg = GetConfig(bus, pThis[ FIELD___connectionSettings ].Dereference()); @@ -167,14 +174,12 @@ HRESULT Library_win_dev_i2c_native_Windows_Devices_I2c_I2cDevice::NativeTransmit } } i2cReleaseBus(cfg.Driver); - i2cStop(cfg.Driver); - returnStatus = I2cTransferStatus_FullTransfer; if (i2cStatus != MSG_OK) { int errorMask = i2cGetErrors(cfg.Driver); - //TODO: return correct error + //TODO: return correct error status regarding UWP API returnStatus = I2cTransferStatus_UnknownError; } @@ -194,8 +199,8 @@ HRESULT Library_win_dev_i2c_native_Windows_Devices_I2c_I2cDevice::GetDeviceSelec { NANOCLR_HEADER(); { - // declare the device selector string whose max size is "I2C1,I2C2,I2C3," + terminator and init with the terminator - char deviceSelectorString[ 15 + 1] = { 0 }; + // declare the device selector string whose max size is "I2C1,I2C2,I2C3,I2C4," + terminator and init with the terminator + char deviceSelectorString[ 20 + 1] = { 0 }; #if STM32_I2C_USE_I2C1 strcat(deviceSelectorString, "I2C1,"); @@ -206,7 +211,9 @@ HRESULT Library_win_dev_i2c_native_Windows_Devices_I2c_I2cDevice::GetDeviceSelec #if STM32_I2C_USE_I2C3 strcat(deviceSelectorString, "I2C3,"); #endif - + #if STM32_I2C_USE_I2C4 + strcat(deviceSelectorString, "I2C4,"); + #endif // replace the last comma with a terminator deviceSelectorString[hal_strlen_s(deviceSelectorString) - 1] = '\0';