Skip to content

driver/i2c: STM32: I2C memory usage and time delay in read-write solved. #14776

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 29, 2021

Conversation

affrinpinhero-2356
Copy link
Contributor

Summary of changes

This PR solves I2C Read Write Take long time and excess usage of RAM. Modified
i2c_device drivers to help user to enable disable I2C timing algorithm. Algorithm Disable
and enable can done using target.json.

Impact of changes

Migration actions required

Documentation


Pull request type

[x] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[] No Tests required for this change (E.g docs only update)
x[] Covered by existing mbed-os tests (Greentea or Unittest)
[] Tests / results supplied as part of this PR

Reviewers


Modified i2c_device.h file. This will solve I2C read
write long time issue. Updated default I2C peripheral clock
value to 160MHz.

fix:
ARMmbed#14732

Signed-off-by: Affrin Pinhero <[email protected]>
@ciarmcom ciarmcom added the release-type: patch Indentifies a PR as containing just a patch label Jun 15, 2021
@ciarmcom ciarmcom requested a review from a team June 15, 2021 10:00
@ciarmcom
Copy link
Member

@affrinpinhero-2356, thank you for your changes.
@ARMmbed/mbed-os-maintainers please review.

Copy link
Collaborator

@jeromecoutant jeromecoutant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this fix #14732 ?

@pilotak

},
"i2c_timing_value_algo": {
"help": "If value was set I2C timing algorithm is enabled. Enabling may leads to performance issue. Keeping this false and changing system clock will cause compilation error)",
"value": true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this value is true ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No missed after testing. changed to false

Copy link
Collaborator

@jeromecoutant jeromecoutant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I2C test is crashing with F072 Nucleo board :-(

@affrinpinhero-2356
Copy link
Contributor Author

affrinpinhero-2356 commented Jun 15, 2021

I2C test is crashing with F072 Nucleo board :-(

okay. Let me run once again. Is there any specific error code that to check?

@jeromecoutant
Copy link
Collaborator

I2C test is crashing with F072 Nucleo board :-(

I checked the issue:

  • i2c_get_timing is called quite at the beginning of i2c_frequency
  • at this time, I2C clock source is not set, so value is 0 which is HSI which is not I2C_PCLK_DEF ==> crash
  • then __HAL_RCC_I2C1_CONFIG(I2CAPI_I2C1_CLKSRC);
  • all next i2c_get_timing call is OK

@affrinpinhero-2356
Copy link
Contributor Author

I2C test is crashing with F072 Nucleo board :-(

I checked the issue:

  • i2c_get_timing is called quite at the beginning of i2c_frequency
  • at this time, I2C clock source is not set, so value is 0 which is HSI which is not I2C_PCLK_DEF ==> crash
  • then __HAL_RCC_I2C1_CONFIG(I2CAPI_I2C1_CLKSRC);
  • all next i2c_get_timing call is OK
    That is strange. If that was the case we cant initialize the value in JSON as false.

Comment on lines 656 to 660
/* Only predefined timing for below frequencies are supported */
MBED_ASSERT((hz == 100000) || (hz == 400000) || (hz == 1000000));
/* Calculates I2C timing value with respect to I2C input clock and I2C bus frequency */
handle->Init.Timing = i2c_get_timing(obj_s->i2c, hz);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope this will solve.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You forgot #ifdef I2C_IP_VERSION_V2

Comment on lines 656 to 660
/* Only predefined timing for below frequencies are supported */
MBED_ASSERT((hz == 100000) || (hz == 400000) || (hz == 1000000));
/* Calculates I2C timing value with respect to I2C input clock and I2C bus frequency */
handle->Init.Timing = i2c_get_timing(obj_s->i2c, hz);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You forgot #ifdef I2C_IP_VERSION_V2

break;
true break;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be an error, the "true" here should not be there, I guess

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

solved.

@affrinpinhero-2356 affrinpinhero-2356 requested review from jeromecoutant and removed request for a team June 16, 2021 08:21
@pilotak
Copy link
Contributor

pilotak commented Jun 16, 2021

Maybe i do something wrong when I compile it for NUCLEO_F091RC i get following error from debug console. I don't actually run it on nucleo but custom board in which case internal clock is used. I also did a test for custom board with external crystal setting - the result is the same

In mbed_config.h there is correct value set

#define MBED_CONF_TARGET_I2C_TIMING_VALUE_ALGO                                0 

from debug

++ MbedOS Error Info ++
Error Status: 0x80FF0144 Code: 324 Module: 255
Error Message: Assertion failed: MBED_CONF_TARGET_I2C_TIMING_VALUE_ALGO
Location: 0x800281D
File: .\mbed-os\targets\TARGET_STM\TARGET_STM32F0\i2c_device.c+84
Error Value: 0x0
Current Thread: main Id: 0x20000AA4 Entry: 0x80019D9 StackSize: 0x1000 StackMem: 0x20000CE0 SP: 0x20001B9C
Next:
main  State: 0xhX Entry: 0x00000002 Stack Size: 0x080019D9 Mem: 0x00001000 SP: 0x20000CE0
Ready:
rtx_idle  State: 0xhX Entry: 0x00000001 Stack Size: 0x08001AD5 Mem: 0x00000200 SP: 0x20000838
Wait:
rtx_timer  State: 0xhX Entry: 0x00000083 Stack Size: 0x08001829 Mem: 0x00000300 SP: 0x20000538
Delay:
For more info, visit: https://mbed.com/s/error?error=0x80FF0144&tgt=NUCLEO_F091RC
-- MbedOS Error Info --

@jeromecoutant
Copy link
Collaborator

@pilotak did you fetch before:

affrinpinhero-2356 force-pushed the affrinpinhero-2356:i2c_longTime_Mem_Solve branch from 2c464c8 to 1c10ea4 20 hours ago

@pilotak
Copy link
Contributor

pilotak commented Jun 16, 2021

@jeromecoutant i'm at a06d6a6

@affrinpinhero-2356
Copy link
Contributor Author

@pilotak are you using default clock configuration or custom?

@pilotak
Copy link
Contributor

pilotak commented Jun 16, 2021

@affrinpinhero-2356 default, as a said I compiled the code for NUCLEO_F091RC and ran on custom board

@affrinpinhero-2356
Copy link
Contributor Author

@pilotak You need to change the value of I2C_TIMING_VALUE_ALGO to true I target.json file. If your clock configuration is not default then this error will get triggered.

@pilotak
Copy link
Contributor

pilotak commented Jun 17, 2021

@affrinpinhero-2356 could you please clarify what do you mean by default configuration? - does it mean that it will only work on nucleo with external clock and not with external crystal / internal clock?

I didn't adjust anything so i'm using default setting USE_PLL_HSE_EXTC|USE_PLL_HSI (NUCLEO_F091RC derived clock from MCU_STM32F0) in which my case EXTC in not provided - that basically means that it's running on internal lock (HSI).

/* If MBED_CONF_TARGET_I2C_TIMING_VALUE_ALGO assert is triggered.
User needs to enable I2C_TIMING_VALUE_ALGO in target.json for specific target.
Enabling this may impact performance*/
MBED_ASSERT(MBED_CONF_TARGET_I2C_TIMING_VALUE_ALGO);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be an error rather and print a message how to fix it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mentioned as a comment what to do assert occurred. So I think this will be enough.

},
"i2c_timing_value_algo": {
"help": "If value was set I2C timing algorithm is enabled. Enabling may leads to performance issue. Keeping this false and changing system clock will cause compilation error)",
"value": false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is false (default value), and I change system clock, why do I get compilation error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this scenario, there will no error while compiling. But you may get an ASSERT while running.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@affrinpinhero-2356 please update help description accordingly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modified help description.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok thanks

@jeromecoutant
Copy link
Collaborator

Hi

Maybe @pilotak issue is related to I2C_2 ?
It seems that I2C_2 is not expected in STM32F0...
https://github.com/ARMmbed/mbed-os/blob/master/targets/TARGET_STM/TARGET_STM32F0/i2c_device.c#L46

@jeromecoutant
Copy link
Collaborator

@facchinm @pennam
I am wondering if PORTENTA should enable "i2c_timing_value_algo" new config ?

@pennam
Copy link
Contributor

pennam commented Jun 22, 2021

@facchinm @pennam
I am wondering if PORTENTA should enable "i2c_timing_value_algo" new config ?

@jeromecoutant thanks for keep us updated! i've just had a quick look at this pr, but yes, by default the "i2c_timing_value_algo" should be enable for PORTENTA.

Copy link
Collaborator

@jeromecoutant jeromecoutant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs update for @pilotak and @pennam

@pilotak
Copy link
Contributor

pilotak commented Jun 22, 2021

@jeromecoutant i'm using PA_9 and PA_10 which is I2C_1

I2C_2 is not expected? really? i'm planning to use it as well so should not happend doesn't seems to be right, F091 has two regular buses

@pilotak
Copy link
Contributor

pilotak commented Jun 22, 2021

Error when using I2C_2 at pins PB_13 and PB_14 (@F091RC)

++ MbedOS Error Info ++
Error Status: 0x80FF0100 Code: 256 Module: 255
Error Message: Fatal Run-time error
Location: 0x80052AD
Error Value: 0x0
Current Thread: main Id: 0x20000AA4 Entry: 0x80019D9 StackSize: 0x1000 StackMem: 0x20000CE0 SP: 0x20001B9C
Next:
main  State: 0xhX Entry: 0x00000002 Stack Size: 0x080019D9 Mem: 0x00001000 SP: 0x20000CE0
Ready:
rtx_idle  State: 0xhX Entry: 0x00000001 Stack Size: 0x08001AD5 Mem: 0x00000200 SP: 0x20000838
Wait:
rtx_timer  State: 0xhX Entry: 0x00000083 Stack Size: 0x08001829 Mem: 0x00000300 SP: 0x20000538
Delay:
For more info, visit: https://mbed.com/s/error?error=0x80FF0100&tgt=NUCLEO_F091RC
-- MbedOS Error Info --
I2C: unknown instance

@pilotak
Copy link
Contributor

pilotak commented Jun 23, 2021

@affrinpinhero-2356 with 2fae588 it's working as expected.

@ciarmcom ciarmcom added the stale Stale Pull Request label Jun 28, 2021
@ciarmcom
Copy link
Member

This pull request has automatically been marked as stale because it has had no recent activity. @jeromecoutant, @0xc0170, please complete review of the changes to move the PR forward. Thank you for your contributions.

},
"i2c_timing_value_algo": {
"help": "If value was set to true I2C timing algorithm is enabled. Enabling may leads to performance issue. Keeping this false and changing system clock will trigger assert.)",
"value": true
Copy link
Collaborator

@jeromecoutant jeromecoutant Jun 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is working ?
As PORTENTA_H7 is inheriting from MCU_STM32H7, "i2c_timing_value_algo" config already exist,
so I think you need to overwrite the value to true in the "overrides" part below ?

mbed test -m PORTENTA_H7_M7 -t ARM
[ERROR] Parameter name 'i2c_timing_value_algo' defined in both 'target:PORTENTA_H7' and 'target:MCU_STM32H7'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to overrides

@@ -3178,10 +3178,6 @@
             "usb_speed": {
                 "help": "USE_USB_OTG_FS or USE_USB_OTG_HS or USE_USB_HS_IN_FS",
                 "value": "USE_USB_OTG_HS"
-            },
-            "i2c_timing_value_algo": {
-                "help": "If value was set to true I2C timing algorithm is enabled. Enabling may leads to performance issue. Keeping this false and changing system clock will trigger assert.)",
-                "value": true
             }
         },
         "macros_add": [
@@ -3202,7 +3198,8 @@
             "clock_source": "USE_PLL_HSE_EXTC",
             "lse_available": 1,
             "lpticker_delay_ticks": 0,
-            "network-default-interface-type": "ETHERNET"
+            "network-default-interface-type": "ETHERNET",
+            "i2c_timing_value_algo": true
         },
         "device_name": "STM32H747XIHx"
     },

@ciarmcom ciarmcom removed the stale Stale Pull Request label Jun 28, 2021
This commit solves excess usage of RAM. User can now enable/disable
I2C timing algorithm. Disabling of I2C timing algorithm would
reduce RAM usage.

Signed-off-by: Affrin Pinhero <[email protected]>
@0xc0170
Copy link
Contributor

0xc0170 commented Jun 29, 2021

CI started

@mbed-ci
Copy link

mbed-ci commented Jun 29, 2021

Jenkins CI Test : ✔️ SUCCESS

Build Number: 1 | 🔒 Jenkins CI Job | 🌐 Logs & Artifacts

CLICK for Detailed Summary

jobs Status
jenkins-ci/mbed-os-ci_unittests ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-ARM ✔️
jenkins-ci/mbed-os-ci_cmake-cloud-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_cmake-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_greentea-test ✔️

@0xc0170 0xc0170 merged commit 8188f5f into ARMmbed:master Jun 29, 2021
@mergify mergify bot removed the ready for merge label Jun 29, 2021
@mbedmain mbedmain added release-version: 6.13.0 Release-pending and removed release-type: patch Indentifies a PR as containing just a patch Release-pending labels Jul 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants