Skip to content

Commit 4e5f95e

Browse files
imi415Rbb666
authored andcommitted
bsp: nxp/mcx/mcxa/frdm-mcxa156: Enable SPI driver support.
This patch: * Enables SPI support * Adds RW001 driver example * Increases heap size to 32kB. Signed-off-by: Yilin Sun <[email protected]>
1 parent 59feb97 commit 4e5f95e

File tree

7 files changed

+225
-8
lines changed

7 files changed

+225
-8
lines changed

bsp/nxp/mcx/mcxa/Libraries/MCXA156/SConscript

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ src += ['MCXA156/drivers/fsl_lpi2c_edma.c']
3939
src += ['MCXA156/drivers/fsl_lptmr.c']
4040
src += ['MCXA156/drivers/fsl_lpuart.c']
4141
src += ['MCXA156/drivers/fsl_lpuart_edma.c']
42+
src += ['MCXA156/drivers/fsl_lpspi.c']
43+
src += ['MCXA156/drivers/fsl_lpspi_edma.c']
4244
src += ['MCXA156/drivers/fsl_ostimer.c']
4345
src += ['MCXA156/drivers/fsl_pwm.c']
4446
src += ['MCXA156/drivers/fsl_reset.c']

bsp/nxp/mcx/mcxa/frdm-mcxa156/board/Kconfig

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,9 @@ menu "On-chip Peripheral Drivers"
5555
default y
5656

5757
if BSP_USING_SPI
58-
config BSP_USING_SPI3
59-
bool "Enable Flexcomm3 as SPI"
58+
config BSP_USING_SPI1
59+
bool "Enable LPSPI1"
6060
default n
61-
62-
config BSP_USING_SPI8
63-
bool "Enable Flexcomm8 as High Speed SPI"
64-
default y
6561
endif
6662

6763
menuconfig BSP_USING_ADC
@@ -167,7 +163,32 @@ endmenu
167163

168164

169165
menu "Board extended module Drivers"
170-
166+
menuconfig BSP_USING_RW007
167+
bool "Enable RW007"
168+
default n
169+
select BSP_USING_SPI
170+
select BSP_USING_SPI1
171+
select PKG_USING_RW007
172+
select RT_USING_MEMPOOL
173+
select RW007_NOT_USE_EXAMPLE_DRIVERS
174+
175+
if BSP_USING_RW007
176+
config BOARD_RW007_SPI_BUS_NAME
177+
string "RW007 BUS NAME"
178+
default "spi1"
179+
180+
config BOARD_RW007_CS_PIN
181+
hex "CS pin index"
182+
default 0x46
183+
184+
config BOARD_RW007_INT_BUSY_PIN
185+
hex "INT/BUSY pin index"
186+
default 0x71
187+
188+
config BOARD_RW007_RST_PIN
189+
hex "RESET pin index"
190+
default 0x2F
191+
endif
171192
endmenu
172193

173194
endmenu

bsp/nxp/mcx/mcxa/frdm-mcxa156/board/MCUX_Config/board/clock_config.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,19 @@ extern uint32_t SystemCoreClock;
5252
void BOARD_InitBootClocks(void)
5353
{
5454
BOARD_BootClockFRO96M();
55+
56+
CLOCK_SetClockDiv(kCLOCK_DivFRO_HF_DIV, 2U);
57+
58+
CLOCK_EnableClock(kCLOCK_GateLPSPI0);
59+
CLOCK_EnableClock(kCLOCK_GateLPSPI1);
60+
CLOCK_EnableClock(kCLOCK_GateDMA);
61+
62+
CLOCK_AttachClk(kFRO_HF_DIV_to_LPSPI0);
63+
CLOCK_AttachClk(kFRO_HF_DIV_to_LPSPI1);
64+
65+
RESET_ReleasePeripheralReset(kLPSPI0_RST_SHIFT_RSTn);
66+
RESET_ReleasePeripheralReset(kLPSPI1_RST_SHIFT_RSTn);
67+
RESET_ReleasePeripheralReset(kDMA_RST_SHIFT_RSTn);
5568
}
5669

5770
/*******************************************************************************

bsp/nxp/mcx/mcxa/frdm-mcxa156/board/MCUX_Config/board/pin_mux.c

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ processor_version: 0.15.0
2222
*/
2323
/* clang-format on */
2424

25+
#include "rtconfig.h"
26+
2527
#include "fsl_common.h"
2628
#include "fsl_port.h"
2729
#include "pin_mux.h"
@@ -159,6 +161,109 @@ void BOARD_InitPins(void)
159161
kPORT_UnlockRegister};
160162
/* PORT3_12 (pin 63) is configured as LED_RED */
161163
PORT_SetPinConfig(PORT3, 12U, &port3_12_pin63_config);
164+
165+
#ifdef BSP_USING_SPI1
166+
const port_pin_config_t port2_12_pin34_config = {/* Internal pull-up/down resistor is disabled */
167+
kPORT_PullDisable,
168+
/* Low internal pull resistor value is selected. */
169+
kPORT_LowPullResistor,
170+
/* Fast slew rate is configured */
171+
kPORT_FastSlewRate,
172+
/* Passive input filter is disabled */
173+
kPORT_PassiveFilterDisable,
174+
/* Open drain output is disabled */
175+
kPORT_OpenDrainDisable,
176+
/* Low drive strength is configured */
177+
kPORT_LowDriveStrength,
178+
/* Normal drive strength is configured */
179+
kPORT_NormalDriveStrength,
180+
/* Pin is configured as LPSPI1_SCK */
181+
kPORT_MuxAlt2,
182+
/* Digital input enabled */
183+
kPORT_InputBufferEnable,
184+
/* Digital input is not inverted */
185+
kPORT_InputNormal,
186+
/* Pin Control Register fields [15:0] are not locked */
187+
kPORT_UnlockRegister};
188+
/* PORT2_12 (pin 34) is configured as LPSPI1_SCK */
189+
PORT_SetPinConfig(PORT2, 12U, &port2_12_pin34_config);
190+
191+
const port_pin_config_t port2_13_pin35_config = {/* Internal pull-up/down resistor is disabled */
192+
kPORT_PullDisable,
193+
/* Low internal pull resistor value is selected. */
194+
kPORT_LowPullResistor,
195+
/* Fast slew rate is configured */
196+
kPORT_FastSlewRate,
197+
/* Passive input filter is disabled */
198+
kPORT_PassiveFilterDisable,
199+
/* Open drain output is disabled */
200+
kPORT_OpenDrainDisable,
201+
/* Low drive strength is configured */
202+
kPORT_LowDriveStrength,
203+
/* Normal drive strength is configured */
204+
kPORT_NormalDriveStrength,
205+
/* Pin is configured as LPSPI1_SDO */
206+
kPORT_MuxAlt2,
207+
/* Digital input enabled */
208+
kPORT_InputBufferEnable,
209+
/* Digital input is not inverted */
210+
kPORT_InputNormal,
211+
/* Pin Control Register fields [15:0] are not locked */
212+
kPORT_UnlockRegister};
213+
/* PORT2_13 (pin 35) is configured as LPSPI1_SDO */
214+
PORT_SetPinConfig(PORT2, 13U, &port2_13_pin35_config);
215+
216+
const port_pin_config_t port2_16_pin37_config = {/* Internal pull-up/down resistor is disabled */
217+
kPORT_PullDisable,
218+
/* Low internal pull resistor value is selected. */
219+
kPORT_LowPullResistor,
220+
/* Fast slew rate is configured */
221+
kPORT_FastSlewRate,
222+
/* Passive input filter is disabled */
223+
kPORT_PassiveFilterDisable,
224+
/* Open drain output is disabled */
225+
kPORT_OpenDrainDisable,
226+
/* Low drive strength is configured */
227+
kPORT_LowDriveStrength,
228+
/* Normal drive strength is configured */
229+
kPORT_NormalDriveStrength,
230+
/* Pin is configured as LPSPI1_SDI */
231+
kPORT_MuxAlt2,
232+
/* Digital input enabled */
233+
kPORT_InputBufferEnable,
234+
/* Digital input is not inverted */
235+
kPORT_InputNormal,
236+
/* Pin Control Register fields [15:0] are not locked */
237+
kPORT_UnlockRegister};
238+
/* PORT2_16 (pin 37) is configured as LPSPI1_SDI */
239+
PORT_SetPinConfig(PORT2, 16U, &port2_16_pin37_config);
240+
241+
const port_pin_config_t port2_6_pin28_config = {/* Internal pull-up/down resistor is disabled */
242+
kPORT_PullDisable,
243+
/* Low internal pull resistor value is selected. */
244+
kPORT_LowPullResistor,
245+
/* Fast slew rate is configured */
246+
kPORT_FastSlewRate,
247+
/* Passive input filter is disabled */
248+
kPORT_PassiveFilterDisable,
249+
/* Open drain output is disabled */
250+
kPORT_OpenDrainDisable,
251+
/* Low drive strength is configured */
252+
kPORT_LowDriveStrength,
253+
/* Normal drive strength is configured */
254+
kPORT_NormalDriveStrength,
255+
/* Pin is configured as LPSPI1_PCS1 */
256+
kPORT_MuxAsGpio,
257+
/* Digital input enabled */
258+
kPORT_InputBufferEnable,
259+
/* Digital input is not inverted */
260+
kPORT_InputNormal,
261+
/* Pin Control Register fields [15:0] are not locked */
262+
kPORT_UnlockRegister};
263+
/* PORT2_6 (pin 20) is configured as LPSPI1_PCS1 */
264+
PORT_SetPinConfig(PORT2, 6U, &port2_6_pin28_config);
265+
#endif
266+
162267
}
163268
/***********************************************************************************************************************
164269
* EOF

bsp/nxp/mcx/mcxa/frdm-mcxa156/board/SConscript

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ MCUX_Config/board/clock_config.c
99
MCUX_Config/board/pin_mux.c
1010
""")
1111

12+
if GetDepend(['BSP_USING_RW007']):
13+
src += Glob('ports/drv_spi_sample_rw007.c')
14+
1215
CPPPATH = [cwd, cwd + '/MCUX_Config/board']
1316
CPPDEFINES = ['DEBUG', 'CPU_MCXA156VLL']
1417

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#include <rtthread.h>
2+
3+
#ifdef BSP_USING_RW007
4+
#include <rtdbg.h>
5+
#include <rtdevice.h>
6+
#include <board.h>
7+
#include <spi_wifi_rw007.h>
8+
9+
#define BOARD_RW007_DEVICE_NAME "rw007"
10+
11+
extern void spi_wifi_isr(int vector);
12+
13+
static void rw007_gpio_init(void)
14+
{
15+
/* Configure IO */
16+
rt_pin_mode(BOARD_RW007_RST_PIN, PIN_MODE_OUTPUT);
17+
rt_pin_mode(BOARD_RW007_INT_BUSY_PIN, PIN_MODE_INPUT_PULLDOWN);
18+
19+
/* Reset rw007 and config mode */
20+
rt_pin_write(BOARD_RW007_RST_PIN, PIN_LOW);
21+
22+
rt_thread_delay(rt_tick_from_millisecond(100));
23+
rt_pin_write(BOARD_RW007_RST_PIN, PIN_HIGH);
24+
25+
/* Wait rw007 ready(exit busy stat) */
26+
while (!rt_pin_read(BOARD_RW007_INT_BUSY_PIN))
27+
{
28+
rt_thread_delay(5);
29+
}
30+
31+
rt_thread_delay(rt_tick_from_millisecond(200));
32+
rt_pin_mode(BOARD_RW007_INT_BUSY_PIN, PIN_MODE_INPUT_PULLUP);
33+
}
34+
35+
int wifi_spi_device_init(void)
36+
{
37+
int ret = 0;
38+
char sn_version[32];
39+
40+
struct rt_spi_device *spi_device = rt_malloc(sizeof(struct rt_spi_device));
41+
if (!spi_device) return -1;
42+
43+
rw007_gpio_init();
44+
ret = rt_spi_bus_attach_device_cspin(spi_device, BOARD_RW007_DEVICE_NAME, BOARD_RW007_SPI_BUS_NAME, BOARD_RW007_CS_PIN, RT_NULL);
45+
if (ret != RT_EOK) return -2;
46+
47+
rt_hw_wifi_init("rw007");
48+
49+
rt_wlan_set_mode(RT_WLAN_DEVICE_STA_NAME, RT_WLAN_STATION);
50+
rt_wlan_set_mode(RT_WLAN_DEVICE_AP_NAME, RT_WLAN_AP);
51+
52+
rw007_sn_get(sn_version);
53+
rt_kprintf("\nrw007 sn: [%s]\n", sn_version);
54+
rw007_version_get(sn_version);
55+
rt_kprintf("rw007 ver: [%s]\n\n", sn_version);
56+
57+
return 0;
58+
}
59+
INIT_APP_EXPORT(wifi_spi_device_init);
60+
61+
static void int_wifi_irq(void *p)
62+
{
63+
((void)p);
64+
spi_wifi_isr(0);
65+
}
66+
67+
void spi_wifi_hw_init(void)
68+
{
69+
rt_pin_attach_irq(BOARD_RW007_INT_BUSY_PIN, PIN_IRQ_MODE_FALLING, int_wifi_irq, 0);
70+
rt_pin_irq_enable(BOARD_RW007_INT_BUSY_PIN, RT_TRUE);
71+
}
72+
73+
#endif

bsp/nxp/mcx/mcxa/frdm-mcxa156/rtconfig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
DEVICE = ' -mcpu=' + CPU + ' -mthumb -mfpu=fpv5-sp-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections'
4848
CFLAGS = DEVICE + ' -Wall -D__FPU_PRESENT'
4949
AFLAGS = ' -c' + DEVICE + ' -x assembler-with-cpp -D__START=entry -D__STARTUP_CLEAR_BSS'
50-
LFLAGS = DEVICE + ' -specs=nano.specs -specs=nosys.specs -Wl,--defsym=__heap_size__=0x2000,--gc-sections,-Map=rtthread.map,--print-memory-usage -Tboard/linker_scripts/MCXA156_flash.ld'
50+
LFLAGS = DEVICE + ' -specs=nano.specs -specs=nosys.specs -Wl,--defsym=__heap_size__=0x8000,--gc-sections,-Map=rtthread.map,--print-memory-usage -Tboard/linker_scripts/MCXA156_flash.ld'
5151

5252
CPATH = ''
5353
LPATH = ''

0 commit comments

Comments
 (0)