xiaoxiang781216 commented on code in PR #19478: URL: https://github.com/apache/nuttx/pull/19478#discussion_r3610876517
########## boards/arm/rk3506/luckfox-lyra-amp/configs/nsh/defconfig: ########## @@ -46,7 +46,7 @@ CONFIG_LIBM=y CONFIG_NSH_BUILTIN_APPS=y CONFIG_NSH_FILEIOSIZE=512 CONFIG_NSH_READLINE=y -CONFIG_RAM_SIZE=15728640 +CONFIG_RAM_SIZE=33554432 Review Comment: merge with the previous patch ########## boards/arm/rk3506/luckfox-lyra-amp/src/rk3506_bringup.c: ########## @@ -0,0 +1,213 @@ +/**************************************************************************** + * boards/arm/rk3506/luckfox-lyra-amp/src/rk3506_bringup.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <sys/types.h> +#include <stdint.h> +#include <stdio.h> +#include <fcntl.h> +#include <syslog.h> +#include <unistd.h> + +#include <nuttx/arch.h> +#include <nuttx/fs/fs.h> +#include <nuttx/kthread.h> +#include <nuttx/serial/serial.h> + +#ifdef CONFIG_SENSORS_FAKESENSOR +# include <nuttx/uorb.h> +# include <nuttx/sensors/fakesensor.h> +#endif + +#include "chip.h" +#include "rk3506.h" + +/* Console uart_dev_t accessor exported by drivers/serial/uart_16550.c. */ + +FAR uart_dev_t *u16550_consoledev(void); + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/* Poll-driven console RX worker. + * + * UART4 RX is wired to GIC SPI IRQ70. On this AMP SoC the GIC distributor is + * shared with Linux, so IRQ70 cannot be delivered to CPU2 reliably (Linux + * owns/reconfigures the distributor and the SPI enable/target for IRQ70 does + * not stick). Polling the UART bypasses the GIC entirely and is reliable; + * TX and the per-CPU PPI timer are unaffected. + */ + +static int rk3506_rxpoll(int argc, char *argv[]) +{ + FAR uart_dev_t *con = u16550_consoledev(); + + /* Disable IRQ70 so the (unreliable) RX interrupt never races this poller + * for the same RBR byte. Give NSH a moment to open the console first. + */ + + usleep(200000); + up_disable_irq(70); + + /* Poll the Line Status Register; when data is ready, push it up through + * the normal serial upper-half via uart_recvchars() - exactly what the RX + * ISR would have done. + * + * LSR @ 0xff0e0000 + (5 << 2), Data-Ready = bit0 + */ + + for (; ; ) + { + uint32_t lsr = *(volatile uint32_t *)(0xff0e0000 + (5 << 2)); + + if (lsr & 0x01) + { + uart_recvchars(con); + } + else + { + usleep(2000); + } + } + + return 0; +} + +#ifdef CONFIG_SENSORS_FAKESENSOR +/* Register a demo accelerometer backed by a small CSV that fakesensor + * replays in a loop. This brings up a live sensor node at + * /dev/uorb/sensor_accel0 with no real hardware, so the full uORB pipeline + * (sensor framework -> uORB -> read/poll) can be exercised on the board: + * + * uorb_listener sensor_accel # watch the live stream + * cat /dev/uorb/sensor_accel0 # raw binary samples + * + * The CSV format is fakesensor's own: first line "interval:<ms>", second + * line the header, then rows of samples. EOF wraps back to the top, so a + * handful of rows produces an endless stream. + */ + +static void rk3506_fakesensor_setup(void) +{ + static const char csv[] = + "interval:100\n" /* 10 Hz */ + "x,y,z\n" + "0.10,0.00,9.81\n" + "0.20,0.05,9.79\n" + "0.05,-0.05,9.82\n" + "-0.10,0.10,9.80\n"; + + const char *path = CONFIG_LIBC_TMPDIR "/accel0.csv"; + struct file f; + int ret; + + ret = file_open(&f, path, O_WRONLY | O_CREAT | O_TRUNC, 0644); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: fakesensor CSV open %s: %d\n", path, ret); + return; + } + + file_write(&f, csv, sizeof(csv) - 1); + file_close(&f); + + /* type, csv path, devno=0, batch buffer = 8 samples */ + + ret = fakesensor_init(SENSOR_TYPE_ACCELEROMETER, path, 0, 8); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: fakesensor_init: %d\n", ret); + return; + } + + syslog(LOG_INFO, "fakesensor accel0 -> /dev/uorb/sensor_accel0\n"); +} +#endif /* CONFIG_SENSORS_FAKESENSOR */ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: rk3506_bringup + * + * Description: + * Bring up board features + * + ****************************************************************************/ + +int rk3506_bringup(void) +{ + int ret; + + UNUSED(ret); + + /* Defer the rest of bring-up (and the subsequent one-shot NSH banner) a + * few seconds. The console UART4 is observed through a board-powered CH340 + * USB-serial adapter that re-enumerates on the host for ~2-3s after every + * board reset. Without this delay the NSH banner is emitted while the host + * port is still gone and is lost. This also exercises the timer tick. + */ + + sleep(3); + + /* Spawn the poll-driven console RX worker (see rk3506_rxpoll above: + * interrupt-driven RX is unreliable on the AMP-shared GIC). + */ + + kthread_create("rxpoll", 100, 2048, rk3506_rxpoll, NULL); Review Comment: why not use wdog ########## arch/arm/src/rk3506/rk3506_boot.c: ########## @@ -0,0 +1,165 @@ +/**************************************************************************** + * arch/arm/src/rk3506/rk3506_boot.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include "arm_internal.h" + +#include "rk3506_irq.h" +#include "rk3506_memorymap.h" +#include "gic.h" + +#ifdef CONFIG_SCHED_INSTRUMENTATION +# include <sched/sched.h> +# include <nuttx/sched_note.h> +#endif + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* RK3506 CRU: force UART4 source clock to the 24MHz crystal (XIN_OSC0). + * + * This mirrors what the Rockchip HAL does for RT-Thread, which is the proven + * configuration that yields a working 1.5Mbaud console on UART4. NuttX does + * not otherwise touch the CRU, so without this the UART4 source clock would + * stay at the (lower) reset/U-Boot value and the 16550 divisor would produce + * the wrong baud rate. + * + * CRU base = 0xff9a0000 + * SCLK_UART4_SEL/_DIV = CLKSEL_CON31 (offset 0x37c) + * - mux bits[15:13]: 0 = XIN_OSC0 (24MHz) + * - div bits[12:8] : 0 = divide by 1 + * Rockchip CRU registers use the upper 16 bits as a write-enable mask for + * the corresponding lower 16 bits. Writing 0xff000000 enables bits[15:8] + * and clears them -> mux=0, div=0 -> UART4 source = 24MHz. + */ + +#define RK3506_CRU_BASE 0xff9a0000 +#define RK3506_CRU_CLKSEL_CON31 (RK3506_CRU_BASE + 0x37c) +#define RK3506_UART4_CLK_24M 0xff000000 + +/* Raw UART4 (dw-apb 16550, reg-shift=2) breadcrumb for early boot. + * Proves arm_boot() runs and the UART hardware works, independent of + * the NuttX serial driver / OS init. Register index << 2 (reg-shift=2). + */ + +#define RK3506_UART4_BASE 0xff0e0000 +#define UART4_REG(idx) \ + (*(volatile uint32_t *)(RK3506_UART4_BASE + ((idx) << 2))) +#define UART4_RBR_THR_DLL UART4_REG(0) /* THR(w) / DLL(DLAB=1) */ +#define UART4_IER_DLM UART4_REG(1) /* IER / DLM(DLAB=1) */ +#define UART4_FCR UART4_REG(2) /* FIFO control */ +#define UART4_LCR UART4_REG(3) /* Line control */ +#define UART4_LSR UART4_REG(5) /* Line status */ +#define UART4_LSR_THRE (1 << 5) /* TX holding empty */ + +static void rk3506_rawuart_init(void) +{ + /* 24MHz / (16 * 1) = 1.5Mbaud, matching the working RT-Thread config. */ + + UART4_LCR = 0x80; /* DLAB=1 */ + UART4_RBR_THR_DLL = 0x01; /* DLL = 1 */ + UART4_IER_DLM = 0x00; /* DLM = 0 */ + UART4_LCR = 0x03; /* DLAB=0, 8N1 */ + UART4_FCR = 0x07; /* enable+clear FIFOs */ +} + +void rk3506_rawuart_puts(const char *s) Review Comment: why not implement up_lowputc and up_lowputs ########## arch/arm/src/rk3506/rk3506_irq.c: ########## @@ -0,0 +1,195 @@ +/**************************************************************************** + * arch/arm/src/rk3506/rk3506_irq.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> +#include <nuttx/arch.h> + +#include "arm_internal.h" +#include "sctlr.h" +#include "gic.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Size of the interrupt stack allocation */ + +#define INTSTACK_ALLOC (CONFIG_SMP_NCPUS * INTSTACK_SIZE) + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#if defined(CONFIG_SMP) && CONFIG_ARCH_INTERRUPTSTACK > 7 +/* In the SMP configuration, we will need custom IRQ and FIQ stacks. + * These definitions provide the aligned stack allocations. + */ + +static uint64_t g_irqstack_alloc[INTSTACK_ALLOC >> 3]; +static uint64_t g_fiqstack_alloc[INTSTACK_ALLOC >> 3]; + +/* These are arrays that point to the top of each interrupt stack */ + +uintptr_t g_irqstack_top[CONFIG_SMP_NCPUS] = +{ + (uintptr_t)g_irqstack_alloc + INTSTACK_SIZE, +#if CONFIG_SMP_NCPUS > 1 + (uintptr_t)g_irqstack_alloc + (2 * INTSTACK_SIZE), +#endif +#if CONFIG_SMP_NCPUS > 2 + (uintptr_t)g_irqstack_alloc + (3 * INTSTACK_SIZE), +#endif +#if CONFIG_SMP_NCPUS > 3 + (uintptr_t)g_irqstack_alloc + (4 * INTSTACK_SIZE) +#endif +}; + +uintptr_t g_fiqstack_top[CONFIG_SMP_NCPUS] = +{ + (uintptr_t)g_fiqstack_alloc + INTSTACK_SIZE, +#if CONFIG_SMP_NCPUS > 1 + (uintptr_t)g_fiqstack_alloc + 2 * INTSTACK_SIZE, +#endif +#if CONFIG_SMP_NCPUS > 2 + (uintptr_t)g_fiqstack_alloc + 3 * INTSTACK_SIZE, +#endif +#if CONFIG_SMP_NCPUS > 3 + (uintptr_t)g_fiqstack_alloc + 4 * INTSTACK_SIZE +#endif +}; + +#endif + +/* Symbols defined via the linker script */ + +extern uint8_t _vector_start[]; /* Beginning of vector block */ +extern uint8_t _vector_end[]; /* End+1 of vector block */ + +/* Raw UART4 debug breadcrumb helpers (defined in rk3506_boot.c). Used to + * localize where boot hangs, independent of the OS/serial driver. The + * marker prints repeatedly so it survives the CH340 USB re-enumeration + * window (board-powered adapter re-enumerates 2-3s on every reset). + */ + +void rk3506_rawuart_puts(const char *s); +void rk3506_dbgmark(const char *tag); Review Comment: why add the unused symbols ########## arch/arm/src/rk3506/CMakeLists.txt: ########## @@ -0,0 +1,37 @@ +# ############################################################################## +# arch/arm/src/qemu/CMakeLists.txt Review Comment: fix the path in all file ########## boards/arm/rk3506/luckfox-lyra-amp/src/rk3506_bringup.c: ########## @@ -0,0 +1,213 @@ +/**************************************************************************** + * boards/arm/rk3506/luckfox-lyra-amp/src/rk3506_bringup.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <sys/types.h> +#include <stdint.h> +#include <stdio.h> +#include <fcntl.h> +#include <syslog.h> +#include <unistd.h> + +#include <nuttx/arch.h> +#include <nuttx/fs/fs.h> +#include <nuttx/kthread.h> +#include <nuttx/serial/serial.h> + +#ifdef CONFIG_SENSORS_FAKESENSOR +# include <nuttx/uorb.h> +# include <nuttx/sensors/fakesensor.h> +#endif + +#include "chip.h" +#include "rk3506.h" + +/* Console uart_dev_t accessor exported by drivers/serial/uart_16550.c. */ + +FAR uart_dev_t *u16550_consoledev(void); + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/* Poll-driven console RX worker. + * + * UART4 RX is wired to GIC SPI IRQ70. On this AMP SoC the GIC distributor is + * shared with Linux, so IRQ70 cannot be delivered to CPU2 reliably (Linux + * owns/reconfigures the distributor and the SPI enable/target for IRQ70 does + * not stick). Polling the UART bypasses the GIC entirely and is reliable; + * TX and the per-CPU PPI timer are unaffected. + */ + +static int rk3506_rxpoll(int argc, char *argv[]) +{ + FAR uart_dev_t *con = u16550_consoledev(); + + /* Disable IRQ70 so the (unreliable) RX interrupt never races this poller + * for the same RBR byte. Give NSH a moment to open the console first. + */ + + usleep(200000); + up_disable_irq(70); + + /* Poll the Line Status Register; when data is ready, push it up through + * the normal serial upper-half via uart_recvchars() - exactly what the RX + * ISR would have done. + * + * LSR @ 0xff0e0000 + (5 << 2), Data-Ready = bit0 + */ + + for (; ; ) + { + uint32_t lsr = *(volatile uint32_t *)(0xff0e0000 + (5 << 2)); + + if (lsr & 0x01) + { + uart_recvchars(con); + } + else + { + usleep(2000); + } + } + + return 0; +} + +#ifdef CONFIG_SENSORS_FAKESENSOR +/* Register a demo accelerometer backed by a small CSV that fakesensor + * replays in a loop. This brings up a live sensor node at + * /dev/uorb/sensor_accel0 with no real hardware, so the full uORB pipeline + * (sensor framework -> uORB -> read/poll) can be exercised on the board: + * + * uorb_listener sensor_accel # watch the live stream + * cat /dev/uorb/sensor_accel0 # raw binary samples + * + * The CSV format is fakesensor's own: first line "interval:<ms>", second + * line the header, then rows of samples. EOF wraps back to the top, so a + * handful of rows produces an endless stream. + */ + +static void rk3506_fakesensor_setup(void) +{ + static const char csv[] = + "interval:100\n" /* 10 Hz */ + "x,y,z\n" + "0.10,0.00,9.81\n" + "0.20,0.05,9.79\n" + "0.05,-0.05,9.82\n" + "-0.10,0.10,9.80\n"; + + const char *path = CONFIG_LIBC_TMPDIR "/accel0.csv"; + struct file f; + int ret; + + ret = file_open(&f, path, O_WRONLY | O_CREAT | O_TRUNC, 0644); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: fakesensor CSV open %s: %d\n", path, ret); + return; + } + + file_write(&f, csv, sizeof(csv) - 1); + file_close(&f); + + /* type, csv path, devno=0, batch buffer = 8 samples */ + + ret = fakesensor_init(SENSOR_TYPE_ACCELEROMETER, path, 0, 8); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: fakesensor_init: %d\n", ret); + return; + } + + syslog(LOG_INFO, "fakesensor accel0 -> /dev/uorb/sensor_accel0\n"); +} +#endif /* CONFIG_SENSORS_FAKESENSOR */ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: rk3506_bringup + * + * Description: + * Bring up board features + * + ****************************************************************************/ + +int rk3506_bringup(void) +{ + int ret; + + UNUSED(ret); + + /* Defer the rest of bring-up (and the subsequent one-shot NSH banner) a + * few seconds. The console UART4 is observed through a board-powered CH340 + * USB-serial adapter that re-enumerates on the host for ~2-3s after every + * board reset. Without this delay the NSH banner is emitted while the host + * port is still gone and is lost. This also exercises the timer tick. + */ + + sleep(3); + + /* Spawn the poll-driven console RX worker (see rk3506_rxpoll above: + * interrupt-driven RX is unreliable on the AMP-shared GIC). + */ + + kthread_create("rxpoll", 100, 2048, rk3506_rxpoll, NULL); + +#ifdef CONFIG_FS_TMPFS + /* Mount the tmpfs file system */ + + ret = nx_mount(NULL, CONFIG_LIBC_TMPDIR, "tmpfs", 0, NULL); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to mount tmpfs at %s: %d\n", + CONFIG_LIBC_TMPDIR, ret); + } +#endif + +#ifdef CONFIG_FS_PROCFS + /* Mount the procfs file system */ + + ret = nx_mount(NULL, "/proc", "procfs", 0, NULL); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to mount procfs at /proc: %d\n", ret); + } +#endif + +#ifdef CONFIG_SENSORS_FAKESENSOR + /* Register a demo accelerometer (CSV-backed) on /dev/uorb/sensor_accel0. */ + + rk3506_fakesensor_setup(); Review Comment: why use fakesensor on the real device ########## arch/arm/src/rk3506/Make.defs: ########## @@ -0,0 +1,36 @@ +############################################################################ +# arch/arm/src/qemu/Make.defs Review Comment: ditto -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
