Skip to content

Commit aeedf86

Browse files
decsnynashif
authored andcommitted
spi_nxp_lpspi: Clarify configuration function
Clarify at the top of the common lpspi file what is the purpose of the file to be clear to future developers that this file is not supposed to make any assumption about a particular implementation of the zephyr API using the LPSPI, because I imagine it could be very likely that more lpspi implementation will be done in the future to make different tradeoffs than the current two. Also the current two are different enough that we should avoid making assumptions even if they currently hold for both because they might not always, as things change. We should disable interrupt events while configuring the LPSPI regardless of implementation. The specific implementation should enable the interrupts it needs on its own transceive implementation. Also clarify and simplify some code in the configure function. Namely, we no longer need to check if we are already configured to write to registers because a recent commit made it so that we clock the peripheral from the zephyr driver init instead of upon the MasterInit call on the SDK. There is also a redundant CR write which I have removed. Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
1 parent 2aa9ec4 commit aeedf86

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

drivers/spi/spi_nxp_lpspi/spi_nxp_lpspi_common.c

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
/*
8+
* This is a collection of functions that would be useful for any driver for LPSPI.
9+
* This function/file has no knowledge of lpspi usage model by the driver
10+
* beyond basic configuration and should avoid making any assumptions about how
11+
* the driver is going to achieve the zephyr API.
12+
*/
13+
714
#include <zephyr/logging/log.h>
815
LOG_MODULE_REGISTER(spi_lpspi, CONFIG_SPI_LOG_LEVEL);
916

@@ -131,23 +138,20 @@ int spi_mcux_configure(const struct device *dev, const struct spi_config *spi_cf
131138
return ret;
132139
}
133140

134-
if (already_configured) {
135-
/* Setting the baud rate in LPSPI_MasterInit requires module to be disabled. Only
136-
* disable if already configured, otherwise the clock is not enabled and the
137-
* CR register cannot be written.
138-
*/
139-
LPSPI_Enable(base, false);
140-
while ((base->CR & LPSPI_CR_MEN_MASK) != 0U) {
141-
/* Wait until LPSPI is disabled. Datasheet:
142-
* After writing 0, MEN (Module Enable) remains set until the LPSPI has
143-
* completed the current transfer and is idle.
144-
*/
145-
}
141+
/* specific driver implementation should set up watermarks and interrupts.
142+
* we reset them here to avoid any unexpected events during configuring.
143+
*/
144+
base->FCR = 0;
145+
base->IER = 0;
146+
147+
/* this is workaround for ERR050456 */
148+
base->CR |= LPSPI_CR_RST_MASK;
149+
base->CR |= LPSPI_CR_RRF_MASK | LPSPI_CR_RTF_MASK;
146150

147-
/* this is workaround for ERR050456 */
148-
base->CR |= LPSPI_CR_RST_MASK;
149-
base->CR |= LPSPI_CR_RRF_MASK | LPSPI_CR_RTF_MASK;
150-
base->CR = 0x00U;
151+
/* Setting the baud rate requires module to be disabled. */
152+
base->CR = 0;
153+
while ((base->CR & LPSPI_CR_MEN_MASK) != 0) {
154+
/* According to datasheet, should wait for this MEN bit to clear once idle */
151155
}
152156

153157
data->ctx.config = spi_cfg;

0 commit comments

Comments
 (0)