Skip to content

Commit 79dca79

Browse files
committed
update frdm-mcxa346 project
1 parent d75ba0f commit 79dca79

File tree

8 files changed

+693
-205
lines changed

8 files changed

+693
-205
lines changed
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-mcxa346/applications/main.c

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,27 @@
99
* 2019-10-24 Magicoe first version
1010
* 2020-01-10 Kevin/Karl Add PS demo
1111
* 2020-09-21 supperthomas fix the main.c
12+
* 2025-08-18 Alex Yang Add P1_7 button with LED blink control
1213
*
1314
*/
1415

1516
#include <rtdevice.h>
1617
#include "drv_pin.h"
1718

18-
#define LED_PIN ((3*32)+18)
19+
#define LED_PIN ((3*32)+18) /* Original LED pin */
20+
#define BUTTON_PIN ((1*32)+7) /* P1_7 button pin */
1921

20-
int main(void)
21-
{
22+
static rt_bool_t led_state = RT_FALSE; /* Current LED state */
2223

2324

25+
/* Button interrupt callback function */
26+
void button_irq_callback(void *args)
27+
{
28+
rt_kprintf("SW2 pressed\n");
29+
}
30+
31+
int main(void)
32+
{
2433
#if defined(__CC_ARM)
2534
rt_kprintf("using armcc, version: %d\n", __ARMCC_VERSION);
2635
#elif defined(__clang__)
@@ -31,16 +40,26 @@ int main(void)
3140
rt_kprintf("using gcc, version: %d.%d\n", __GNUC__, __GNUC_MINOR__);
3241
#endif
3342

34-
rt_kprintf("MCXA346 HelloWorld\r\n");
35-
rt_pin_mode(LED_PIN, PIN_MODE_OUTPUT); /* Set GPIO as Output */
43+
rt_kprintf("FRDM-MCXA346\r\n");
44+
45+
/* Configure LED pin as output */
46+
rt_pin_mode(LED_PIN, PIN_MODE_OUTPUT);
47+
rt_pin_write(LED_PIN, PIN_LOW);
48+
49+
/* Configure button pin as input with pull-up */
50+
rt_pin_mode(BUTTON_PIN, PIN_MODE_INPUT_PULLUP);
51+
52+
/* Attach interrupt to button pin */
53+
rt_pin_attach_irq(BUTTON_PIN, PIN_IRQ_MODE_FALLING, button_irq_callback, RT_NULL);
54+
rt_pin_irq_enable(BUTTON_PIN, PIN_IRQ_ENABLE);
3655

3756
while (1)
3857
{
39-
rt_pin_write(LED_PIN, PIN_HIGH); /* Set GPIO output 1 */
40-
rt_thread_mdelay(500); /* Delay 500mS */
41-
rt_pin_write(LED_PIN, PIN_LOW); /* Set GPIO output 0 */
42-
rt_thread_mdelay(500); /* Delay 500mS */
58+
/* Toggle LED state */
59+
led_state = !led_state;
60+
61+
rt_pin_write(LED_PIN, led_state ? PIN_HIGH : PIN_LOW);
62+
63+
rt_thread_mdelay(500);
4364
}
4465
}
45-
46-
// end file

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

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,8 @@ menu "On-chip Peripheral Drivers"
4040
default y
4141

4242
if BSP_USING_I2C
43-
config BSP_USING_I2C0
44-
bool "Enable Flexcomm0 I2C"
45-
default y
46-
config BSP_USING_I2C1
47-
bool "Enable Flexcomm1 I2C"
43+
config BSP_USING_I2C3
44+
bool "Enable Flexcomm3 I2C"
4845
default y
4946
endif
5047

@@ -67,26 +64,8 @@ menu "On-chip Peripheral Drivers"
6764
default y
6865

6966
if BSP_USING_ADC
70-
config BSP_USING_ADC0_CH0
71-
bool "Enable ADC0 Channel0"
72-
default y
73-
74-
config BSP_USING_ADC0_CH1
75-
bool "Enable ADC0 Channel1"
76-
default n
77-
78-
config BSP_USING_ADC0_CH8
79-
bool "Enable ADC0 Channel8"
80-
default n
81-
82-
83-
config BSP_USING_ADC0_CH13
84-
bool "Enable ADC0 Channel13"
85-
default n
86-
87-
88-
config BSP_USING_ADC0_CH26
89-
bool "Enable ADC0 Channel26"
67+
config BSP_USING_ADC0_CH22
68+
bool "Enable ADC0 Channel22"
9069
default n
9170

9271
endif
@@ -162,15 +141,15 @@ menu "Board extended module Drivers"
162141

163142
config BOARD_RW007_CS_PIN
164143
hex "CS pin index"
165-
default 0x46
144+
default 107
166145

167146
config BOARD_RW007_INT_BUSY_PIN
168147
hex "INT/BUSY pin index"
169-
default 0x71
148+
default 109
170149

171150
config BOARD_RW007_RST_PIN
172151
hex "RESET pin index"
173-
default 0x2F
152+
default 131
174153
endif
175154

176155

0 commit comments

Comments
 (0)