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

The divider should be rounded to the next full integer to ensure that
the resulting SPI frequency is <= target frequency, i.e. the SPI is
not overclocked.
This commit is contained in:
Ville Juven 2023-11-28 19:09:45 +02:00 committed by Xiang Xiao
parent 9858dfde32
commit 8494fd2097
1 changed files with 2 additions and 2 deletions

View File

@ -543,9 +543,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);