Skip to content

Commit 1afa49e

Browse files
magp-nordicmasz-nordic
authored andcommitted
drivers: mspi: add calculating CNT0 value
Add calculating VTIM CNT0 value base don required frequency. Also, add checking if required frequency is not too small. Signed-off-by: Magdalena Pastula <magdalena.pastula@nordicsemi.no>
1 parent 8a50295 commit 1afa49e

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

drivers/mspi/mspi_nrfe.c

+13-6
Original file line numberDiff line numberDiff line change
@@ -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,

include/drivers/mspi/nrfe_mspi.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ typedef struct {
4949
enum mspi_cpp_mode cpp;
5050
uint8_t ce_index;
5151
enum mspi_ce_polarity ce_polarity;
52-
uint32_t freq;
52+
uint16_t cnt0_value;
5353
} nrfe_mspi_dev_config_t;
5454

5555
typedef struct {

0 commit comments

Comments
 (0)