1.. zephyr:code-sample:: stm32_i2c_v2_timings 2 :name: I2C V2 timings 3 :relevant-api: i2c_interface 4 5 Retrieve I2C V2 timings at runtime. 6 7Overview 8******** 9This sample simply demonstrate the **get_config** API of the stm32 I2C driver. 10The I2C peripheral configuration is checked regarding the I2C bitrate which can be: 11 12 - <I2C_BITRATE_FAST_STANDARD> 13 - <I2C_BITRATE_FAST> 14 - <I2C_BITRATE_FAST_PLUS> 15 16 17In case of the I2C V2, the I2C peripheral of the STM32 microcontrollers have 18a TIMING register to write in order to generate the correct I2C clock signal. 19This value depends on the peripheral clock input and the I2C speed. 20The calculation of that TIMING value can be given by the `STM32CubeMX`_ application 21**or** by the present sample. 22 23Because the code sequence to calculate the I2C V2 TIMING value is heavy, 24it is not advised to enable it in production binary. 25By enabling CONFIG_I2C_STM32_V2_TIMING flag, this sample allows to 26retrieve timing register configuration for the defined ``clock-frequency``. 27User can then configure timing in his application by adapting the following dts 28snippet with the output of this sample: 29 30 31 .. code-block:: c 32 33 &i2c { 34 timings = <160000000 I2C_BITRATE_STANDARD 0xB0C03E40>, 35 <160000000 I2C_BITRATE_FAST 0xC041090F>, 36 <160000000 I2C_BITRATE_FAST_PLUS 0x6021050A>; 37 } 38 39 40Building and Running 41******************** 42 43In order to run this sample, make sure to 44 45- enable ``i2c`` node in your board DT file. 46- enable the CONFIG_I2C_STM32_V2_TIMING=y in the board **conf** file 47- alias the **i2c-0** to your ``i2c`` node of the board **overlay** file 48 49 .. zephyr-app-commands:: 50 :zephyr-app: samples/boards/st/i2c_timing 51 :board: b_u585i_iot02a 52 :goals: build 53 :compact: 54 55Sample Output 56============= 57When setting the b_u585i_iot02a.overlay to 58 59 .. code-block:: c 60 61 / { 62 aliases { 63 i2c-0 = &i2c2; 64 }; 65 }; 66 &i2c2 { 67 /delete-property/ clock-frequency; 68 clock-frequency = <I2C_BITRATE_FAST>; 69 }; 70 71The sample gives the corresponding TIMING value to report to the Device Tree: 72 73.. code-block:: console 74 75 I2C timing value, report to the DTS : 76 timings = <160000000 I2C_BITRATE_FAST 0xC041090F>; 77 78 I2C config : I2C_BITRATE_FAST 79 80 81.. _STM32CubeMX: 82 https://www.st.com/en/development-tools/stm32cubemx.html 83