[nxp/mcxn] add SPI6 support (#8704)
* [bsp][nxp] add missing drv_spi.h Otherwise when building spi users such as u8g2, gcc will complain can't find the drv_spi.h. * [bsp][nxp] enable spi6 * [bsp][nxp] add spi sample code which uses spi6 to loopback Connect spi6's MISO <--> MSIO, I.E P3_20 and P3_22 with Dupont Line The sample usage and output would be: msh >spi_sample spi rbuf : 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f spi loopback mode test over!
This commit is contained in:
parent
447a10c964
commit
e0e9eb8b15
|
@ -20,6 +20,11 @@ enum
|
|||
#ifdef BSP_USING_SPI3
|
||||
SPI3_INDEX,
|
||||
#endif
|
||||
|
||||
#ifdef BSP_USING_SPI6
|
||||
SPI6_INDEX,
|
||||
#endif
|
||||
|
||||
#ifdef BSP_USING_SPI7
|
||||
SPI7_INDEX,
|
||||
#endif
|
||||
|
@ -63,7 +68,20 @@ static struct lpc_spi lpc_obj[] =
|
|||
.rx_dma_chl = 3,
|
||||
.name = "spi3",
|
||||
},
|
||||
#endif
|
||||
#endif /* BSP_USING_SPI3 */
|
||||
#ifdef BSP_USING_SPI6
|
||||
{
|
||||
.LPSPIx = LPSPI6,
|
||||
.clock_attach_id = kFRO_HF_DIV_to_FLEXCOMM6,
|
||||
.clock_div_name = kCLOCK_DivFlexcom6Clk,
|
||||
.clock_name = kCLOCK_FroHf,
|
||||
.tx_dma_request = kDmaRequestMuxLpFlexcomm6Tx,
|
||||
.rx_dma_request = kDmaRequestMuxLpFlexcomm6Rx,
|
||||
.DMAx = DMA0,
|
||||
.tx_dma_chl = 4,
|
||||
.rx_dma_chl = 5,
|
||||
.name = "spi6",
|
||||
#endif /* BSP_USING_SPI6 */
|
||||
#ifdef BSP_USING_SPI7
|
||||
{
|
||||
.LPSPIx = LPSPI7,
|
||||
|
@ -77,7 +95,7 @@ static struct lpc_spi lpc_obj[] =
|
|||
.rx_dma_chl = 3,
|
||||
.name = "spi7",
|
||||
},
|
||||
#endif
|
||||
#endif /* BSP_USING_SPI7 */
|
||||
};
|
||||
|
||||
|
||||
|
@ -146,7 +164,7 @@ static rt_ssize_t spixfer(struct rt_spi_device *device, struct rt_spi_message *m
|
|||
// if(message->length < MAX_DMA_TRANSFER_SIZE)
|
||||
if(0)
|
||||
{
|
||||
// SPI_MasterTransferBlocking(spi->SPIx, &transfer);
|
||||
LPSPI_MasterTransferBlocking(spi->LPSPIx, &transfer);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2024, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2024-03-22 Jisheng Zhang The first version for mcxn
|
||||
*/
|
||||
|
||||
#ifndef __DRV_SPI_H__
|
||||
#define __DRV_SPI_H__
|
||||
|
||||
#include <rtdevice.h>
|
||||
|
||||
rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name, rt_base_t cs_pin);
|
||||
|
||||
#endif /*__DRV_SPI_H__ */
|
|
@ -64,6 +64,15 @@ menu "On-chip Peripheral Drivers"
|
|||
bool "Enable Flexcomm3 as SPI"
|
||||
default n
|
||||
|
||||
config BSP_USING_SPI6
|
||||
bool "Enable Flexcomm6 as SPI"
|
||||
default n
|
||||
if BSP_USING_SPI6
|
||||
config BSP_USING_SPI6_SAMPLE
|
||||
bool "Enable SPI6 BUS Sample"
|
||||
default n
|
||||
endif
|
||||
|
||||
config BSP_USING_SPI7
|
||||
bool "Enable Flexcomm7 as SPI"
|
||||
default n
|
||||
|
|
|
@ -99,8 +99,12 @@ void BOARD_InitBootPins(void)
|
|||
PORT2->PCR[6] = PORT_PCR_MUX(3) | PORT_PCR_PE(1) | PORT_PCR_PS(1) | PORT_PCR_IBE(1); /* SDHC0_D3 */
|
||||
PORT2->PCR[7] = PORT_PCR_MUX(3) | PORT_PCR_PE(1) | PORT_PCR_PS(1) | PORT_PCR_IBE(1); /* SDHC0_D2 */
|
||||
|
||||
PORT3->PCR[20] = PORT_PCR_MUX(3) | PORT_PCR_PS(0) | PORT_PCR_IBE(1); /* FC6_P0 */
|
||||
PORT3->PCR[21] = PORT_PCR_MUX(3) | PORT_PCR_PS(0) | PORT_PCR_IBE(1); /* FC6_P1 */
|
||||
/* mikroBUS SPI6 */
|
||||
PORT3->PCR[20] = PORT_PCR_MUX(3) | PORT_PCR_PS(0) | PORT_PCR_PE(0) | PORT_PCR_IBE(1); /* FC6_P0 SDO/D[0], FC6_SPI_MOSI */
|
||||
PORT3->PCR[21] = PORT_PCR_MUX(3) | PORT_PCR_PS(0) | PORT_PCR_PE(0) | PORT_PCR_IBE(1); /* FC6_P1 SCK, FC6_SPI_CLK */
|
||||
PORT3->PCR[22] = PORT_PCR_MUX(3) | PORT_PCR_PS(0) | PORT_PCR_PE(0) | PORT_PCR_IBE(1); /* FC6_P2 SDI/D[1], FC3_SPI_MISO */
|
||||
PORT3->PCR[23] = PORT_PCR_MUX(0) | PORT_PCR_PS(0) | PORT_PCR_PE(0) | PORT_PCR_IBE(1); /* CS */
|
||||
|
||||
|
||||
// PORT1->PCR[20] = PORT_PCR_MUX(3) | PORT_PCR_PS(0) | PORT_PCR_PE(0) | PORT_PCR_IBE(1); /* FC4_0 */
|
||||
// PORT1->PCR[21] = PORT_PCR_MUX(3) | PORT_PCR_PS(0) | PORT_PCR_PE(0) | PORT_PCR_IBE(1); /* FC4_1 */
|
||||
|
|
|
@ -9,6 +9,9 @@ MCUX_Config/board/clock_config.c
|
|||
MCUX_Config/board/pin_mux.c
|
||||
""")
|
||||
|
||||
if GetDepend(['BSP_USING_SPI6_SAMPLE']):
|
||||
src += Glob('ports/spi_sample.c')
|
||||
|
||||
CPPPATH = [cwd, cwd + '/MCUX_Config/board']
|
||||
CPPDEFINES = ['DEBUG', 'CPU_MCXN947VDF_cm33_core0']
|
||||
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-07-19 Rbbb666 first version
|
||||
* 2024-03-30 xhackerustc 2nd version for FRDM-MCXN947
|
||||
*/
|
||||
|
||||
#include "board.h"
|
||||
|
||||
#include <drv_spi.h>
|
||||
|
||||
#define SPI_NAME "spi60"
|
||||
#define CS_PIN (3*32+23)
|
||||
static struct rt_spi_device *spi_dev;
|
||||
|
||||
/* attach spi device */
|
||||
static int rt_spi_device_init(void)
|
||||
{
|
||||
struct rt_spi_configuration cfg;
|
||||
|
||||
rt_hw_spi_device_attach("spi6", SPI_NAME, CS_PIN);
|
||||
|
||||
cfg.data_width = 8;
|
||||
cfg.mode = RT_SPI_MASTER | RT_SPI_MODE_0 | RT_SPI_MSB | RT_SPI_NO_CS;
|
||||
cfg.max_hz = 1 *1000 *1000;
|
||||
|
||||
spi_dev = (struct rt_spi_device *)rt_device_find(SPI_NAME);
|
||||
|
||||
if (RT_NULL == spi_dev)
|
||||
{
|
||||
rt_kprintf("spi sample run failed! can't find %s device!\n", SPI_NAME);
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
rt_spi_configure(spi_dev, &cfg);
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
INIT_APP_EXPORT(rt_spi_device_init);
|
||||
|
||||
/* spi loopback mode test case */
|
||||
static int spi_sample(int argc, char **argv)
|
||||
{
|
||||
rt_uint8_t t_buf[32], r_buf[32];
|
||||
int i = 0;
|
||||
static struct rt_spi_message msg1;
|
||||
|
||||
for (i = 0; i < sizeof(t_buf); i++)
|
||||
{
|
||||
t_buf[i] = i;
|
||||
}
|
||||
|
||||
msg1.send_buf = &t_buf;
|
||||
msg1.recv_buf = &r_buf;
|
||||
msg1.length = sizeof(t_buf);
|
||||
msg1.cs_take = 1;
|
||||
msg1.cs_release = 1;
|
||||
msg1.next = RT_NULL;
|
||||
|
||||
rt_spi_transfer_message(spi_dev, &msg1);
|
||||
|
||||
rt_kprintf("spi rbuf : ");
|
||||
for (i = 0; i < sizeof(r_buf); i++)
|
||||
{
|
||||
rt_kprintf("%x ", r_buf[i]);
|
||||
}
|
||||
|
||||
rt_kprintf("\nspi loopback mode test over!\n");
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
MSH_CMD_EXPORT(spi_sample, spi loopback test);
|
Loading…
Reference in New Issue