Skip to content

TARGET_STM: L0 CUBE SPI async mode send next byte after previous one is read #12362

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 1 commit into from
Feb 5, 2020

Conversation

ABOSTM
Copy link
Contributor

@ABOSTM ABOSTM commented Feb 4, 2020

Summary of changes

TARGET_STM: L0 CUBE SPI async mode send next byte after previous one read

In STM32 Cube HAL, in interrupt mode (async),
2 bytes can be prepared in hardware registers without any read
(1 in regular register, the other in shift register),
but Only 1 RX byte can stored in hardware register, specially when there is no hardware FIFO.
If interrupt handling is fast enough, each read is made in parralele of the write.
But if interrupt handling is too long or is interrupted for too long,
it can happen that one read byte is lost (overrun).
For STM32F4, Tickless has been deactivated to avoid such issue.
For STM32L0, we don't want to deactivate tickless,
because those chips are specially design for lowpower.

So instead of removing SPI async mode,
we propose to change the HAL behavior specially for L0:
each byte is send only when previous read is performed.
Thus only 1 RX byte at a time which is saved in hardware register.
This prevent overrun, but it introduceS some latency between each byte send,
this is why it is not applied to all STM32 families.


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)
[] Covered by existing mbed-os tests (Greentea or Unittest)
[x] Tests / results supplied as part of this PR

test SPI ci-shield and FPGA passed on NUCLEO_L073RZ

mbedgt: test suite report:
| target                | platform_name | test suite            | result | elapsed_time (sec) | copy_method |
|-----------------------|---------------|-----------------------|--------|--------------------|-------------|
| NUCLEO_L073RZ-ARMC6   | NUCLEO_L073RZ | tests-api-spi         | OK     | 23.22              | default     |
| NUCLEO_L073RZ-ARMC6   | NUCLEO_L073RZ | tests-assumptions-spi | OK     | 19.53              | default     |
| NUCLEO_L073RZ-GCC_ARM | NUCLEO_L073RZ | tests-api-spi         | OK     | 27.56              | default     |
| NUCLEO_L073RZ-GCC_ARM | NUCLEO_L073RZ | tests-assumptions-spi | OK     | 22.42              | default     |
| NUCLEO_L073RZ-IAR     | NUCLEO_L073RZ | tests-api-spi         | OK     | 23.44              | default     |
| NUCLEO_L073RZ-IAR     | NUCLEO_L073RZ | tests-assumptions-spi | OK     | 19.7               | default     |
mbedgt: test suite results: 6 OK

mbedgt: test case report:
| target            | platform_name | test suite                             | test case                                  | passed | failed | result | elapsed_time (sec) |
|-------------------|---------------|----------------------------------------|--------------------------------------------|--------|--------|--------|--------------------|
| NUCLEO_L073RZ-IAR | NUCLEO_L073RZ | tests-mbed_hal_fpga_ci_test_shield-spi | SPI - async mode (hw ss)                   | 1      | 0      | OK     | 0.41               |
| NUCLEO_L073RZ-IAR | NUCLEO_L073RZ | tests-mbed_hal_fpga_ci_test_shield-spi | SPI - async mode (sw ss)                   | 1      | 0      | OK     | 0.42               |
| NUCLEO_L073RZ-IAR | NUCLEO_L073RZ | tests-mbed_hal_fpga_ci_test_shield-spi | SPI - basic test                           | 1      | 0      | OK     | 0.46               |
| NUCLEO_L073RZ-IAR | NUCLEO_L073RZ | tests-mbed_hal_fpga_ci_test_shield-spi | SPI - basic test (direct init)             | 1      | 0      | OK     | 0.48               |
| NUCLEO_L073RZ-IAR | NUCLEO_L073RZ | tests-mbed_hal_fpga_ci_test_shield-spi | SPI - block write                          | 1      | 0      | OK     | 0.42               |
| NUCLEO_L073RZ-IAR | NUCLEO_L073RZ | tests-mbed_hal_fpga_ci_test_shield-spi | SPI - block write(one sym)                 | 1      | 0      | OK     | 0.41               |
| NUCLEO_L073RZ-IAR | NUCLEO_L073RZ | tests-mbed_hal_fpga_ci_test_shield-spi | SPI - buffers tx < rx                      | 1      | 0      | OK     | 0.42               |
| NUCLEO_L073RZ-IAR | NUCLEO_L073RZ | tests-mbed_hal_fpga_ci_test_shield-spi | SPI - buffers tx > rx                      | 1      | 0      | OK     | 0.42               |
| NUCLEO_L073RZ-IAR | NUCLEO_L073RZ | tests-mbed_hal_fpga_ci_test_shield-spi | SPI - frequency testing (2 MHz)            | 1      | 0      | OK     | 0.43               |
| NUCLEO_L073RZ-IAR | NUCLEO_L073RZ | tests-mbed_hal_fpga_ci_test_shield-spi | SPI - frequency testing (200 kHz)          | 1      | 0      | OK     | 0.45               |
| NUCLEO_L073RZ-IAR | NUCLEO_L073RZ | tests-mbed_hal_fpga_ci_test_shield-spi | SPI - frequency testing (capabilities max) | 1      | 0      | OK     | 0.44               |
| NUCLEO_L073RZ-IAR | NUCLEO_L073RZ | tests-mbed_hal_fpga_ci_test_shield-spi | SPI - frequency testing (capabilities min) | 1      | 0      | OK     | 0.45               |
| NUCLEO_L073RZ-IAR | NUCLEO_L073RZ | tests-mbed_hal_fpga_ci_test_shield-spi | SPI - hardware ss handling                 | 1      | 0      | OK     | 0.43               |
| NUCLEO_L073RZ-IAR | NUCLEO_L073RZ | tests-mbed_hal_fpga_ci_test_shield-spi | SPI - hardware ss handling(block)          | 1      | 0      | OK     | 0.42               |
| NUCLEO_L073RZ-IAR | NUCLEO_L073RZ | tests-mbed_hal_fpga_ci_test_shield-spi | SPI - init/free test all pins              | 1      | 0      | OK     | 0.78               |
| NUCLEO_L073RZ-IAR | NUCLEO_L073RZ | tests-mbed_hal_fpga_ci_test_shield-spi | SPI - mode testing (MODE_1)                | 1      | 0      | OK     | 0.42               |
| NUCLEO_L073RZ-IAR | NUCLEO_L073RZ | tests-mbed_hal_fpga_ci_test_shield-spi | SPI - mode testing (MODE_2)                | 1      | 0      | OK     | 0.44               |
| NUCLEO_L073RZ-IAR | NUCLEO_L073RZ | tests-mbed_hal_fpga_ci_test_shield-spi | SPI - mode testing (MODE_3)                | 1      | 0      | OK     | 0.42               |
| NUCLEO_L073RZ-IAR | NUCLEO_L073RZ | tests-mbed_hal_fpga_ci_test_shield-spi | SPI - symbol size testing (12)             | 1      | 0      | OK     | 0.3                |
| NUCLEO_L073RZ-IAR | NUCLEO_L073RZ | tests-mbed_hal_fpga_ci_test_shield-spi | SPI - symbol size testing (16)             | 1      | 0      | OK     | 0.43               |
| NUCLEO_L073RZ-IAR | NUCLEO_L073RZ | tests-mbed_hal_fpga_ci_test_shield-spi | SPI - symbol size testing (24)             | 1      | 0      | OK     | 0.3                |
| NUCLEO_L073RZ-IAR | NUCLEO_L073RZ | tests-mbed_hal_fpga_ci_test_shield-spi | SPI - symbol size testing (32)             | 1      | 0      | OK     | 0.3                |
| NUCLEO_L073RZ-IAR | NUCLEO_L073RZ | tests-mbed_hal_fpga_ci_test_shield-spi | SPI - symbol size testing (4)              | 1      | 0      | OK     | 0.29               |
mbedgt: test case results: 23 OK

Reviewers


…read

In STM32 Cube HAL, in interrupt mode (async),
2 bytes can be prepared in hardware registers without any read
(1 in regular register, the other in shift register),
but Only 1 RX byte can stored in hardware register, specially when there is no hardware FIFO.
If interrupt handling is fast enough, each read is made in parralele of the write.
But if interrupt handling is too long or is interrupted for too long,
it can happen that one read byte is lost (overrun).
For STM32F4, Tickless has been deactivated to avoid such issue.
For STM32L0, we don't want to deactivate tickless,
because those chips are specially design for lowpower.

So instead of removing SPI async mode,
we propose to change the HAL behavior specially for L0:
each byte is send only when previous read is performed.
Thus only 1 RX byte at a time which is saved in hardware register.
This prevent overrun, but it introduceS some latency between each byte send,
this is why it is not applied to all STM32 families.
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.

No internal ticket opened.
This patch is mbed-os only.

@jeromecoutant
Copy link
Collaborator

@mprse @bulislaw @LMESTM

@ciarmcom ciarmcom requested a review from a team February 4, 2020 14:00
@ciarmcom
Copy link
Member

ciarmcom commented Feb 4, 2020

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

Copy link
Contributor

@mprse mprse left a comment

Choose a reason for hiding this comment

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

@ABOSTM Well done!
Thanks for solving this issue. I will close now #12354.

@0xc0170
Copy link
Contributor

0xc0170 commented Feb 4, 2020

CI started

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

mbed-ci commented Feb 4, 2020

Test run: SUCCESS

Summary: 11 of 11 test jobs passed
Build number : 1
Build artifacts

@0xc0170 0xc0170 added the release-version: 6.0.0-alpha-2 Second pre-release version of 6.0.0 label Feb 5, 2020
@0xc0170 0xc0170 merged commit 841b846 into ARMmbed:master Feb 5, 2020
@mergify mergify bot removed the ready for merge label Feb 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-version: 6.0.0-alpha-2 Second pre-release version of 6.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants