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

mpfs/mpfs_corespi.c: Round up divider to prevent overlock of SPI #188

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions arch/risc-v/src/mpfs/mpfs_corespi.c
Original file line number Diff line number Diff line change
Expand Up @@ -542,9 +542,9 @@ static uint32_t mpfs_spi_setfrequency(struct spi_dev_s *dev,

priv->frequency = frequency;

/* Formula is SPICLK = PCLK/(2*(CFG_CLK + 1)) */
/* Formula is SPICLK = PCLK/(2*(CFG_CLK + 1)) (result is rounded up) */

divider = ((MPFS_FPGA_PERIPHERAL_CLK / frequency) >> 1) - 1;
divider = (MPFS_FPGA_PERIPHERAL_CLK / frequency) >> 1;
priv->actual = MPFS_FPGA_PERIPHERAL_CLK / ((divider + 1) << 1);

DEBUGASSERT(divider < 256u);
Expand Down
Loading