Skip to content

STM32H7: Compute I2C timing according current I2C clock source #14030

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 7 commits into from
Feb 15, 2021

Conversation

facchinm
Copy link
Contributor

Summary of changes

I2C clock dividers were calculated based on the assumption that the feed clock is always 54MHz.
Borrow the proper calculation from STM32CubeH7
100617806-4d5ce800-331b-11eb-9f60-fdb62a607d1b
100617819-4fbf4200-331b-11eb-9abd-0f1c00f27705

Impact of changes

Migration actions required

Documentation

None


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

@jeromecoutant @pennam


@ciarmcom ciarmcom added the release-type: patch Indentifies a PR as containing just a patch label Dec 11, 2020
@ciarmcom ciarmcom requested review from jeromecoutant and a team December 11, 2020 13:30
@ciarmcom
Copy link
Member

@facchinm, thank you for your changes.
@jeromecoutant @ARMmbed/team-st-mcd @ARMmbed/mbed-os-maintainers please review.

@jeromecoutant
Copy link
Collaborator

@facchinm
Copy link
Contributor Author

@jeromecoutant nope, it's from https://github.com/STMicroelectronics/STM32CubeH7/blob/beced99ac090fece04d1e0eb6648b8075e156c6c/Drivers/BSP/STM32H747I-DISCO/stm32h747i_discovery_bus.c (as reported in the description).
BSD 3-clause should be compatible with mbed allowed licenses AFAIU.

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 tests are failed with this patch with NUCLEO_H743ZI2

@facchinm
Copy link
Contributor Author

facchinm commented Jan 4, 2021

@jeromecoutant you mean in your internal hardware CI?

@jeromecoutant
Copy link
Collaborator

you mean in your internal hardware CI?

Yes, with this test:
https://github.com/ARMmbed/ci-test-shield/tree/master/TESTS/API/I2C

@facchinm
Copy link
Contributor Author

facchinm commented Jan 4, 2021

A particular test case or just all of them?

@jeromecoutant
Copy link
Collaborator

A particular test case or just all of them?

  • Running case 1: 'I2C - Instantiation of I2C Object'... => OK
  • Running case 2: 'I2C - LM75B Temperature Read'... => OK
  • Running case 3: 'I2C - EEProm WR Single Byte'... => OK
  • Running case 4: 'I2C - EEProm 2nd WR Single Byte'... => OK
  • Running case 5: 'I2C - EEProm WR 2 Bytes'... => CRASH
[1609780483.61][CONN][RXD] ++ MbedOS Error Info ++
[1609780483.66][CONN][RXD] Error Status: 0x80FF013D Code: 317 Module: 255
[1609780483.69][CONN][RXD] Error Message: Fault exception
[1609780483.72][CONN][RXD] Location: 0x8005D30
[1609780483.74][CONN][RXD] Error Value: 0x240033E4
[1609780483.87][CONN][RXD] Current Thread: main <handler> Id: 0x24005154 Entry: 0x800EAC7 StackSize: 0x1000 StackMem: 0x24002078 SP: 0x2407FF78
[1609780484.01][CONN][RXD] For more info, visit: https://mbed.com/s/error?error=0x80FF013D&osver=60600&core=0x411FC271&comp=1&ver=6150002&tgt=NUCLEO_H743ZI2
[1609780484.02][CONN][RXD] -- MbedOS Error Info --

Note I added quick printf to display new values:
[1609780125.55][CONN][RXD] hz=100000 tim=0x70d04648
[1609780125.63][CONN][RXD] hz=400000 tim=0x60f00c16

@mergify
Copy link

mergify bot commented Jan 5, 2021

This PR cannot be merged due to conflicts. Please rebase to resolve them.

@pennam
Copy link
Contributor

pennam commented Jan 5, 2021

Hi @jeromecoutant i've updated the patch adding

I2c_valid_timing_nbr = 0;
that was missing. I2c_valid_timing_nbr must be cleared each time a new calculation is performed to make sure only valid values of I2c_valid_timig array are considered. Now it shouldn't raise any exception. Could you please re-run tests? If everything runs fine i will then rebase.

@jeromecoutant
Copy link
Collaborator

Hi @pennam

ci-test-shield I2C test is now OK!

But unfortunately, FPGA I2C test was OK, and is now FAILED...
https://github.com/ARMmbed/mbed-os/blob/master/hal/tests/TESTS/mbed_hal_fpga_ci_test_shield/i2c/main.cpp

FPGA_I2C_TEST.zip

@pennam
Copy link
Contributor

pennam commented Jan 7, 2021

@jeromecoutant thanks for the reports, at least is not crashing anymore. Next week, most probably on wednesday, i will have an fpga shield to make further investigations on this issue.

@pennam
Copy link
Contributor

pennam commented Jan 18, 2021

@jeromecoutant i've received the fpga shield and made several tests, from my side I2C tests are always ok. I'm using STM32H747I-DISCO board. Could you please check if test are always failing on your board or it was just a glitch?

i2c_tests.log

@ciarmcom ciarmcom added the stale Stale Pull Request label Jan 20, 2021
@ciarmcom
Copy link
Member

This pull request has automatically been marked as stale because it has had no recent activity. @facchinm, please carry out any necessary work to get the changes merged. Thank you for your contributions.

@jeromecoutant
Copy link
Collaborator

@jeromecoutant i've received the fpga shield and made several tests, from my side I2C tests are always ok. I'm using STM32H747I-DISCO board. Could you please check if test are always failing on your board or it was just a glitch?

I confirm that with H747 DISCO is OK...
And there is still failure with H743 NUCLEO...
I am checking

I2c_valid_timing_nbr = 0;

/* we will use D2PCLK1 to calculate I2C timings */
MBED_ASSERT(RCC_I2C1CLKSOURCE_D2PCLK1 ==__HAL_RCC_GET_I2C1_SOURCE());
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is strange as H747-DISCO is suing I2C4 for D14/D15 pins.

NUCLEO H743 is using I2C1...

Copy link
Contributor

Choose a reason for hiding this comment

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

When i wrote this line i was making wrong assumptions and it is completely useless. On DISCO I2C1_SOURCE is actually D2PCLK1 so we never hit the assert, moreover as you wrote I2C4 is used for the tests... On DISCO tests are ok because PCLK1_Frequency, PCLK2_Frequency, PCLK3_Frequency and PCLK4_Frequency have all the same value.

On the other side I2C1 instance is used for running tests on the NUCLEO and we doesn't hit the assert too, this means we are using the correct clock source to compute timings... so i thinks there is something else i'm missing to make things work on the NUCLEO.

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.

Changes seems not compliant with all I2C instances

LL_RCC_ClocksTypeDef rcc_clocks;
LL_RCC_GetSystemClocksFreq(&rcc_clocks);

tim = I2C_ComputeTiming(rcc_clocks.PCLK1_Frequency, hz);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I2C4 seems connected to PCLK2

Copy link
Contributor

Choose a reason for hiding this comment

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

from my understanding I2C4 on DISCO uses RCC_I2C4CLKSOURCE_D3PCLK1 as clock source that is the same of rcc_clocks.PCLK4_Frequency. I don't know why here https://github.com/STMicroelectronics/STM32CubeH7/blob/beced99ac090fece04d1e0eb6648b8075e156c6c/Drivers/BSP/STM32H747I-DISCO/stm32h747i_discovery_bus.c#L224 PCLK2 is used. From the reference manual I2C4 can be used with PCLK4, PLL3, HSI and CSI.
image

@pennam
Copy link
Contributor

pennam commented Jan 20, 2021

I need to understand how to get the correct clock source of each I2C instance. I start working on it now.

@pennam
Copy link
Contributor

pennam commented Jan 21, 2021

I've found a way to use the proper clock source for any I2C instance, hopefully tomorrow i will get a NUCLEO board to repeat test on my side.

@mergify mergify bot removed the needs: work label Feb 3, 2021
@mbed-ci
Copy link

mbed-ci commented Feb 3, 2021

Jenkins CI Test : ❌ FAILED

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_cmake-example-ARM
jenkins-ci/mbed-os-ci_cmake-example-GCC_ARM
jenkins-ci/mbed-os-ci_build-greentea-GCC_ARM
jenkins-ci/mbed-os-ci_build-cloud-example-ARM
jenkins-ci/mbed-os-ci_build-greentea-ARM
jenkins-ci/mbed-os-ci_build-cloud-example-GCC_ARM
jenkins-ci/mbed-os-ci_build-example-GCC_ARM
jenkins-ci/mbed-os-ci_build-example-ARM

Comment on lines 536 to 541
#ifdef TARGET_STM32H7
handle->Init.Timing = get_i2c_timing(obj_s->i2c, hz);
#else
handle->Init.Timing = get_i2c_timing(hz);
#endif

Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be kept within #ifdef I2C_IP_VERSION_V2

Copy link
Contributor

Choose a reason for hiding this comment

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

I've fixed it and added i2c_device.c to CMakeLists.txt

@mergify mergify bot dismissed 0xc0170’s stale review February 3, 2021 14:27

Pull request has been modified.

@0xc0170
Copy link
Contributor

0xc0170 commented Feb 4, 2021

CI started

@mergify mergify bot added needs: work and removed needs: CI labels Feb 4, 2021
@mbed-ci
Copy link

mbed-ci commented Feb 4, 2021

Jenkins CI Test : ❌ FAILED

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

CLICK for Detailed Summary

jobs Status
jenkins-ci/mbed-os-ci_unittests ✔️
jenkins-ci/mbed-os-ci_cmake-example-ARM ✔️
jenkins-ci/mbed-os-ci_cmake-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_build-example-GCC_ARM
jenkins-ci/mbed-os-ci_build-example-ARM
jenkins-ci/mbed-os-ci_build-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-ARM ✔️

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.

About last correction in stm32h7xx_hal_rcc_ex.h
correction is approved by ST driver team and will be present in the next delivery.

Thx a lot

@pennam
Copy link
Contributor

pennam commented Feb 10, 2021

@0xc0170 last CI issue should be fixed by dc2d860 . Is it possible to run CI again?

@jeromecoutant
Copy link
Collaborator

@0xc0170 ping :-)

@0xc0170
Copy link
Contributor

0xc0170 commented Feb 15, 2021

CI started

@mergify mergify bot added needs: CI and removed needs: work labels Feb 15, 2021
@mbed-ci
Copy link

mbed-ci commented Feb 15, 2021

Jenkins CI Test : ✔️ SUCCESS

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

CLICK for Detailed Summary

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

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.

7 participants