This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 932557119805567d603573803291021041c79114 Author: Maarten Zanders <[email protected]> AuthorDate: Tue Feb 24 11:31:37 2026 +0100 boards/arm/imx9: add i.MX93 Quick Start Board (QSB) support. Add board support for the NXP i.MX93 QSB targeting the Cortex-M33 core. Three configurations are provided: - nsh: run from ITCM (128 kB), LPUART2 console - nsh-ddr: run from DDR, LPUART2 console - rpmsg: run from ITCM, RPMsg/OpenAMP transport, NSH on /dev/tty-nsh via RPMSG_UART_RAW Linker scripts: - itcm.ld: vectors + text in ITCM, data in DTCM - ddr.ld: vectors + text + data in DDR (0x89000000, 16 MB) Tool to enable local debug interface through USB. Signed-off-by: Maarten Zanders <[email protected]> --- boards/Kconfig | 12 ++ boards/arm/imx9/imx93-qsb/CMakeLists.txt | 30 +++++ boards/arm/imx9/imx93-qsb/Kconfig | 22 ++++ .../arm/imx9/imx93-qsb/configs/nsh-ddr/defconfig | 52 ++++++++ boards/arm/imx9/imx93-qsb/configs/nsh/defconfig | 50 ++++++++ boards/arm/imx9/imx93-qsb/configs/rpmsg/defconfig | 60 ++++++++++ boards/arm/imx9/imx93-qsb/include/board.h | 79 ++++++++++++ boards/arm/imx9/imx93-qsb/scripts/Make.defs | 54 +++++++++ boards/arm/imx9/imx93-qsb/scripts/ddr.ld | 129 ++++++++++++++++++++ boards/arm/imx9/imx93-qsb/scripts/itcm.ld | 127 ++++++++++++++++++++ boards/arm/imx9/imx93-qsb/src/CMakeLists.txt | 35 ++++++ boards/arm/imx9/imx93-qsb/src/Makefile | 32 +++++ boards/arm/imx9/imx93-qsb/src/imx93-qsb.h | 62 ++++++++++ boards/arm/imx9/imx93-qsb/src/imx93_appinit.c | 76 ++++++++++++ boards/arm/imx9/imx93-qsb/src/imx93_boardinit.c | 116 ++++++++++++++++++ boards/arm/imx9/imx93-qsb/src/imx93_bringup.c | 133 +++++++++++++++++++++ .../imx9/imx93-qsb/tools/enable_onboard_debug.py | 55 +++++++++ 17 files changed, 1124 insertions(+) diff --git a/boards/Kconfig b/boards/Kconfig index 470dd1052f1..0e96b908b66 100644 --- a/boards/Kconfig +++ b/boards/Kconfig @@ -885,6 +885,14 @@ config ARCH_BOARD_IMXRT1170_EVK This is the board configuration for the port of NuttX to the NXP i.MXRT evaluation kit, MIMXRT1170-EVK. This board features the MIMXRT1176DVMAA MCU. +config ARCH_BOARD_IMX93_QSB + bool "NXP i.MX 93 QSB (Cortex M33)" + depends on ARCH_CHIP_IMX9_CORTEX_M + select ARCH_HAVE_LEDS + ---help--- + This is the board configuration for the port of NuttX to the NXP i.MX93 QSB + (Quick Start Board), targeting the M33 core of the i.MX93 MCU. + config ARCH_BOARD_IMX95_EVK bool "NXP i.MX 95 EVK" depends on ARCH_CHIP_IMX9_CORTEX_M @@ -3611,6 +3619,7 @@ config ARCH_BOARD default "imxrt1060-evk" if ARCH_BOARD_IMXRT1060_EVK default "imxrt1064-evk" if ARCH_BOARD_IMXRT1064_EVK default "imxrt1170-evk" if ARCH_BOARD_IMXRT1170_EVK + default "imx93-qsb" if ARCH_BOARD_IMX93_QSB default "imx95-evk" if ARCH_BOARD_IMX95_EVK default "mr-navq95b" if ARCH_BOARD_MR_NAVQ95B default "kwikstik-k40" if ARCH_BOARD_KWIKSTIK_K40 @@ -4051,6 +4060,9 @@ endif if ARCH_BOARD_IMXRT1170_EVK source "boards/arm/imxrt/imxrt1170-evk/Kconfig" endif +if ARCH_BOARD_IMX93_QSB +source "boards/arm/imx9/imx93-qsb/Kconfig" +endif if ARCH_BOARD_IMX95_EVK source "boards/arm/imx9/imx95-evk/Kconfig" endif diff --git a/boards/arm/imx9/imx93-qsb/CMakeLists.txt b/boards/arm/imx9/imx93-qsb/CMakeLists.txt new file mode 100644 index 00000000000..f763b17a70a --- /dev/null +++ b/boards/arm/imx9/imx93-qsb/CMakeLists.txt @@ -0,0 +1,30 @@ +# ############################################################################## +# boards/arm/imx9/imx93-qsb/CMakeLists.txt +# +# 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. +# +# ############################################################################## + +add_subdirectory(src) + +if(NOT CONFIG_BUILD_FLAT) + add_subdirectory(kernel) + set_property( + GLOBAL PROPERTY LD_SCRIPT_USER ${CMAKE_CURRENT_LIST_DIR}/scripts/memory.ld + ${CMAKE_CURRENT_LIST_DIR}/scripts/user-space.ld) +endif() diff --git a/boards/arm/imx9/imx93-qsb/Kconfig b/boards/arm/imx9/imx93-qsb/Kconfig new file mode 100644 index 00000000000..2fecb4bc9fc --- /dev/null +++ b/boards/arm/imx9/imx93-qsb/Kconfig @@ -0,0 +1,22 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +choice IMX93_CODE_LOCATION + prompt "Code location" + +config IMX93_RUN_FROM_ITCM + bool "Run from Tightly Coupled Memory (128kB) (ITCM)" + depends on BOOT_RUNFROMISRAM + +config IMX93_RUN_FROM_DDR + bool "Run from SDRAM (DDR)" + depends on BOOT_RUNFROMSDRAM + +endchoice + +config IMX93_START_NSH_ON_RPMSG + bool "Start NSH session on /dev/tty-nsh" + default y + depends on RPMSG_UART_RAW && NSH_LIBRARY diff --git a/boards/arm/imx9/imx93-qsb/configs/nsh-ddr/defconfig b/boards/arm/imx9/imx93-qsb/configs/nsh-ddr/defconfig new file mode 100644 index 00000000000..8914d5f0e3b --- /dev/null +++ b/boards/arm/imx9/imx93-qsb/configs/nsh-ddr/defconfig @@ -0,0 +1,52 @@ +# +# This file is autogenerated: PLEASE DO NOT EDIT IT. +# +# You can use "make menuconfig" to make any modifications to the installed .config file. +# You can then do "make savedefconfig" to generate a new defconfig file that includes your +# modifications. +# +# CONFIG_ARCH_LEDS is not set +# CONFIG_ARCH_RAMFUNCS is not set +# CONFIG_NSH_CMDOPT_HEXDUMP is not set +CONFIG_ARCH="arm" +CONFIG_ARCH_BOARD="imx93-qsb" +CONFIG_ARCH_BOARD_IMX93_QSB=y +CONFIG_ARCH_CHIP="imx9" +CONFIG_ARCH_CHIP_IMX93_M33=y +CONFIG_ARCH_CHIP_IMX9_CORTEX_M=y +CONFIG_ARCH_INTERRUPTSTACK=4096 +CONFIG_ARCH_STACKDUMP=y +CONFIG_ARMV8M_DTCM=y +CONFIG_ARMV8M_ITCM=y +CONFIG_BOARD_LOOPSPERMSEC=613 +CONFIG_BOOT_RUNFROMSDRAM=y +CONFIG_BUILTIN=y +CONFIG_DEBUG_FEATURES=y +CONFIG_DEBUG_FULLOPT=y +CONFIG_DEBUG_SYMBOLS=y +CONFIG_DISABLE_ENVIRON=y +CONFIG_FS_PROCFS=y +CONFIG_FS_PROCFS_REGISTER=y +CONFIG_IMX9_LPCAC_PC=y +CONFIG_IMX9_LPCAC_PS=y +CONFIG_IMX9_LPUART2=y +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_LPUART2_SERIAL_CONSOLE=y +CONFIG_NSH_ARCHINIT=y +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_FILEIOSIZE=64 +CONFIG_NSH_MAXARGUMENTS=6 +CONFIG_PREALLOC_TIMERS=4 +CONFIG_RAMLOG=y +CONFIG_RAMLOG_BUFSIZE=2048 +CONFIG_RAMLOG_SYSLOG=y +CONFIG_RAM_SIZE=129024 +CONFIG_RAM_START=0xC5000800 +CONFIG_RAW_BINARY=y +CONFIG_READLINE_CMD_HISTORY=y +CONFIG_READLINE_CMD_HISTORY_LEN=8 +CONFIG_READLINE_TABCOMPLETION=y +CONFIG_SYMTAB_ORDEREDBYNAME=y +CONFIG_SYSLOG_CHAR=y +CONFIG_SYSTEM_NSH=y +CONFIG_TASK_NAME_SIZE=0 diff --git a/boards/arm/imx9/imx93-qsb/configs/nsh/defconfig b/boards/arm/imx9/imx93-qsb/configs/nsh/defconfig new file mode 100644 index 00000000000..aa233b4fc87 --- /dev/null +++ b/boards/arm/imx9/imx93-qsb/configs/nsh/defconfig @@ -0,0 +1,50 @@ +# +# This file is autogenerated: PLEASE DO NOT EDIT IT. +# +# You can use "make menuconfig" to make any modifications to the installed .config file. +# You can then do "make savedefconfig" to generate a new defconfig file that includes your +# modifications. +# +# CONFIG_ARCH_LEDS is not set +# CONFIG_ARCH_RAMFUNCS is not set +# CONFIG_NSH_CMDOPT_HEXDUMP is not set +CONFIG_ARCH="arm" +CONFIG_ARCH_BOARD="imx93-qsb" +CONFIG_ARCH_BOARD_IMX93_QSB=y +CONFIG_ARCH_CHIP="imx9" +CONFIG_ARCH_CHIP_IMX93_M33=y +CONFIG_ARCH_CHIP_IMX9_CORTEX_M=y +CONFIG_ARCH_INTERRUPTSTACK=4096 +CONFIG_ARCH_STACKDUMP=y +CONFIG_ARMV8M_DTCM=y +CONFIG_ARMV8M_ITCM=y +CONFIG_BOARD_LOOPSPERMSEC=2399 +CONFIG_BOOT_RUNFROMISRAM=y +CONFIG_BUILTIN=y +CONFIG_DEBUG_FEATURES=y +CONFIG_DEBUG_FULLOPT=y +CONFIG_DEBUG_SYMBOLS=y +CONFIG_DISABLE_ENVIRON=y +CONFIG_FS_PROCFS=y +CONFIG_FS_PROCFS_REGISTER=y +CONFIG_IMX9_LPUART2=y +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_LPUART2_SERIAL_CONSOLE=y +CONFIG_NSH_ARCHINIT=y +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_FILEIOSIZE=64 +CONFIG_NSH_MAXARGUMENTS=6 +CONFIG_PREALLOC_TIMERS=4 +CONFIG_RAMLOG=y +CONFIG_RAMLOG_BUFSIZE=2048 +CONFIG_RAMLOG_SYSLOG=y +CONFIG_RAM_SIZE=129024 +CONFIG_RAM_START=0x0FFC0800 +CONFIG_RAW_BINARY=y +CONFIG_READLINE_CMD_HISTORY=y +CONFIG_READLINE_CMD_HISTORY_LEN=8 +CONFIG_READLINE_TABCOMPLETION=y +CONFIG_SYMTAB_ORDEREDBYNAME=y +CONFIG_SYSLOG_CHAR=y +CONFIG_SYSTEM_NSH=y +CONFIG_TASK_NAME_SIZE=0 diff --git a/boards/arm/imx9/imx93-qsb/configs/rpmsg/defconfig b/boards/arm/imx9/imx93-qsb/configs/rpmsg/defconfig new file mode 100644 index 00000000000..8f81d703c4f --- /dev/null +++ b/boards/arm/imx9/imx93-qsb/configs/rpmsg/defconfig @@ -0,0 +1,60 @@ +# +# This file is autogenerated: PLEASE DO NOT EDIT IT. +# +# You can use "make menuconfig" to make any modifications to the installed .config file. +# You can then do "make savedefconfig" to generate a new defconfig file that includes your +# modifications. +# +# CONFIG_ARCH_LEDS is not set +# CONFIG_ARCH_RAMFUNCS is not set +# CONFIG_NSH_CMDOPT_HEXDUMP is not set +CONFIG_ARCH="arm" +CONFIG_ARCH_BOARD="imx93-qsb" +CONFIG_ARCH_BOARD_IMX93_QSB=y +CONFIG_ARCH_CHIP="imx9" +CONFIG_ARCH_CHIP_IMX93_M33=y +CONFIG_ARCH_CHIP_IMX9_CORTEX_M=y +CONFIG_ARCH_INTERRUPTSTACK=4096 +CONFIG_ARCH_STACKDUMP=y +CONFIG_ARMV8M_DTCM=y +CONFIG_ARMV8M_ITCM=y +CONFIG_BOARD_LOOPSPERMSEC=2399 +CONFIG_BOOT_RUNFROMISRAM=y +CONFIG_BUILTIN=y +CONFIG_DEBUG_FEATURES=y +CONFIG_DEBUG_FULLOPT=y +CONFIG_DEBUG_RPMSG=y +CONFIG_DEBUG_RPMSG_ERROR=y +CONFIG_DEBUG_RPMSG_INFO=y +CONFIG_DEBUG_RPMSG_WARN=y +CONFIG_DEBUG_SYMBOLS=y +CONFIG_DEV_RPMSG=y +CONFIG_DEV_SIMPLE_ADDRENV=y +CONFIG_DISABLE_ENVIRON=y +CONFIG_FS_PROCFS=y +CONFIG_FS_PROCFS_REGISTER=y +CONFIG_IMX9_LPUART2=y +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_LPUART2_SERIAL_CONSOLE=y +CONFIG_NSH_ARCHINIT=y +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_FILEIOSIZE=64 +CONFIG_NSH_MAXARGUMENTS=6 +CONFIG_PREALLOC_TIMERS=4 +CONFIG_RAMLOG=y +CONFIG_RAMLOG_BUFSIZE=2048 +CONFIG_RAMLOG_SYSLOG=y +CONFIG_RAM_SIZE=129024 +CONFIG_RAM_START=0x0FFC0800 +CONFIG_RAW_BINARY=y +CONFIG_READLINE_CMD_HISTORY=y +CONFIG_READLINE_CMD_HISTORY_LEN=8 +CONFIG_READLINE_TABCOMPLETION=y +CONFIG_RPMSG_LOCAL_CPUNAME="m33" +CONFIG_RPMSG_UART_RAW=y +CONFIG_RPTUN=y +CONFIG_SCHED_WAITPID=y +CONFIG_SYMTAB_ORDEREDBYNAME=y +CONFIG_SYSLOG_CHAR=y +CONFIG_SYSTEM_NSH=y +CONFIG_TASK_NAME_SIZE=0 diff --git a/boards/arm/imx9/imx93-qsb/include/board.h b/boards/arm/imx9/imx93-qsb/include/board.h new file mode 100644 index 00000000000..30b7aaaf82e --- /dev/null +++ b/boards/arm/imx9/imx93-qsb/include/board.h @@ -0,0 +1,79 @@ +/**************************************************************************** + * boards/arm/imx9/imx93-qsb/include/board.h + * + * SPDX-License-Identifier: Apache-2.0 + * SPDX-FileCopyrightText: 2024 NXP + * + * 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. + * + ****************************************************************************/ + +#ifndef __BOARDS_ARM_IMX9_IMX93_QSB_INCLUDE_BOARD_H +#define __BOARDS_ARM_IMX9_IMX93_QSB_INCLUDE_BOARD_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define BOARD_XTAL_FREQUENCY 24000000 + +#define BOARD_CPU_FREQUENCY BOARD_XTAL_FREQUENCY + +#define LPUART2_CLK (LPUART2_CLK_ROOT_OSC_24M | CLOCK_DIV(1)) + +/* Default PAD configurations */ + +#define IOMUX_LPI2C_DEFAULT (IOMUXC_PAD_OD_ENABLE | IOMUXC_PAD_FSEL_SFAST | IOMUXC_PAD_DSE_X6) +#define IOMUX_LPSPI_DEFAULT (IOMUXC_PAD_PU_ON | IOMUXC_PAD_FSEL_FAST | IOMUXC_PAD_DSE_X6) +#define IOMUX_GPIO_DEFAULT (IOMUXC_PAD_FSEL_SLOW | IOMUXC_PAD_DSE_X6) + +/* UART pin muxings */ + +#define MUX_LPUART2_RX IOMUX_CFG(IOMUXC_PAD_UART2_RXD_LPUART2_RX, 0, IOMUXC_MUX_SION_ON) +#define MUX_LPUART2_TX IOMUX_CFG(IOMUXC_PAD_UART2_TXD_LPUART2_TX, IOMUXC_PAD_FSEL_SLOW | IOMUXC_PAD_DSE_X4, 0) + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifndef __ASSEMBLY__ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* __ASSEMBLY__ */ +#endif /* __BOARDS_ARM_IMX9_IMX93_QSB_INCLUDE_BOARD_H */ diff --git a/boards/arm/imx9/imx93-qsb/scripts/Make.defs b/boards/arm/imx9/imx93-qsb/scripts/Make.defs new file mode 100644 index 00000000000..78410644a33 --- /dev/null +++ b/boards/arm/imx9/imx93-qsb/scripts/Make.defs @@ -0,0 +1,54 @@ +############################################################################ +# boards/arm/imx9/imx93-qsb/scripts/Make.defs +# +# SPDX-License-Identifier: Apache-2.0 +# SPDX-FileCopyrightText: 2024 NXP +# +# 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. +# +############################################################################ + +include $(TOPDIR)/.config +include $(TOPDIR)/tools/Config.mk +include $(TOPDIR)/arch/arm/src/armv7-m/Toolchain.defs + +ifeq ($(CONFIG_IMX93_RUN_FROM_ITCM),y) +LDSCRIPT = itcm.ld +else ifeq ($(CONFIG_IMX93_RUN_FROM_DDR),y) +LDSCRIPT = ddr.ld +endif + +ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT) + +ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10 + +CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe +CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS) +CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe +CXXPICFLAGS = $(ARCHPICFLAGS) $(CXXFLAGS) +CPPFLAGS := $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) +AFLAGS := $(CFLAGS) -D__ASSEMBLY__ + +NXFLATLDFLAGS1 = -r -d -warn-common +NXFLATLDFLAGS2 = $(NXFLATLDFLAGS1) -T$(TOPDIR)/binfmt/libnxflat/gnu-nxflat-pcrel.ld -no-check-sections +LDNXFLATFLAGS = -e main -s 2048 + +# Loadable module definitions + +CMODULEFLAGS = $(CFLAGS) -mlong-calls # --target1-abs + +LDMODULEFLAGS = -r -e module_initialize +LDMODULEFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)/libs/libc/elf/gnu-elf.ld) diff --git a/boards/arm/imx9/imx93-qsb/scripts/ddr.ld b/boards/arm/imx9/imx93-qsb/scripts/ddr.ld new file mode 100644 index 00000000000..b045af1e730 --- /dev/null +++ b/boards/arm/imx9/imx93-qsb/scripts/ddr.ld @@ -0,0 +1,129 @@ +/**************************************************************************** + * boards/arm/imx9/imx93-qsb/scripts/ddr.ld + * + * SPDX-License-Identifier: Apache-2.0 + * SPDX-FileCopyrightText: 2024 NXP + * + * 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. + * + * + ****************************************************************************/ + + +MEMORY +{ + m_interrupts (rx) : ORIGIN = 0x89000000, LENGTH = 0x00000800 + dram (rx) : ORIGIN = 0x89000800, LENGTH = 0x00FFF800 + itcm (rx) : ORIGIN = 0x0FFE0000, LENGTH = 128K + dtcm (rwx) : ORIGIN = 0x20000000, LENGTH = 120K + ocram (rwx) : ORIGIN = 0x20480000, LENGTH = 640K +} + +OUTPUT_ARCH(arm) +EXTERN(_vectors) +ENTRY(_stext) + +SECTIONS +{ + .interrupts : + { + __VECTOR_TABLE = .; + __Vectors = .; + . = ALIGN(4); + KEEP(*(.vectors)) /* Startup code */ + . = ALIGN(4); + } > m_interrupts + + .text : { + _stext = ABSOLUTE(.); + *(.text .text.*) + *(.fixup) + *(.gnu.warning) + *(.rodata .rodata.*) + *(.gnu.linkonce.t.*) + *(.glue_7) + *(.glue_7t) + *(.got) + *(.gcc_except_table) + *(.gnu.linkonce.r.*) + _etext = ABSOLUTE(.); + } > dram + + .resource_table : + { + . = ALIGN(8); + KEEP(*(.resource_table)) + . = ALIGN(4); + } > dram + + .init_section : { + _sinit = ABSOLUTE(.); + KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*))) + KEEP(*(.init_array .ctors)) + _einit = ABSOLUTE(.); + } > dram + + .ARM.extab : { + *(.ARM.extab*) + } > dram + + __exidx_start = ABSOLUTE(.); + .ARM.exidx : { + *(.ARM.exidx*) + } > dram + __exidx_end = ABSOLUTE(.); + + _eronly = ABSOLUTE(.); + + .data : { + _sdata = ABSOLUTE(.); + *(.data .data.*) + *(.gnu.linkonce.d.*) + CONSTRUCTORS + . = ALIGN(4); + _edata = ABSOLUTE(.); + } > dram + + .bss : { + _sbss = ABSOLUTE(.); + *(.bss .bss.*) + *(.gnu.linkonce.b.*) + *(COMMON) + . = ALIGN(4); + _ebss = ABSOLUTE(.); + } > dram + + /* Stabs debugging sections. */ + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + .stab.excl 0 : { *(.stab.excl) } + .stab.exclstr 0 : { *(.stab.exclstr) } + .stab.index 0 : { *(.stab.index) } + .stab.indexstr 0 : { *(.stab.indexstr) } + .comment 0 : { *(.comment) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_info 0 : { *(.debug_info) } + .debug_line 0 : { *(.debug_line) } + .debug_pubnames 0 : { *(.debug_pubnames) } + .debug_aranges 0 : { *(.debug_aranges) } + + _ram_start = ORIGIN(dram); + _ram_size = LENGTH(dram); + _ram_end = ORIGIN(dram) + LENGTH(dram); + _ocram_start = ORIGIN(ocram); + _ocram_size = LENGTH(ocram); + _ocram_end = ORIGIN(ocram) + LENGTH(ocram); +} diff --git a/boards/arm/imx9/imx93-qsb/scripts/itcm.ld b/boards/arm/imx9/imx93-qsb/scripts/itcm.ld new file mode 100644 index 00000000000..52839208e51 --- /dev/null +++ b/boards/arm/imx9/imx93-qsb/scripts/itcm.ld @@ -0,0 +1,127 @@ +/**************************************************************************** + * boards/arm/imx9/imx93-qsb/scripts/itcm.ld + * + * SPDX-License-Identifier: Apache-2.0 + * SPDX-FileCopyrightText: 2024 NXP + * + * 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. + * + * + ****************************************************************************/ + +MEMORY +{ + m_interrupts (rx) : ORIGIN = 0x0FFE0000, LENGTH = 0x00000800 + itcm (rx) : ORIGIN = 0x0FFE0800, LENGTH = 0x0001F800 + dtcm (rwx) : ORIGIN = 0x20000000, LENGTH = 120K + ocram (rwx) : ORIGIN = 0x20480000, LENGTH = 640K +} + +OUTPUT_ARCH(arm) +EXTERN(_vectors) +ENTRY(_stext) + +SECTIONS +{ + .interrupts : + { + __VECTOR_TABLE = .; + __Vectors = .; + . = ALIGN(4); + KEEP(*(.vectors)) /* Startup code */ + . = ALIGN(4); + } > m_interrupts + + .text : { + _stext = ABSOLUTE(.); + *(.text .text.*) + *(.fixup) + *(.gnu.warning) + *(.rodata .rodata.*) + *(.gnu.linkonce.t.*) + *(.glue_7) + *(.glue_7t) + *(.got) + *(.gcc_except_table) + *(.gnu.linkonce.r.*) + _etext = ABSOLUTE(.); + } > itcm + + .resource_table : + { + . = ALIGN(8); + KEEP(*(.resource_table)) + . = ALIGN(4); + } > itcm + + .init_section : { + _sinit = ABSOLUTE(.); + KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*))) + KEEP(*(.init_array .ctors)) + _einit = ABSOLUTE(.); + } > itcm + + .ARM.extab : { + *(.ARM.extab*) + } > itcm + + __exidx_start = ABSOLUTE(.); + .ARM.exidx : { + *(.ARM.exidx*) + } > itcm + __exidx_end = ABSOLUTE(.); + + _eronly = ABSOLUTE(.); + + .data : { + _sdata = ABSOLUTE(.); + *(.data .data.*) + *(.gnu.linkonce.d.*) + CONSTRUCTORS + . = ALIGN(4); + _edata = ABSOLUTE(.); + } > dtcm AT > itcm + + .bss : { + _sbss = ABSOLUTE(.); + *(.bss .bss.*) + *(.gnu.linkonce.b.*) + *(COMMON) + . = ALIGN(4); + _ebss = ABSOLUTE(.); + } > dtcm + + /* Stabs debugging sections. */ + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + .stab.excl 0 : { *(.stab.excl) } + .stab.exclstr 0 : { *(.stab.exclstr) } + .stab.index 0 : { *(.stab.index) } + .stab.indexstr 0 : { *(.stab.indexstr) } + .comment 0 : { *(.comment) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_info 0 : { *(.debug_info) } + .debug_line 0 : { *(.debug_line) } + .debug_pubnames 0 : { *(.debug_pubnames) } + .debug_aranges 0 : { *(.debug_aranges) } + + _ram_start = ORIGIN(dtcm); + _ram_size = LENGTH(dtcm); + _ram_end = ORIGIN(dtcm) + LENGTH(dtcm); + _ocram_start = ORIGIN(ocram); + _ocram_size = LENGTH(ocram); + _ocram_end = ORIGIN(ocram) + LENGTH(ocram); +} diff --git a/boards/arm/imx9/imx93-qsb/src/CMakeLists.txt b/boards/arm/imx9/imx93-qsb/src/CMakeLists.txt new file mode 100644 index 00000000000..1e9702770a8 --- /dev/null +++ b/boards/arm/imx9/imx93-qsb/src/CMakeLists.txt @@ -0,0 +1,35 @@ +# ############################################################################## +# boards/arm/imx9/imx93-qsb/src/CMakeLists.txt +# +# 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. +# +# ############################################################################## + +set(SRCS imx93_boardinit.c imx93_bringup.c) + +if(CONFIG_BOARDCTL) + list(APPEND SRCS imx93_appinit.c) +endif() + +target_sources(board PRIVATE ${SRCS}) + +if(CONFIG_IMX93_RUN_FROM_ITCM) + set_property(GLOBAL PROPERTY LD_SCRIPT "${NUTTX_BOARD_DIR}/scripts/itcm.ld") +elseif(CONFIG_IMX93_RUN_FROM_DDR) + set_property(GLOBAL PROPERTY LD_SCRIPT "${NUTTX_BOARD_DIR}/scripts/ddr.ld") +endif() diff --git a/boards/arm/imx9/imx93-qsb/src/Makefile b/boards/arm/imx9/imx93-qsb/src/Makefile new file mode 100644 index 00000000000..953a4c7109b --- /dev/null +++ b/boards/arm/imx9/imx93-qsb/src/Makefile @@ -0,0 +1,32 @@ +############################################################################ +# boards/arm/imx9/imx93-qsb/src/Makefile +# +# SPDX-License-Identifier: Apache-2.0 +# SPDX-FileCopyrightText: 2024 NXP +# +# 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. +# +############################################################################ + +include $(TOPDIR)/Make.defs + +CSRCS = imx93_boardinit.c imx93_bringup.c + +ifeq ($(CONFIG_BOARDCTL),y) +CSRCS += imx93_appinit.c +endif + +include $(TOPDIR)/boards/Board.mk diff --git a/boards/arm/imx9/imx93-qsb/src/imx93-qsb.h b/boards/arm/imx9/imx93-qsb/src/imx93-qsb.h new file mode 100644 index 00000000000..28ca0acb055 --- /dev/null +++ b/boards/arm/imx9/imx93-qsb/src/imx93-qsb.h @@ -0,0 +1,62 @@ +/**************************************************************************** + * boards/arm/imx9/imx93-qsb/src/imx93-qsb.h + * + * SPDX-License-Identifier: Apache-2.0 + * SPDX-FileCopyrightText: 2024 NXP + * + * 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. + * + ****************************************************************************/ + +#ifndef __BOARDS_ARM_IMX9_IMX93_QSB_SRC_IMX93_QSB_H +#define __BOARDS_ARM_IMX9_IMX93_QSB_SRC_IMX93_QSB_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <stdint.h> + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifndef __ASSEMBLY__ + +/**************************************************************************** + * Public Functions Definitions + ****************************************************************************/ + +/**************************************************************************** + * Name: imx93_bringup + * + * Description: + * Bring up board features + * + ****************************************************************************/ + +#if defined(CONFIG_BOARDCTL) || defined(CONFIG_BOARD_LATE_INITIALIZE) +int imx93_bringup(void); +#endif + +#endif /* __ASSEMBLY__ */ +#endif /* __BOARDS_ARM_IMX9_IMX93_QSB_SRC_IMX93_QSB_H */ diff --git a/boards/arm/imx9/imx93-qsb/src/imx93_appinit.c b/boards/arm/imx9/imx93-qsb/src/imx93_appinit.c new file mode 100644 index 00000000000..e7836900add --- /dev/null +++ b/boards/arm/imx9/imx93-qsb/src/imx93_appinit.c @@ -0,0 +1,76 @@ +/**************************************************************************** + * boards/arm/imx9/imx93-qsb/src/imx93_appinit.c + * + * SPDX-License-Identifier: Apache-2.0 + * SPDX-FileCopyrightText: 2024 NXP + * + * 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 <nuttx/board.h> +#include "imx93-qsb.h" + +#ifdef CONFIG_BOARDCTL + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_app_initialize + * + * Description: + * Perform application specific initialization. This function is never + * called directly from application code, but only indirectly via the + * (non-standard) boardctl() interface using the command BOARDIOC_INIT. + * + * Input Parameters: + * arg - The boardctl() argument is passed to the board_app_initialize() + * implementation without modification. The argument has no + * meaning to NuttX; the meaning of the argument is a contract + * between the board-specific initialization logic and the + * matching application logic. The value could be such things as a + * mode enumeration value, a set of DIP switch switch settings, a + * pointer to configuration data read from a file or serial FLASH, + * or whatever you would like to do with it. Every implementation + * should accept zero/NULL as a default configuration. + * + * Returned Value: + * Zero (OK) is returned on success; a negated errno value is returned on + * any failure to indicate the nature of the failure. + * + ****************************************************************************/ + +int board_app_initialize(uintptr_t arg) +{ + UNUSED(arg); +#ifndef CONFIG_BOARD_LATE_INITIALIZE + /* Perform board initialization */ + + return imx93_bringup(); +#else + return OK; +#endif +} + +#endif /* CONFIG_BOARDCTL */ diff --git a/boards/arm/imx9/imx93-qsb/src/imx93_boardinit.c b/boards/arm/imx9/imx93-qsb/src/imx93_boardinit.c new file mode 100644 index 00000000000..a7a3dd52613 --- /dev/null +++ b/boards/arm/imx9/imx93-qsb/src/imx93_boardinit.c @@ -0,0 +1,116 @@ +/**************************************************************************** + * boards/arm/imx9/imx93-qsb/src/imx93_boardinit.c + * + * SPDX-License-Identifier: Apache-2.0 + * SPDX-FileCopyrightText: 2024 NXP + * + * 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/board.h> +#include <stdint.h> +#include "imx93-qsb.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: imx93_memory_initialize + * + * Description: + * All i.MX9 architectures must provide the following entry point. This + * entry point is called early in the initialization before memory has + * been configured. This board-specific function is responsible for + * configuring any on-board memories. + * + * Logic in imx93_memory_initialize must be careful to avoid using any + * global variables because those will be uninitialized at the time this + * function is called. + * + * Input Parameters: + * None + * + * Returned Value: + * None + * + ****************************************************************************/ + +void imx93_memory_initialize(void) +{ + /* SDRAM was initialized by a bootloader in the supported configurations. */ +} + +/**************************************************************************** + * Name: imx93_board_initialize + * + * Description: + * All i.MX9 architectures must provide the following entry point. This + * entry point is called in the initialization phase -- after + * imx_memory_initialize and after all memory has been configured and + * mapped but before any devices have been initialized. + * + * Input Parameters: + * None + * + * Returned Value: + * None + * + ****************************************************************************/ + +void imx9_boardinitialize(void) +{ +#ifdef CONFIG_ARCH_LEDS + /* Configure on-board LEDs if LED support has been selected. */ + +#endif +} + +/**************************************************************************** + * Name: board_late_initialize + * + * Description: + * If CONFIG_BOARD_LATE_INITIALIZE is selected, then an additional + * initialization call will be performed in the boot-up sequence to a + * function called board_late_initialize(). board_late_initialize() will be + * called immediately after up_intitialize() is called and just before the + * initial application is started. This additional initialization phase + * may be used, for example, to initialize board-specific device drivers. + * + ****************************************************************************/ + +#ifdef CONFIG_BOARD_LATE_INITIALIZE +void board_late_initialize(void) +{ + /* Perform board initialization */ + + imx93_bringup(); +} +#endif /* CONFIG_BOARD_LATE_INITIALIZE */ diff --git a/boards/arm/imx9/imx93-qsb/src/imx93_bringup.c b/boards/arm/imx9/imx93-qsb/src/imx93_bringup.c new file mode 100644 index 00000000000..b13b2d05aa9 --- /dev/null +++ b/boards/arm/imx9/imx93-qsb/src/imx93_bringup.c @@ -0,0 +1,133 @@ +/**************************************************************************** + * boards/arm/imx9/imx93-qsb/src/imx93_bringup.c + * + * SPDX-License-Identifier: Apache-2.0 + * SPDX-FileCopyrightText: 2024 NXP + * + * 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/fs/fs.h> +#include <sys/types.h> +#include <syslog.h> +#include "imx93-qsb.h" + +#include <fcntl.h> // For O_RDWR +#include <unistd.h> // For sleep, dup2, close +#include <nuttx/board.h> + +#include <stdio.h> + +#ifdef CONFIG_RPTUN +# include <imx9_rptun.h> +#endif + +#ifdef CONFIG_RPMSG_UART_RAW +# include <nuttx/serial/uart_rpmsg_raw.h> +#endif + +#ifdef CONFIG_NSH_LIBRARY +extern int nsh_consolemain(int argc, FAR char *argv[]); +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +#ifdef CONFIG_IMX93_START_NSH_ON_RPMSG +static int nsh_rpmsg_task(int argc, FAR char *argv[]) +{ + int fd; + int ret; + + sleep(1); + + fd = open("/dev/tty-nsh", O_RDWR); + + if (fd < 0) + { + syslog(LOG_ERR, "Failed to open /dev/tty-nsh: %d\n", errno); + return -1; + } + + dup2(fd, 0); + dup2(fd, 1); + dup2(fd, 2); + + close(fd); + + ret = nsh_consolemain(0, NULL); + + return ret; +} +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#ifdef CONFIG_RPMSG_UART_RAW +void rpmsg_serialrawinit(void) +{ +#ifdef CONFIG_IMX93_START_NSH_ON_RPMSG + uart_rpmsg_raw_init("netcore", "-nsh", 4096, true); +#endif +} +#endif + +/**************************************************************************** + * Name: imx_bringup + * + * Description: + * Bring up board features + * + ****************************************************************************/ + +int imx93_bringup(void) +{ + int ret; + +#ifdef CONFIG_RPTUN + imx9_rptun_init("imx9-shmem", "netcore"); +#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_IMX93_START_NSH_ON_RPMSG + task_create("nsh_rpmsg", + CONFIG_SYSTEM_NSH_PRIORITY, + CONFIG_SYSTEM_NSH_STACKSIZE, + nsh_rpmsg_task, + NULL); +#endif + + UNUSED(ret); + return OK; +} diff --git a/boards/arm/imx9/imx93-qsb/tools/enable_onboard_debug.py b/boards/arm/imx9/imx93-qsb/tools/enable_onboard_debug.py new file mode 100644 index 00000000000..1d6e9462753 --- /dev/null +++ b/boards/arm/imx9/imx93-qsb/tools/enable_onboard_debug.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python3 +############################################################################ +# boards/arm/imx9/imx93-qsb/tools/enable_onboard_debug.py +# +# 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. +# +############################################################################ + +from pyftdi.i2c import I2cController + +i2c = I2cController() +i2c.configure("ftdi://ftdi:4232h/2") + +slave_addr = 0x21 # IO expander address +port = i2c.get_port(slave_addr) + + +def set_bit(value, bit): + return value | (1 << bit) + + +def clear_bit(value, bit): + return value & ~(1 << bit) + + +def read_modify_write(port, reg_addr, bit, set_high=True): + current = port.read_from(reg_addr, 1)[0] + new_val = set_bit(current, bit) if set_high else clear_bit(current, bit) + if new_val != current: + port.write_to(reg_addr, bytes([new_val])) + return new_val + + +# Set bit 4 high in register 0x03 (rc_sel high) +read_modify_write(port, 0x03, bit=4, set_high=True) + +# Clear bit 4 in register 0x07 (configure rc_sel as output) +read_modify_write(port, 0x07, bit=4, set_high=False) + +i2c.terminate()
