Skip to content

Commit 09e31d6

Browse files
decsnyfabiobaltieri
authored andcommitted
spi_nxp_lpspi: Fix faulting register access
On some platforms, the module is not getting clocked until call to LPSPI_MasterInit, this will be fixed soon with upcoming update to native driver and will clock the module in driver init instead of start of transfer, but for now, move this code within the condition check that already exists for this purpose. Signed-off-by: Declan Snyder <[email protected]>
1 parent 25f3210 commit 09e31d6

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

drivers/spi/spi_nxp_lpspi/spi_nxp_lpspi_common.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ int spi_mcux_configure(const struct device *dev, const struct spi_config *spi_cf
2222
{
2323
const struct spi_mcux_config *config = dev->config;
2424
struct spi_mcux_data *data = dev->data;
25+
struct spi_context *ctx = &data->ctx;
2526
LPSPI_Type *base = (LPSPI_Type *)DEVICE_MMIO_NAMED_GET(dev, reg_base);
2627
uint32_t word_size = SPI_WORD_SIZE_GET(spi_cfg->operation);
28+
bool configured = ctx->config != NULL;
2729
lpspi_master_config_t master_config;
2830
uint32_t clock_freq;
2931
int ret;
@@ -57,11 +59,7 @@ int spi_mcux_configure(const struct device *dev, const struct spi_config *spi_cf
5759
return ret;
5860
}
5961

60-
base->CR |= LPSPI_CR_RST_MASK;
61-
base->CR |= LPSPI_CR_RRF_MASK | LPSPI_CR_RTF_MASK;
62-
base->CR = 0x00U;
63-
64-
if (data->ctx.config != NULL) {
62+
if (configured) {
6563
/* Setting the baud rate in LPSPI_MasterInit requires module to be disabled. Only
6664
* disable if already configured, otherwise the clock is not enabled and the
6765
* CR register cannot be written.
@@ -73,6 +71,11 @@ int spi_mcux_configure(const struct device *dev, const struct spi_config *spi_cf
7371
* completed the current transfer and is idle.
7472
*/
7573
}
74+
75+
/* this is workaround for ERR050456 */
76+
base->CR |= LPSPI_CR_RST_MASK;
77+
base->CR |= LPSPI_CR_RRF_MASK | LPSPI_CR_RTF_MASK;
78+
base->CR = 0x00U;
7679
}
7780

7881
data->ctx.config = spi_cfg;

0 commit comments

Comments
 (0)