@@ -21,11 +21,12 @@ LOG_MODULE_REGISTER(mspi_nrfe, CONFIG_MSPI_LOG_LEVEL);
2121#include <hal/nrf_gpio.h>
2222#include <drivers/mspi/nrfe_mspi.h>
2323
24- #define MSPI_NRFE_NODE DT_DRV_INST(0)
25- #define MAX_TX_MSG_SIZE (DT_REG_SIZE(DT_NODELABEL(sram_tx)))
26- #define MAX_RX_MSG_SIZE (DT_REG_SIZE(DT_NODELABEL(sram_rx)))
27- #define IPC_TIMEOUT_MS 100
28- #define EP_SEND_TIMEOUT_MS 10
24+ #define MSPI_NRFE_NODE DT_DRV_INST(0)
25+ #define MAX_TX_MSG_SIZE (DT_REG_SIZE(DT_NODELABEL(sram_tx)))
26+ #define MAX_RX_MSG_SIZE (DT_REG_SIZE(DT_NODELABEL(sram_rx)))
27+ #define IPC_TIMEOUT_MS 100
28+ #define EP_SEND_TIMEOUT_MS 10
29+ #define CNT0_TOP_CALCULATE (freq ) (NRFX_CEIL_DIV(SystemCoreClock, freq * 2) - 1)
2930
3031#define SDP_MPSI_PINCTRL_DEV_CONFIG_INIT (node_id ) \
3132 { \
@@ -439,6 +440,12 @@ static int api_dev_config(const struct device *dev, const struct mspi_dev_id *de
439440 drv_cfg -> mspicfg .max_freq );
440441 return - EINVAL ;
441442 }
443+
444+ if (CNT0_TOP_CALCULATE (cfg -> freq ) > UINT16_MAX ) {
445+ LOG_ERR ("Invalid frequency: %u. MIN: %u" , cfg -> freq ,
446+ NRFX_CEIL_DIV (drv_cfg -> mspicfg .max_freq , UINT16_MAX ));
447+ return - EINVAL ;
448+ }
442449 }
443450
444451 if (param_mask & MSPI_DEVICE_CONFIG_IO_MODE ) {
@@ -467,7 +474,7 @@ static int api_dev_config(const struct device *dev, const struct mspi_dev_id *de
467474 mspi_dev_config_msg .dev_config .io_mode = cfg -> io_mode ;
468475 mspi_dev_config_msg .dev_config .cpp = cfg -> cpp ;
469476 mspi_dev_config_msg .dev_config .ce_polarity = cfg -> ce_polarity ;
470- mspi_dev_config_msg .dev_config .freq = cfg -> freq ;
477+ mspi_dev_config_msg .dev_config .cnt0_value = CNT0_TOP_CALCULATE ( cfg -> freq ) ;
471478 mspi_dev_config_msg .dev_config .ce_index = cfg -> ce_num ;
472479
473480 return send_data (NRFE_MSPI_CONFIG_DEV , (void * )& mspi_dev_config_msg ,
0 commit comments