From bb544d1865647eb3d4cd94a90732e8446167f2d7 Mon Sep 17 00:00:00 2001 From: Christian Mauderer Date: Mon, 23 May 2022 09:12:40 +0200 Subject: [PATCH 01/25] Makefile and similar: Prepare update to RTEMS 6 --- .gitignore | 1 + Makefile | 59 ++++++++++---------------------------------------- demo/Makefile | 2 +- src/bsp.mk | 2 +- src/config.ini | 46 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 61 insertions(+), 49 deletions(-) create mode 100644 src/config.ini diff --git a/.gitignore b/.gitignore index 37e77f6..b0b8d59 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ /external/fdt/*.tar.gz /fdt/b-dtb /rtems/5 +/rtems/6 build /demo*/b-*/ external/libinih/b-imx7 diff --git a/Makefile b/Makefile index 8df1afc..f344728 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ MAKEFILE_DIR = $(dir $(realpath $(firstword $(MAKEFILE_LIST)))) ARCH = arm BSP = imx7 BSP_GRISP1 = atsamv -RTEMS_VERSION = 5 +RTEMS_VERSION = 6 TARGET = $(ARCH)-rtems$(RTEMS_VERSION) PREFIX = $(MAKEFILE_DIR)/rtems/$(RTEMS_VERSION) RSB = $(MAKEFILE_DIR)/external/rtems-source-builder @@ -83,7 +83,7 @@ help: .PHONY: install #H Build and install the complete toolchain, libraries, fdt and so on. -install: submodule-update toolchain toolchain-revision bootstrap bsp bsp-grisp1 libbsd fdt bsp.mk libgrisp libinih cryptoauthlib barebox-install blas +install: submodule-update toolchain toolchain-revision bsp libbsd fdt bsp.mk libgrisp libinih cryptoauthlib barebox-install blas .PHONY: submodule-update #H Update the submodules. @@ -91,11 +91,6 @@ submodule-update: git submodule update --init cd $(SRC_LIBBSD) && git submodule update --init rtems_waf -.PHONY: bootstrap -#H Run bootstrap for RTEMS. -bootstrap: - cd $(SRC_RTEMS) && $(RSB)/source-builder/sb-bootstrap - .PHONY: toolchain #H Build and install the toolchain. toolchain: @@ -124,46 +119,16 @@ toolchain-revision: .PHONY: bsp #H Build the RTEMS board support package. bsp: - rm -rf $(BUILD_BSP) - mkdir -p $(BUILD_BSP) - cd $(BUILD_BSP) && $(SRC_RTEMS)/configure \ - --target=$(ARCH)-rtems$(RTEMS_VERSION) \ - --prefix=$(PREFIX) \ - --enable-posix \ - --enable-rtemsbsp=$(BSP) \ - --enable-maintainer-mode \ - --disable-networking \ - $(EXTRA_BSP_OPTS) \ - IMX_CCM_IPG_HZ=66000000 \ - IMX_CCM_UART_HZ=80000000 \ - IMX_CCM_AHB_HZ=66000000 \ - IMX_CCM_SDHCI_HZ=198000000 \ - IMX_CCM_ECSPI_HZ=60000000 - cd $(BUILD_BSP) && make -j $(NUMCORE) - cd $(BUILD_BSP) && make -j $(NUMCORE) install - -.PHONY: bsp-grisp1 -#H Build the RTEMS board support package for GRiSP1. -bsp-grisp1: - rm -rf $(BUILD_BSP_GRISP1) - mkdir -p $(BUILD_BSP_GRISP1) - cd $(BUILD_BSP_GRISP1) && $(SRC_RTEMS)/configure \ - --target=$(ARCH)-rtems$(RTEMS_VERSION) \ - --prefix=$(PREFIX) \ - --enable-posix \ - --enable-rtemsbsp=$(BSP_GRISP1) \ - --enable-maintainer-mode \ - --disable-networking \ - --disable-tests \ - $(EXTRA_BSP_OPTS) \ - --enable-chip=same70q21 \ - --enable-sdram=is42s16320f-7bl \ - ATSAM_CONSOLE_DEVICE_TYPE=1 \ - ATSAM_CONSOLE_DEVICE_INDEX=2 \ - ATSAM_MEMORY_QSPIFLASH_SIZE=0x0 \ - ATSAM_MEMORY_NOCACHE_SIZE=0x8000 - cd $(BUILD_BSP_GRISP1) && make -j $(NUMCORE) - cd $(BUILD_BSP_GRISP1) && make -j $(NUMCORE) install + cd $(SRC_RTEMS) && ./waf clean || true + cp src/config.ini $(SRC_RTEMS) + if [ "$(DEBUG)" == "1" ]; then cd $(SRC_RTEMS) && sed -i \ + -e "s|OPTIMIZATION_FLAGS = -O2|OPTIMIZATION_FLAGS = -O0|g" \ + -e "s|RTEMS_DEBUG = False|RTEMS_DEBUG = True|g" \ + config.ini; \ + fi + cd $(SRC_RTEMS) && ./waf configure --prefix=$(PREFIX) + cd $(SRC_RTEMS) && ./waf + cd $(SRC_RTEMS) && ./waf install .PHONY: bsp.mk #H Build a Makefile helper for the applications. diff --git a/demo/Makefile b/demo/Makefile index 299e342..4cdec88 100644 --- a/demo/Makefile +++ b/demo/Makefile @@ -1,5 +1,5 @@ MAKEFILE_DIR = $(dir $(realpath $(firstword $(MAKEFILE_LIST)))) -RTEMS_ROOT ?= $(MAKEFILE_DIR)/../rtems/5 +RTEMS_ROOT ?= $(MAKEFILE_DIR)/../rtems/6 RTEMS_BSP ?= imx7 include $(RTEMS_ROOT)/make/custom/$(RTEMS_BSP).mk diff --git a/src/bsp.mk b/src/bsp.mk index f458fcb..b685439 100644 --- a/src/bsp.mk +++ b/src/bsp.mk @@ -14,7 +14,7 @@ exec_prefix = $(RTEMS_ROOT)/$(RTEMS_CPU)-rtems$(RTEMS_API) include $(RTEMS_ROOT)/make/custom/$(RTEMS_BSP).cfg DEPFLAGS = -MT $@ -MD -MP -MF $(basename $@).d -SYSFLAGS = -B $(PROJECT_LIB) -specs bsp_specs -qrtems +SYSFLAGS = -B $(PROJECT_LIB) -qrtems WARNFLAGS = -Wall -Wextra -Wconversion -Wformat-security -Wformat=2 -Wshadow -Wcast-qual -Wcast-align -Wredundant-decls CWARNFLAGS = $(WARNFLAGS) -Wstrict-prototypes -Wbad-function-cast OPTFLAGS = $(CFLAGS_OPTIMIZE_V) diff --git a/src/config.ini b/src/config.ini new file mode 100644 index 0000000..00f8ecb --- /dev/null +++ b/src/config.ini @@ -0,0 +1,46 @@ +# Note: Only the most relevant options are listed in this file. All others fall +# back to default values. Use the following commands in the RTEMS source tree to +# get all default values: +# ./waf bsp_defaults --rtems-bsps=arm/imx7 +# ./waf bsp_defaults --rtems-bsps=arm/atsamv + +[arm/imx7] +# Enable the RTEMS internal debug support +RTEMS_DEBUG = False +# Enable support for POSIX signals +RTEMS_POSIX_API = True +# AHB clock frequency in Hz +IMX_CCM_AHB_HZ = 66000000 +# ECSPI clock frequency in Hz +IMX_CCM_ECSPI_HZ = 60000000 +# IPG clock frequency in Hz +IMX_CCM_IPG_HZ = 66000000 +# SDHCI clock frequency in Hz +IMX_CCM_SDHCI_HZ = 198000000 +# UART clock frequency in Hz +IMX_CCM_UART_HZ = 80000000 +# Optimization flags passed to the C and C++ compiler +OPTIMIZATION_FLAGS = -O2 -g -fdata-sections -ffunction-sections + +[arm/atsamv] +# Enable the RTEMS internal debug support +RTEMS_DEBUG = False +# Enable support for POSIX signals +RTEMS_POSIX_API = True +# Build the sample programs (may be also enabled by BUILD_TESTS) +BUILD_SAMPLES = True +# Chip variant +ATSAM_CHIP = same70q21 +# device index for /dev/console (default 1, e.g. USART1) +ATSAM_CONSOLE_DEVICE_INDEX = 2 +# device type for /dev/console, use 0 for USART and 1 for UART +# (default USART) +ATSAM_CONSOLE_DEVICE_TYPE = 1 +# size of NOCACHE section in bytes +ATSAM_MEMORY_NOCACHE_SIZE = 0x8000 +# size of QSPI flash in bytes +ATSAM_MEMORY_QSPIFLASH_SIZE = 0x0 +# SDRAM variant +ATSAM_SDRAM = is42s16320f-7bl +# Optimization flags passed to the C and C++ compiler +OPTIMIZATION_FLAGS = -O2 -g -fdata-sections -ffunction-sections From c20c75d9b2e91c0b8a40fcc66caf76a6f6d7bf02 Mon Sep 17 00:00:00 2001 From: Christian Mauderer Date: Tue, 4 Jun 2024 15:35:43 +0200 Subject: [PATCH 02/25] RSB, RTEMS, libbsd: Update to RTEMS6 based versions. --- external/rtems | 2 +- external/rtems-libbsd | 2 +- external/rtems-source-builder | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/external/rtems b/external/rtems index 0fe6bd6..c1aa06d 160000 --- a/external/rtems +++ b/external/rtems @@ -1 +1 @@ -Subproject commit 0fe6bd64cf9943e1fe9afa14aa4b3185cbea0735 +Subproject commit c1aa06dbd2f055afd14415f3e6f63fb74765d6ff diff --git a/external/rtems-libbsd b/external/rtems-libbsd index 4857ef8..675a867 160000 --- a/external/rtems-libbsd +++ b/external/rtems-libbsd @@ -1 +1 @@ -Subproject commit 4857ef80680dcf9ea73815b26721d8b9526f6f63 +Subproject commit 675a867f08c263b6f45d1fbd48e7923bff27dd7b diff --git a/external/rtems-source-builder b/external/rtems-source-builder index 78c6538..7ebed67 160000 --- a/external/rtems-source-builder +++ b/external/rtems-source-builder @@ -1 +1 @@ -Subproject commit 78c6538e1d2c932c182dc6e1fc8983e408a82d50 +Subproject commit 7ebed67752d4b2a630e2213f40d1473a26495340 From c8c20f3674bf30213dd0f2aaa44001ea8d008d23 Mon Sep 17 00:00:00 2001 From: Christian Mauderer Date: Mon, 11 Apr 2022 09:33:45 +0200 Subject: [PATCH 03/25] fdt: Add IGRiSP --- fdt/Makefile | 8 +- fdt/imx6ull-industrialgrisp.dts | 266 ++++++++++++++++++++++++++++++++ 2 files changed, 270 insertions(+), 4 deletions(-) create mode 100644 fdt/imx6ull-industrialgrisp.dts diff --git a/fdt/Makefile b/fdt/Makefile index 38df5cc..46b3d3b 100644 --- a/fdt/Makefile +++ b/fdt/Makefile @@ -1,7 +1,7 @@ # Note: $(PWD) doesn't work together with -C option of make MAKEFILE_DIR = $(dir $(realpath $(firstword $(MAKEFILE_LIST)))) -BOARD = imx6ul-grisp2 +DTS = imx6ul-grisp2.dts imx6ull-industrialgrisp.dts SRC_FDT = $(MAKEFILE_DIR)/../external/fdt FDT_SYS = $(SRC_FDT)/sys FDT_SCRIPTS = $(FDT_SYS)/tools/fdt @@ -11,19 +11,19 @@ BUILDDIR = $(MAKEFILE_DIR)/b-dtb export DTC = dtc export MACHINE = arm -DTB = $(BUILDDIR)/$(BOARD).dtb +DTB = $(DTS:%.dts=$(BUILDDIR)/%.dtb) all: $(DTB) install: all mkdir -p $(PREFIX)/fdt - cp $(BOARD).dts $(PREFIX)/fdt/ + cp $(DTS) $(PREFIX)/fdt/ cp $(DTB) $(PREFIX)/fdt/ $(BUILDDIR): mkdir $(BUILDDIR) -$(DTB): $(BOARD).dts $(BUILDDIR) +$(BUILDDIR)/%.dtb: %.dts $(BUILDDIR) sh -x $(FDT_SCRIPTS)/make_dtb.sh $(FDT_SYS) $< $(BUILDDIR) clean: diff --git a/fdt/imx6ull-industrialgrisp.dts b/fdt/imx6ull-industrialgrisp.dts new file mode 100644 index 0000000..12356fd --- /dev/null +++ b/fdt/imx6ull-industrialgrisp.dts @@ -0,0 +1,266 @@ +// SPDX-License-Identifier: (GPL-2.0+ OR BSD-2-Clause) +/* + * Copyright (C) 2020 embedded brains GmbH. + */ + +/dts-v1/; +#include "custom-imx6ul.dtsi" +#include "imx6ul-phytec-phycore-som.dtsi" + +/ { + model = "IndustrialGRiSP"; + compatible = "embeddedbrains,industrialgrisp", "phytec,imx6ul-pcl063-emmc", "fsl,imx6ull"; + + gpio_leds_grisp2: leds { + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_gpioleds_grisp2>; + compatible = "gpio-leds"; + + igrisp-mcu-led { + gpios = <&gpio1 25 GPIO_ACTIVE_HIGH>; + }; + igrisp-rfid-led { + gpios = <&gpio1 0 GPIO_ACTIVE_HIGH>; + }; + }; + + pmod_spi: pmod-spi { + pinctrl-names = "default", "gpio"; + pinctrl-0 = <&pinctrl_spi3>; + pinctrl-1 = <&pinctrl_spi3_gpio>; + status = "okay"; + + /* SPI mode */ + grisp,spi-alias = "spi2"; /* use with spi_bus_register_imx */ + grisp,int-gpios = <&gpio1 3 GPIO_ACTIVE_HIGH>; + + /* GPIO mode */ + grisp,gpios = + <&gpio1 20 GPIO_ACTIVE_HIGH>, /* X803.1 */ + <&gpio1 22 GPIO_ACTIVE_HIGH>, /* X803.2 */ + <&gpio1 23 GPIO_ACTIVE_HIGH>, /* X803.3 */ + <&gpio1 21 GPIO_ACTIVE_HIGH>, /* X803.4 */ + <&gpio1 3 GPIO_ACTIVE_HIGH>, /* X803.7 */ + <&gpio5 0 GPIO_ACTIVE_HIGH>, /* X803.8 */ + <&gpio1 1 GPIO_ACTIVE_HIGH>, /* X803.9 */ + <&gpio1 18 GPIO_ACTIVE_HIGH>; /* X803.10 */ + }; +}; + +&fec1 { + status = "okay"; + pinctrl-0 = <&pinctrl_enet1_igrisp>; + + /delete-node/ mdio; +}; + +&fec2 { + status = "okay"; + + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_enet2>; + phy-mode = "rmii"; + phy-handle = <ðphy2>; + + mdio: mdio { + #address-cells = <1>; + #size-cells = <0>; + + ethphy1: ethernet-phy@1 { + reg = <1>; + interrupt-parent = <&gpio1>; + interrupts = <2 IRQ_TYPE_LEVEL_LOW>; + micrel,led-mode = <1>; + clocks = <&clks IMX6UL_CLK_ENET_REF>; + clock-names = "rmii-ref"; + status = "okay"; + }; + + ethphy2: ethernet-phy@2 { + reg = <2>; + interrupt-parent = <&gpio4>; + interrupts = <16 IRQ_TYPE_LEVEL_LOW>; + micrel,led-mode = <1>; + clocks = <&clks IMX6UL_CLK_ENET_REF>; + clock-names = "rmii-ref"; + status = "okay"; + }; + }; +}; + +&i2c1 { + status = "okay"; + + at24mac402_eeprom: eeprom@57 { + compatible = "atmel,24c02"; + reg = <0x57>; + status = "okay"; + }; + at24mac402_eui: eeprom@5f { + compatible = "atmel,at24mac402-eui"; + reg = <0x5f>; + status = "okay"; + }; + atecc608: cryptoauth@36 { + compatible = "microchip,atecc608", "atmel,at24c16"; + reg = <0x36>; + status = "okay"; + }; +}; + +&usdhc2 { + pinctrl-names = "default"; + status = "okay"; +}; + +&ecspi1 { + status = "okay"; + pinctrl-0 = <&pinctrl_spi1>; + + cs-gpios = <&gpio4 26 GPIO_ACTIVE_HIGH>, + <&gpio3 10 GPIO_ACTIVE_HIGH>, + <&gpio3 11 GPIO_ACTIVE_HIGH>; + + rfid: rfid@0 { + compatible = "ti,trf7970a"; + reg = <0>; + + spi-max-frequency = <2000000>; + interrupt-parent = <&gpio4>; + interrupts = <19 IRQ_TYPE_LEVEL_LOW>; + grisp,int-gpios = <&gpio4 19 GPIO_ACTIVE_HIGH>; + grisp,led-gpios = <&gpio3 4 GPIO_ACTIVE_HIGH>; + }; + + dio1: dio@2 { + compatible = "maxim,max14906"; + /* Really 2 for DIO1: The SS pins are numbered odd! */ + reg = <2>; + + spi-max-frequency = <2000000>; + interrupt-parent = <&gpio3>; + interrupts = <0 IRQ_TYPE_LEVEL_HIGH>; + maxim,fault = <&gpio3 0 GPIO_ACTIVE_HIGH>; + maxim,ready = <&gpio3 1 GPIO_ACTIVE_HIGH>; + }; + + dio2: dio@1 { + compatible = "maxim,max14906"; + /* Really 1 for DIO2: The SS pins are numbered odd! */ + reg = <1>; + + spi-max-frequency = <2000000>; + interrupt-parent = <&gpio3>; + interrupts = <2 IRQ_TYPE_LEVEL_HIGH>; + maxim,fault = <&gpio3 2 GPIO_ACTIVE_HIGH>; + maxim,ready = <&gpio3 3 GPIO_ACTIVE_HIGH>; + }; +}; + +&ecspi3 { + status = "okay"; + pinctrl-0 = <&pinctrl_spi3>; + + cs-gpios = <&gpio1 20 GPIO_ACTIVE_HIGH>; + + grisp,int-gpios = <&gpio1 3 GPIO_ACTIVE_HIGH>; +}; + +&iomuxc { + pinctrl_spi1: spi1grp { + fsl,pins = < + MX6UL_PAD_CSI_DATA04__ECSPI1_SCLK 0x8 /* SPI_SCK */ + MX6UL_PAD_CSI_DATA06__ECSPI1_MOSI 0x8 /* SPI_MOSI */ + MX6UL_PAD_CSI_DATA07__ECSPI1_MISO 0x2000 /* SPI_MISO */ + + MX6UL_PAD_CSI_DATA05__GPIO4_IO26 0x8 /* SPI_SS0 */ + MX6UL_PAD_LCD_DATA05__GPIO3_IO10 0x8 /* SPI_SS1 */ + MX6UL_PAD_LCD_DATA06__GPIO3_IO11 0x8 /* SPI_SS2/SPI_GPIO0 */ + MX6UL_PAD_LCD_RESET__GPIO3_IO04 0x8 /* SPI_GPIO1 */ + MX6UL_PAD_CSI_DATA03__GPIO4_IO24 0x8 /* SPI_RESET */ + MX6UL_PAD_CSI_VSYNC__GPIO4_IO19 0x8 /* SPI_INT */ + MX6UL_PAD_LCD_ENABLE__GPIO3_IO01 0x8 /* SPI_READY1 */ + MX6UL_PAD_LCD_CLK__GPIO3_IO00 0x8 /* SPI_FAULT1 */ + MX6UL_PAD_LCD_VSYNC__GPIO3_IO03 0x8 /* SPI_READY2 */ + MX6UL_PAD_LCD_HSYNC__GPIO3_IO02 0x8 /* SPI_FAULT2 */ + >; + }; + + pinctrl_spi3: spi3grp { + fsl,pins = < + MX6UL_PAD_UART2_RX_DATA__ECSPI3_SCLK 0x8 /* SPI3_SCK */ + MX6UL_PAD_UART2_CTS_B__ECSPI3_MOSI 0x8 /* SPI3_MOSI */ + MX6UL_PAD_UART2_RTS_B__ECSPI3_MISO 0x2000 /* SPI3_MISO */ + + MX6UL_PAD_UART2_TX_DATA__GPIO1_IO20 0x8 /* SPI3_SS0 */ + MX6UL_PAD_GPIO1_IO01__GPIO1_IO01 0x8 /* SPI3_GPIO0 */ + MX6UL_PAD_GPIO1_IO03__GPIO1_IO03 0x8 /* SPI3_INT */ + MX6UL_PAD_SNVS_TAMPER0__GPIO5_IO00 0x8 /* SPI3_RESET */ + MX6UL_PAD_UART1_CTS_B__GPIO1_IO18 0x8 /* SPI3_GPIO1 */ + >; + }; + + pinctrl_spi3_gpio: spi3grp { + fsl,pins = < + MX6UL_PAD_UART2_RX_DATA__GPIO1_IO21 0x8 /* SPI3_SCK / X803.4 */ + MX6UL_PAD_UART2_CTS_B__GPIO1_IO22 0x8 /* SPI3_MOSI / X803.2 */ + MX6UL_PAD_UART2_RTS_B__GPIO1_IO23 0x8 /* SPI3_MISO / X803.3 */ + MX6UL_PAD_UART2_TX_DATA__GPIO1_IO20 0x8 /* SPI3_SS0 / X803.1 */ + MX6UL_PAD_GPIO1_IO01__GPIO1_IO01 0x8 /* SPI3_GPIO0 / X803.9 */ + MX6UL_PAD_GPIO1_IO03__GPIO1_IO03 0x8 /* SPI3_INT / X803.7 */ + MX6UL_PAD_SNVS_TAMPER0__GPIO5_IO00 0x8 /* SPI3_RESET / X803.8 */ + MX6UL_PAD_UART1_CTS_B__GPIO1_IO18 0x8 /* SPI3_GPIO1 / X803.10 */ + >; + }; + + pinctrl_version: versiongrp { + fsl,pins = < + MX6UL_PAD_SNVS_TAMPER1__GPIO5_IO01 0x8 /* */ + MX6UL_PAD_SNVS_TAMPER3__GPIO5_IO03 0x8 /* */ + MX6UL_PAD_SNVS_TAMPER5__GPIO5_IO05 0x8 /* */ + MX6UL_PAD_SNVS_TAMPER9__GPIO5_IO09 0x8 /* */ + >; + }; + + /delete-node/ pinctrl_enet1; + + pinctrl_enet1_igrisp: enet1grp { + fsl,pins = < + MX6UL_PAD_ENET1_RX_EN__ENET1_RX_EN 0x1b0b0 + MX6UL_PAD_ENET1_RX_ER__ENET1_RX_ER 0x1b0b0 + MX6UL_PAD_ENET1_RX_DATA0__ENET1_RDATA00 0x1b0b0 + MX6UL_PAD_ENET1_RX_DATA1__ENET1_RDATA01 0x1b0b0 + MX6UL_PAD_ENET1_TX_EN__ENET1_TX_EN 0x1b010 + MX6UL_PAD_ENET1_TX_DATA0__ENET1_TDATA00 0x1b010 + MX6UL_PAD_ENET1_TX_DATA1__ENET1_TDATA01 0x1b010 + MX6UL_PAD_ENET1_TX_CLK__ENET1_REF_CLK1 0x4001b010 + MX6UL_PAD_GPIO1_IO02__GPIO1_IO02 0x17059 + >; + }; + + pinctrl_enet2: enet2grp { + fsl,pins = < + MX6UL_PAD_ENET2_TX_DATA0__ENET2_TDATA00 0x1b010 /* ENET2_TX_D0 */ + MX6UL_PAD_ENET2_TX_DATA1__ENET2_TDATA01 0x1b010 /* ENET2_TX_D1 */ + MX6UL_PAD_ENET2_TX_EN__ENET2_TX_EN 0x1b010 /* ENET2_TX_EN */ + MX6UL_PAD_ENET2_TX_CLK__ENET2_REF_CLK2 0x4001b010 /* ENET2_TX_CLK */ + + MX6UL_PAD_ENET2_RX_DATA0__ENET2_RDATA00 0x1b0b0 /* ENET2_RX_D0 */ + MX6UL_PAD_ENET2_RX_DATA1__ENET2_RDATA01 0x1b0b0 /* ENET2_RX_D1 */ + MX6UL_PAD_ENET2_RX_EN__ENET2_RX_EN 0x1b0b0 /* ENET2_RX_EN */ + MX6UL_PAD_ENET2_RX_ER__ENET2_RX_ER 0x1b0b0 /* ENET2_RX_ER */ + + MX6UL_PAD_NAND_DQS__GPIO4_IO16 0x8 /* ENET2_INT */ + + MX6UL_PAD_GPIO1_IO07__ENET2_MDC 0x10010 + MX6UL_PAD_GPIO1_IO06__ENET2_MDIO 0x10010 + >; + }; + + pinctrl_gpioleds_grisp2: gpioledsgrisp2grp { + fsl,pins = < + MX6UL_PAD_UART3_RX_DATA__GPIO1_IO25 0x00088 /* MCU_LED */ + MX6UL_PAD_GPIO1_IO00__GPIO1_IO00 0x00088 /* RFId_LED */ + >; + }; +}; From a384898b6ba9ea79d32a2e19a73c854a27eb6f40 Mon Sep 17 00:00:00 2001 From: Christian Mauderer Date: Mon, 23 May 2022 10:29:53 +0200 Subject: [PATCH 04/25] libgrisp: Update for IGRiSP --- external/libgrisp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/libgrisp b/external/libgrisp index 1347e6e..572237e 160000 --- a/external/libgrisp +++ b/external/libgrisp @@ -1 +1 @@ -Subproject commit 1347e6eed151fcea11daf32e9b5d0aad728d80f4 +Subproject commit 572237e32110bcfa550215649ad9cdf3c2611ad4 From b84f61d8ac56d3a3c6d7ab24bdaa0ed14a868308 Mon Sep 17 00:00:00 2001 From: Christian Mauderer Date: Fri, 13 May 2022 13:01:03 +0200 Subject: [PATCH 05/25] demo: No WiFi on IGrisp --- demo/init.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/demo/init.c b/demo/init.c index c545e56..0f4c647 100644 --- a/demo/init.c +++ b/demo/init.c @@ -289,8 +289,11 @@ Init(rtems_task_argument arg) grisp_init_dhcpcd(PRIO_DHCP); grisp_led_set2(false, false, true); - sleep(3); - grisp_init_wpa_supplicant(wpa_supplicant_conf, PRIO_WPA, create_wlandev); + if (!grisp_is_industrialgrisp()) { + sleep(3); + grisp_init_wpa_supplicant(wpa_supplicant_conf, PRIO_WPA, + create_wlandev); + } #ifdef EVENT_RECORDING rtems_record_start_server(10, 1234, 10); From e038ff7fe51579314e75de2c7080afc2e3b9bf2c Mon Sep 17 00:00:00 2001 From: Christian Mauderer Date: Mon, 11 Apr 2022 17:03:48 +0200 Subject: [PATCH 06/25] iGRiSP: Add a DIO test command This is based on Weizhong Xu's work for PMOD DIO --- demo/init.c | 40 +++- demo/pmod_dio.c | 487 ++++++++++++++++++++++++++++++++++++++++++++++++ demo/pmod_dio.h | 47 +++++ 3 files changed, 565 insertions(+), 9 deletions(-) create mode 100644 demo/pmod_dio.c create mode 100644 demo/pmod_dio.h diff --git a/demo/init.c b/demo/init.c index 0f4c647..561c5f1 100644 --- a/demo/init.c +++ b/demo/init.c @@ -57,6 +57,7 @@ #define IS_GRISP2 1 #endif +#include #ifdef IS_GRISP1 #include #include @@ -69,6 +70,7 @@ #include "sd-card-test.h" #include "1wire.h" #include "pmod_rfid.h" +#include "pmod_dio.h" #define STACK_SIZE_INIT_TASK (64 * 1024) #define STACK_SIZE_SHELL (64 * 1024) @@ -79,7 +81,6 @@ #define PRIO_WPA (RTEMS_MAXIMUM_PRIORITY - 1) #define SPI_FDT_NAME "spi0" -#define SPI_BUS "/dev/spibus" #define CMD_SPI_MAX_LEN 32 @@ -249,14 +250,30 @@ Init(rtems_task_argument arg) assert(rv == 0); #endif #ifdef IS_GRISP2 - rv = spi_bus_register_imx(SPI_BUS, SPI_FDT_NAME); - assert(rv == 0); + if (grisp_is_industrialgrisp()) { + /* Industrial GRiSP */ + rv = spi_bus_register_imx(GRISP_SPI_DEVICE, + GRISP_INDUSTRIAL_SPI_ONBOARD_FDT_ALIAS); + assert(rv == 0); + rv = spi_bus_register_imx(GRISP_SPI_DEVICE "-pmod", + GRISP_INDUSTRIAL_SPI_PMOD_FDT_ALIAS); + assert(rv == 0); + + rv = i2c_bus_register_imx(GRISP_I2C0_DEVICE, + GRISP_INDUSTRIAL_I2C_FDT_ALIAS); + assert(rv == 0); + } else { + /* GRiSP2 */ + rv = spi_bus_register_imx(GRISP_SPI_DEVICE, + GRISP_SPI_FDT_ALIAS); + assert(rv == 0); - rv = i2c_bus_register_imx("/dev/i2c-1", "i2c0"); - assert(rv == 0); + rv = i2c_bus_register_imx("/dev/i2c-1", "i2c0"); + assert(rv == 0); - rv = i2c_bus_register_imx("/dev/i2c-2", "i2c1"); - assert(rv == 0); + rv = i2c_bus_register_imx("/dev/i2c-2", "i2c1"); + assert(rv == 0); + } #endif /* IS_GRISP2 */ printf("Init EEPROM\n"); @@ -302,8 +319,13 @@ Init(rtems_task_argument arg) init_led(); #ifdef IS_GRISP2 - // uncomment for testing RFID - //pmod_rfid_init(SPI_BUS, 1); + if (grisp_is_industrialgrisp()) { + pmod_rfid_init(GRISP_SPI_DEVICE, 0); + pmod_dio_init(GRISP_SPI_DEVICE); + } else { + // uncomment for testing RFID + //pmod_rfid_init(GRISP_SPI_DEVICE, 1); + } #endif /* IS_GRISP2 */ start_shell(); diff --git a/demo/pmod_dio.c b/demo/pmod_dio.c new file mode 100644 index 0000000..0f3d474 --- /dev/null +++ b/demo/pmod_dio.c @@ -0,0 +1,487 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/* + * Copyright (C) 2022 embedded brains GmbH (http://www.embedded-brains.de) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +#include + +#ifdef GRISP_PLATFORM_GRISP2 +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "pmod_rfid.h" + +#define MAX14906_SetOUT 0x00 +#define MAX14906_SetLED 0x01 +#define MAX14906_DoiLevel 0x02 +#define MAX14906_Interrupt 0x03 +#define MAX14906_OvrLdChF 0x04 +#define MAX14906_OpnWirChF 0x05 +#define MAX14906_ShtVDDChF 0x06 +#define MAX14906_GlobalErr 0x07 +#define MAX14906_OpnWrEn 0x08 +#define MAX14906_ShtVDDEn 0x09 +#define MAX14906_Config1 0x0A +#define MAX14906_Config2 0x0B +#define MAX14906_ConfigDI 0x0C +#define MAX14906_ConfigDO 0x0D +#define MAX14906_CurrLim 0x0E +#define MAX14906_Mask 0x0F + +#define MAX14906_REGISTERS 0x10 + +#define MAX_CASCADED_BOARDS 4 + +#define CLEAR_BIT(x, bit) (x &= (uint8_t)~(1u << (bit))) +#define SET_BIT(x, bit) (x |= (uint8_t)(1u << (bit))) + +struct pmod_dio_ctx { + rtems_shell_cmd_t shell_cmd; + int bus; + uint8_t cs; + struct imx_gpio_pin fault; + struct imx_gpio_pin ready; + bool initialized; + uint8_t regs[MAX_CASCADED_BOARDS][MAX14906_REGISTERS]; +}; + +static uint8_t +max14906_build_addr(int board, uint8_t addr, uint8_t write) +{ + return (uint8_t)((board << 6) + (addr << 1) + write); +} + +/* + * Calculate the CRC from first_bit to last_bit. According to AN 6633, the + * checksum from CPU to MAX14915 is calculated from bit 0 to bit 18 and the + * checksum from MAX14915 to CPU is calculated from bit 2 to bit 18. + */ +static uint8_t +max14906_crc5encode(uint8_t *buf, size_t first_bit, size_t last_bit) +{ + uint8_t crc5_start = 0x1f; + uint8_t crc5_poly = 0x15; + uint8_t crc_result = crc5_start; + size_t i; + + for (i = first_bit; i <= last_bit; ++i) { + uint8_t bit = (buf[i/8] >> (7-(i%8))) & 0x01; + uint8_t crc_result_bit4 = (crc_result >> 4) & 0x01; + + if (bit ^ crc_result_bit4) { + crc_result = + (uint8_t)(crc5_poly ^ ((crc_result<<1) & 0x1f)); + } else { + crc_result = (uint8_t)((crc_result<<1) & 0x1f); + } + } + + return crc_result; +} + +/* + * Return returned second byte on success or -1 on error. + */ +static int +pmod_dio_register_rw( + struct pmod_dio_ctx *ctx, + int board, + uint8_t addr, + uint8_t write, + uint8_t value +) +{ + uint8_t tx_buf[] = { + max14906_build_addr(board, addr, write), + value, + 0 + }; + uint8_t rx_buf[sizeof(tx_buf)]; + spi_ioc_transfer msg = { + .len = sizeof(tx_buf), + .rx_buf = rx_buf, + .tx_buf = tx_buf, + .speed_hz = 200000, + .bits_per_word = 8, + .mode = SPI_MODE_0, + .cs = ctx->cs, + .cs_change = true, + }; + int error; + uint8_t crc; + + tx_buf[sizeof(tx_buf)-1] = max14906_crc5encode(tx_buf, 0, + sizeof(tx_buf) * 8 - 6); + + error = ioctl(ctx->bus, SPI_IOC_MESSAGE(1), &msg); + if (error != 0) { + return -1; + } + crc = max14906_crc5encode(rx_buf, 2, sizeof(rx_buf) * 8 - 6); + if (crc != (rx_buf[sizeof(rx_buf)-1] & 0x1F)) { + return -1; + } + return rx_buf[1]; +} + +static int +pmod_dio_register_write( + struct pmod_dio_ctx *ctx, + int board, + uint8_t addr +) +{ + return pmod_dio_register_rw(ctx, board, addr, 1, + ctx->regs[board][addr]); +} + +static int +pmod_dio_register_read( + struct pmod_dio_ctx *ctx, + int board, + uint8_t addr +) +{ + return pmod_dio_register_rw(ctx, board, addr, 0, 0); +} + +static int +pmod_dio_set_op_mode_func( + struct pmod_dio_ctx *ctx, + int board, + int chan, + int op_mode +) +{ + int rv; + + if (chan < 0 || chan > 3 || op_mode < 0 || op_mode > 6) { + printf("Usage:\n%s", ctx->shell_cmd.usage); + return -1; + }; + + if (op_mode < 4) { + CLEAR_BIT(ctx->regs[board][MAX14906_SetOUT], chan+4); + + if (op_mode == 0) { /* High-side */ + CLEAR_BIT(ctx->regs[board][MAX14906_ConfigDO], chan*2); + CLEAR_BIT(ctx->regs[board][MAX14906_ConfigDO], chan*2+1); + } else if (op_mode == 1) { /* High-side with 2x inrush current */ + SET_BIT(ctx->regs[board][MAX14906_ConfigDO], chan*2); + CLEAR_BIT(ctx->regs[board][MAX14906_ConfigDO], chan*2+1); + } else if (op_mode == 2) { /* Active-clamp push-pull */ + CLEAR_BIT(ctx->regs[board][MAX14906_ConfigDO], chan*2); + SET_BIT(ctx->regs[board][MAX14906_ConfigDO], chan*2+1); + } else { /* Simple push-pull */ + SET_BIT(ctx->regs[board][MAX14906_ConfigDO], chan*2); + SET_BIT(ctx->regs[board][MAX14906_ConfigDO], chan*2+1); + } + + rv = pmod_dio_register_write(ctx, board, MAX14906_SetOUT); + assert(rv >= 0); + rtems_task_wake_after(RTEMS_MILLISECONDS_TO_TICKS(500)); + + rv = pmod_dio_register_write(ctx, board, MAX14906_ConfigDO); + assert(rv >= 0); + rtems_task_wake_after(RTEMS_MILLISECONDS_TO_TICKS(500)); + } else { + SET_BIT(ctx->regs[board][MAX14906_SetOUT], chan+4); + + if (op_mode == 4) { /* Low-leakage, High-impedance */ + SET_BIT(ctx->regs[board][MAX14906_ConfigDO], (chan*2+1)); + } else if (op_mode == 5) { /* DI Mode, Type 1 and 3 */ + CLEAR_BIT(ctx->regs[board][MAX14906_ConfigDI], 7); + CLEAR_BIT(ctx->regs[board][MAX14906_ConfigDO], (chan*2+1)); + } else if (op_mode == 6) { /* DI Mode, Type 2 */ + SET_BIT(ctx->regs[board][MAX14906_ConfigDI], 7); + CLEAR_BIT(ctx->regs[board][MAX14906_ConfigDO], (chan*2+1)); + } + + rv = pmod_dio_register_write(ctx, board, MAX14906_SetOUT); + assert(rv >= 0); + rtems_task_wake_after(RTEMS_MILLISECONDS_TO_TICKS(500)); + + rv = pmod_dio_register_write(ctx, board, MAX14906_ConfigDO); + assert(rv >= 0); + rtems_task_wake_after(RTEMS_MILLISECONDS_TO_TICKS(500)); + + rv = pmod_dio_register_write(ctx, board, MAX14906_ConfigDI); + assert(rv >= 0); + rtems_task_wake_after(RTEMS_MILLISECONDS_TO_TICKS(500)); + } + + return 0; +} + +static int +pmod_dio_read_input_func(struct pmod_dio_ctx *ctx, int board, int chan) +{ + int rv; + + if (chan < 0 || chan > 3) { + printf("Usage:\n%s", ctx->shell_cmd.usage); + return -1; + }; + + /* VDDFaultSe = 0 */ + CLEAR_BIT(ctx->regs[board][MAX14906_ConfigDI], 4); + rv = pmod_dio_register_write(ctx, board, MAX14906_ConfigDI); + assert(rv >= 0); + rtems_task_wake_after(RTEMS_MILLISECONDS_TO_TICKS(500)); + + /* Read input */ + rv = pmod_dio_register_read(ctx, board, MAX14906_DoiLevel); + assert(rv >= 0); + ctx->regs[board][MAX14906_DoiLevel] = (uint8_t) rv; + + if ((rv & (1 << chan)) != 0) { + printf("input is high\n"); + } else { + printf("input is low\n"); + } + + return 0; +} + +static int +pmod_dio_write_output_func( + struct pmod_dio_ctx *ctx, + int board, + int chan, + int lvl +) +{ + int rv; + + /* FIXME: Better error handling instead of asserts */ + + if (chan < 0 || chan > 3 || lvl < 0 || lvl > 1) { + printf("Usage:\n%s", ctx->shell_cmd.usage); + return -1; + }; + + if (lvl == 0) { + CLEAR_BIT(ctx->regs[board][MAX14906_SetOUT], chan); + } else { + SET_BIT(ctx->regs[board][MAX14906_SetOUT], chan); + } + + rv = pmod_dio_register_write(ctx, board, MAX14906_SetOUT); + assert(rv >= 0); + + return 0; +} + +static int +pmod_dio_init_board_func(struct pmod_dio_ctx *ctx, int board) +{ + size_t i; + int rv; + + /* FIXME: Better error handling instead of asserts */ + + /* copy all registers */ + for (i = 0; i < MAX14906_REGISTERS; ++i) { + rv = pmod_dio_register_read(ctx, board, (uint8_t)i); + assert(rv >= 0); + ctx->regs[board][i] = (uint8_t)rv; + rtems_task_wake_after(RTEMS_MILLISECONDS_TO_TICKS(100)); + } + + /* Set LEDs which are controlled directly by the MAX14906 */ + CLEAR_BIT(ctx->regs[board][MAX14906_Config1], 0); + CLEAR_BIT(ctx->regs[board][MAX14906_Config1], 1); + rv = pmod_dio_register_write(ctx, board, MAX14906_Config1); + assert(rv >= 0); + rtems_task_wake_after(RTEMS_MILLISECONDS_TO_TICKS(100)); + + /* Enable gate driver */ + SET_BIT(ctx->regs[board][MAX14906_OpnWrEn], 4); + SET_BIT(ctx->regs[board][MAX14906_OpnWrEn], 5); + SET_BIT(ctx->regs[board][MAX14906_OpnWrEn], 6); + SET_BIT(ctx->regs[board][MAX14906_OpnWrEn], 7); + rv = pmod_dio_register_write(ctx, board, MAX14906_OpnWrEn); + assert(rv >= 0); + rtems_task_wake_after(RTEMS_MILLISECONDS_TO_TICKS(100)); + + /* current limit up to 1.2 A */ + ctx->regs[board][MAX14906_CurrLim] = 0xff; + rv = pmod_dio_register_write(ctx, board, MAX14906_CurrLim); + assert(rv >= 0); + rtems_task_wake_after(RTEMS_MILLISECONDS_TO_TICKS(100)); + + return 0; +} + +static struct pmod_dio_ctx * +pmod_dio_get_ctx_from_shell(char **argv) +{ + rtems_shell_cmd_t *shell_cmd; + + shell_cmd = rtems_shell_lookup_cmd(argv[0]); + return RTEMS_CONTAINER_OF(shell_cmd, struct pmod_dio_ctx, shell_cmd); +} + +static int +pmod_dio_func(int argc, char **argv) +{ + struct pmod_dio_ctx *ctx = pmod_dio_get_ctx_from_shell(argv); + int board = 0; /* Number of the cascaded board */ + int second = -1; /* Second numeric argument */ + int third = -1; /* Third numeric argument */ + + if (argc < 2) { + printf("Usage:\n%s", ctx->shell_cmd.usage); + return -1; + } + + if (argc >= 3) { + errno = 0; + board = (uint8_t)strtol(argv[2], NULL, 0); + if (errno != 0 || board < 0 || board >= MAX_CASCADED_BOARDS) { + printf("Usage:\n%s", ctx->shell_cmd.usage); + return -1; + } + } + + if (argc >= 4) { + errno = 0; + second = (uint8_t)strtol(argv[3], NULL, 0); + if (errno != 0) { + printf("Usage:\n%s", ctx->shell_cmd.usage); + return -1; + } + } + + if (argc >= 5) { + errno = 0; + third = (uint8_t)strtol(argv[4], NULL, 0); + if (errno != 0) { + printf("Usage:\n%s", ctx->shell_cmd.usage); + return -1; + } + } + + if (strcmp(argv[1], "set_op_mode") == 0) { + return pmod_dio_set_op_mode_func(ctx, board, second, third); + } else if (strcmp(argv[1], "init_board") == 0) { + return pmod_dio_init_board_func(ctx, board); + } else if (strcmp(argv[1], "read_input") == 0) { + return pmod_dio_read_input_func(ctx, board, second); + } else if (strcmp(argv[1], "write_output") == 0) { + return pmod_dio_write_output_func(ctx, board, second, third); + } else { + printf("Usage:\n%s", ctx->shell_cmd.usage); + return -1; + } +} + +static void +pmod_dio_do_init(const void *fdt, int node, const char *spi_bus) +{ + struct pmod_dio_ctx *ctx; + const void *prop; + const char *name; + static const char topic[] = "dio"; + static const char usage[] = "Call with:\n" + " dioX init_board \n" + " dioX set_op_mode \n" + " dioX read_input \n" + " dioX write_output \n" + "where:\n" + " Number of the cascaded board. [0..3]\n" + " Channel to read / write. [0..3]\n" + " Level to set. [0..1]\n" + " operational mode:\n" + " 0: High-side\n" + " 1: High-side with 2x inrush current\n" + " 2: Active-clamp push-pull\n" + " 3: Simple push-pull\n" + " 4: Low-leakage, High-impedance\n" + " 5: DI Mode, Type 1 and 3\n" + " 6: DI Mode, Type 2\n"; + rtems_status_code sc; + rtems_shell_cmd_t *cmd; + + /* FIXME: Should use better error handling than asserts! But it's only a + * test so let's use them for now. */ + + name = fdt_get_name(fdt, node, NULL); + assert(name != NULL); + + ctx = calloc(sizeof(*ctx), 1); + assert(ctx != NULL); + + ctx->shell_cmd.name = name; + ctx->shell_cmd.usage = usage; + ctx->shell_cmd.topic = topic; + ctx->shell_cmd.command = pmod_dio_func; + + ctx->bus = open(spi_bus, O_RDWR); + assert(ctx->bus >= 0); + + prop = fdt_getprop(fdt, node, "reg", NULL); + assert(prop != NULL); + ctx->cs = (uint8_t) fdt32_ld(prop); + + sc = imx_gpio_init_from_fdt_property( + &ctx->fault, node, "maxim,fault", IMX_GPIO_MODE_INPUT, 0); + assert(sc == RTEMS_SUCCESSFUL); + sc = imx_gpio_init_from_fdt_property( + &ctx->ready, node, "maxim,ready", IMX_GPIO_MODE_INPUT, 0); + assert(sc == RTEMS_SUCCESSFUL); + + cmd = rtems_shell_add_cmd_struct(&ctx->shell_cmd); + assert(cmd != NULL); +} + +void +pmod_dio_init(const char *spi_bus) +{ + const void *fdt = bsp_fdt_get(); + int node = -1; + + do { + node = fdt_node_offset_by_compatible(fdt, node, + "maxim,max14906"); + + if (node >= 0) { + pmod_dio_do_init(fdt, node, spi_bus); + } + } while (node >= 0); +} +#endif /* IS_GRISP2 */ diff --git a/demo/pmod_dio.h b/demo/pmod_dio.h new file mode 100644 index 0000000..afaa10c --- /dev/null +++ b/demo/pmod_dio.h @@ -0,0 +1,47 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/* + * Copyright (C) 2022 embedded brains GmbH (http://www.embedded-brains.de) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef DEMO_PMOD_DIO_H +#define DEMO_PMOD_DIO_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* + * Initialize necessary stuff and add shell commands to work with PMOD_DIO. + * Note: This function will get most of the necessary information from FDT. + */ +void pmod_dio_init(const char *spi_bus); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* DEMO_PMOD_RFID_H */ From b049e04ae700fe5b5489d816bfcc33ee2823c287 Mon Sep 17 00:00:00 2001 From: Christian Mauderer Date: Fri, 13 May 2022 14:31:48 +0200 Subject: [PATCH 07/25] demo: Add PMOD RFID to IGRiSP --- demo/pmod_rfid.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/demo/pmod_rfid.c b/demo/pmod_rfid.c index 1468ba8..152a491 100644 --- a/demo/pmod_rfid.c +++ b/demo/pmod_rfid.c @@ -620,19 +620,21 @@ pmod_rfid_init_pins(struct pmod_rfid_ctx *ctx) { rtems_status_code sc; int node; - const char *path; const void *fdt; fdt = bsp_fdt_get(); - path = fdt_get_alias(fdt, "spi0"); - if (path == 0) { + + node = fdt_node_offset_by_compatible(fdt, -1, "ti,trf7970a"); + if (node < 0) { return RTEMS_UNSATISFIED; } - node = fdt_path_offset(fdt, path); - /* LED is connected to SS3 */ + /* LED */ sc = imx_gpio_init_from_fdt_property(&ctx->led, - node, "cs-gpios", IMX_GPIO_MODE_OUTPUT, 3); + node, "grisp,led-gpios", IMX_GPIO_MODE_OUTPUT, 0); + if (sc != RTEMS_SUCCESSFUL) { + return sc; + } /* Interrupt pin */ /* FIXME: The interrupt pin isn't used yet. Initialization is done so it From e30325ebe937c8881b2f6e28241ed11ed84319dd Mon Sep 17 00:00:00 2001 From: Weizhong Xu Date: Tue, 17 May 2022 10:46:54 +0200 Subject: [PATCH 08/25] demo: Fix chip select for RFID --- demo/pmod_rfid.c | 1 + 1 file changed, 1 insertion(+) diff --git a/demo/pmod_rfid.c b/demo/pmod_rfid.c index 152a491..c64da27 100644 --- a/demo/pmod_rfid.c +++ b/demo/pmod_rfid.c @@ -228,6 +228,7 @@ pmod_rfid_transfer( .bits_per_word = 8, .mode = SPI_MODE_1, .cs = ctx->cs, + .cs_change = true, }; verb_print(ctx, VERBOSE_ALL, "Tx: "); From 4c22b38585533a9578b596f34e0594577141425c Mon Sep 17 00:00:00 2001 From: Christian Mauderer Date: Thu, 20 Jul 2023 11:29:37 +0200 Subject: [PATCH 09/25] Add RTC driver for GRiSP Charger --- demo/init.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/demo/init.c b/demo/init.c index 561c5f1..9211321 100644 --- a/demo/init.c +++ b/demo/init.c @@ -30,6 +30,7 @@ */ #undef EVENT_RECORDING +#define RTC_ENABLED #include #include @@ -45,6 +46,10 @@ #include #include #include +#ifdef RTC_ENABLED +#include +#include +#endif #ifdef EVENT_RECORDING #include #include @@ -276,6 +281,10 @@ Init(rtems_task_argument arg) } #endif /* IS_GRISP2 */ +#ifdef RTC_ENABLED + setRealTimeToRTEMS(); +#endif + printf("Init EEPROM\n"); grisp_eeprom_init(); rv = grisp_eeprom_get(&eeprom); @@ -332,6 +341,17 @@ Init(rtems_task_argument arg) exit(0); } +#ifdef RTC_ENABLED +static struct mcp7940m_rtc rtc_ctx = + MCP7940M_RTC_INITIALIZER("/dev/i2c-1", 0x6f, false); + +rtc_tbl RTC_Table[] = { + MCP7940M_RTC_TBL_ENTRY("/dev/rtc", &rtc_ctx), +}; + +size_t RTC_Count = (sizeof(RTC_Table)/sizeof(rtc_tbl)); +#endif + /* * Configure LibBSD. */ @@ -346,6 +366,9 @@ Init(rtems_task_argument arg) */ #define CONFIGURE_MICROSECONDS_PER_TICK 10000 +#ifdef RTC_ENABLED +#define CONFIGURE_APPLICATION_NEEDS_RTC_DRIVER +#endif #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER #define CONFIGURE_APPLICATION_NEEDS_STUB_DRIVER From 991581efd4ebe2388db33cfce543e4f77b6bb8a3 Mon Sep 17 00:00:00 2001 From: Christian Mauderer Date: Wed, 5 Jun 2024 08:30:15 +0200 Subject: [PATCH 10/25] RSB: Download first and retry downloads a few times --- Makefile | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f344728..b882f8e 100644 --- a/Makefile +++ b/Makefile @@ -96,10 +96,25 @@ submodule-update: toolchain: mkdir -p $(BUILD_LOGS) rm -rf $(RSB)/rtems/build + # Downloading sometimes fails on the first try. So start with + # downloading twice cd $(RSB)/rtems && ../source-builder/sb-set-builder \ + --source-only-download \ --prefix=$(PREFIX) \ --log=$(BUILD_LOGS)/rsb-toolchain.log \ - --with-fortran \ + --with-fortran \ + $(RTEMS_VERSION)/rtems-$(ARCH) || true + cd $(RSB)/rtems && ../source-builder/sb-set-builder \ + --source-only-download \ + --prefix=$(PREFIX) \ + --log=$(BUILD_LOGS)/rsb-toolchain.log \ + --with-fortran \ + $(RTEMS_VERSION)/rtems-$(ARCH) + # Now build the tools + cd $(RSB)/rtems && ../source-builder/sb-set-builder \ + --prefix=$(PREFIX) \ + --log=$(BUILD_LOGS)/rsb-toolchain.log \ + --with-fortran \ $(RTEMS_VERSION)/rtems-$(ARCH) rm -rf $(RSB)/rtems/build From 1750859382da3fc72f3e94e21862814b2e4d26b0 Mon Sep 17 00:00:00 2001 From: Christian Mauderer Date: Wed, 5 Jun 2024 09:07:37 +0200 Subject: [PATCH 11/25] GDB now needs gmp and mpfr --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c4e39be..8df4c1d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,6 +32,8 @@ jobs: device-tree-compiler \ u-boot-tools \ lzop \ + libgmp3-dev \ + libmpfr-dev \ libusb-1.0-0-dev \ python3 \ python-is-python3 \ From 2f512a18a1fa0c9f7fe85f32f0093c21fbf36aa9 Mon Sep 17 00:00:00 2001 From: Christian Mauderer Date: Fri, 7 Jun 2024 11:29:33 +0200 Subject: [PATCH 12/25] CI: Work arround issue with rate limited server for gmp --- .github/workflows/ci.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8df4c1d..e971cee 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,6 +49,13 @@ jobs: - name: Build toolchain shell: bash run: | + # Hack: Downloading gmp often fails on github. Seems that the server + # is rate limited or something like that. So pre-fetch the file from a + # mirror. + make submodule-update + mkdir external/rtems-source-builder/rtems/sources + wget -O external/rtems-source-builder/rtems/sources/gmp-6.3.0.tar.bz2 https://ftp.gnu.org/gnu/gmp/gmp-6.3.0.tar.bz2 + # Hack end make install if [ "$RUNNER_OS" == "Linux" ]; then make barebox From f4430814555105341ac2bf74330ba01125e1cc23 Mon Sep 17 00:00:00 2001 From: Christian Mauderer Date: Thu, 17 Oct 2024 10:27:35 +0200 Subject: [PATCH 13/25] Add GRiSP Nano --- Makefile | 71 ++++++++++++++++++++++------------- external/libgrisp | 2 +- external/rtems | 2 +- external/rtems-libbsd | 2 +- external/rtems-source-builder | 2 +- src/config.ini | 10 +++++ 6 files changed, 58 insertions(+), 31 deletions(-) diff --git a/Makefile b/Makefile index b882f8e..b23bd26 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,8 @@ MAKEFILE_DIR = $(dir $(realpath $(firstword $(MAKEFILE_LIST)))) ARCH = arm -BSP = imx7 +BSP_GRISP_NANO = stm32u5-grisp-nano +BSP_GRISP2 = imx7 BSP_GRISP1 = atsamv RTEMS_VERSION = 6 TARGET = $(ARCH)-rtems$(RTEMS_VERSION) @@ -20,8 +21,6 @@ SRC_OPENOCD = $(MAKEFILE_DIR)/external/openocd-code SRC_IMX_USB_LOADER = $(MAKEFILE_DIR)/external/imx_usb_loader SRC_CRYPTOAUTHLIB = $(MAKEFILE_DIR)/external/cryptoauthlib SRC_BLAS = $(MAKEFILE_DIR)/external/lapack -BUILD_BSP = $(MAKEFILE_DIR)/build/b-$(BSP) -BUILD_BSP_GRISP1 = $(MAKEFILE_DIR)/build/b-$(BSP_GRISP1) BUILD_LOGS = $(MAKEFILE_DIR)/build BUILD_OPENOCD = $(MAKEFILE_DIR)/build/b-openocd LIBBSD_BUILDSET = $(MAKEFILE_DIR)/src/libbsd.ini @@ -124,10 +123,10 @@ toolchain-revision: mkdir -p ${PREFIX} echo "${GRISP_TOOLCHAIN_REVISION}" > "${PREFIX}/GRISP_TOOLCHAIN_REVISION" echo "${GRISP_TOOLCHAIN_PLATFORM}" > "${PREFIX}/GRISP_TOOLCHAIN_PLATFORM" - mkdir -p ${PREFIX}/${TARGET}/${BSP}/lib/include/grisp - echo "" > "${PREFIX}/${TARGET}/${BSP}/lib/include/grisp/grisp-buildinfo.h" + mkdir -p ${PREFIX}/${TARGET}/${BSP_GRISP2}/lib/include/grisp + echo "" > "${PREFIX}/${TARGET}/${BSP_GRISP2}/lib/include/grisp/grisp-buildinfo.h" echo "$$GRISP_BUILDINFO_C" > \ - "${PREFIX}/${TARGET}/${BSP}/lib/include/grisp/grisp-buildinfo.h" + "${PREFIX}/${TARGET}/${BSP_GRISP2}/lib/include/grisp/grisp-buildinfo.h" echo "$$GRISP_BUILDINFO_ERL" > \ "${PREFIX}/grisp_buildinfo.hrl" @@ -147,11 +146,11 @@ bsp: .PHONY: bsp.mk #H Build a Makefile helper for the applications. -bsp.mk: $(PREFIX)/make/custom/$(BSP).mk $(PREFIX)/make/custom/$(BSP_GRISP1).mk -$(PREFIX)/make/custom/$(BSP).mk: src/bsp.mk +bsp.mk: $(PREFIX)/make/custom/$(BSP_GRISP2).mk $(PREFIX)/make/custom/$(BSP_GRISP1).mk $(PREFIX)/make/custom/$(BSP_GRISP_NANO).mk +$(PREFIX)/make/custom/$(BSP_GRISP2).mk: src/bsp.mk cat $^ | sed \ -e "s/##RTEMS_API##/$(RTEMS_VERSION)/g" \ - -e "s/##RTEMS_BSP##/$(BSP)/g" \ + -e "s/##RTEMS_BSP##/$(BSP_GRISP2)/g" \ -e "s/##RTEMS_CPU##/$(ARCH)/g" \ > $@ $(PREFIX)/make/custom/$(BSP_GRISP1).mk: src/bsp.mk @@ -160,6 +159,12 @@ $(PREFIX)/make/custom/$(BSP_GRISP1).mk: src/bsp.mk -e "s/##RTEMS_BSP##/$(BSP_GRISP1)/g" \ -e "s/##RTEMS_CPU##/$(ARCH)/g" \ > $@ +$(PREFIX)/make/custom/$(BSP_GRISP_NANO).mk: src/bsp.mk + cat $^ | sed \ + -e "s/##RTEMS_API##/$(RTEMS_VERSION)/g" \ + -e "s/##RTEMS_BSP##/$(BSP_GRISP_NANO)/g" \ + -e "s/##RTEMS_CPU##/$(ARCH)/g" \ + > $@ .PHONY: libbsd #H Build and install libbsd. @@ -167,37 +172,47 @@ libbsd: rm -rf $(SRC_LIBBSD)/build cd $(SRC_LIBBSD) && ./waf configure \ --prefix=$(PREFIX) \ - --rtems-bsps=$(ARCH)/$(BSP),$(ARCH)/$(BSP_GRISP1) \ + --rtems-bsps=$(ARCH)/$(BSP_GRISP2),$(ARCH)/$(BSP_GRISP1),$(ARCH)/$(BSP_GRISP_NANO) \ --enable-warnings \ --optimization=$(OPTIMIZATION) \ --buildset=$(LIBBSD_BUILDSET) \ --rtems-version=$(RTEMS_VERSION) - # Workaround for GRiSP1 + # Workaround for GRiSP1 and Nano [ ! -e "$(PREFIX)/$(TARGET)/$(BSP_GRISP1)/lib/linkcmds.org" ] && \ mv "$(PREFIX)/$(TARGET)/$(BSP_GRISP1)/lib/linkcmds" \ "$(PREFIX)/$(TARGET)/$(BSP_GRISP1)/lib/linkcmds.org" || \ true - cp "$(PREFIX)/$(TARGET)/$(BSP_GRISP1)/lib/linkcmds.sdram" \ - "$(PREFIX)/$(TARGET)/$(BSP_GRISP1)/lib/linkcmds" - # End of workaround for GRiSP1 + echo "INCLUDE linkcmds.sdram" > \ + "$(PREFIX)/$(TARGET)/$(BSP_GRISP1)/lib/linkcmds" + [ ! -e "$(PREFIX)/$(TARGET)/$(BSP_GRISP_NANO)/lib/linkcmds.org" ] && \ + mv "$(PREFIX)/$(TARGET)/$(BSP_GRISP_NANO)/lib/linkcmds" \ + "$(PREFIX)/$(TARGET)/$(BSP_GRISP_NANO)/lib/linkcmds.org" || \ + true + echo "INCLUDE linkcmds.ospi" > \ + "$(PREFIX)/$(TARGET)/$(BSP_GRISP_NANO)/lib/linkcmds" + # End of workaround for GRiSP1 and Nano cd $(SRC_LIBBSD) && ./waf cd $(SRC_LIBBSD) && ./waf install - # Workaround for GRiSP1 + # Workarounds for GRiSP1 and Nano cp "$(PREFIX)/$(TARGET)/$(BSP_GRISP1)/lib/linkcmds.org" \ "$(PREFIX)/$(TARGET)/$(BSP_GRISP1)/lib/linkcmds" - # End of workaround for GRiSP1 + cp "$(PREFIX)/$(TARGET)/$(BSP_GRISP_NANO)/lib/linkcmds.org" \ + "$(PREFIX)/$(TARGET)/$(BSP_GRISP_NANO)/lib/linkcmds" + # End of workarounds for GRiSP1 and Nano .PHONY: libgrisp #H Build and install libgrisp. libgrisp: - make RTEMS_ROOT=$(PREFIX) RTEMS_BSP=$(BSP) -C $(SRC_LIBGRISP) install + make RTEMS_ROOT=$(PREFIX) RTEMS_BSP=$(BSP_GRISP2) -C $(SRC_LIBGRISP) install make RTEMS_ROOT=$(PREFIX) RTEMS_BSP=$(BSP_GRISP1) -C $(SRC_LIBGRISP) install + make RTEMS_ROOT=$(PREFIX) RTEMS_BSP=$(BSP_GRISP_NANO) -C $(SRC_LIBGRISP) install .PHONY: libinih #H Build and install libinih libinih: - make RTEMS_ROOT=$(PREFIX) RTEMS_BSP=$(BSP) -C $(SRC_LIBINIH) clean install + make RTEMS_ROOT=$(PREFIX) RTEMS_BSP=$(BSP_GRISP2) -C $(SRC_LIBINIH) clean install make RTEMS_ROOT=$(PREFIX) RTEMS_BSP=$(BSP_GRISP1) -C $(SRC_LIBINIH) clean install + make RTEMS_ROOT=$(PREFIX) RTEMS_BSP=$(BSP_GRISP_NANO) -C $(SRC_LIBINIH) clean install .PHONY: fdt #H Build the flattened device tree. @@ -289,7 +304,7 @@ imx_uart: cmake_toolchain_config: cat $(CMAKE_TOOLCHAIN_TEMPLATE) | sed \ -e "s|##PREFIX##|$(PREFIX)|g" \ - -e "s|##BSP##|$(BSP)|g" \ + -e "s|##BSP##|$(BSP_GRISP2)|g" \ -e "s|##TARGET##|$(TARGET)|g" \ > $(CMAKE_TOOLCHAIN_CONFIG) @@ -322,11 +337,11 @@ cryptoauthlib: cmake_toolchain_config cd $(SRC_CRYPTOAUTHLIB)/build && \ make DESTDIR=$(SRC_CRYPTOAUTHLIB)/install install && \ cp -r $(SRC_CRYPTOAUTHLIB)/install/usr/lib/libcryptoauth.a \ - $(PREFIX)/$(TARGET)/$(BSP)/lib/ && \ + $(PREFIX)/$(TARGET)/$(BSP_GRISP2)/lib/ && \ cp -r $(SRC_CRYPTOAUTHLIB)/install/usr/include/cryptoauthlib \ - $(PREFIX)/$(TARGET)/$(BSP)/lib/include/ && \ - touch $(PREFIX)/$(TARGET)/$(BSP)/lib/include/cryptoauthlib/atca_start_config.h && \ - touch $(PREFIX)/$(TARGET)/$(BSP)/lib/include/cryptoauthlib/atca_start_iface.h + $(PREFIX)/$(TARGET)/$(BSP_GRISP2)/lib/include/ && \ + touch $(PREFIX)/$(TARGET)/$(BSP_GRISP2)/lib/include/cryptoauthlib/atca_start_config.h && \ + touch $(PREFIX)/$(TARGET)/$(BSP_GRISP2)/lib/include/cryptoauthlib/atca_start_iface.h BLAS_TOOLS=\ @@ -358,22 +373,24 @@ blas: $(AR) -qc libblas.a *.o &&\ rm *.o &&\ $(RANLIB) libblas.a - cp $(SRC_BLAS)/libblas.a $(PREFIX)/$(TARGET)/$(BSP)/lib/libblas.a - cp $(SRC_BLAS)/CBLAS/include/cblas.h $(PREFIX)/$(TARGET)/$(BSP)/lib/include/cblas.h - cp $(SRC_BLAS)/CBLAS/include/cblas_mangling.h $(PREFIX)/$(TARGET)/$(BSP)/lib/include/cblas_mangling.h - cp $(SRC_BLAS)/LAPACKE/include/*.h $(PREFIX)/$(TARGET)/$(BSP)/lib/include/ + cp $(SRC_BLAS)/libblas.a $(PREFIX)/$(TARGET)/$(BSP_GRISP2)/lib/libblas.a + cp $(SRC_BLAS)/CBLAS/include/cblas.h $(PREFIX)/$(TARGET)/$(BSP_GRISP2)/lib/include/cblas.h + cp $(SRC_BLAS)/CBLAS/include/cblas_mangling.h $(PREFIX)/$(TARGET)/$(BSP_GRISP2)/lib/include/cblas_mangling.h + cp $(SRC_BLAS)/LAPACKE/include/*.h $(PREFIX)/$(TARGET)/$(BSP_GRISP2)/lib/include/ .PHONY: demo #H Build the demo application. demo: make -C demo RTEMS_BSP=$(BSP_GRISP1) make -C demo + RTEMS_BSP=$(BSP_GRISP_NANO) make -C demo .PHONY: demo-clean #H Clean the demo application. demo-clean: make -C demo clean RTEMS_BSP=$(BSP_GRISP1) make -C demo clean + RTEMS_BSP=$(BSP_GRISP_NANO) make -C demo clean .PHONY: shell #H Start a shell with the environment for building for example the RTEMS BSP. diff --git a/external/libgrisp b/external/libgrisp index 572237e..c4f2963 160000 --- a/external/libgrisp +++ b/external/libgrisp @@ -1 +1 @@ -Subproject commit 572237e32110bcfa550215649ad9cdf3c2611ad4 +Subproject commit c4f2963e6701d5998d1d3bcdfcf963582edd8557 diff --git a/external/rtems b/external/rtems index c1aa06d..c9ff75c 160000 --- a/external/rtems +++ b/external/rtems @@ -1 +1 @@ -Subproject commit c1aa06dbd2f055afd14415f3e6f63fb74765d6ff +Subproject commit c9ff75c113026afe13a789895ce129d523f0426c diff --git a/external/rtems-libbsd b/external/rtems-libbsd index 675a867..e4cf715 160000 --- a/external/rtems-libbsd +++ b/external/rtems-libbsd @@ -1 +1 @@ -Subproject commit 675a867f08c263b6f45d1fbd48e7923bff27dd7b +Subproject commit e4cf7156d8e19a79ba7afd2f5cc2fabb3571b4e9 diff --git a/external/rtems-source-builder b/external/rtems-source-builder index 7ebed67..9dd2dda 160000 --- a/external/rtems-source-builder +++ b/external/rtems-source-builder @@ -1 +1 @@ -Subproject commit 7ebed67752d4b2a630e2213f40d1473a26495340 +Subproject commit 9dd2dda7a473c124542f0333abfdf9cdc067fdd9 diff --git a/src/config.ini b/src/config.ini index 00f8ecb..72a29b8 100644 --- a/src/config.ini +++ b/src/config.ini @@ -44,3 +44,13 @@ ATSAM_MEMORY_QSPIFLASH_SIZE = 0x0 ATSAM_SDRAM = is42s16320f-7bl # Optimization flags passed to the C and C++ compiler OPTIMIZATION_FLAGS = -O2 -g -fdata-sections -ffunction-sections + +[arm/stm32u5-grisp-nano] +# Enable the RTEMS internal debug support +RTEMS_DEBUG = False +# Enable support for POSIX signals +RTEMS_POSIX_API = True +# Optimization flags passed to the C and C++ compiler +OPTIMIZATION_FLAGS = -O2 -g -fdata-sections -ffunction-sections +# The default linker command file +STM32U5_DEFAULT_LINKCMDS = linkcmds.flash+ospi From 4b57d082c60aa504ab0c3de0dcd08282150b2013 Mon Sep 17 00:00:00 2001 From: Christian Mauderer Date: Wed, 23 Oct 2024 16:40:08 +0200 Subject: [PATCH 14/25] Add trace32 scripts for nano --- debug/trace-32-nano/make.cmm | 56 ++++++++++++++++++++++++++++++++++++ debug/trace-32-nano/win.cmm | 39 +++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 debug/trace-32-nano/make.cmm create mode 100644 debug/trace-32-nano/win.cmm diff --git a/debug/trace-32-nano/make.cmm b/debug/trace-32-nano/make.cmm new file mode 100644 index 0000000..e3568be --- /dev/null +++ b/debug/trace-32-nano/make.cmm @@ -0,0 +1,56 @@ +global &initialized + +; Target can be one of RAM, Flash +;&mem_target="RAM" +&mem_target="Flash" +;&mem_target="Flash_Erase" + +&app="~~~~/../../external/rtems-libbsd/build/arm-rtems6-stm32u5-grisp-nano/media01.exe" + +if "&initialized"=="" +( + &initialized="1" + RESet + SYStem.CPU STM32U5G7VJ + SYStem.CONFIG.DEBUGPORTTYPE SWD + IF COMBIPROBE()||UTRACE() + ( + ; depending on the board + SYStem.CONFIG.CONNECTOR MIPI20T + ) + SYStem.Option DUALPORT ON + SYStem.Up + + do win +) + +SYStem.Up + +if "&mem_target"=="RAM" +( + Data.LOAD.Elf "&app" +) +if "&mem_target"=="Flash" +( + DO ~~/demo/arm/flash/stm32u5 PREPAREONLY + FLASH.ReProgram ALL + Data.LOAD.Elf "&app" + FLASH.ReProgram OFF +) +if "&mem_target"=="Flash_Erase" +( + DO ~~/demo/arm/flash/stm32u5 PREPAREONLY + FLASH.Erase ALL +) + +; Disable interrupts +PER.Set.simple ASD:0xE000E180 %Long 0xFFFFFFFF +PER.Set.simple ASD:0xE000E184 %Long 0xFFFFFFFF +PER.Set.simple ASD:0xE000E188 %Long 0xFFFFFFFF +PER.Set.simple ASD:0xE000E18C %Long 0xFFFFFFFF +PER.Set.simple ASD:0xE000E190 %Long 0xFFFFFFFF + +break.set _Terminate +break.set bsp_reset + +enddo diff --git a/debug/trace-32-nano/win.cmm b/debug/trace-32-nano/win.cmm new file mode 100644 index 0000000..176e922 --- /dev/null +++ b/debug/trace-32-nano/win.cmm @@ -0,0 +1,39 @@ +// T32 Thu Jan 9 09:58:44 2020 + + B:: + + TOOLBAR ON + STATUSBAR ON + FramePOS 0.0,0.0,,,Maximized + WinPAGE.RESet + + WinPAGE.Create P000 + WinCLEAR + + WinPOS 0.16667 0.0 77. 20. 0. 0. W002 + ws.register + + WinPOS 185.17 0.0 110. 19. 5. 0. W000 + ws.Var.Frame + + WinPOS 185.83 25.308 110. 6. 23. 1. W005 + WinTABS 13. 16. 0. 0. 0. 0. 0. + ws.Break.List + + WinPOS 186.17 37.769 110. 19. 0. 1. W001 + WinTABS 57. 26. + ws.sYmbol.Browse + + WinPOS 81.5 0.46154 43. 21. 0. 0. W006 + ws.AREA + + WinPOS 1.6667 25.308 119. 25. 13. 1. W004 + WinTABS 10. 10. 25. 62. + ws.data.list + + WinPOS 128.83 0.15385 40. 17. 0. 0. W003 + system + + WinPAGE.select P000 + + ENDDO From 6f7c6fd02d662039b848c62fb59e47acbae3375b Mon Sep 17 00:00:00 2001 From: Christian Mauderer Date: Wed, 27 Nov 2024 08:55:15 +0100 Subject: [PATCH 15/25] libgrisp: Update for GRiSP nano --- external/libgrisp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/libgrisp b/external/libgrisp index c4f2963..ee52ab4 160000 --- a/external/libgrisp +++ b/external/libgrisp @@ -1 +1 @@ -Subproject commit c4f2963e6701d5998d1d3bcdfcf963582edd8557 +Subproject commit ee52ab439ff27464cda352c5299a53682e826680 From b0034d655284e341c6517dc3edf64e73a1d7a8d7 Mon Sep 17 00:00:00 2001 From: Christian Mauderer Date: Wed, 27 Nov 2024 13:37:16 +0100 Subject: [PATCH 16/25] rtems: Don't reinitialize clocks during boot --- external/rtems | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/rtems b/external/rtems index c9ff75c..964ae03 160000 --- a/external/rtems +++ b/external/rtems @@ -1 +1 @@ -Subproject commit c9ff75c113026afe13a789895ce129d523f0426c +Subproject commit 964ae03aec4ba1ae0f6755cb6a0f677dd763c9bd From 3882bc714355715f9886b9397b5c4ee79e4334a1 Mon Sep 17 00:00:00 2001 From: Christian Mauderer Date: Wed, 27 Nov 2024 08:56:42 +0100 Subject: [PATCH 17/25] nano-bootloader: Add --- .gitignore | 2 + nano-bootlader/Makefile | 28 ++ nano-bootlader/init.c | 430 +++++++++++++++++++++++++++++ nano-bootlader/linkcmds.bootloader | 35 +++ 4 files changed, 495 insertions(+) create mode 100644 nano-bootlader/Makefile create mode 100644 nano-bootlader/init.c create mode 100644 nano-bootlader/linkcmds.bootloader diff --git a/.gitignore b/.gitignore index b0b8d59..f7f0ebb 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,8 @@ /rtems/6 build /demo*/b-*/ +/nano*/b-*/ external/libinih/b-imx7 external/libinih/b-atsamv +external/libinih/b-stm32* /package diff --git a/nano-bootlader/Makefile b/nano-bootlader/Makefile new file mode 100644 index 0000000..1f26470 --- /dev/null +++ b/nano-bootlader/Makefile @@ -0,0 +1,28 @@ +MAKEFILE_DIR = $(dir $(realpath $(firstword $(MAKEFILE_LIST)))) +RTEMS_ROOT ?= $(MAKEFILE_DIR)/../rtems/6 +RTEMS_BSP ?= stm32u5-grisp-nano + +include $(RTEMS_ROOT)/make/custom/$(RTEMS_BSP).mk + +GRISP_BL_VERSION := $(shell git describe --dirty --always --match="nano") +CFLAGS += -DGRISP_BL_VERSION="\"$(GRISP_BL_VERSION)\"" +CFLAGS += -O2 -g +LDFLAGS += -qnolinkcmds -T linkcmds.bootloader + +APP = $(BUILDDIR)/nano-bootloader +APP_PIECES = $(wildcard *.c) +APP_OBJS = $(APP_PIECES:%.c=$(BUILDDIR)/%.o) +APP_DEPS = $(APP_PIECES:%.c=$(BUILDDIR)/%.d) + +all: $(BUILDDIR) $(APP).exe + +$(BUILDDIR): + mkdir $(BUILDDIR) + +$(APP).exe: $(APP_OBJS) + $(CCLINK) $^ -lgrisp -linih -lbsd -lm -o $@ + +clean: + rm -rf $(BUILDDIR) + +-include $(APP_DEPS) diff --git a/nano-bootlader/init.c b/nano-bootlader/init.c new file mode 100644 index 0000000..9ceff1e --- /dev/null +++ b/nano-bootlader/init.c @@ -0,0 +1,430 @@ +/* + * Copyright (c) 2016-2024 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Dornierstr. 4 + * 82178 Puchheim + * Germany + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include + +#define STACK_SIZE_INIT_TASK (32 * 1024) +#define STACK_SIZE_SHELL (32 * 1024) + +#define PRIO_SHELL 150 + +extern char stm32u5_memory_app_begin[]; +extern char stm32u5_memory_app_end[]; +extern char stm32u5_memory_app_size[]; +#define RESET_VECTOR_OFFSET 0x00000004 +#define RESET_VECTOR_SIZE 4 + +static const char ini_file[] = "/media/mmcsd-0-0/grisp.ini"; +static int timeout_in_seconds = 3; +static char image_path[PATH_MAX + 1] = "/media/mmcsd-0-0/grisp-nano.bin"; +static rtems_id led_timer_id = RTEMS_INVALID_ID; + +static int +ini_value_copy(void *dst, size_t dst_size, const char *value) +{ + int ok = 1; + size_t value_size = strlen(value) + 1; + + if (value_size <= dst_size) { + memcpy(dst, value, value_size); + } else { + ok = 0; + } + + return ok; +} + +static int +ini_file_handler(void *arg, const char *section, const char *name, + const char *value) +{ + int ok = 0; + + (void)arg; + + if (strcmp(section, "boot-nano") == 0) { + if (strcmp(name, "image_path") == 0) { + ok = ini_value_copy(&image_path[0], sizeof(image_path), + value); + } + if (strcmp(name, "timeout_in_seconds") == 0) { + rtems_status_code sc = rtems_string_to_int(value, + &timeout_in_seconds, NULL, 10); + ok = sc == RTEMS_SUCCESSFUL; + } + } else { + /* All other sections are not relevant */ + ok = 1; + } + + if (!ok) { + printf("boot: error in configuration file: section \"%s\", name \"%s\", value \"%s\"\n", + section, name, value); + ok = 1; + } + + return ok; +} + +static void +evaluate_ini_file(const char *filename) +{ + ini_parse(filename, ini_file_handler, NULL); +} + +static void print_message(int fd, int seconds_remaining, void *arg) +{ + (void) fd; + (void) seconds_remaining; + (void) arg; + + printf("boot: press key to enter service mode\n"); +} + +static bool +wait_for_user_input(void) +{ + bool service_mode_requested; + int fd; + + fd = open(CONSOLE_DEVICE_NAME, O_RDWR); + assert(fd >= 0); + + rtems_status_code sc = rtems_shell_wait_for_input( + fd, timeout_in_seconds, print_message, NULL); + service_mode_requested = (sc == RTEMS_SUCCESSFUL); + + return service_mode_requested; +} + +#if 0 +static void +led_timer(rtems_id timer, void *arg) +{ + rtems_status_code sc; + static bool is_on = false; + + (void) arg; + + sc = rtems_timer_reset(timer); + assert(sc == RTEMS_SUCCESSFUL); + + is_on = !is_on; + grisp_led_set1(is_on, false, false); +} + +static void +init_led_timer(void) +{ + rtems_status_code sc; + + sc = rtems_timer_create(rtems_build_name('L', 'E', 'D', ' '), + &led_timer_id); + assert(sc == RTEMS_SUCCESSFUL); + + sc = rtems_timer_server_fire_after( + led_timer_id, + rtems_clock_get_ticks_per_second() / 2, + led_timer, + NULL + ); + assert(sc == RTEMS_SUCCESSFUL); + grisp_led_set1(true, false, false); +} + +static void +stop_led_timer(void) +{ + rtems_status_code sc = rtems_timer_cancel(led_timer_id); + assert(sc == RTEMS_SUCCESSFUL); +} + +static void +led_not_ok(void) +{ + rtems_status_code sc; + + sc = rtems_timer_cancel(led_timer_id); + assert(sc == RTEMS_SUCCESSFUL); + + grisp_led_set1(true, false, false); + + sc = rtems_timer_server_fire_after( + led_timer_id, + rtems_clock_get_ticks_per_second() / 4, + led_timer, + NULL + ); + assert(sc == RTEMS_SUCCESSFUL); +} +#endif + +static void +init_led_timer(void) +{ + grisp_led_set1(true, false, false); + grisp_led_set2(false, false, false); +} + +static void +stop_led_timer(void) +{ +} + +static void +led_not_ok(void) +{ + grisp_led_set1(false, false, false); + grisp_led_set2(true, false, false); +} + +static void _ARMV7M_Systick_cleanup(void) +{ + volatile ARMV7M_Systick *systick = _ARMV7M_Systick; + systick->csr = 0; +} + +static void +jump_to_app(void* start) +{ + rtems_interrupt_level level; + + rtems_interrupt_disable(level); + (void)level; + rtems_cache_disable_instruction(); + rtems_cache_disable_data(); + rtems_cache_invalidate_entire_instruction(); + rtems_cache_invalidate_entire_data(); + _ARMV7M_Systick_cleanup(); + + void(*foo)(void) = (void(*)(void))(start); + foo(); +} + +static void +start_app_from_ram(void) +{ + uint32_t *reset_vector; + void *app_start; + + reset_vector = (void *)(stm32u5_memory_app_begin + RESET_VECTOR_OFFSET); + app_start = (void *)(*reset_vector); + jump_to_app(app_start); +} + +static void +print_status(bool ok) +{ + if (ok) { + printf("done\n"); + } else { + printf("failed\n"); + } +} + +static void +load_via_file(const char *file) +{ + int fd; + bool ok; + ssize_t in; + int rv; + size_t max_app_size = (size_t) (stm32u5_memory_app_size); + + printf("boot: open file \"%s\"... ", file); + fd = open(file, O_RDONLY); + ok = (fd >= 0); + print_status(ok); + if (ok) { + printf("boot: read file \"%s\"... ", file); + in = read(fd, stm32u5_memory_app_begin, max_app_size); + printf("received %zi bytes\n", in); + + rv = close(fd); + assert(rv == 0); + + if (in > RESET_VECTOR_OFFSET + RESET_VECTOR_SIZE) { + stop_led_timer(); + + /* Enough time to print all messages. */ + rtems_task_wake_after(RTEMS_MILLISECONDS_TO_TICKS(100)); + + start_app_from_ram(); + } + } + return; +} + +static void +service_mode(void) +{ + rtems_status_code sc = rtems_shell_init( + "SHLL", + STACK_SIZE_SHELL, + PRIO_SHELL, + CONSOLE_DEVICE_NAME, + false, + true, + NULL + ); + assert(sc == RTEMS_SUCCESSFUL); +} + +static void +Init(rtems_task_argument arg) +{ + bool service_mode_requested; + rtems_status_code sc; + + (void)arg; + + init_led_timer(); + puts("\n---------------------\n" + "GRiSP nano bootloader\n" + "---------------------\n" + "Rev.: " GRISP_BL_VERSION "\n"); + + grisp_power_switch(GRISP_POWER_SD, true); + grisp_init_sd_card("/media/mmcsd-0-0"); + grisp_init_lower_self_prio(); + grisp_init_libbsd(); + + /* Wait for the SD card */ + sc = grisp_init_wait_for_sd(); + if(sc == RTEMS_SUCCESSFUL) { + evaluate_ini_file(ini_file); + + if (timeout_in_seconds == 0) { + service_mode_requested = false; + } else { + service_mode_requested = wait_for_user_input(); + } + + if (!service_mode_requested) { + const char *image = image_path; + if (strlen(image) > 0) { + load_via_file(image); + } + + /* Fallback: Show error and star service mode */ + led_not_ok(); + } + } else { + printf("ERROR: SD could not be mounted after timeout\n"); + led_not_ok(); + } + + service_mode(); + + exit(0); +} + +/* + * Configure LibBSD. + */ +#include +#define RTEMS_BSD_CONFIG_INIT +#define RTEMS_BSD_CONFIG_DOMAIN_PAGE_MBUFS_SIZE (3 * 1024 * 1024) + +#include + +/* + * Configure RTEMS. + */ +#define CONFIGURE_MICROSECONDS_PER_TICK 10000 + +#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER +#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER +#define CONFIGURE_APPLICATION_NEEDS_STUB_DRIVER +#define CONFIGURE_APPLICATION_NEEDS_ZERO_DRIVER +#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK + +#define CONFIGURE_FILESYSTEM_DOSFS +#define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 32 + +#define CONFIGURE_UNLIMITED_OBJECTS +#define CONFIGURE_UNIFIED_WORK_AREAS +#define CONFIGURE_MAXIMUM_USER_EXTENSIONS 1 + +#define CONFIGURE_INIT_TASK_STACK_SIZE STACK_SIZE_INIT_TASK +#define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_DEFAULT_MODES +#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT + +#define CONFIGURE_BDBUF_BUFFER_MAX_SIZE (32 * 1024) +#define CONFIGURE_BDBUF_MAX_READ_AHEAD_BLOCKS 2 +#define CONFIGURE_BDBUF_CACHE_MEMORY_SIZE (128 * 1024) +#define CONFIGURE_BDBUF_READ_AHEAD_TASK_PRIORITY 97 +#define CONFIGURE_SWAPOUT_TASK_PRIORITY 97 + +#define CONFIGURE_STACK_CHECKER_ENABLED + +#define CONFIGURE_RTEMS_INIT_TASKS_TABLE +#define CONFIGURE_INIT + +#include + +/* + * Configure Shell. + */ +#include +#define CONFIGURE_SHELL_COMMANDS_INIT + +#define CONFIGURE_SHELL_USER_COMMANDS \ + &rtems_shell_SYSCTL_Command, \ + &rtems_shell_BLKSTATS_Command + +#define CONFIGURE_SHELL_COMMANDS_ALL + +#include diff --git a/nano-bootlader/linkcmds.bootloader b/nano-bootlader/linkcmds.bootloader new file mode 100644 index 0000000..f4fe629 --- /dev/null +++ b/nano-bootlader/linkcmds.bootloader @@ -0,0 +1,35 @@ +INCLUDE linkcmds.memory +MEMORY { + APP : ORIGIN = 0x90000000, LENGTH = 0x01000000 - 4M + BL : ORIGIN = 0x91000000 - 4M, LENGTH = 4M +} + +stm32u5_memory_app_begin = ORIGIN (APP); +stm32u5_memory_app_end = ORIGIN (APP) + LENGTH (APP); +stm32u5_memory_app_size = LENGTH (APP); + +stm32u5_memory_bl_begin = ORIGIN (BL); +stm32u5_memory_bl_end = ORIGIN (BL) + LENGTH (BL); +stm32u5_memory_bl_size = LENGTH (BL); + +REGION_ALIAS ("REGION_START", FLASH); +REGION_ALIAS ("REGION_VECTOR", FLASH); +REGION_ALIAS ("REGION_TEXT", FLASH); +REGION_ALIAS ("REGION_TEXT_LOAD", FLASH); +REGION_ALIAS ("REGION_RODATA", FLASH); +REGION_ALIAS ("REGION_RODATA_LOAD", FLASH); +REGION_ALIAS ("REGION_DATA", BL); +REGION_ALIAS ("REGION_DATA_LOAD", FLASH); +REGION_ALIAS ("REGION_FAST_TEXT", FLASH); +REGION_ALIAS ("REGION_FAST_TEXT_LOAD", FLASH); +REGION_ALIAS ("REGION_FAST_DATA", INT_SRAM); +REGION_ALIAS ("REGION_FAST_DATA_LOAD", FLASH); +REGION_ALIAS ("REGION_BSS", BL); +REGION_ALIAS ("REGION_WORK", BL); +REGION_ALIAS ("REGION_STACK", INT_SRAM); +REGION_ALIAS ("REGION_NOCACHE", INT_SRAM); +REGION_ALIAS ("REGION_NOCACHE_LOAD", FLASH); + +bsp_vector_table_in_start_section = 1; + +INCLUDE linkcmds.armv7m From d50c12cffbc7c7c727ce4b038cb400181d412e6a Mon Sep 17 00:00:00 2001 From: Christian Mauderer Date: Wed, 27 Nov 2024 11:42:11 +0100 Subject: [PATCH 18/25] demo: Adapt for GRiSP nano --- demo/Makefile | 3 ++ demo/init.c | 79 ++++++++++++++++++++++++++++++------------------ demo/pmod_rfid.c | 8 ++--- 3 files changed, 55 insertions(+), 35 deletions(-) diff --git a/demo/Makefile b/demo/Makefile index 4cdec88..9e88308 100644 --- a/demo/Makefile +++ b/demo/Makefile @@ -8,6 +8,9 @@ CFLAGS += -O0 ifeq ($(RTEMS_BSP),atsamv) LDFLAGS += -qnolinkcmds -T linkcmds.sdram endif +ifeq ($(RTEMS_BSP),stm32u5-grisp-nano) +LDFLAGS += -qnolinkcmds -T linkcmds.ospi +endif APP = $(BUILDDIR)/demo APP_PIECES = $(wildcard *.c) diff --git a/demo/init.c b/demo/init.c index 9211321..7af8cbc 100644 --- a/demo/init.c +++ b/demo/init.c @@ -32,6 +32,8 @@ #undef EVENT_RECORDING #define RTC_ENABLED +#include + #include #include @@ -45,6 +47,7 @@ #include #include #include +#include #include #ifdef RTC_ENABLED #include @@ -56,17 +59,12 @@ #endif /* EVENT_RECORDING */ #include -#ifdef LIBBSP_ARM_ATSAM_BSP_H -#define IS_GRISP1 1 -#else -#define IS_GRISP2 1 -#endif #include -#ifdef IS_GRISP1 +#ifdef GRISP_PLATFORM_GRISP_BASE #include #include -#endif /* IS_GRISP1 */ +#endif /* GRISP_PLATFORM_GRISP_BASE */ #include #include #include @@ -91,12 +89,13 @@ const char *wpa_supplicant_conf = "/media/mmcsd-0-0/wpa_supplicant.conf"; -#ifdef IS_GRISP1 +#ifdef GRISP_PLATFORM_GRISP_BASE const Pin atsam_pin_config[] = {GRISP_PIN_CONFIG}; const size_t atsam_pin_config_count = PIO_LISTSIZE(atsam_pin_config); const uint32_t atsam_matrix_ccfg_sysio = GRISP_MATRIX_CCFG_SYSIO; -#endif /* IS_GRISP1 */ +#endif /* GRISP_PLATFORM_GRISP_BASE */ +#ifndef GRISP_PLATFORM_GRISP_NANO struct rtems_ftpd_configuration rtems_ftpd_configuration = { .priority = 100, .max_hook_filesize = 0, @@ -107,6 +106,7 @@ struct rtems_ftpd_configuration rtems_ftpd_configuration = { .idle = 5 * 60, .access = 0 }; +#endif static void start_shell(void) @@ -123,6 +123,7 @@ start_shell(void) assert(sc == RTEMS_SUCCESSFUL); } +#ifndef GRISP_PLATFORM_GRISP_NANO static void create_wlandev(void) { @@ -166,6 +167,7 @@ create_wlandev(void) } } } +#endif static void led_task(rtems_task_argument arg) @@ -211,6 +213,7 @@ init_led(void) assert(sc == RTEMS_SUCCESSFUL); } +#ifndef GRISP_PLATFORM_GRISP_NANO static int command_startftp(int argc, char *argv[]) { @@ -238,6 +241,7 @@ rtems_shell_cmd_t rtems_shell_STARTFTP_Command = { NULL, /* next */ 0, 0, 0 }; +#endif static void Init(rtems_task_argument arg) @@ -250,11 +254,11 @@ Init(rtems_task_argument arg) puts("\nGRiSP2 RTEMS Demo\n"); -#ifdef IS_GRISP1 +#ifdef GRISP_PLATFORM_GRISP_BASE rv = atsam_register_i2c_0(); assert(rv == 0); #endif -#ifdef IS_GRISP2 +#ifdef GRISP_PLATFORM_GRISP2 if (grisp_is_industrialgrisp()) { /* Industrial GRiSP */ rv = spi_bus_register_imx(GRISP_SPI_DEVICE, @@ -279,26 +283,32 @@ Init(rtems_task_argument arg) rv = i2c_bus_register_imx("/dev/i2c-2", "i2c1"); assert(rv == 0); } -#endif /* IS_GRISP2 */ +#endif /* GRISP_PLATFORM_GRISP2 */ #ifdef RTC_ENABLED setRealTimeToRTEMS(); #endif +#ifndef GRISP_PLATFORM_GRISP_NANO printf("Init EEPROM\n"); grisp_eeprom_init(); rv = grisp_eeprom_get(&eeprom); -#ifndef IS_GRISP1 /* On GRiSP1 the checksum hasn't been calculated correctly */ +#ifndef GRISP_PLATFORM_GRISP_BASE /* On GRiSP1 the checksum hasn't been calculated correctly */ if (rv == 0) { #endif grisp_eeprom_dump(&eeprom); -#ifndef IS_GRISP1 +#ifndef GRISP_PLATFORM_GRISP_BASE } else { printf("ERROR: Invalid EEPROM\n"); } #endif +#else + /* FIXME: EEPROM would have to be re-implemented using STM HAL */ + (void) rv; + (void) eeprom; +#endif - grisp_init_sd_card(); + grisp_init_sd_card("/media/mmcsd-0-0"); grisp_init_lower_self_prio(); grisp_init_libbsd(); @@ -312,6 +322,7 @@ Init(rtems_task_argument arg) } sleep(1); +#ifndef GRISP_PLATFORM_GRISP_NANO grisp_init_dhcpcd(PRIO_DHCP); grisp_led_set2(false, false, true); @@ -320,6 +331,7 @@ Init(rtems_task_argument arg) grisp_init_wpa_supplicant(wpa_supplicant_conf, PRIO_WPA, create_wlandev); } +#endif #ifdef EVENT_RECORDING rtems_record_start_server(10, 1234, 10); @@ -327,7 +339,7 @@ Init(rtems_task_argument arg) #endif /* EVENT_RECORDING */ init_led(); -#ifdef IS_GRISP2 +#ifdef GRISP_PLATFORM_GRISP2 if (grisp_is_industrialgrisp()) { pmod_rfid_init(GRISP_SPI_DEVICE, 0); pmod_dio_init(GRISP_SPI_DEVICE); @@ -335,13 +347,14 @@ Init(rtems_task_argument arg) // uncomment for testing RFID //pmod_rfid_init(GRISP_SPI_DEVICE, 1); } -#endif /* IS_GRISP2 */ +#endif /* GRISP_PLATFORM_GRISP2 */ start_shell(); exit(0); } #ifdef RTC_ENABLED +#ifdef GRISP_PLATFORM_GRISP2 static struct mcp7940m_rtc rtc_ctx = MCP7940M_RTC_INITIALIZER("/dev/i2c-1", 0x6f, false); @@ -351,6 +364,7 @@ rtc_tbl RTC_Table[] = { size_t RTC_Count = (sizeof(RTC_Table)/sizeof(rtc_tbl)); #endif +#endif /* * Configure LibBSD. @@ -411,23 +425,30 @@ size_t RTC_Count = (sizeof(RTC_Table)/sizeof(rtc_tbl)); #include #define CONFIGURE_SHELL_COMMANDS_INIT +#ifdef GRISP_PLATFORM_GRISP_NANO + #define GRISP_NET_CMDS +#else + #define GRISP_NET_CMDS \ + &rtems_shell_ARP_Command, \ + &rtems_shell_PFCTL_Command, \ + &rtems_shell_PING_Command, \ + &rtems_shell_IFCONFIG_Command, \ + &rtems_shell_ROUTE_Command, \ + &rtems_shell_NETSTAT_Command, \ + &rtems_shell_DHCPCD_Command, \ + &rtems_shell_HOSTNAME_Command, \ + &rtems_shell_WLANSTATS_Command, \ + &rtems_shell_STARTFTP_Command, \ + &rtems_shell_WPA_SUPPLICANT_Command, \ + &rtems_shell_WPA_SUPPLICANT_FORK_Command, +#endif + #define CONFIGURE_SHELL_USER_COMMANDS \ &bsp_interrupt_shell_command, \ - &rtems_shell_ARP_Command, \ - &rtems_shell_PFCTL_Command, \ - &rtems_shell_PING_Command, \ - &rtems_shell_IFCONFIG_Command, \ - &rtems_shell_ROUTE_Command, \ - &rtems_shell_NETSTAT_Command, \ - &rtems_shell_DHCPCD_Command, \ - &rtems_shell_HOSTNAME_Command, \ &rtems_shell_SYSCTL_Command, \ &rtems_shell_VMSTAT_Command, \ - &rtems_shell_WLANSTATS_Command, \ - &rtems_shell_STARTFTP_Command, \ &rtems_shell_BLKSTATS_Command, \ - &rtems_shell_WPA_SUPPLICANT_Command, \ - &rtems_shell_WPA_SUPPLICANT_FORK_Command, \ + GRISP_NET_CMDS \ &shell_PATTERN_FILL_Command, \ &shell_PATTERN_CHECK_Command, \ &shell_1wiretemp_command, \ diff --git a/demo/pmod_rfid.c b/demo/pmod_rfid.c index c64da27..5877e49 100644 --- a/demo/pmod_rfid.c +++ b/demo/pmod_rfid.c @@ -25,17 +25,13 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#include #include -#ifdef LIBBSP_ARM_ATSAM_BSP_H -#define IS_GRISP1 1 -#else -#define IS_GRISP2 1 -#endif #include #include -#ifdef IS_GRISP2 +#ifdef GRISP_PLATFORM_GRISP2 #include #include From acaa456b06ca9cc90072e07a0ab1557b5a9aef85 Mon Sep 17 00:00:00 2001 From: Christian Mauderer Date: Wed, 27 Nov 2024 13:36:51 +0100 Subject: [PATCH 19/25] debug: Update trace scripts --- debug/trace-32-nano/bp.bak | 18 ++++++++++++++++++ debug/trace-32-nano/bp.cmm | 17 +++++++++++++++++ debug/trace-32-nano/make.cmm | 14 ++++++++++++-- 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 debug/trace-32-nano/bp.bak create mode 100644 debug/trace-32-nano/bp.cmm diff --git a/debug/trace-32-nano/bp.bak b/debug/trace-32-nano/bp.bak new file mode 100644 index 0000000..e632d7a --- /dev/null +++ b/debug/trace-32-nano/bp.bak @@ -0,0 +1,18 @@ +// T32 Wed Nov 27 12:36:08 2024 + +B:: + +Break.RESet +Break.CONFIG.VarConvert OFF +Break.CONFIG.InexactData ON +Break.CONFIG.InexactTrigger OFF +Break.CONFIG.InexactResume ON +Break.CONFIG.InexactAddress ON +Break.CONFIG.MatchZone OFF +Break.CONFIG.AlwaysAlive OFF +Break.Set bsp_reset /Program +Break.Set rtems_bdbuf_read+0xF6 /Program +Break.Set rtems_bdbuf_peek+0x64 /Program +Break.Set _Terminate /Program + +ENDDO diff --git a/debug/trace-32-nano/bp.cmm b/debug/trace-32-nano/bp.cmm new file mode 100644 index 0000000..c7e3188 --- /dev/null +++ b/debug/trace-32-nano/bp.cmm @@ -0,0 +1,17 @@ +// T32 Wed Nov 27 13:17:02 2024 + +B:: + +Break.RESet +Break.CONFIG.VarConvert OFF +Break.CONFIG.InexactData ON +Break.CONFIG.InexactTrigger OFF +Break.CONFIG.InexactResume ON +Break.CONFIG.InexactAddress ON +Break.CONFIG.MatchZone OFF +Break.CONFIG.AlwaysAlive OFF +Break.Set bsp_reset /Program +Break.Set jump_to_app\12 /Program +Break.Set _Terminate /Program + +ENDDO diff --git a/debug/trace-32-nano/make.cmm b/debug/trace-32-nano/make.cmm index e3568be..90a60aa 100644 --- a/debug/trace-32-nano/make.cmm +++ b/debug/trace-32-nano/make.cmm @@ -2,10 +2,12 @@ global &initialized ; Target can be one of RAM, Flash ;&mem_target="RAM" -&mem_target="Flash" +&mem_target="RAM_nocode" +;&mem_target="Flash" ;&mem_target="Flash_Erase" -&app="~~~~/../../external/rtems-libbsd/build/arm-rtems6-stm32u5-grisp-nano/media01.exe" +;&app="~~~~/../../nano-bootlader/b-stm32u5-grisp-nano/nano-bootloader.exe" +&app="~~~~/../../demo/b-stm32u5-grisp-nano/demo.exe" if "&initialized"=="" ( @@ -30,6 +32,14 @@ if "&mem_target"=="RAM" ( Data.LOAD.Elf "&app" ) +if "&mem_target"=="RAM_nocode" +( + Data.LOAD.Elf "&app" /nocode + break.set _start + break.set _Terminate + break.set bsp_reset + enddo +) if "&mem_target"=="Flash" ( DO ~~/demo/arm/flash/stm32u5 PREPAREONLY From 08ed7cb4bd3754880c9a65ec7f415472fc30929c Mon Sep 17 00:00:00 2001 From: Christian Mauderer Date: Fri, 29 Nov 2024 07:39:32 +0100 Subject: [PATCH 20/25] nano-bootloader: Add binary target --- nano-bootlader/Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nano-bootlader/Makefile b/nano-bootlader/Makefile index 1f26470..cf80d57 100644 --- a/nano-bootlader/Makefile +++ b/nano-bootlader/Makefile @@ -14,7 +14,7 @@ APP_PIECES = $(wildcard *.c) APP_OBJS = $(APP_PIECES:%.c=$(BUILDDIR)/%.o) APP_DEPS = $(APP_PIECES:%.c=$(BUILDDIR)/%.d) -all: $(BUILDDIR) $(APP).exe +all: $(BUILDDIR) $(APP).exe $(APP).bin $(BUILDDIR): mkdir $(BUILDDIR) @@ -22,6 +22,9 @@ $(BUILDDIR): $(APP).exe: $(APP_OBJS) $(CCLINK) $^ -lgrisp -linih -lbsd -lm -o $@ +$(APP).bin: $(APP).exe + $(OBJCOPY) -O binary $< $@ + clean: rm -rf $(BUILDDIR) From 907f824308bc2130dd83e328421d63fda63fb191 Mon Sep 17 00:00:00 2001 From: Christian Mauderer Date: Mon, 2 Dec 2024 08:28:34 +0100 Subject: [PATCH 21/25] libgrisp: Update with empty led_set_som --- external/libgrisp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/libgrisp b/external/libgrisp index ee52ab4..fec054e 160000 --- a/external/libgrisp +++ b/external/libgrisp @@ -1 +1 @@ -Subproject commit ee52ab439ff27464cda352c5299a53682e826680 +Subproject commit fec054edb7fb88dfeec50bbbac0aa261b125671a From 90bda57e6f44b5d4df944f1c7b720e2e0d28d75e Mon Sep 17 00:00:00 2001 From: Christian Mauderer Date: Tue, 3 Dec 2024 09:12:31 +0100 Subject: [PATCH 22/25] nano-bootloader: Increase memory size --- nano-bootlader/init.c | 2 +- nano-bootlader/linkcmds.bootloader | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/nano-bootlader/init.c b/nano-bootlader/init.c index 9ceff1e..a305bef 100644 --- a/nano-bootlader/init.c +++ b/nano-bootlader/init.c @@ -376,7 +376,7 @@ Init(rtems_task_argument arg) */ #include #define RTEMS_BSD_CONFIG_INIT -#define RTEMS_BSD_CONFIG_DOMAIN_PAGE_MBUFS_SIZE (3 * 1024 * 1024) +#define RTEMS_BSD_CONFIG_DOMAIN_PAGE_MBUFS_SIZE (4 * 1024 * 1024) #include diff --git a/nano-bootlader/linkcmds.bootloader b/nano-bootlader/linkcmds.bootloader index f4fe629..4688406 100644 --- a/nano-bootlader/linkcmds.bootloader +++ b/nano-bootlader/linkcmds.bootloader @@ -1,7 +1,7 @@ INCLUDE linkcmds.memory MEMORY { - APP : ORIGIN = 0x90000000, LENGTH = 0x01000000 - 4M - BL : ORIGIN = 0x91000000 - 4M, LENGTH = 4M + APP : ORIGIN = 0x90000000, LENGTH = 0x01000000 - 5M + BL : ORIGIN = 0x91000000 - 5M, LENGTH = 5M } stm32u5_memory_app_begin = ORIGIN (APP); From 6a2087ab2439e3f66b5817c20c2b02aa74ba0cad Mon Sep 17 00:00:00 2001 From: Christian Mauderer Date: Fri, 20 Dec 2024 10:20:34 +0100 Subject: [PATCH 23/25] Experimental reduction of memory size --- Makefile | 24 +++++++++++++++++------- external/libgrisp | 2 +- external/rtems-libbsd | 2 +- src/libbsd-nano.ini | 11 +++++++++++ 4 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 src/libbsd-nano.ini diff --git a/Makefile b/Makefile index b23bd26..e91266d 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,7 @@ SRC_BLAS = $(MAKEFILE_DIR)/external/lapack BUILD_LOGS = $(MAKEFILE_DIR)/build BUILD_OPENOCD = $(MAKEFILE_DIR)/build/b-openocd LIBBSD_BUILDSET = $(MAKEFILE_DIR)/src/libbsd.ini +LIBBSD_NANO_BUILDSET = $(MAKEFILE_DIR)/src/libbsd-nano.ini CMAKE_TOOLCHAIN_TEMPLATE = $(MAKEFILE_DIR)/cryptoauthlib/grisp2-toolchain.cmake.in CMAKE_TOOLCHAIN_CONFIG = $(PREFIX)/share/grisp2-toolchain.cmake PACKAGE_DIR = package @@ -170,13 +171,6 @@ $(PREFIX)/make/custom/$(BSP_GRISP_NANO).mk: src/bsp.mk #H Build and install libbsd. libbsd: rm -rf $(SRC_LIBBSD)/build - cd $(SRC_LIBBSD) && ./waf configure \ - --prefix=$(PREFIX) \ - --rtems-bsps=$(ARCH)/$(BSP_GRISP2),$(ARCH)/$(BSP_GRISP1),$(ARCH)/$(BSP_GRISP_NANO) \ - --enable-warnings \ - --optimization=$(OPTIMIZATION) \ - --buildset=$(LIBBSD_BUILDSET) \ - --rtems-version=$(RTEMS_VERSION) # Workaround for GRiSP1 and Nano [ ! -e "$(PREFIX)/$(TARGET)/$(BSP_GRISP1)/lib/linkcmds.org" ] && \ mv "$(PREFIX)/$(TARGET)/$(BSP_GRISP1)/lib/linkcmds" \ @@ -191,6 +185,22 @@ libbsd: echo "INCLUDE linkcmds.ospi" > \ "$(PREFIX)/$(TARGET)/$(BSP_GRISP_NANO)/lib/linkcmds" # End of workaround for GRiSP1 and Nano + cd $(SRC_LIBBSD) && ./waf configure \ + --prefix=$(PREFIX) \ + --rtems-bsps=$(ARCH)/$(BSP_GRISP2),$(ARCH)/$(BSP_GRISP1) \ + --enable-warnings \ + --optimization=$(OPTIMIZATION) \ + --buildset=$(LIBBSD_BUILDSET) \ + --rtems-version=$(RTEMS_VERSION) + cd $(SRC_LIBBSD) && ./waf + cd $(SRC_LIBBSD) && ./waf install + cd $(SRC_LIBBSD) && ./waf configure \ + --prefix=$(PREFIX) \ + --rtems-bsps=$(ARCH)/$(BSP_GRISP_NANO) \ + --enable-warnings \ + --optimization=$(OPTIMIZATION) \ + --buildset=$(LIBBSD_NANO_BUILDSET) \ + --rtems-version=$(RTEMS_VERSION) cd $(SRC_LIBBSD) && ./waf cd $(SRC_LIBBSD) && ./waf install # Workarounds for GRiSP1 and Nano diff --git a/external/libgrisp b/external/libgrisp index fec054e..2329d9f 160000 --- a/external/libgrisp +++ b/external/libgrisp @@ -1 +1 @@ -Subproject commit fec054edb7fb88dfeec50bbbac0aa261b125671a +Subproject commit 2329d9f2164c2cc033072502fece972d445c3b71 diff --git a/external/rtems-libbsd b/external/rtems-libbsd index e4cf715..3c16d8d 160000 --- a/external/rtems-libbsd +++ b/external/rtems-libbsd @@ -1 +1 @@ -Subproject commit e4cf7156d8e19a79ba7afd2f5cc2fabb3571b4e9 +Subproject commit 3c16d8d96d62cdde99882ceb9915522a006b678a diff --git a/src/libbsd-nano.ini b/src/libbsd-nano.ini new file mode 100644 index 0000000..581e210 --- /dev/null +++ b/src/libbsd-nano.ini @@ -0,0 +1,11 @@ +[general] +name = grisp-nano + +[modules] +base = on +cam = on +mmc = on +mmc_ti = on +fdt = on +rtems = on +user_space = on From a492f8bdb10f99626812e995d01de760de31e6d4 Mon Sep 17 00:00:00 2001 From: Luca Succi Date: Tue, 27 May 2025 14:48:45 +0200 Subject: [PATCH 24/25] Fix the Dockerfile --- Dockerfile | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5394fa0..a3fefe0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,13 +7,18 @@ RUN apt-get update && apt-get install -y \ u-boot-tools lzop libusb-1.0-0-dev python3 python-is-python3 \ unzip libpython3-dev python3-dev locales -# https://devel.rtems.org/ticket/4726 -RUN echo "en_US.ISO-8859-15 ISO-8859-15" >> /etc/locale.gen \ +# Set locale to UTF-8 +RUN echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen \ && locale-gen -ENV LANG=en_US.iso885915 +ENV LANG=en_US.UTF-8 +ENV LC_ALL=en_US.UTF-8 WORKDIR /grisp2-rtems-toolchain COPY . . + +# Create necessary directory structure, fails without doing this... +RUN mkdir -p rtems/6/arm-rtems6/imx7/lib/include/{machine,sys,vm,x86} + RUN make install # ------------------------------------------------------------------------------ @@ -27,8 +32,8 @@ RUN apt-get update && apt-get install -y \ apt-get clean && rm -rf /var/lib/apt/lists/* WORKDIR /grisp2-rtems-toolchain -COPY --from=build-stage /grisp2-rtems-toolchain/rtems/5/ rtems/5/ +COPY --from=build-stage /grisp2-rtems-toolchain/rtems/6/ rtems/6/ -ENV GRISP_TOOLCHAIN=/grisp2-rtems-toolchain/rtems/5 -ENV GRISP_TC_ROOT=/grisp2-rtems-toolchain/rtems/5 -ENV PATH="/grisp2-rtems-toolchain/rtems/5/bin:${PATH}" +ENV GRISP_TOOLCHAIN=/grisp2-rtems-toolchain/rtems/6 +ENV GRISP_TC_ROOT=/grisp2-rtems-toolchain/rtems/6 +ENV PATH="/grisp2-rtems-toolchain/rtems/6/bin:${PATH}" From 9a8664d0c2089072916b951266db94cd9ff7175b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Lajk=C3=B3?= Date: Wed, 28 May 2025 11:18:48 +0200 Subject: [PATCH 25/25] Update libbsd-nano.ini --- src/libbsd-nano.ini | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/libbsd-nano.ini b/src/libbsd-nano.ini index 581e210..1e28583 100644 --- a/src/libbsd-nano.ini +++ b/src/libbsd-nano.ini @@ -1,11 +1,10 @@ [general] name = grisp-nano +extends = default.ini [modules] -base = on -cam = on -mmc = on -mmc_ti = on -fdt = on -rtems = on -user_space = on +dev_usb_wlan = on +dev_wlan_rtwn = on +net80211 = on +user_space_wlanstats = on +usr_sbin_wpa_supplicant = on