Skip to content
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

cpu/sam0_common: mitigate rounding errors of SPI baud rate calculation #13537

Merged
merged 2 commits into from
Mar 4, 2020

Conversation

jue89
Copy link
Contributor

@jue89 jue89 commented Mar 3, 2020

Contribution description

After the merge of #13526 @benpicco pointed out that there is room for improvement of the SPI baud rate calculation. This PR implements his proposed formula.

I checked this using a spread sheet. I highlighted cells with a higher frequency than expected resp. desired if the CPU is clocked with 16MHz. Those configurations may cause communication errors since the peripheral may not handle the high SPI clock.

baud rate comparison

Furthermore, I reverted the commit of #13526. The desired frequency of 5MHz now results into 4MHz, not 8MHz.

Testing procedure

examples/gnrc_networking should work of the samr30-xpro board.

Issues/PRs references

#13526

jue89 added 2 commits March 3, 2020 12:32
Instead of always rounding up, the driver now rounds to the nearest integer. This reduces the absolut rounding error when setting SPI baud rates.
This reverts commit a9faac7.

The changed rounding behavior sets the SPI baud rate to 4MHz, which is a suitable rate for the AT86RF212B.
@jue89 jue89 requested review from dylad and MrKevinWeiss as code owners March 3, 2020 11:47
@benpicco benpicco added Area: cpu Area: CPU/MCU ports Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Reviewed: 3-testing The PR was tested according to the maintainer guidelines labels Mar 3, 2020
Copy link
Contributor

@benpicco benpicco left a comment

Choose a reason for hiding this comment

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

samr21-xpro also continues to work, as does same54-xpro and our custom board with samd51 & at86rf215.

@benpicco benpicco merged commit 681678e into RIOT-OS:master Mar 4, 2020
@jue89 jue89 deleted the feature/sam0-spi-frequency branch March 4, 2020 16:06
@kmartinez
Copy link

good work! Now we just need an easy EU/USA/CH frequency/page in the Makefile to make it easier to remain legal ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: cpu Area: CPU/MCU ports CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Reviewed: 3-testing The PR was tested according to the maintainer guidelines Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants