Skip to content

spi: spi_ll_stm32: Fix spi_slave case in transceive() #7687

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
May 25, 2018

Conversation

avisconti
Copy link
Collaborator

@avisconti avisconti commented May 21, 2018

If we are in SPI slave context we need to check, before
exiting the transceive() routine, whether the ret value
really represents a I/O error or instead is the number
of frames received.

Signed-off-by: Armando Visconti [email protected]

@avisconti avisconti requested a review from superna9999 as a code owner May 21, 2018 12:54
@galak galak requested review from tbursztyka and erwango May 21, 2018 16:01
@galak galak added bug The issue is a bug, or the PR is fixing a bug area: SPI SPI bus platform: STM32 ST Micro STM32 labels May 21, 2018
@avisconti
Copy link
Collaborator Author

I realized that the git commit message was not clear at all. I re-formulated it and re-pushed the commit.

return ret; /* number of frames received */
}
#endif

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually, I would have rewritten how ret is handled here in transceive: removing the below test for logging error, and removing the ret ? -EIO : 0; to me, in case of error, ret should already have the right error code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure I got your proposal.
For example ret == 0x40, may be generated by an OVR error or by a correct reception of 64 frames in slave mode. How can we distinguish between the two case w/o re-reading the SR in transceive()?

Copy link
Collaborator

Choose a reason for hiding this comment

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

you'll need to make the function returning errors giving directly the right error code with relevant changes depending on whether you are slave or master.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't understand why this should be Slave specific, from API point of view Slave or Master transfers should be the same, with the same error return scheme.
ret != 0 means an error, ret = 0 mean you no error
why do you want the number of frames when an error occurs ?

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 part of the SPI changes that happened recently. In slave mode: if an error occurs it will need to return a negative error code, but in case of success it will have to return the number of received frames.
Master mode is as before: 0 on success, an negative error code otherwise.

Copy link
Collaborator Author

@avisconti avisconti May 23, 2018

Choose a reason for hiding this comment

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

As I commented few minutes ago after re-pushing the commit, the situation is now clean and aligned with other SPI controllers (like dw or intel), except when CONFIG_SPI_STM32_INTERRUPT is disabled. In that case I had to add a check that in all other cases is already done in spi_context_wait_for_completion () routine.
Question: do we really need the stm32 case with interrupt disabled?

Copy link
Collaborator

Choose a reason for hiding this comment

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

My bad, I missed the point, sorry

@codecov-io
Copy link

codecov-io commented May 22, 2018

Codecov Report

Merging #7687 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #7687   +/-   ##
=======================================
  Coverage   55.02%   55.02%           
=======================================
  Files         483      483           
  Lines       53969    53969           
  Branches    10501    10501           
=======================================
  Hits        29695    29695           
  Misses      19986    19986           
  Partials     4288     4288

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5b20350...d50030e. Read the comment docs.

@avisconti avisconti force-pushed the spi-slave-fix branch 2 times, most recently from 2e34536 to 461a787 Compare May 23, 2018 09:46
@avisconti
Copy link
Collaborator Author

@tbursztyka
I aligned the transceive() more or less to what the other cases (dw, intel, ...) are doing.
This when STM32 interrupts are enabled. If not, I had to add the test that usually is done inside the wait_for_completion context routine.

if (sr & SPI_STM32_ERR_MSK) {
SYS_LOG_ERR("%s: err=%d", __func__,
sr & SPI_STM32_ERR_MSK);
return(-EIO);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add a space before (-EIO)

Copy link
Collaborator

@superna9999 superna9999 left a comment

Choose a reason for hiding this comment

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

With the small (-EIO), LGTM

@avisconti
Copy link
Collaborator Author

avisconti commented May 24, 2018

@superna9999

With the small (-EIO), LGTM

I'm changing it right now

In SPI slave case the transceive should return either the negative
errno code in case of error or the number of frames received.
So, now:

 1. the spi_stm32_get_err() routine already checks whether
    the SPI cell got an error and returns -EIO in that case.

 2. the transceive() routine always returns whatever the
    spi_context_wait_for_completion() has returned, which
    is either:
        a. -EIO in case of error
        b. 0 in spi_master ok case
        c. the number of frames received in spi_slave ok case

Signed-off-by: Armando Visconti <[email protected]>
@galak galak merged commit bb9fe42 into zephyrproject-rtos:master May 25, 2018
@avisconti avisconti deleted the spi-slave-fix branch May 28, 2018 07:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: SPI SPI bus bug The issue is a bug, or the PR is fixing a bug platform: STM32 ST Micro STM32
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants