Skip to content

Stm32 spi 3 wires mode support #4975

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 5 commits into from
Sep 5, 2017
Merged

Conversation

LMESTM
Copy link
Contributor

@LMESTM LMESTM commented Aug 25, 2017

Description

This PR contains the required changes for supporting SPI 3-wires mode communication.
This allows to save 1 pin in constrained PCB designs.

Status

READY

Tests

This mode has been validated by using a ST Sensor by @mapellil @nikapov-ST
The SPI standard mode has been tested with tests-api-spi of ci-test-shield suite and has not shown any regression on any of all STM32 target families.

mapellil and others added 4 commits August 17, 2017 11:02
In case MISO is not passed at SPI init, then we consider a 3 wires SPI
configuration is requested, which corresponds to SPI_DIRECTION_1LINE
configuration parameter in STM32 HAL layer.

We're then handling this specific case of SPI_DIRECTION_1LINE,
in spi_master_write or spi_master_block_write, we call to HAL API
Enabling SPI causes the clock to be output by default.

Most devices will not care about extra clock cycles, especially as long
as chip select is not active, nevertheless this may cause side issues
with other devices especially during init phase.

This was actually the case with a 3 wire device (LPS22HB sensor).
this is more a cosmetic change, but since LL was introduced, we can now
use it here as well.
} else {
return (int)spi->DR;
return LL_SPI_ReceiveData8(SPI_INST(obj));
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at the LL function, I am not sure that the 8bit data reading will work...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

as discussed, this LL function has been verified and tested fine

@screamerbg
Copy link
Contributor

cc @0xc0170 @BartSX

@LMESTM
Copy link
Contributor Author

LMESTM commented Aug 31, 2017

@0xc0170 thx
BTW here is an example from @mapellil taking benefit of 3 wires mode:
https://developer.mbed.org/teams/ST-Expansion-SW-Team/code/X_NUCLEO_IKS01A2_SPI3W/

@0xc0170
Copy link
Contributor

0xc0170 commented Aug 31, 2017

@mapellil
Copy link

mapellil commented Aug 31, 2017 via email

@nikapov-ST
Copy link

Anyway, I made it public now in case to want to have a look.

@LMESTM
Copy link
Contributor Author

LMESTM commented Aug 31, 2017

@0xc0170 @nikapov-ST @mapellil
Sorry about that guys - I've been too quick ... just wanted to share how this was tested :-)

@nikapov-ST
Copy link

@LMESTM no worries :-)

@studavekar
Copy link
Contributor

/morph test

@mbed-bot
Copy link

mbed-bot commented Sep 4, 2017

Result: SUCCESS

Your command has finished executing! Here's what you wrote!

/morph test

Output

mbed Build Number: 1189

All builds and test passed!

} else {
/* In case of 1 WIRE only, first handle TX, then Rx */
if (tx_length != 0) {
if (HAL_OK != HAL_SPI_Transmit(handle, (uint8_t*)tx_buffer, tx_length, tx_length*10)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

tx_length*10 why is it multiplied here and also for rx ? If buffer contains 5 characters, will this send 50?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The last parameter is a timeout: more characters = longer timeout

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, it might be more clear to create a separate variable that would indicate this (`xxx timeout =length * 10), and explain why the timeout is 10 (in case it fails in future we will know how *10 was chosen).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok - I pushed 1 commit with #define to make parameter more explicit.

This makes the code more explicit about what is last parameter of
HAL_SPI_Transmit/HAL_SPI_Receive functions.
@0xc0170
Copy link
Contributor

0xc0170 commented Sep 4, 2017

/morph test

@mbed-bot
Copy link

mbed-bot commented Sep 5, 2017

Result: SUCCESS

Your command has finished executing! Here's what you wrote!

/morph test

Output

mbed Build Number: 1207

All builds and test passed!

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.

9 participants