diff --git a/Documentation/platforms/arm/gd32f4/boards/gd32f450zk-aiotbox/gd32f450z_aiotbox.png b/Documentation/platforms/arm/gd32f4/boards/gd32f450zk-aiotbox/gd32f450z_aiotbox.png new file mode 100644 index 00000000000..9c9ad992d42 Binary files /dev/null and b/Documentation/platforms/arm/gd32f4/boards/gd32f450zk-aiotbox/gd32f450z_aiotbox.png differ diff --git a/Documentation/platforms/arm/gd32f4/boards/gd32f450zk-aiotbox/index.rst b/Documentation/platforms/arm/gd32f4/boards/gd32f450zk-aiotbox/index.rst new file mode 100644 index 00000000000..6a67c8d2cee --- /dev/null +++ b/Documentation/platforms/arm/gd32f4/boards/gd32f450zk-aiotbox/index.rst @@ -0,0 +1,11 @@ +================== +gd32f450zk-aiotbox +================== + +The GD32F450Z-AIOTBOX board is a Xiaomi AIoT development platform U1 +control board that uses the GD32F450ZK chip as the core. + +.. figure:: gd32f450z_aiotbox.png + :align: center + :alt: gd32f450z_aiotbox + diff --git a/Documentation/platforms/arm/gd32f4/boards/gd32f470zk-aiotbox/gd32f470z_aiotbox.png b/Documentation/platforms/arm/gd32f4/boards/gd32f470zk-aiotbox/gd32f470z_aiotbox.png new file mode 100644 index 00000000000..6ae043fab20 Binary files /dev/null and b/Documentation/platforms/arm/gd32f4/boards/gd32f470zk-aiotbox/gd32f470z_aiotbox.png differ diff --git a/Documentation/platforms/arm/gd32f4/boards/gd32f470zk-aiotbox/index.rst b/Documentation/platforms/arm/gd32f4/boards/gd32f470zk-aiotbox/index.rst new file mode 100644 index 00000000000..334d193ff9c --- /dev/null +++ b/Documentation/platforms/arm/gd32f4/boards/gd32f470zk-aiotbox/index.rst @@ -0,0 +1,15 @@ +================== +gd32f470zk-aiotbox +================== + +The GD32F470Z-AIOTBOX board is a Xiaomi AIoT development platform U1 +control board that uses the GD32F470ZK chip as the core. + +The GD32F470ZK features a single-core ARM Cortex-M4F MCU which can run up +to 240 MHz with flash accesses zero wait states, 3072kiB of Flash, 256kiB +of SRAM and 114 GPIOs. + +.. figure:: gd32f470z_aiotbox.png + :align: center + :alt: gd32f470z_aiotbox + diff --git a/boards/Kconfig b/boards/Kconfig index 36f89d65a91..b6204b21627 100644 --- a/boards/Kconfig +++ b/boards/Kconfig @@ -638,6 +638,25 @@ config ARCH_BOARD_GD32F450ZK_EVAL ---help--- GD32 MCU GD32F450ZK-EVAL board based on the GD32F4 GD32F450ZKT6 MCU. +config ARCH_BOARD_GD32F450ZK_AIOTBOX + bool "GD32 MCU GD32F450ZK-AIOTBOX" + depends on ARCH_CHIP_GD32F450ZK + select ARCH_HAVE_LEDS + select ARCH_HAVE_BUTTONS + select ARCH_HAVE_IRQBUTTONS + ---help--- + GD32 MCU GD32F450ZK-AIOTBOX board based on the GD32F4 GD32F450ZKT6 MCU. + +config ARCH_BOARD_GD32F470ZK_AIOTBOX + bool "GD32 MCU GD32F470ZK-AIOTBOX" + depends on ARCH_CHIP_GD32F470ZK + select ARCH_HAVE_LEDS + select ARCH_HAVE_BUTTONS + select ARCH_HAVE_IRQBUTTONS + ---help--- + GD32 MCU GD32F470ZK-AIOTBOX board based on the GD32F4 GD32F470ZKT6 MCU. + + config ARCH_BOARD_GD32F470ZK_EVAL bool "GD32 MCU GD32F470ZK" depends on ARCH_CHIP_GD32F470ZK @@ -3159,7 +3178,9 @@ config ARCH_BOARD default "freedom-kl25z" if ARCH_BOARD_FREEDOM_KL25Z default "freedom-kl26z" if ARCH_BOARD_FREEDOM_KL26Z default "gd32f450zk-eval" if ARCH_BOARD_GD32F450ZK_EVAL + default "gd32f450zk-aiotbox" if ARCH_BOARD_GD32F450ZK_AIOTBOX default "gd32f470zk-eval" if ARCH_BOARD_GD32F470ZK_EVAL + default "gd32f470zk-aiotbox" if ARCH_BOARD_GD32F470ZK_AIOTBOX default "gd32f470ik-eval" if ARCH_BOARD_GD32F470IK_EVAL default "hifive1-revb" if ARCH_BOARD_HIFIVE1_REVB default "hymini-stm32v" if ARCH_BOARD_HYMINI_STM32V @@ -3584,9 +3605,15 @@ endif if ARCH_BOARD_GD32F450ZK_EVAL source "boards/arm/gd32f4/gd32f450zk-eval/Kconfig" endif +if ARCH_BOARD_GD32F450ZK_AIOTBOX +source "boards/arm/gd32f4/gd32f450zk-aiotbox/Kconfig" +endif if ARCH_BOARD_GD32F470ZK_EVAL source "boards/arm/gd32f4/gd32f470zk-eval/Kconfig" endif +if ARCH_BOARD_GD32F470ZK_AIOTBOX +source "boards/arm/gd32f4/gd32f470zk-aiotbox/Kconfig" +endif if ARCH_BOARD_GD32F470IK_EVAL source "boards/arm/gd32f4/gd32f470ik-eval/Kconfig" endif diff --git a/boards/arm/gd32f4/gd32f450zk-aiotbox/Kconfig b/boards/arm/gd32f4/gd32f450zk-aiotbox/Kconfig new file mode 100644 index 00000000000..673c14a6df3 --- /dev/null +++ b/boards/arm/gd32f4/gd32f450zk-aiotbox/Kconfig @@ -0,0 +1,87 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +if ARCH_BOARD_GD32F450ZK_AIOTBOX + +choice + prompt "Select Console wiring." + default GD32F450ZK_AIOTBOX_CONSOLE_BOARD + ---help--- + Select where you will connect the console. + + Virtual COM Port: + + Advantage: Use the ST-Link as a console. No Extra wiring + needed. + + Disadvantage: Not the best choice for initial bring up. + + BOARD USART Connector: + + Advantage: You have a shield so it is easy. + + Disadvantage: You loose the use of the + other functions on PA9, PA10 + + GD32F450ZK_AIOTBOX + USART0 GPIO + -- ----- --------- ---- + RX USART0_RX PB7 + TX USART0_TX PB6 + -- ----- --------- --- + +config GD32F450ZK_AIOTBOX_CONSOLE_BOARD + bool "Aiotbox Com Connector" + select GD32_USART0 + select USART0_SERIALDRIVER + +config GD32F450ZK_AIOTBOX_CONSOLE_VIRTUAL + bool "Aiotbox Virtual ComPort" + select GD32_USART3 + select USART3_SERIALDRIVER + +config GD32F450ZK_AIOTBOX_CONSOLE_NONE + bool "No Serial Console" + +endchoice # "Select Console wiring" + + +choice + prompt "GD32F4 MCU Crystal Selected" + default GD32F4_BOARD_USE_HXTAL_AIOTBOX + +config GD32F4_BOARD_USE_HXTAL_AIOTBOX + bool "Aiotbox Use Hxtal as clock source" + # select GD32F4_BOARD_HXTAL_VALUE + +config GD32F4_BOARD_USE_IRC16_AIOTBOX + bool "Aiotbox Use IRC16M as clock source" + +endchoice # CPU Frequency + +config GD32F4_BOARD_HXTAL_VALUE + int "GD32F450Z Aiotbox Board Hxtal Value" + default 25000000 + depends on GD32F4_BOARD_USE_HXTAL_AIOTBOX + ---help--- + GD32F450Z Aiotbox Board Hxtal Value, default is 25MHz. + +choice + prompt "GD32F4 MCU System Frequency" + default GD32F4_200MHZ_AIOTBOX + +config GD32F4_200MHZ_AIOTBOX + bool "200 MHz" + +config GD32F4_168MHZ_AIOTBOX + bool "168 MHz" + +config GD32F4_120MHZ_AIOTBOX + bool "120 MHz" + +endchoice # CPU Frequency + + +endif # ARCH_BOARD_GD32F450ZK_AIOTBOX diff --git a/boards/arm/gd32f4/gd32f450zk-aiotbox/configs/aiotboxnsh/defconfig b/boards/arm/gd32f4/gd32f450zk-aiotbox/configs/aiotboxnsh/defconfig new file mode 100644 index 00000000000..c6bca4e3298 --- /dev/null +++ b/boards/arm/gd32f4/gd32f450zk-aiotbox/configs/aiotboxnsh/defconfig @@ -0,0 +1,56 @@ +# +# 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_FPU is not set +CONFIG_ARCH="arm" +CONFIG_ARCH_BOARD="gd32f450zk-aiotbox" +CONFIG_ARCH_BOARD_GD32F450ZK_AIOTBOX=y +CONFIG_ARCH_BUTTONS=y +CONFIG_ARCH_CHIP="gd32f4" +CONFIG_ARCH_CHIP_GD32F450ZK=y +CONFIG_ARCH_CHIP_GD32F4=y +CONFIG_ARCH_INTERRUPTSTACK=256 +CONFIG_ARCH_STACKDUMP=y +CONFIG_BOARD_LOOPSPERMSEC=16717 +CONFIG_BUILTIN=y +CONFIG_DEBUG_CUSTOMOPT=y +CONFIG_DEBUG_FEATURES=y +CONFIG_DEBUG_IRQ=y +CONFIG_DEBUG_LEDS=y +CONFIG_DEBUG_OPTLEVEL="-O0" +CONFIG_DEBUG_SCHED=y +CONFIG_DEBUG_SYMBOLS=y +CONFIG_GD32F4_DISABLE_IDLE_SLEEP_DURING_DEBUG=y +CONFIG_GD32F4_FLASH_CONFIG_K=y +CONFIG_GD32F4_I2C0=y +CONFIG_GD32F4_I2C1=y +CONFIG_GD32F4_USART2=y +CONFIG_HAVE_CXX=y +CONFIG_HAVE_CXXINITIALIZE=y +CONFIG_I2C=y +CONFIG_I2C_POLLED=y +CONFIG_I2C_RESET=y +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_INTELHEX_BINARY=y +CONFIG_MM_REGIONS=2 +CONFIG_NSH_ARCHINIT=y +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_FILEIOSIZE=512 +CONFIG_NSH_LINELEN=64 +CONFIG_NSH_READLINE=y +CONFIG_RAM_SIZE=114688 +CONFIG_RAM_START=0x20000000 +CONFIG_RAW_BINARY=y +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_WAITPID=y +CONFIG_START_DAY=6 +CONFIG_START_MONTH=12 +CONFIG_START_YEAR=2011 +CONFIG_SYSTEM_I2CTOOL=y +CONFIG_SYSTEM_NSH=y +CONFIG_TASK_NAME_SIZE=0 +CONFIG_USART0_SERIAL_CONSOLE=y diff --git a/boards/arm/gd32f4/gd32f450zk-aiotbox/include/board.h b/boards/arm/gd32f4/gd32f450zk-aiotbox/include/board.h new file mode 100644 index 00000000000..c5f3cbacdf6 --- /dev/null +++ b/boards/arm/gd32f4/gd32f450zk-aiotbox/include/board.h @@ -0,0 +1,389 @@ +/**************************************************************************** + * boards/arm/gd32f4/gd32f450zk-aiotbox/include/board.h + * + * 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_GD32F450ZK_AIOTBOX_INCLUDE_BOARD_H +#define __BOARDS_ARM_GD32F450ZK_AIOTBOX_INCLUDE_BOARD_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#ifndef __ASSEMBLY__ +# include +#endif + +#define GD32_BOARD_SYSCLK_PLL_HXTAL + +/* Do not include GD32F4 header files here */ + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Clocking *****************************************************************/ + +/* The GD32F450ZK-EVAL board features a single 25MHz crystal. + * + * This is the default configuration: + * System clock source : PLL (HXTAL) + * SYSCLK(Hz) : 200000000 Determined by PLL config + * HCLK(Hz) : 200000000 (GD32_SYSCLK_FREQUENCY) + * AHB Prescaler : 1 (GD32_RCU_CFG0_AHB_PSC) + * APB2 Prescaler : 2 (GD32_RCU_CFG0_APB2_PSC) + * APB1 Prescaler : 4 (GD32_RCU_CFG0_APB1_PSC) + * HXTAL value(Hz) : 25000000 (GD32_BOARD_XTAL) + * PLLM : 25 (GD32_PLL_PLLM) + * PLLN : 400 (RCU_PLL_PLLN) + * PLLP : 2 (GD32_PLL_PLLP) + * PLLQ : 7 (GD32_PLL_PLLQ) + */ + +/* IRC16M - 16 MHz RC factory-trimmed + * IRC32K - 32 KHz RC + * HXTAL - On-board crystal frequency is 25MHz + * LXTAL - 32.768 kHz + */ + +#ifndef CONFIG_GD32F4_BOARD_HXTAL_VALUE +# define GD32_BOARD_HXTAL 25000000ul +#else +# define GD32_BOARD_HXTAL CONFIG_GD32F4_BOARD_HXTAL_VALUE +#endif + +#define GD32_IRC16M_VALUE 16000000ul +#define GD32_IRC32K_VALUE 32000u +#define GD32_HXTAL_VALUE GD32_BOARD_HXTAL +#define GD32_LXTAL_VALUE 32768u + +#if defined(CONFIG_GD32F4_200MHZ_AIOTBOX) + +/* Main PLL Configuration. + * + * PLL source is HXTAL + * PLL_VCO = (GD32_HXTAL_VALUE / PLLM) * PLLN + * = (25,000,000 / 25) * 400 + * = 400,000,000 + * SYSCLK = PLL_VCO / PLLP + * = 400,000,000 / 2 = 168,000,000 + * USB, SDIO and RNG Clock + * = PLL_VCO / PLLQ + * = 48,000,000 + */ + +#define GD32_PLL_PLLPSC RCU_PLL_PLLPSC(25) +#define GD32_PLL_PLLN RCU_PLL_PLLN(400) +#define GD32_PLL_PLLP RCU_PLL_PLLP(2) +#define GD32_PLL_PLLQ RCU_PLL_PLLQ(7) + +#define GD32_SYSCLK_FREQUENCY 200000000ul + +#elif defined(CONFIG_GD32F4_168MHZ_AIOTBOX) + +/* Main PLL Configuration. + * + * PLL source is HXTAL + * PLL_VCO = (GD32_HXTAL_VALUE / PLLM) * PLLN + * = (25,000,000 / 25) * 336 + * = 336,000,000 + * SYSCLK = PLL_VCO / PLLP + * = 336,000,000 / 2 = 168,000,000 + * USB, SDIO and RNG Clock + * = PLL_VCO / PLLQ + * = 48,000,000 + */ + +#define GD32_PLL_PLLPSC RCU_PLL_PLLPSC(25) +#define GD32_PLL_PLLN RCU_PLL_PLLN(336) +#define GD32_PLL_PLLP RCU_PLL_PLLP(2) +#define GD32_PLL_PLLQ RCU_PLL_PLLQ(7) + +#define GD32_SYSCLK_FREQUENCY 168000000ul + +#endif + +/* AHB clock (HCLK) is SYSCLK */ + +#define GD32_RCU_CFG0_AHB_PSC RCU_CFG0_AHBPSC_CKSYS_DIV1 /* HCLK = SYSCLK / 1 */ +#define GD32_HCLK_FREQUENCY GD32_SYSCLK_FREQUENCY + +/* APB2 clock (PCLK2) is HCLK/2 */ + +#define GD32_RCU_CFG0_APB2_PSC RCU_CFG0_APB2PSC_CKAHB_DIV2 /* PCLK2 = HCLK / 2 */ +#define GD32_PCLK2_FREQUENCY (GD32_HCLK_FREQUENCY/2) + +/* APB1 clock (PCLK1) is HCLK/4 */ + +#define GD32_RCU_CFG0_APB1_PSC RCU_CFG0_APB1PSC_CKAHB_DIV4 /* PCLK1 = HCLK / 4 */ +#define GD32_PCLK1_FREQUENCY (GD32_HCLK_FREQUENCY / 4) + +/* Timers driven from APB1 will be twice PCLK1 */ + +#define GD32_APB1_TIMER2_CLKIN (2*GD32_PCLK1_FREQUENCY) +#define GD32_APB1_TIMER3_CLKIN (2*GD32_PCLK1_FREQUENCY) +#define GD32_APB1_TIMER4_CLKIN (2*GD32_PCLK1_FREQUENCY) +#define GD32_APB1_TIMER5_CLKIN (2*GD32_PCLK1_FREQUENCY) +#define GD32_APB1_TIMER6_CLKIN (2*GD32_PCLK1_FREQUENCY) +#define GD32_APB1_TIMER7_CLKIN (2*GD32_PCLK1_FREQUENCY) +#define GD32_APB1_TIMER12_CLKIN (2*GD32_PCLK1_FREQUENCY) +#define GD32_APB1_TIMER13_CLKIN (2*GD32_PCLK1_FREQUENCY) +#define GD32_APB1_TIMER14_CLKIN (2*GD32_PCLK1_FREQUENCY) + +/* Timers driven from APB2 will be twice PCLK2 */ + +#define GD32_APB2_TIMER1_CLKIN (2*GD32_PCLK2_FREQUENCY) +#define GD32_APB2_TIMER8_CLKIN (2*GD32_PCLK2_FREQUENCY) +#define GD32_APB2_TIMER9_CLKIN (2*GD32_PCLK2_FREQUENCY) +#define GD32_APB2_TIMER10_CLKIN (2*GD32_PCLK2_FREQUENCY) +#define GD32_APB2_TIMER11_CLKIN (2*GD32_PCLK2_FREQUENCY) + +/* Timer Frequencies, if APBx is set to 1, frequency is same to APBx + * otherwise frequency is 2xAPBx. + * Note: TIMER1,8 are on APB2, others on APB1 + */ + +#define BOARD_TIMER1_FREQUENCY GD32_HCLK_FREQUENCY +#define BOARD_TIMER2_FREQUENCY (GD32_HCLK_FREQUENCY/2) +#define BOARD_TIMER3_FREQUENCY (GD32_HCLK_FREQUENCY/2) +#define BOARD_TIMER4_FREQUENCY (GD32_HCLK_FREQUENCY/2) +#define BOARD_TIMER5_FREQUENCY (GD32_HCLK_FREQUENCY/2) +#define BOARD_TIMER6_FREQUENCY (GD32_HCLK_FREQUENCY/2) +#define BOARD_TIMER7_FREQUENCY (GD32_HCLK_FREQUENCY/2) +#define BOARD_TIMER8_FREQUENCY GD32_HCLK_FREQUENCY + +/* LED definitions **********************************************************/ + +/* The GD32F450ZK_EVAL board has board has three LEDs. The LED1, LED2 and + * LED3 are controlled by GPIO. LED1 is connected to PD4, LED2 is connected + * to PD5, LED3 is connected to PG3 + * + * If CONFIG_ARCH_LEDS is not defined, then the user can control the LEDs + * in any way. + * The following definitions are used to access individual LEDs. + */ + +/* LED index values */ + +typedef enum +{ + BOARD_LED1 = 0, + BOARD_LED2 = 1, + BOARD_LED3 = 2, + BOARD_LEDS +} led_typedef_enum; + +/* LED bits */ + +#define BOARD_LED1_BIT (1 << BOARD_LED1) +#define BOARD_LED2_BIT (1 << BOARD_LED2) +#define BOARD_LED3_BIT (1 << BOARD_LED3) + +/* If CONFIG_ARCH_LEDS is defined, the usage by the board port is defined in + * include/board.h and src/gd32f4xx_autoleds.c. The LEDs are used to encode + * OS-related events as follows: + * + * + * SYMBOL Meaning LED state + * LED1 LED2 LED3 + * ---------------------- -------------------------- ------ ------ --- + */ + +#define LED_STARTED 0 /* NuttX has been started OFF OFF OFF */ +#define LED_HEAPALLOCATE 1 /* Heap has been allocated ON OFF OFF */ +#define LED_IRQSENABLED 2 /* Interrupts enabled OFF ON OFF */ +#define LED_STACKCREATED 3 /* Idle stack created OFF OFF ON */ +#define LED_INIRQ 4 /* In an interrupt ON ON OFF */ +#define LED_SIGNAL 5 /* In a signal handler ON OFF ON */ +#define LED_ASSERTION 6 /* An assertion failed OFF ON ON */ +#define LED_PANIC 7 /* The system has crashed FLASH ON ON */ +#define LED_IDLE 8 /* MCU is is sleep mode OFF FLASH OFF */ + +/* Button definitions *******************************************************/ + +/* The GD32F450Z Eval supports three user buttons: Wakeup, Tamper and + * User key, they are connected to GPIO PA0, PC13, PB14. + * A low value will be sensed when the button is depressed. + */ + +typedef enum +{ + BUTTON_WAKEUP = 0, + BUTTON_TAMPER = 1, + BUTTON_USER = 2, + NUM_BUTTONS +} key_typedef_enum; + +#define BUTTON_WAKEUP_BIT (1 << BUTTON_WAKEUP) +#define BUTTON_TAMPER_BIT (1 << BUTTON_TAMPER) +#define BUTTON_USER_BIT (1 << BUTTON_USER) + +/* Alternate function pin selections ****************************************/ + +#if defined(CONFIG_GD32F450ZK_AIOTBOX_CONSOLE_BOARD) + +/* USART0: + * + * These configurations assume that you are using a standard RS-232 + * shield with the serial interface with RX on PA10 and TX on PA10: + * + * -------- --------------- + * GD32F450ZK-EVAL + * -- ----- --------- ----- + * RX USART0_RX PB7 + * TX USART0_TX PB6 + * -- ----- --------- ----- + */ + +# define GPIO_USART0_RX GPIO_USART0_RX_3 +# define GPIO_USART0_TX GPIO_USART0_TX_3 + +# define GPIO_USART2_RX GPIO_USART2_RX_3 +# define GPIO_USART2_TX GPIO_USART2_TX_2 + +#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_USART0_IFLOWCONTROL) +# define GPIO_USART0_RTS GPIO_USART0_RTS_1 +# endif +#if defined(CONFIG_SERIAL_OFLOWCONTROL) && defined(CONFIG_USART0_OFLOWCONTROL) +# define GPIO_USART0_CTS GPIO_USART0_CTS_1 +# endif +#endif + +#if CONFIG_GD32F4_USART0_TXDMA +# define DMA_CHANNEL_USART0_TX DMA_REQ_USART0_TX +#endif +#if CONFIG_GD32F4_USART0_RXDMA +# define DMA_CHANNEL_USART0_RX DMA_REQ_USART0_RX_1 +#endif + +#if defined(CONFIG_GD32F4_USART_RXDMA) || defined(CONFIG_GD32F4_USART_TXDMA) +# define USART_DMA_INTEN (DMA_CHXCTL_SDEIE | DMA_CHXCTL_TAEIE | DMA_CHXCTL_FTFIE) +#endif + +/* USART3: + * Use USART3 and the USB virtual COM port + */ + +#if defined(GD32F450ZK_AIOTBOX_CONSOLE_VIRTUAL) +# define GPIO_USART3_RX GPIO_USART3_RX_3 +# define GPIO_USART3_TX GPIO_USART3_TX_3 +#endif + +/* I2C0 gpios: + * + * PB6 I2C0_SCL + * PB7 I2C0_SDA + * + */ + +#define GPIO_I2C0_SCL GPIO_I2C0_SCL_2 +#define GPIO_I2C0_SDA GPIO_I2C0_SDA_2 + +#define GPIO_I2C1_SCL GPIO_I2C1_SCL_2 +#define GPIO_I2C1_SDA GPIO_I2C1_SDA_4 + +/* SPI flash + * + * PG12 SPI5_MISO + * PG14 SPI5_MOSI + * PG13 SPI5_SCK + * + * PG9 SPI5_CS + * + */ + +#define GPIO_SPI5_CSPIN (GPIO_CFG_PORT_G | GPIO_PIN9_OUTPUT) + +#define GPIO_SPI5_MISO_PIN ((GPIO_SPI5_MISO & ~GPIO_CFG_SPEED_MASK) | GPIO_CFG_SPEED_25MHZ) +#define GPIO_SPI5_MOSI_PIN ((GPIO_SPI5_MOSI & ~GPIO_CFG_SPEED_MASK) | GPIO_CFG_SPEED_25MHZ) +#define GPIO_SPI5_SCK_PIN ((GPIO_SPI5_SCK & ~GPIO_CFG_SPEED_MASK) | GPIO_CFG_SPEED_25MHZ) + +#define GPIO_SPI5_IO2_PIN ((GPIO_SPI5_IO2 & ~GPIO_CFG_SPEED_MASK) | GPIO_CFG_SPEED_25MHZ) +#define GPIO_SPI5_IO3_PIN ((GPIO_SPI5_IO3 & ~GPIO_CFG_SPEED_MASK) | GPIO_CFG_SPEED_25MHZ) + +#ifdef CONFIG_GD32F4_SPI0 +# define GPIO_SPI0_CSPIN (GPIO_CFG_PORT_B | GPIO_PIN9_OUTPUT) +# define GPIO_SPI0_MISO_PIN ((GPIO_SPI0_MISO_1 & ~GPIO_CFG_SPEED_MASK) | GPIO_CFG_SPEED_25MHZ) +# define GPIO_SPI0_MOSI_PIN ((GPIO_SPI0_MOSI_1 & ~GPIO_CFG_SPEED_MASK) | GPIO_CFG_SPEED_25MHZ) +# define GPIO_SPI0_SCK_PIN ((GPIO_SPI0_SCK_1 & ~GPIO_CFG_SPEED_MASK) | GPIO_CFG_SPEED_25MHZ) +#endif + +#ifdef CONFIG_GD32F4_SPI0_DMA +# define DMA_CHANNEL_SPI0_TX DMA_REQ_SPI0_TX_1 +# define DMA_CHANNEL_SPI0_RX DMA_REQ_SPI0_RX_1 +#endif + +#ifdef CONFIG_GD32F4_SPI_DMA +# define SPI_DMA_INTEN (DMA_CHXCTL_SDEIE | DMA_CHXCTL_TAEIE | DMA_CHXCTL_FTFIE) +#endif + +/* The GD32 F4 connects to a DP83848 PHY using these pins: + * + * GD32F450Z Eval BOARD DP83848 + * GPIO SIGNAL PIN NAME + * -------- ------------ ------------- + * PB11 RMII_TX_EN TXEN + * PB12 RMII_TXD0 TXD0 + * PB13 RMII_TXD1 TXD1 + * PC4 RMII_RXD0 RXD_0/PHYAD1 + * PC5 RMII_RXD1 RXD_1/PHYAD2 + * PA7 RMII_CRS_DV RX_DV/MII_MODE + * PC1 RMII_MDC MDC + * PA2 RMII_MDIO MDIO + * NRST NRST RESET_N + * PA1 RMII_REF_CLK X1 + * PB15 RMII_INT PWR_DOWN/INT + * + * The PHY address is 1. + */ + +#define GPIO_ENET_RMII_TX_EN GPIO_ENET_RMII_TX_EN_1 +#define GPIO_ENET_RMII_TXD0 GPIO_ENET_RMII_TXD0_1 +#define GPIO_ENET_RMII_TXD1 GPIO_ENET_RMII_TXD1_1 + +#ifdef CONFIG_GD32F4_ENET_PTP + /* Enable pulse-per-second (PPS) output signal */ + +# define GPIO_ENET_PPS_OUT GPIO_ENET_PPS_OUT_1 +#endif + +/* SDIO gpios + * + * PD2 SDIO_CMD + * PC12 SDIO_CLK + * PC8 SDIO_DAT0 + * PC9 SDIO_DAT1 + * PC10 SDIO_DAT2 + * PC11 SDIO_DAT3 + * + */ + +#define GPIO_SDIO_CMD_PIN GPIO_SDIO_CMD_2 +#define GPIO_SDIO_CLK_PIN GPIO_SDIO_CK_2 +#define GPIO_SDIO_DAT0_PIN GPIO_SDIO_D0_2 +#define GPIO_SDIO_DAT1_PIN GPIO_SDIO_D1_3 +#define GPIO_SDIO_DAT2_PIN GPIO_SDIO_D2_3 +#define GPIO_SDIO_DAT3_PIN GPIO_SDIO_D3 + +#ifdef CONFIG_GD32F4_SDIO_DMA +# define SDIO_DMA_INTEN (DMA_CHXCTL_SDEIE | DMA_CHXCTL_TAEIE | DMA_CHXCTL_FTFIE) +#endif + +#endif /* __BOARDS_ARM_GD32F450ZK_EVAL_INCLUDE_BOARD_H */ diff --git a/boards/arm/gd32f4/gd32f450zk-aiotbox/scripts/Make.defs b/boards/arm/gd32f4/gd32f450zk-aiotbox/scripts/Make.defs new file mode 100644 index 00000000000..347dcfd2d09 --- /dev/null +++ b/boards/arm/gd32f4/gd32f450zk-aiotbox/scripts/Make.defs @@ -0,0 +1,41 @@ +############################################################################ +# boards/arm/gd32f4/gd32f450zk-eval/scripts/Make.defs +# +# 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 + +LDSCRIPT = ld.script +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 + +EXEEXT = .elf diff --git a/boards/arm/gd32f4/gd32f450zk-aiotbox/scripts/gnu-elf.ld b/boards/arm/gd32f4/gd32f450zk-aiotbox/scripts/gnu-elf.ld new file mode 100644 index 00000000000..71448aa6cd9 --- /dev/null +++ b/boards/arm/gd32f4/gd32f450zk-aiotbox/scripts/gnu-elf.ld @@ -0,0 +1,116 @@ +/**************************************************************************** + * boards/arm/gd32f4/gd32f450zk-eval/scripts/gnu-elf.ld + * + * 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. + * + ****************************************************************************/ + +SECTIONS +{ + .text 0x00000000 : + { + _stext = . ; + *(.text) + *(.text.*) + *(.gnu.warning) + *(.stub) + *(.glue_7) + *(.glue_7t) + *(.jcr) + + /* C++ support: The .init and .fini sections contain specific logic + * to manage static constructors and destructors. + */ + + *(.gnu.linkonce.t.*) + *(.init) /* Old ABI */ + *(.fini) /* Old ABI */ + _etext = . ; + } + + .rodata : + { + _srodata = . ; + *(.rodata) + *(.rodata1) + *(.rodata.*) + *(.gnu.linkonce.r*) + _erodata = . ; + } + + .data : + { + _sdata = . ; + *(.data) + *(.data1) + *(.data.*) + *(.gnu.linkonce.d*) + . = ALIGN(4); + _edata = . ; + } + + /* C++ support. For each global and static local C++ object, + * GCC creates a small subroutine to construct the object. Pointers + * to these routines (not the routines themselves) are stored as + * simple, linear arrays in the .ctors section of the object file. + * Similarly, pointers to global/static destructor routines are + * stored in .dtors. + */ + + .ctors : + { + _sctors = . ; + *(.ctors) /* Old ABI: Unallocated */ + *(.init_array) /* New ABI: Allocated */ + _edtors = . ; + } + + .dtors : + { + _sdtors = . ; + *(.dtors) /* Old ABI: Unallocated */ + *(.fini_array) /* New ABI: Allocated */ + _edtors = . ; + } + + .bss : + { + _sbss = . ; + *(.bss) + *(.bss.*) + *(.sbss) + *(.sbss.*) + *(.gnu.linkonce.b*) + *(COMMON) + . = ALIGN(4); + _ebss = . ; + } + + /* 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) } +} diff --git a/boards/arm/gd32f4/gd32f450zk-aiotbox/scripts/kernel-space.ld b/boards/arm/gd32f4/gd32f450zk-aiotbox/scripts/kernel-space.ld new file mode 100644 index 00000000000..7018a914599 --- /dev/null +++ b/boards/arm/gd32f4/gd32f450zk-aiotbox/scripts/kernel-space.ld @@ -0,0 +1,98 @@ +/**************************************************************************** + * boards/arm/gd32f4/gd32f450zk-eval/scripts/kernel-space.ld + * + * 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. + * + ****************************************************************************/ + +/* NOTE: This depends on the memory.ld script having been included prior to + * this script. + */ + +OUTPUT_ARCH(arm) +EXTERN(_vectors) +ENTRY(_stext) +SECTIONS +{ + .text : { + _stext = ABSOLUTE(.); + *(.vectors) + *(.text .text.*) + *(.fixup) + *(.gnu.warning) + *(.rodata .rodata.*) + *(.gnu.linkonce.t.*) + *(.glue_7) + *(.glue_7t) + *(.got) + *(.gcc_except_table) + *(.gnu.linkonce.r.*) + _etext = ABSOLUTE(.); + } > kflash + + .init_section : { + _sinit = ABSOLUTE(.); + KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*))) + KEEP(*(.init_array .ctors)) + _einit = ABSOLUTE(.); + } > kflash + + .ARM.extab : { + *(.ARM.extab*) + } > kflash + + __exidx_start = ABSOLUTE(.); + .ARM.exidx : { + *(.ARM.exidx*) + } > kflash + + __exidx_end = ABSOLUTE(.); + + _eronly = ABSOLUTE(.); + + .data : { + _sdata = ABSOLUTE(.); + *(.data .data.*) + *(.gnu.linkonce.d.*) + CONSTRUCTORS + . = ALIGN(4); + _edata = ABSOLUTE(.); + } > ksram AT > kflash + + .bss : { + _sbss = ABSOLUTE(.); + *(.bss .bss.*) + *(.gnu.linkonce.b.*) + *(COMMON) + . = ALIGN(4); + _ebss = ABSOLUTE(.); + } > ksram + + /* 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) } +} diff --git a/boards/arm/gd32f4/gd32f450zk-aiotbox/scripts/ld.script b/boards/arm/gd32f4/gd32f450zk-aiotbox/scripts/ld.script new file mode 100644 index 00000000000..bb0866acc1c --- /dev/null +++ b/boards/arm/gd32f4/gd32f450zk-aiotbox/scripts/ld.script @@ -0,0 +1,131 @@ +/**************************************************************************** + * boards/arm/gd32f4/gd32f450zk-eval/scripts/ld.script + * + * 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. + * + ****************************************************************************/ + +/* The GD32F450ZKT6 has 3072Kb of FLASH beginning at address 0x0800:0000 and + * 256Kb of SRAM. SRAM is split up into four blocks: + * + * 1) 112Kb of SRAM beginning at address 0x2000:0000 + * 2) 16Kb of SRAM beginning at address 0x2001:c000 + * 3) 64Kb of SRAM beginning at address 0x2002:0000 + * 4) 64Kb of TCMSRAM beginning at address 0x1000:0000 + * + * When booting from FLASH, FLASH memory is aliased to address 0x0000:0000 + * where the code expects to begin execution by jumping to the entry point in + * the 0x0800:0000 address + * range. + */ + +MEMORY +{ + flash (rx) : ORIGIN = 0x08000000, LENGTH = 3072K + sram (rwx) : ORIGIN = 0x20000000, LENGTH = 112K +} + +OUTPUT_ARCH(arm) +EXTERN(_vectors) +ENTRY(_stext) +SECTIONS +{ + .text : { + _stext = ABSOLUTE(.); + *(.vectors) + *(.text .text.*) + *(.fixup) + *(.gnu.warning) + *(.rodata .rodata.*) + *(.gnu.linkonce.t.*) + *(.glue_7) + *(.glue_7t) + *(.got) + *(.gcc_except_table) + *(.gnu.linkonce.r.*) + _etext = ABSOLUTE(.); + } > flash + + .init_section : ALIGN(4) { + _sinit = ABSOLUTE(.); + KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*))) + KEEP(*(.init_array .ctors)) + _einit = ABSOLUTE(.); + } > flash + + .ARM.extab : ALIGN(4) { + *(.ARM.extab*) + } > flash + + .ARM.exidx : ALIGN(4) { + __exidx_start = ABSOLUTE(.); + *(.ARM.exidx*) + __exidx_end = ABSOLUTE(.); + } > flash + + .tdata : { + _stdata = ABSOLUTE(.); + *(.tdata .tdata.* .gnu.linkonce.td.*); + _etdata = ABSOLUTE(.); + } > flash + + .tbss : { + _stbss = ABSOLUTE(.); + *(.tbss .tbss.* .gnu.linkonce.tb.* .tcommon); + _etbss = ABSOLUTE(.); + } > flash + + _eronly = ABSOLUTE(.); + + /* The RAM vector table (if present) should lie at the beginning of SRAM */ + + .ram_vectors : { + *(.ram_vectors) + } > sram + + .data : ALIGN(4) { + _sdata = ABSOLUTE(.); + *(.data .data.*) + *(.gnu.linkonce.d.*) + CONSTRUCTORS + . = ALIGN(4); + _edata = ABSOLUTE(.); + } > sram AT > flash + + .bss : ALIGN(4) { + _sbss = ABSOLUTE(.); + *(.bss .bss.*) + *(.gnu.linkonce.b.*) + *(COMMON) + . = ALIGN(4); + _ebss = ABSOLUTE(.); + } > sram + + /* 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) } +} diff --git a/boards/arm/gd32f4/gd32f450zk-aiotbox/scripts/memory.ld b/boards/arm/gd32f4/gd32f450zk-aiotbox/scripts/memory.ld new file mode 100644 index 00000000000..d540022dbcd --- /dev/null +++ b/boards/arm/gd32f4/gd32f450zk-aiotbox/scripts/memory.ld @@ -0,0 +1,85 @@ +/**************************************************************************** + * boards/arm/gd32f4/gd32f450zk-eval/scripts/memory.ld + * + * 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. + * + ****************************************************************************/ + +/* The GD32F450ZKT6 has 3072Kb of FLASH beginning at address 0x0800:0000 and + * 256Kb of SRAM. SRAM is split up into four blocks: + * + * 1) 112KB of SRAM beginning at address 0x2000:0000 + * 2) 16KB of SRAM beginning at address 0x2001:c000 + * 3) 64KB of SRAM beginning at address 0x2002:0000 + * 4) 64KB of TCMSRAM beginning at address 0x1000:0000 + * + * When booting from FLASH, FLASH memory is aliased to address 0x0000:0000 + * where the code expects to begin execution by jumping to the entry point in + * the 0x0800:0000 address range. + * + * For MPU support, the kernel-mode NuttX section is assumed to be 128Kb of + * FLASH and 4Kb of SRAM. That is an excessive amount for the kernel which + * should fit into 64KB and, of course, can be optimized as needed. Allowing the + * additional does permit addition debug instrumentation to be added to the + * kernel space without overflowing the partition. + * + * Alignment of the user space FLASH partition is also a critical factor: + * The user space FLASH partition will be spanned with a single region of + * size 2**n bytes. The alignment of the user-space region must be the same. + * As a consequence, as the user-space increases in size, the alignment + * requirement also increases. + * + * This alignment requirement means that the largest user space FLASH region + * you can have will be 512KB at it would have to be positioned at + * 0x08800000. If you change this address, don't forget to change the + * CONFIG_NUTTX_USERSPACE configuration setting to match and to modify + * the check in kernel/userspace.c. + * + * For the same reasons, the maximum size of the SRAM mapping is limited to + * 4KB. Both of these alignment limitations could be reduced by using + * multiple regions to map the FLASH/SDRAM range or perhaps with some + * clever use of subregions. + * + * A detailed memory map for the 112KB SRAM region is as follows: + * + * 0x20000 0000: Kernel .data region. Typical size: 0.1KB + * ------- ---- Kernel .bss region. Typical size: 1.8KB + * 0x20000 0800: Kernel IDLE thread stack (approximate). Size is + * determined by CONFIG_IDLETHREAD_STACKSIZE and + * adjustments for alignment. Typical is 1KB. + * ------- ---- Padded to 4KB + * 0x20000 1000: User .data region. Size is variable. + * ------- ---- User .bss region Size is variable. + * 0x20000 2000: Beginning of kernel heap. Size determined by + * CONFIG_MM_KERNEL_HEAPSIZE. + * ------- ---- Beginning of user heap. Can vary with other settings. + * 0x20001 c000: End+1 of CPU RAM + */ + +MEMORY +{ + /* 1024Kb FLASH */ + + kflash (rx) : ORIGIN = 0x08000000, LENGTH = 128K + uflash (rx) : ORIGIN = 0x08020000, LENGTH = 128K + xflash (rx) : ORIGIN = 0x08040000, LENGTH = 768K + + /* 112Kb of contiguous SRAM */ + + ksram (rwx) : ORIGIN = 0x20000000, LENGTH = 4K + usram (rwx) : ORIGIN = 0x20001000, LENGTH = 4K + xsram (rwx) : ORIGIN = 0x20002000, LENGTH = 104K +} diff --git a/boards/arm/gd32f4/gd32f450zk-aiotbox/scripts/user-space.ld b/boards/arm/gd32f4/gd32f450zk-aiotbox/scripts/user-space.ld new file mode 100644 index 00000000000..6a02688b69c --- /dev/null +++ b/boards/arm/gd32f4/gd32f450zk-aiotbox/scripts/user-space.ld @@ -0,0 +1,112 @@ +/**************************************************************************** + * boards/arm/gd32f4/gd32f450zk-eval/scripts/user-space.ld + * + * 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. + * + ****************************************************************************/ + +/* NOTE: This depends on the memory.ld script having been included prior to + * this script. + */ + +/* Make sure that the critical memory management functions are in user-space. + * the user heap memory manager will reside in user-space but be usable both + * by kernel- and user-space code + */ + +EXTERN(umm_initialize) +EXTERN(umm_addregion) + +EXTERN(malloc) +EXTERN(realloc) +EXTERN(zalloc) +EXTERN(free) + +OUTPUT_ARCH(arm) +SECTIONS +{ + .userspace : { + *(.userspace) + } > uflash + + .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(.); + } > uflash + + .init_section : { + _sinit = ABSOLUTE(.); + KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*))) + KEEP(*(.init_array .ctors)) + _einit = ABSOLUTE(.); + } > uflash + + .ARM.extab : { + *(.ARM.extab*) + } > uflash + + __exidx_start = ABSOLUTE(.); + .ARM.exidx : { + *(.ARM.exidx*) + } > uflash + + __exidx_end = ABSOLUTE(.); + + _eronly = ABSOLUTE(.); + + .data : { + _sdata = ABSOLUTE(.); + *(.data .data.*) + *(.gnu.linkonce.d.*) + CONSTRUCTORS + . = ALIGN(4); + _edata = ABSOLUTE(.); + } > usram AT > uflash + + .bss : { + _sbss = ABSOLUTE(.); + *(.bss .bss.*) + *(.gnu.linkonce.b.*) + *(COMMON) + . = ALIGN(4); + _ebss = ABSOLUTE(.); + } > usram + + /* 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) } +} diff --git a/boards/arm/gd32f4/gd32f450zk-aiotbox/src/Makefile b/boards/arm/gd32f4/gd32f450zk-aiotbox/src/Makefile new file mode 100644 index 00000000000..a20313af23f --- /dev/null +++ b/boards/arm/gd32f4/gd32f450zk-aiotbox/src/Makefile @@ -0,0 +1,61 @@ +############################################################################ +# boards/arm/gd32f4/gd32f450zk-aiotbox/src/Make.defs +# +# 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 = gd32f4xx_boot.c + +# ifeq ($(CONFIG_BOARDCTL),y) +# CSRCS += gd32f4xx_appinit.c +# endif + +ifeq ($(CONFIG_BOARDCTL),y) +CSRCS += gd32f4xx_appinit.c gd32f4xx_bringup.c +else ifeq ($(CONFIG_BOARD_LATE_INITIALIZE),y) +CSRCS += gd32f4xx_bringup.c +endif + +ifeq ($(CONFIG_ARCH_LEDS),y) +CSRCS += gd32f4xx_autoleds.c +else +CSRCS += gd32f4xx_userleds.c +endif + +ifeq ($(CONFIG_DEV_GPIO),y) +CSRCS += gd32f4xx_gpio.c +endif + +ifeq ($(CONFIG_ARCH_BUTTONS),y) +CSRCS += gd32f4xx_buttons.c +endif + +ifeq ($(CONFIG_SPI),y) +CSRCS += gd32f4xx_spi.c +endif + +ifeq ($(CONFIG_MMCSD),y) +CSRCS += gd32f4xx_sdio.c +endif + +ifeq ($(CONFIG_I2C), y) +CSRCS += gd32f4xx_i2c.c +endif + +include $(TOPDIR)/boards/Board.mk diff --git a/boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f450z_aiotbox.h b/boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f450z_aiotbox.h new file mode 100644 index 00000000000..16649845f58 --- /dev/null +++ b/boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f450z_aiotbox.h @@ -0,0 +1,423 @@ +/**************************************************************************** + * boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f450z_aiotbox.h + * + * 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_GD32F4_GD32F450ZK_AIOTBOX_SRC_GD32F450Z_AIOTBOX_H +#define __BOARDS_ARM_GD32F4_GD32F450ZK_AIOTBOX_SRC_GD32F450Z_AIOTBOX_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Configuration ************************************************************/ + +/* procfs File System */ + +#ifdef CONFIG_FS_PROCFS +# ifdef CONFIG_NSH_PROC_MOUNTPOINT +# define GD32_PROCFS_MOUNTPOINT CONFIG_NSH_PROC_MOUNTPOINT +# else +# define GD32_PROCFS_MOUNTPOINT "/proc" +# endif +#endif + +#ifdef CONFIG_FS_NXFFS +# ifndef CONFIG_GD32F4_NXFFS_MOUNTPT +# define CONFIG_GD32F4_NXFFS_MOUNTPT "/mnt/gd32nxffs" +# endif +#endif + +/* GD32F450ZK GPIO Pin Definitions ******************************************/ + +/* LED + * + * The GD32F450ZK-EVAL board has three LEDs, LED1, LED2 and LED3, that can be + * controlled by software. + * The following definitions assume the default Solder Bridges are installed. + */ + +#define GPIO_LED1 (GPIO_CFG_PORT_D | GPIO_CFG_OUTPUT_RESET | GPIO_PIN4_OUTPUT) +#define GPIO_LED2 (GPIO_CFG_PORT_D | GPIO_CFG_OUTPUT_RESET | GPIO_PIN5_OUTPUT) +#define GPIO_LED3 (GPIO_CFG_PORT_G | GPIO_CFG_OUTPUT_RESET | GPIO_PIN3_OUTPUT) + +#define LED1 GPIO_LED1 +#define LED2 GPIO_LED2 +#define LED3 GPIO_LED3 + +#define LED_DRIVER_PATH "/dev/userleds" + +/* BUTTONS + * + * The GD32F450Z Eval board has User, Tamper, and Wakeup key, the are + * connected to GPIO PB14, PC13 and PA0. + * A low value will be sensed when the button is depressed. + * + * Note: + * That the EXTI is included in the definition to enable + * an interrupt on this IO. + */ + +#define GPIO_BTN_USER (GPIO_CFG_PORT_B | GPIO_CFG_EXTI | GPIO_PIN14_INPUT) +#define GPIO_BTN_TAMPER (GPIO_CFG_PORT_C | GPIO_CFG_EXTI | GPIO_PIN13_INPUT) +#define GPIO_BTN_WAKEUP (GPIO_CFG_PORT_A | GPIO_CFG_EXTI | GPIO_PIN0_INPUT) +/* GPIO pins used by the GPIO Subsystem */ + +#define BOARD_NGPIOIN 1 /* Amount of GPIO Input pins */ +#define BOARD_NGPIOOUT 1 /* Amount of GPIO Output pins */ +#define BOARD_NGPIOINT 1 /* Amount of GPIO Input w/ Interruption pins */ + +#define GPIO_IN1 (GPIO_CFG_MODE_INPUT | GPIO_CFG_PUPD_NONE | GPIO_CFG_PORT_B | GPIO_CFG_PIN_0) +#define GPIO_OUT1 (GPIO_CFG_MODE_OUTPUT | GPIO_CFG_OUTPUT_SET | GPIO_CFG_SPEED_50MHZ | \ + GPIO_CFG_PORT_B | GPIO_CFG_PIN_1) +#define GPIO_INT1 (GPIO_CFG_MODE_INPUT | GPIO_CFG_PUPD_NONE | GPIO_CFG_PORT_B | GPIO_CFG_PIN_2) + +/* Can't support MMC/SD features if mountpoints are disabled or if SDIO + * support is not enabled. + */ + +#if defined(CONFIG_DISABLE_MOUNTPOINT) || !defined(CONFIG_GD32_SDIO) +# undef HAVE_SDIO +#endif + +#define SDIO_MINOR 0 /* Any minor number, default 0 */ +#define SDIO_SLOTNO 0 /* Only one slot */ + +#ifdef HAVE_SDIO +# if !defined(CONFIG_NSH_MMCSDSLOTNO) +# define CONFIG_NSH_MMCSDSLOTNO SDIO_SLOTNO +# elif CONFIG_NSH_MMCSDSLOTNO != 0 +# warning "Only one MMC/SD slot, slot 0" +# undef CONFIG_NSH_MMCSDSLOTNO +# define CONFIG_NSH_MMCSDSLOTNO SDIO_SLOTNO +# endif + +# if defined(CONFIG_NSH_MMCSDMINOR) +# define SDIO_MINOR CONFIG_NSH_MMCSDMINOR +# else +# define SDIO_MINOR 0 +# endif +#endif + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifndef __ASSEMBLY__ + +/**************************************************************************** + * Name: gd32_bringup + * + * Description: + * Perform architecture specific initialization + * + * CONFIG_BOARDCTL=y: + * If CONFIG_NSH_ARCHINIT=y: + * Called from the NSH library (or other application) + * Otherwise, assumed to be called from some other application. + * + * Otherwise CONFIG_BOARD_LATE_INITIALIZE=y: + * Called from board_late_initialize(). + * + * Otherwise, bad news: Never called + * + ****************************************************************************/ + +int gd32_bringup(void); + +/**************************************************************************** + * Name: gd32_spidev_initialize + * + * Description: + * Called to configure SPI chip select GPIO pins for the GD32F450Z + * Eval board. + * + ****************************************************************************/ + +#if defined(CONFIG_SPI) +void gd32_spidev_initialize(void); +#endif + +/**************************************************************************** + * Name: gd32_gpio_initialize + * + * Description: + * Initialize GPIO drivers for use with /apps/examples/gpio + * + ****************************************************************************/ + +#ifdef CONFIG_DEV_GPIO +int gd32_gpio_initialize(void); +#endif + +/**************************************************************************** + * Name: gd32_dma_alloc_init + * + * Description: + * Called to create a FAT DMA allocator + * + * Returned Value: + * 0 on success or -ENOMEM + * + ****************************************************************************/ + +void gd32_dma_alloc_init(void); + +#if defined (CONFIG_FAT_DMAMEMORY) +int gd32_dma_alloc_init(void); +#endif + +/**************************************************************************** + * Name: gd32_sdio_initialize + * + * Description: + * Called at application startup time to initialize the SCMMC + * functionality. + * + ****************************************************************************/ + +#ifdef CONFIG_MMCSD +int gd32_sdio_initialize(void); +#endif + +#endif /* __ASSEMBLY__ */ +#endif /* __BOARDS_ARM_GD32F4_GD32F450ZK_AIOTBOX_SRC_GD32F450Z_AIOTBOX_H */ + +#ifdef CONFIG_I2C +void gd32_i2c_initialize(void); +#endif +/**************************************************************************** + * boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f450z_aiotbox.h + * + * 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_GD32F4_GD32F450ZK_AIOTBOX_SRC_GD32F450Z_AIOTBOX_H +#define __BOARDS_ARM_GD32F4_GD32F450ZK_AIOTBOX_SRC_GD32F450Z_AIOTBOX_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Configuration ************************************************************/ + +/* procfs File System */ + +#ifdef CONFIG_FS_PROCFS +# ifdef CONFIG_NSH_PROC_MOUNTPOINT +# define GD32_PROCFS_MOUNTPOINT CONFIG_NSH_PROC_MOUNTPOINT +# else +# define GD32_PROCFS_MOUNTPOINT "/proc" +# endif +#endif + +#ifdef CONFIG_FS_NXFFS +# ifndef CONFIG_GD32F4_NXFFS_MOUNTPT +# define CONFIG_GD32F4_NXFFS_MOUNTPT "/mnt/gd32nxffs" +# endif +#endif + +/* GD32F450ZK GPIO Pin Definitions ******************************************/ + +/* LED + * + * The GD32F450ZK-EVAL board has three LEDs, LED1, LED2 and LED3, that can be + * controlled by software. + * The following definitions assume the default Solder Bridges are installed. + */ + +#define GPIO_LED1 (GPIO_CFG_PORT_D | GPIO_CFG_OUTPUT_RESET | GPIO_PIN4_OUTPUT) +#define GPIO_LED2 (GPIO_CFG_PORT_D | GPIO_CFG_OUTPUT_RESET | GPIO_PIN5_OUTPUT) +#define GPIO_LED3 (GPIO_CFG_PORT_G | GPIO_CFG_OUTPUT_RESET | GPIO_PIN3_OUTPUT) + +#define LED1 GPIO_LED1 +#define LED2 GPIO_LED2 +#define LED3 GPIO_LED3 + +#define LED_DRIVER_PATH "/dev/userleds" + +/* BUTTONS + * + * The GD32F450Z Eval board has User, Tamper, and Wakeup key, the are + * connected to GPIO PB14, PC13 and PA0. + * A low value will be sensed when the button is depressed. + * + * Note: + * That the EXTI is included in the definition to enable + * an interrupt on this IO. + */ + +#define GPIO_BTN_USER (GPIO_CFG_PORT_B | GPIO_CFG_EXTI | GPIO_PIN14_INPUT) +#define GPIO_BTN_TAMPER (GPIO_CFG_PORT_C | GPIO_CFG_EXTI | GPIO_PIN13_INPUT) +#define GPIO_BTN_WAKEUP (GPIO_CFG_PORT_A | GPIO_CFG_EXTI | GPIO_PIN0_INPUT) + +/* GPIO pins used by the GPIO Subsystem */ + +#define BOARD_NGPIOIN 1 /* Amount of GPIO Input pins */ +#define BOARD_NGPIOOUT 1 /* Amount of GPIO Output pins */ +#define BOARD_NGPIOINT 1 /* Amount of GPIO Input w/ Interruption pins */ + +#define GPIO_IN1 (GPIO_CFG_MODE_INPUT | GPIO_CFG_PUPD_NONE | GPIO_CFG_PORT_B | GPIO_CFG_PIN_0) +#define GPIO_OUT1 (GPIO_CFG_MODE_OUTPUT | GPIO_CFG_OUTPUT_SET | GPIO_CFG_SPEED_50MHZ | \ + GPIO_CFG_PORT_B | GPIO_CFG_PIN_1) +#define GPIO_INT1 (GPIO_CFG_MODE_INPUT | GPIO_CFG_PUPD_NONE | GPIO_CFG_PORT_B | GPIO_CFG_PIN_2) + +/* Can't support MMC/SD features if mountpoints are disabled or if SDIO + * support is not enabled. + */ + +#if defined(CONFIG_DISABLE_MOUNTPOINT) || !defined(CONFIG_GD32_SDIO) +# undef HAVE_SDIO +#endif + +#define SDIO_MINOR 0 /* Any minor number, default 0 */ +#define SDIO_SLOTNO 0 /* Only one slot */ + +#ifdef HAVE_SDIO +# if !defined(CONFIG_NSH_MMCSDSLOTNO) +# define CONFIG_NSH_MMCSDSLOTNO SDIO_SLOTNO +# elif CONFIG_NSH_MMCSDSLOTNO != 0 +# warning "Only one MMC/SD slot, slot 0" +# undef CONFIG_NSH_MMCSDSLOTNO +# define CONFIG_NSH_MMCSDSLOTNO SDIO_SLOTNO +# endif + +# if defined(CONFIG_NSH_MMCSDMINOR) +# define SDIO_MINOR CONFIG_NSH_MMCSDMINOR +# else +# define SDIO_MINOR 0 +# endif +#endif + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifndef __ASSEMBLY__ + +/**************************************************************************** + * Name: gd32_bringup + * + * Description: + * Perform architecture specific initialization + * + * CONFIG_BOARDCTL=y: + * If CONFIG_NSH_ARCHINIT=y: + * Called from the NSH library (or other application) + * Otherwise, assumed to be called from some other application. + * + * Otherwise CONFIG_BOARD_LATE_INITIALIZE=y: + * Called from board_late_initialize(). + * + * Otherwise, bad news: Never called + * + ****************************************************************************/ + +int gd32_bringup(void); + +/**************************************************************************** + * Name: gd32_spidev_initialize + * + * Description: + * Called to configure SPI chip select GPIO pins for the GD32F450Z + * Eval board. + * + ****************************************************************************/ + +#if defined(CONFIG_SPI) +void gd32_spidev_initialize(void); +#endif + +/**************************************************************************** + * Name: gd32_gpio_initialize + * + * Description: + * Initialize GPIO drivers for use with /apps/examples/gpio + * + ****************************************************************************/ + +#ifdef CONFIG_DEV_GPIO +int gd32_gpio_initialize(void); +#endif + +/**************************************************************************** + * Name: gd32_dma_alloc_init + * + * Description: + * Called to create a FAT DMA allocator + * + * Returned Value: + * 0 on success or -ENOMEM + * + ****************************************************************************/ + +void gd32_dma_alloc_init(void); + +#if defined (CONFIG_FAT_DMAMEMORY) +int gd32_dma_alloc_init(void); +#endif + +/**************************************************************************** + * Name: gd32_sdio_initialize + * + * Description: + * Called at application startup time to initialize the SCMMC + * functionality. + * + ****************************************************************************/ + +#ifdef CONFIG_MMCSD +int gd32_sdio_initialize(void); +#endif + +#endif /* __ASSEMBLY__ */ +#endif /* __BOARDS_ARM_GD32F4_GD32F450ZK_AIOTBOX_SRC_GD32F450Z_AIOTBOX_H */ + +#ifdef CONFIG_I2C +void gd32_i2c_initialize(void); +#endif \ No newline at end of file diff --git a/boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_appinit.c b/boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_appinit.c new file mode 100644 index 00000000000..76275d9b587 --- /dev/null +++ b/boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_appinit.c @@ -0,0 +1,71 @@ +/**************************************************************************** + * boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_appinit.c + * + * 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 + +#include +#include +#include +#include + +#include + +#include "gd32f4xx.h" +#include "gd32f450z_aiotbox.h" + +/**************************************************************************** + * 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) +{ + /* Perform board initialization here */ + + return gd32_bringup(); +} diff --git a/boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_autoleds.c b/boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_autoleds.c new file mode 100644 index 00000000000..311a0881bfd --- /dev/null +++ b/boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_autoleds.c @@ -0,0 +1,177 @@ +/**************************************************************************** + * boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_autoleds.c + * + * 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 + +#include +#include + +#include + +#include +#include + +#include "gd32f4xx_gpio.h" +#include "gd32f450z_aiotbox.h" +#ifdef CONFIG_ARCH_LEDS + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* LED index */ + +static const uint32_t g_led_map[BOARD_LEDS] = +{ + LED1, + LED2, + LED3 +}; + +static bool g_initialized; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/* Turn on selected led */ + +static void gd32_aiotbox_led_on(led_typedef_enum led_num) +{ + gd32_gpio_write(g_led_map[led_num], true); +} + +/* Turn off selected led */ + +static void gd32_aiotbox_led_off(led_typedef_enum led_num) +{ + gd32_gpio_write(g_led_map[led_num], false); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_autoled_initialize + ****************************************************************************/ + +void board_autoled_initialize(void) +{ + int i; + + /* Configure the LED GPIO for output. */ + + for (i = 0; i < nitems(g_led_map); i++) + { + gd32_gpio_config(g_led_map[i]); + } +} + +/**************************************************************************** + * Name: board_autoled_on + ****************************************************************************/ + +void board_autoled_on(int led) +{ + switch (led) + { + default: + break; + + case LED_HEAPALLOCATE: + gd32_aiotbox_led_on(BOARD_LED1); + break; + + case LED_IRQSENABLED: + gd32_aiotbox_led_on(BOARD_LED2); + break; + + case LED_STACKCREATED: + gd32_aiotbox_led_on(BOARD_LED3); + g_initialized = true; + break; + + case LED_INIRQ: + gd32_aiotbox_led_on(BOARD_LED1); + gd32_aiotbox_led_on(BOARD_LED2); + break; + + case LED_SIGNAL: + gd32_aiotbox_led_on(BOARD_LED1); + gd32_aiotbox_led_on(BOARD_LED3); + break; + + case LED_ASSERTION: + gd32_aiotbox_led_on(BOARD_LED2); + gd32_aiotbox_led_on(BOARD_LED3); + break; + + case LED_PANIC: + gd32_aiotbox_led_on(BOARD_LED1); + break; + + case LED_IDLE : /* IDLE */ + gd32_aiotbox_led_on(BOARD_LED2); + break; + } +} + +/**************************************************************************** + * Name: board_autoled_off + ****************************************************************************/ + +void board_autoled_off(int led) +{ + switch (led) + { + default: + break; + + case LED_SIGNAL: + gd32_aiotbox_led_off(BOARD_LED1); + gd32_aiotbox_led_off(BOARD_LED3); + break; + + case LED_INIRQ: + gd32_aiotbox_led_off(BOARD_LED1); + gd32_aiotbox_led_off(BOARD_LED2); + break; + + case LED_ASSERTION: + gd32_aiotbox_led_off(BOARD_LED2); + gd32_aiotbox_led_off(BOARD_LED3); + break; + + case LED_PANIC: + gd32_aiotbox_led_off(BOARD_LED1); + break; + + case LED_IDLE : /* IDLE */ + gd32_aiotbox_led_off(BOARD_LED2); + break; + } +} + +#endif /* CONFIG_ARCH_LEDS */ diff --git a/boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_boot.c b/boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_boot.c new file mode 100644 index 00000000000..d8c90a88300 --- /dev/null +++ b/boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_boot.c @@ -0,0 +1,85 @@ +/**************************************************************************** + * boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_boot.c + * + * 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 + +#include + +#include +#include + +#include "gd32f450z_aiotbox.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: gd32_boardinitialize + * + * Description: + * All GD32F4xx architectures must provide the following entry point. + * This entry point is called early in the initialization + * after all memory has been configured and mapped but + * before any devices have been initialized. + * + ****************************************************************************/ + +void gd32_boardinitialize(void) +{ +#ifdef CONFIG_ARCH_LEDS + /* Configure on-board LEDs if LED support has been selected. */ + + board_autoled_initialize(); +#endif + +#if defined(CONFIG_SPI) + /* Configure SPI chip selects */ + + gd32_spidev_initialize(); +#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_initialize() 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-specific initialization */ + + gd32_bringup(); +} +#endif diff --git a/boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_bringup.c b/boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_bringup.c new file mode 100644 index 00000000000..d068cec903f --- /dev/null +++ b/boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_bringup.c @@ -0,0 +1,363 @@ +/**************************************************************************** + * boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_bringup.c + * + * 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 + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "gd32f4xx.h" + +#ifdef CONFIG_USERLED +# include +#endif + +#ifdef CONFIG_INPUT_BUTTONS +# include +#endif + +#ifdef CONFIG_GD32F4_ROMFS +#include "gd32f4xx_romfs.h" +#endif + +#include "gd32f450z_aiotbox.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: gd32_bringup + * + * Description: + * Perform architecture-specific initialization + * + * CONFIG_BOARD_LATE_INITIALIZE=y : + * Called from board_late_initialize(). + * + * CONFIG_BOARD_LATE_INITIALIZE=n && CONFIG_BOARDCTL=y : + * Called from the NSH library via boardctl() + * + ****************************************************************************/ + +int gd32_bringup(void) +{ +#ifdef CONFIG_RAMMTD + uint8_t *ramstart; +#endif + + int ret = OK; + +#ifdef CONFIG_FS_PROCFS + /* Mount the procfs file system */ + + ret = nx_mount(NULL, GD32_PROCFS_MOUNTPOINT, "procfs", 0, NULL); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to mount procfs at %s: %d\n", + GD32_PROCFS_MOUNTPOINT, ret); + } +#endif + +#ifdef CONFIG_RAMMTD + /* Create a RAM MTD device if configured */ + + ramstart = kmm_malloc(64 * 1024); + if (ramstart == NULL) + { + syslog(LOG_ERR, "ERROR: Allocation for RAM MTD failed\n"); + } + else + { + /* Initialized the RAM MTD */ + + struct mtd_dev_s *mtd = rammtd_initialize(ramstart, 64 * 1024); + if (mtd == NULL) + { + syslog(LOG_ERR, "ERROR: rammtd_initialize failed\n"); + kmm_free(ramstart); + } + else + { + /* Erase the RAM MTD */ + + ret = mtd->ioctl(mtd, MTDIOC_BULKERASE, 0); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: IOCTL MTDIOC_BULKERASE failed\n"); + } + +#if defined(CONFIG_MTD_SMART) && defined(CONFIG_FS_SMARTFS) + /* Initialize a SMART Flash block device and bind it to the MTD + * device. + */ + + smart_initialize(0, mtd, NULL); + +#elif defined(CONFIG_FS_SPIFFS) + /* Register the MTD driver so that it can be accessed from the + * VFS. + */ + + ret = register_mtddriver("/dev/rammtd", mtd, 0755, NULL); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to register MTD driver: %d\n", + ret); + } + + /* Mount the SPIFFS file system */ + + ret = nx_mount("/dev/rammtd", "/mnt/spiffs", "spiffs", 0, NULL); + if (ret < 0) + { + syslog(LOG_ERR, + "ERROR: Failed to mount SPIFFS at /mnt/spiffs: %d\n", + ret); + } + +#elif defined(CONFIG_FS_LITTLEFS) + /* Register the MTD driver so that it can be accessed from the + * VFS. + */ + + ret = register_mtddriver("/dev/rammtd", mtd, 0755, NULL); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to register MTD driver: %d\n", + ret); + } + + /* Mount the LittleFS file system */ + + ret = nx_mount("/dev/rammtd", "/mnt/lfs", "littlefs", 0, + "forceformat"); + if (ret < 0) + { + syslog(LOG_ERR, + "ERROR: Failed to mount LittleFS at /mnt/lfs: %d\n", + ret); + } + +#elif defined(CONFIG_FS_NXFFS) + /* Initialize to provide NXFFS on the MTD interface */ + + ret = nxffs_initialize(mtd); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: NXFFS initialization failed: %d\n", + ret); + } +#endif + } + } +#endif + +#if defined(CONFIG_INPUT_BUTTONS_LOWER) + ret = btn_lower_initialize("/dev/buttons"); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: btn_lower_initialize() failed: %d\n", ret); + } +#endif + +#ifdef CONFIG_GD32F4_ROMFS + /* Mount the romfs partition */ + + ret = gd32_romfs_initialize(); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to mount romfs at %s: %d\n", + CONFIG_GD32F4_ROMFS_MOUNTPOINT, ret); + } +#endif + +#ifndef CONFIG_DISABLE_MOUNTPOINT + +# ifdef CONFIG_GD32F4_PROGMEM + + /* Create an instance of the GD32F4 FLASH program memory + * device driver + */ + + struct mtd_dev_s *mtd = progmem_initialize(); + if (!mtd) + { + syslog(LOG_ERR, "ERROR: progmem_initialize failed\n"); + } + +# if defined(CONFIG_FS_NXFFS) + /* Initialize to provide NXFFS on the MTD interface */ + + ret = nxffs_initialize(mtd); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: NXFFS initialization failed: %d\n", + ret); + } + + /* Mount the file system */ + + ret = nx_mount(NULL, CONFIG_GD32F4_NXFFS_MOUNTPT, "nxffs", 0, NULL); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to mount the NXFFS volume: %d\n", + ret); + } +# elif defined(CONFIG_FS_LITTLEFS) + /* Initialize to provide LittleFS on the MTD interface */ + + ret = register_mtddriver("/dev/fmc", mtd, 0755, NULL); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to register MTD: %d\n", ret); + return ret; + } + + /* Mount the file system at /mnt/fmc */ + + ret = nx_mount("/dev/fmc", "/mnt/fmc", "littlefs", 0, NULL); + if (ret < 0) + { + ret = nx_mount("/dev/fmc", "/mnt/fmc", "littlefs", 0, + "forceformat"); + if (ret < 0) + { + ferr("ERROR: Failed to mount the FS volume: %d\n", ret); + return ret; + } + } + + syslog(LOG_INFO, "INFO: LittleFS volume /mnt/fmc mount " \ + "on chip flash success: %d\n", ret); +# endif +# endif + +# ifdef HAVE_GD25 + + ret = gd32_gd25_automount(0); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to mount the NXFFS \ + volume on spi flash: %d\n", ret); + } + +# endif + +# ifdef HAVE_AT24 + + ret = gd32_at24_wr_test(AT24_MINOR); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: I2C EEPROM write and read test fail: \ + %d\n", ret); + } + +# endif + +#endif /* CONFIG_FS_NXFFS */ + +#ifdef CONFIG_DEV_GPIO + /* Register the GPIO driver */ + + ret = gd32_gpio_initialize(); + if (ret < 0) + { + syslog(LOG_ERR, "Failed to initialize GPIO Driver: %d\n", ret); + return ret; + } +#endif + +#ifdef CONFIG_I2C + gd32_i2c_initialize(); +#endif + +#ifdef CONFIG_INPUT_BUTTONS +#ifdef CONFIG_INPUT_BUTTONS_LOWER + /* Register the BUTTON driver */ + + ret = btn_lower_initialize("/dev/buttons"); + if (ret != OK) + { + syslog(LOG_ERR, "ERROR: btn_lower_initialize() failed: %d\n", ret); + return ret; + } +#else + /* Enable BUTTON support for some other purpose */ + + board_button_initialize(); +#endif /* CONFIG_INPUT_BUTTONS_LOWER */ +#endif /* CONFIG_INPUT_BUTTONS */ + +#if !defined(CONFIG_ARCH_LEDS) && defined(CONFIG_USERLED_LOWER) + /* Register the LED driver */ + + ret = userled_lower_initialize(LED_DRIVER_PATH); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: userled_lower_initialize() failed: %d\n", + ret); + } +#endif + + /* Configure SDIO chip selects */ + +#ifdef CONFIG_ARCH_HAVE_SDIO + ret = gd32_sdio_initialize(); + if (ret != OK) + { + syslog(LOG_ERR, "ERROR: gd32_sdio_initialize() failed: %d\n", ret); + return ret; + } + + /* Mount the file system at /mnt/sd */ + + ret = nx_mount("/dev/mmcsd0", "/mnt/sd", "vfat", 0, NULL); + if (ret < 0) + { + ret = nx_mount("/dev/mmcsd0", "/mnt/sd", "vfat", 0, + "forceformat"); + if (ret < 0) + { + ferr("ERROR: Failed to mount the SD card: %d\n", ret); + return ret; + } + } + + syslog(LOG_INFO, "INFO: FAT volume /mnt/sd mount " \ + "sd card success: %d\n", ret); +#endif + return ret; +} diff --git a/boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_buttons.c b/boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_buttons.c new file mode 100644 index 00000000000..3506eca15fd --- /dev/null +++ b/boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_buttons.c @@ -0,0 +1,190 @@ +/**************************************************************************** + * boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_buttons.c + * + * 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 + +#include +#include + +#include +#include + +#include + +#include "gd32f4xx.h" +#include "gd32f450z_aiotbox.h" + +#ifdef CONFIG_ARCH_BUTTONS + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const uint32_t g_button_boards[NUM_BUTTONS] = +{ + GPIO_BTN_USER, GPIO_BTN_TAMPER, GPIO_BTN_WAKEUP +}; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_button_initialize + * + * Description: + * board_button_initialize() must be called to initialize button resources. + * After that, board_buttons() may be called to collect the current state + * of all buttons or board_button_irq() may be called to register button + * interrupt handlers. + * + ****************************************************************************/ + +uint32_t board_button_initialize(void) +{ + int i; + + /* Configure each button */ + + for (i = 0; i < NUM_BUTTONS; i++) + { + gd32_gpio_config(g_button_boards[i]); + } + + return NUM_BUTTONS; +} + +/**************************************************************************** + * Name: board_buttons + * After board_button_initialize() has been called, board_buttons() may be + * called to collect the state of all buttons. board_buttons() returns an + * 32-bit bit set with each bit associated with a button. See the BUTTON* + * definitions above for the meaning of each bit in the returned value. + * + ****************************************************************************/ + +uint32_t board_buttons(void) +{ + uint32_t ret; + int i; + + /* Check each button */ + + for (i = 0, ret = 0; i < NUM_BUTTONS; i++) + { + /* The low value is sensed when the button is pressed */ + + if (!gd32_gpio_read(g_button_boards[i])) + { + ret |= (1 << i); + } + } + + return ret; +} + +/**************************************************************************** + * Button support. + * + * Description: + * board_button_initialize() must be called to initialize button resources. + * After that, board_buttons() may be called to collect the current + * state of all buttons or board_button_irq() may be called to register + * button interrupt handlers. + * + * After board_button_initialize() has been called, board_buttons() + * may be called to collect the state of all buttons. board_buttons() + * returns an 32-bit bit set with each bit associated with a button. + * See the BUTTON_*_BIT definitions in board.h for the meaning of each + * bit. + * + * board_button_irq() may be called to register an interrupt handler that + * will be called when a button is depressed or released. The ID value + * is a button enumeration value that uniquely identifies a button + * resource. See the BUTTON_* definitions in board.h for the meaning of + * enumeration value. + * + ****************************************************************************/ + +#ifdef CONFIG_ARCH_IRQBUTTONS +int board_button_irq(int id, xcpt_t irqhandler, void *arg) +{ + if (id >= 0 && id < NUM_BUTTONS) + { + uint8_t gpio_irq; + uint8_t gpio_irqnum; + irqstate_t flags; + int ret; + + /* Disable interrupts until we are done. This guarantees that the + * following operations are atomic. + */ + + flags = enter_critical_section(); + + /* Get gpio irq numbers */ + + ret = gd32_gpio_exti_irqnum_get(g_button_boards[id], &gpio_irqnum); + + if (ret < 0) + { + leave_critical_section(flags); + return ret; + } + + /* Are we attaching or detaching? */ + + if (irqhandler != NULL) + { + ret = gd32_exti_gpioirq_init(g_button_boards[id], EXTI_INTERRUPT, + EXTI_TRIG_RISING, &gpio_irq); + + if (ret < 0) + { + leave_critical_section(flags); + return ret; + } + + /* Attach and enable the interrupt */ + + gd32_exti_gpio_irq_attach(gpio_irq, irqhandler, arg); + up_enable_irq(gpio_irqnum); + } + else + { + /* Disable and detach the interrupt */ + + up_disable_irq(gpio_irqnum); + irq_detach(gpio_irqnum); + } + + leave_critical_section(flags); + } + + /* Return the old button handler (so that it can be restored) */ + + return OK; +} +#endif +#endif /* CONFIG_ARCH_BUTTONS */ diff --git a/boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_gpio.c b/boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_gpio.c new file mode 100644 index 00000000000..b9c279c0953 --- /dev/null +++ b/boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_gpio.c @@ -0,0 +1,397 @@ +/**************************************************************************** + * boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_gpio.c + * + * 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 + +#include +#include +#include + +#include +#include +#include + +#include + +#include "chip.h" + +#include "gd32f4xx.h" +#include "gd32f450z_aiotbox.h" + +#if defined(CONFIG_DEV_GPIO) && !defined(CONFIG_GPIO_LOWER_HALF) + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct gd32gpio_dev_s +{ + struct gpio_dev_s gpio; + uint8_t id; +}; + +struct gd32gpint_dev_s +{ + struct gd32gpio_dev_s gd32gpio; + pin_interrupt_t callback; +}; + +irqstate_t flags; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static int gpio_setpintype(struct gpio_dev_s *dev, + enum gpio_pintype_e gp_pintype); + +#if BOARD_NGPIOIN > 0 +static int gpin_read(struct gpio_dev_s *dev, bool *value); +#endif + +#if BOARD_NGPIOOUT > 0 +static int gpout_read(struct gpio_dev_s *dev, bool *value); +static int gpout_write(struct gpio_dev_s *dev, bool value); +#endif + +#if BOARD_NGPIOINT > 0 +static int gpint_read(struct gpio_dev_s *dev, bool *value); +static int gpint_attach(struct gpio_dev_s *dev, + pin_interrupt_t callback); +static int gpint_enable(struct gpio_dev_s *dev, bool enable); +#endif + +/**************************************************************************** + * Private Data + ****************************************************************************/ + + #if BOARD_NGPIOIN > 0 +static const struct gpio_operations_s gpin_ops = +{ + .go_read = gpin_read, + .go_write = NULL, + .go_attach = NULL, + .go_enable = NULL, + .go_setpintype = gpio_setpintype, +}; + +/* This array maps the GPIO pins used as INPUT */ + +static const uint32_t g_gpioinputs[BOARD_NGPIOIN] = +{ + GPIO_IN1, +}; + +static struct gd32gpio_dev_s g_gpin[BOARD_NGPIOIN]; +#endif + +#if BOARD_NGPIOOUT > 0 + +static const struct gpio_operations_s gpout_ops = +{ + .go_read = gpout_read, + .go_write = gpout_write, + .go_attach = NULL, + .go_enable = NULL, + .go_setpintype = gpio_setpintype, +}; + +/* This array maps the GPIO pins used as OUTPUT */ + +static const uint32_t g_gpiooutputs[BOARD_NGPIOOUT] = +{ + GPIO_OUT1, +}; + +static struct gd32gpio_dev_s g_gpout[BOARD_NGPIOOUT]; +#endif + +#if BOARD_NGPIOINT > 0 + +static const struct gpio_operations_s gpint_ops = +{ + .go_read = gpint_read, + .go_write = NULL, + .go_attach = gpint_attach, + .go_enable = gpint_enable, + .go_setpintype = gpio_setpintype, +}; + +/* This array maps the GPIO pins used as INTERRUPT INPUTS */ + +static const uint32_t g_gpiointinputs[BOARD_NGPIOINT] = +{ + GPIO_INT1, +}; + +static struct gd32gpint_dev_s g_gpint[BOARD_NGPIOINT]; +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: gpio_setpintype + * + * Description: + * set gpio pintype. + * + ****************************************************************************/ + +static int gpio_setpintype(struct gpio_dev_s *dev, + enum gpio_pintype_e gpio_pintype) +{ + struct gd32gpint_dev_s *gd32gpint = (struct gd32gpint_dev_s *)dev; + + UNUSED(gd32gpint); + UNUSED(gpio_pintype); + + gpioinfo("setpintype is not supported. \n"); + + return 0; +} + +#if BOARD_NGPIOIN > 0 +static int gpin_read(struct gpio_dev_s *dev, bool *value) +{ + struct gd32gpio_dev_s *gd32gpio = (struct gd32gpio_dev_s *)dev; + + DEBUGASSERT(gd32gpio != NULL && value != NULL); + DEBUGASSERT(gd32gpio->id < BOARD_NGPIOIN); + gpioinfo("Reading...\n"); + + *value = gd32_gpio_read(g_gpioinputs[gd32gpio->id]); + return OK; +} +#endif + +#if BOARD_NGPIOOUT > 0 +static int gpout_read(struct gpio_dev_s *dev, bool *value) +{ + struct gd32gpio_dev_s *gd32gpio = (struct gd32gpio_dev_s *)dev; + + DEBUGASSERT(gd32gpio != NULL && value != NULL); + DEBUGASSERT(gd32gpio->id < BOARD_NGPIOOUT); + gpioinfo("Reading...\n"); + + *value = gd32_gpio_read(g_gpiooutputs[gd32gpio->id]); + return OK; +} + +static int gpout_write(struct gpio_dev_s *dev, bool value) +{ + struct gd32gpio_dev_s *gd32gpio = (struct gd32gpio_dev_s *)dev; + + DEBUGASSERT(gd32gpio != NULL); + DEBUGASSERT(gd32gpio->id < BOARD_NGPIOOUT); + gpioinfo("Writing %d\n", (int)value); + + gd32_gpio_write(g_gpiooutputs[gd32gpio->id], value); + return OK; +} +#endif + +#if BOARD_NGPIOINT > 0 + +static int gd32gpio_interrupt(int irq, void *context, void *arg) +{ + struct gd32gpint_dev_s *gd32gpint = (struct gd32gpint_dev_s *)arg; + + DEBUGASSERT(gd32gpint != NULL && gd32gpint->callback != NULL); + gpioinfo("Interrupt! callback=%p\n", gd32gpint->callback); + + gd32gpint->callback(&gd32gpint->gd32gpio.gpio, gd32gpint->gd32gpio.id); + return OK; +} + +static int gpint_read(struct gpio_dev_s *dev, bool *value) +{ + struct gd32gpint_dev_s *gd32gpint = (struct gd32gpint_dev_s *)dev; + + DEBUGASSERT(gd32gpint != NULL && value != NULL); + DEBUGASSERT(gd32gpint->gd32gpio.id < BOARD_NGPIOINT); + gpioinfo("Reading int pin...\n"); + + *value = gd32_gpio_read(g_gpiointinputs[gd32gpint->gd32gpio.id]); + return OK; +} + +static int gpint_attach(struct gpio_dev_s *dev, pin_interrupt_t callback) +{ + struct gd32gpint_dev_s *gd32gpint = (struct gd32gpint_dev_s *)dev; + int ret; + uint8_t gpio_irq; + uint8_t gpio_irqnum; + + gpioinfo("Attaching the callback\n"); + + flags = enter_critical_section(); + + /* Make sure the interrupt is disabled */ + + ret = gd32_exti_gpioirq_init(g_gpiointinputs[gd32gpint->gd32gpio.id], + EXTI_INTERRUPT, EXTI_TRIG_RISING, &gpio_irq); + + if (ret < 0) + { + leave_critical_section(flags); + return ret; + } + + gd32_gpio_exti_irqnum_get(g_gpiointinputs[gd32gpint->gd32gpio.id], + &gpio_irqnum); + + /* Attach and disable the interrupt */ + + gd32_exti_gpio_irq_attach(gpio_irq, gd32gpio_interrupt, + &g_gpint[gd32gpint->gd32gpio.id]); + + /* Disable and the interrupt */ + + up_disable_irq(gpio_irqnum); + + leave_critical_section(flags); + gpioinfo("Attach %p\n", callback); + gd32gpint->callback = callback; + return OK; +} + +static int gpint_enable(struct gpio_dev_s *dev, bool enable) +{ + struct gd32gpint_dev_s *gd32gpint = (struct gd32gpint_dev_s *)dev; + int ret; + uint8_t gpio_irqnum; + + flags = enter_critical_section(); + + /* Get gpio irq numbers */ + + ret = gd32_gpio_exti_irqnum_get(g_gpiointinputs[gd32gpint->gd32gpio.id], + &gpio_irqnum); + if (ret < 0) + { + leave_critical_section(flags); + return ret; + } + + if (enable) + { + if (gd32gpint->callback != NULL) + { + gpioinfo("Enabling the interrupt\n"); + + /* Enable the interrupt */ + + up_disable_irq(gpio_irqnum); + } + } + else + { + up_disable_irq(gpio_irqnum); + gpioinfo("Disable the interrupt\n"); + } + + leave_critical_section(flags); + return OK; +} +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: gd32_gpio_initialize + * + * Description: + * Initialize GPIO drivers for use with /apps/examples/gpio + * + ****************************************************************************/ + +int gd32_gpio_initialize(void) +{ + int pincount = 0; + int i; + +#if BOARD_NGPIOIN > 0 + for (i = 0; i < BOARD_NGPIOIN; i++) + { + /* Setup and register the GPIO pin */ + + g_gpin[i].gpio.gp_pintype = GPIO_INPUT_PIN; + g_gpin[i].gpio.gp_ops = &gpin_ops; + g_gpin[i].id = i; + + gpio_pin_register(&g_gpin[i].gpio, pincount); + + /* Configure the pin that will be used as input */ + + gd32_gpio_config(g_gpioinputs[i]); + + pincount++; + } +#endif + +#if BOARD_NGPIOOUT > 0 + for (i = 0; i < BOARD_NGPIOOUT; i++) + { + /* Setup and register the GPIO pin */ + + g_gpout[i].gpio.gp_pintype = GPIO_OUTPUT_PIN; + g_gpout[i].gpio.gp_ops = &gpout_ops; + g_gpout[i].id = i; + + gpio_pin_register(&g_gpout[i].gpio, pincount); + + /* Configure the pin that will be used as output */ + + gd32_gpio_write(g_gpiooutputs[i], 0); + gd32_gpio_config(g_gpiooutputs[i]); + + pincount++; + } +#endif + +#if BOARD_NGPIOINT > 0 + for (i = 0; i < BOARD_NGPIOINT; i++) + { + /* Setup and register the GPIO pin */ + + g_gpint[i].gd32gpio.gpio.gp_pintype = GPIO_INTERRUPT_PIN; + g_gpint[i].gd32gpio.gpio.gp_ops = &gpint_ops; + g_gpint[i].gd32gpio.id = i; + (void)gpio_pin_register(&g_gpint[i].gd32gpio.gpio, pincount); + + /* Configure the pin that will be used as interrupt input */ + + gd32_gpio_config(g_gpiointinputs[i]); + + pincount++; + } +#endif + + return 0; +} +#endif /* CONFIG_DEV_GPIO && !CONFIG_GPIO_LOWER_HALF */ diff --git a/boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_i2c.c b/boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_i2c.c new file mode 100644 index 00000000000..259c3ac7252 --- /dev/null +++ b/boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_i2c.c @@ -0,0 +1,95 @@ +/**************************************************************************** + * boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_i2c.c + * + * 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 +#include +#include +#include +#include + +#include + +#include"gd32f4xx.h" +#include"gd32f450z_aiotbox.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#ifdef CONFIG_I2C +void gd32_i2c_initialize(void) +{ + FAR struct i2c_master_s *i2c; + int ret; + i2cinfo("Initialize I2c\n"); + +#ifdef CONFIG_GD32F4_I2C0 + i2c = gd32_i2cbus_initialize(0); + + if (i2c == NULL) + { + i2cerr("init i2c0 faild.\n"); + return; + } + else + { + ret = i2c_register(i2c, 0); + + if (ret < 0) + { + i2cerr("registering i2c0 faild.\n"); + } + else + { + i2cinfo("registering i2c0 successed.\n"); + } + } + + i2c = NULL; +#endif +#ifdef CONFIG_GD32F4_I2C1 + i2c = gd32_i2cbus_initialize(1); + + if (i2c == NULL) + { + i2cerr("init i2c1 faild.\n"); + return; + } + else + { + ret = i2c_register(i2c, 1); + + if (ret < 0) + { + i2cerr("registering i2c1 faild.\n"); + } + else + { + i2cinfo("registering i2c1 successed.\n"); + } + } + +#endif +} + +#endif \ No newline at end of file diff --git a/boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_romfs.c b/boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_romfs.c new file mode 100644 index 00000000000..1dccd7521ee --- /dev/null +++ b/boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_romfs.c @@ -0,0 +1,137 @@ +/**************************************************************************** + * boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_romfs.c + * + * 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 + +#include +#include +#include +#include +#include + +#include +#include +#include "gd32f4xx_romfs.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifndef CONFIG_GD32F4_ROMFS +# error "CONFIG_GD32F4_ROMFS must be defined" +#else + +#ifndef CONFIG_GD32F4_ROMFS_IMAGEFILE +# error "CONFIG_GD32F4_ROMFS_IMAGEFILE must be defined" +#endif + +#ifndef CONFIG_GD32F4_ROMFS_DEV_MINOR +# error "CONFIG_GD32F4_ROMFS_DEV_MINOR must be defined" +#endif + +#ifndef CONFIG_GD32F4_ROMFS_MOUNTPOINT +# error "CONFIG_GD32F4_ROMFS_MOUNTPOINT must be defined" +#endif + +#define NSECTORS(size) (((size) + ROMFS_SECTOR_SIZE - 1)/ROMFS_SECTOR_SIZE) + +#define STR2(m) #m +#define STR(m) STR2(m) + +#define MKMOUNT_DEVNAME(m) "/dev/ram" STR(m) +#define MOUNT_DEVNAME MKMOUNT_DEVNAME(CONFIG_GD32F4_ROMFS_DEV_MINOR) + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +__asm__ ( + " .section .rodata \n" + " .balign 16 \n" + " .globl romfs_data_begin \n" + "romfs_data_begin: \n" + " .incbin " STR(CONFIG_GD32F4_ROMFS_IMAGEFILE)"\n" + " .balign " STR(ROMFS_SECTOR_SIZE) "\n" + " .globl romfs_data_end \n" + "romfs_data_end: \n" + ); + +extern const uint8_t romfs_data_begin[]; +extern const uint8_t romfs_data_end[]; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: gd32_romfs_initialize + * + * Description: + * Registers the aboveincluded binary file as block device. + * Then mounts the block device as ROMFS filesystems. + * + * Returned Value: + * Zero (OK) on success, a negated errno value on error. + * + * Assumptions/Limitations: + * Memory addresses [romfs_data_begin .. romfs_data_end) should contain + * ROMFS volume data, as included in the assembly snippet above. + * + ****************************************************************************/ + +int gd32_romfs_initialize(void) +{ + uintptr_t romfs_data_len; + int ret; + + /* Create a ROM disk for the /etc filesystem */ + + romfs_data_len = romfs_data_end - romfs_data_begin; + + ret = romdisk_register(CONFIG_GD32F4_ROMFS_DEV_MINOR, romfs_data_begin, + NSECTORS(romfs_data_len), ROMFS_SECTOR_SIZE); + if (ret < 0) + { + ferr("ERROR: romdisk_register failed: %d\n", -ret); + return ret; + } + + /* Mount the file system */ + + finfo("Mounting ROMFS filesystem at target=%s with source=%s\n", + CONFIG_GD32F4_ROMFS_MOUNTPOINT, MOUNT_DEVNAME); + + ret = nx_mount(MOUNT_DEVNAME, CONFIG_GD32F4_ROMFS_MOUNTPOINT, + "romfs", MS_RDONLY, NULL); + if (ret < 0) + { + ferr("ERROR: nx_mount(%s,%s,romfs) failed: %d\n", + MOUNT_DEVNAME, CONFIG_GD32F4_ROMFS_MOUNTPOINT, ret); + return ret; + } + + return OK; +} + +#endif /* CONFIG_GD32F4_ROMFS */ diff --git a/boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_romfs.h b/boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_romfs.h new file mode 100644 index 00000000000..4f07aa926fa --- /dev/null +++ b/boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_romfs.h @@ -0,0 +1,62 @@ +/**************************************************************************** + * boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_romfs.h + * + * 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_GD32F4_GD32F450ZK_AIOTBOX_SRC_GD32F4XX_ROMFS_H +#define __BOARDS_ARM_GD32F4_GD32F450ZK_AIOTBOX_SRC_GD32F4XX_ROMFS_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#ifdef CONFIG_GD32F4_ROMFS + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define ROMFS_SECTOR_SIZE 64 + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: gd32_romfs_initialize + * + * Description: + * Registers built-in ROMFS image as block device and mounts it. + * + * Returned Value: + * Zero (OK) on success, a negated errno value on error. + * + * Assumptions/Limitations: + * Memory addresses [romfs_data_begin .. romfs_data_end) should contain + * ROMFS volume data, as included in the assembly snippet in + * gd32f4xx_romfs.c. + * + ****************************************************************************/ + +int gd32_romfs_initialize(void); + +#endif /* CONFIG_GD32F4_ROMFS */ + +#endif /* __BOARDS_ARM_GD32F4_GD32F450ZK_EVAL_SRC_GD32F4XX_ROMFS_H */ diff --git a/boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_sdio.c b/boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_sdio.c new file mode 100644 index 00000000000..b60338c2257 --- /dev/null +++ b/boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_sdio.c @@ -0,0 +1,149 @@ +/**************************************************************************** + * boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_sdio.c + * + * 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 + +#include +#include +#include +#include + +#include +#include + +#include "chip.h" +#include "gd32f4xx.h" +#include "gd32f450z_aiotbox.h" + +#ifdef CONFIG_MMCSD + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Configuration ************************************************************/ + +/* Card detections requires card support and a card detection GPIO */ + +#define HAVE_NCD 1 +#if !defined(GPIO_SDMMC1_NCD) +# undef HAVE_NCD +#endif + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static struct sdio_dev_s *g_sdio_dev; +#ifdef HAVE_NCD +static bool g_sd_inserted; +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: gd32_ncd_interrupt + * + * Description: + * Card detect interrupt handler. + * + ****************************************************************************/ + +#ifdef HAVE_NCD +static int gd32_ncd_interrupt(int irq, void *context) +{ + bool present; + + present = !gd32_gpio_read(GPIO_SDMMC1_NCD); + if (g_sdio_dev && present != g_sd_inserted) + { + sdio_mediachange(g_sdio_dev, present); + g_sd_inserted = present; + } + + return OK; +} +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: gd32_sdio_initialize + * + * Description: + * Initialize SDIO-based MMC/SD card support + * + ****************************************************************************/ + +int gd32_sdio_initialize(void) +{ + int ret; + + /* Mount the SDIO-based MMC/SD block driver + * First, get an instance of the SDIO interface + */ + + finfo("Initializing SDIO slot %d\n", SDIO_SLOTNO); + + g_sdio_dev = sdio_initialize(SDIO_SLOTNO); + if (!g_sdio_dev) + { + ferr("ERROR: Failed to initialize SDIO slot %d\n", SDIO_SLOTNO); + return -ENODEV; + } + + /* Now bind the SDIO interface to the MMC/SD driver */ + + finfo("Bind SDIO to the MMC/SD driver, minor=%d\n", SDIO_MINOR); + + ret = mmcsd_slotinitialize(SDIO_MINOR, g_sdio_dev); + if (ret != OK) + { + ferr("ERROR: Failed to bind SDIO to the MMC/SD driver: %d\n", ret); + return ret; + } + + finfo("Successfully bound SDIO to the MMC/SD driver\n"); + +#ifdef HAVE_NCD + /* Use SD card detect pin to check if a card is g_sd_inserted */ + + g_sd_inserted = !gd32_gpio_read(GPIO_SDMMC1_NCD); + finfo("Card detect : %d\n", g_sd_inserted); + + sdio_mediachange(g_sdio_dev, g_sd_inserted); +#else + /* Assume that the SD card is inserted. What choice do we have? */ + + sdio_mediachange(g_sdio_dev, true); +#endif + + return OK; +} + +#endif /* CONFIG_MMCSD */ diff --git a/boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_spi.c b/boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_spi.c new file mode 100644 index 00000000000..e0a133ad244 --- /dev/null +++ b/boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_spi.c @@ -0,0 +1,283 @@ +/**************************************************************************** + * boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_spi.c + * + * 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 + +#include +#include +#include +#include + +#include +#include + +#include "chip.h" +#include "gd32f4xx.h" +#include "gd32f450z_aiotbox.h" + +#if defined(CONFIG_SPI) + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: gd32_spidev_initialize + * + * Description: + * Called to configure SPI chip select GPIO pins for the GD32F450Z-EVAL. + * + ****************************************************************************/ + +void weak_function gd32_spidev_initialize(void) +{ +#ifdef CONFIG_GD32F4_SPI0 + /* Configure SPI0 CS GPIO for output */ + + gd32_gpio_config(GPIO_SPI0_CSPIN); + gd32_gpio_write(GPIO_SPI0_CSPIN, 1); +#endif +#ifdef CONFIG_GD32F4_SPI1 + /* Configure SPI1 CS GPIO for output */ + + gd32_gpio_config(GPIO_SPI1_CSPIN); + gd32_gpio_write(GPIO_SPI1_CSPIN, 1); +#endif +#ifdef CONFIG_GD32F4_SPI2 + /* Configure SPI2 CS GPIO for output */ + + gd32_gpio_config(GPIO_SPI2_CSPIN); + gd32_gpio_write(GPIO_SPI2_CSPIN, 1); +#endif +#ifdef CONFIG_GD32F4_SPI3 + /* Configure SPI3 CS GPIO for output */ + + gd32_gpio_config(GPIO_SPI3_CSPIN); + gd32_gpio_write(GPIO_SPI3_CSPIN, 1); +#endif +#ifdef CONFIG_GD32F4_SPI4 + /* Configure SPI4 CS GPIO for output */ + + gd32_gpio_config(GPIO_SPI4_CSPIN); + gd32_gpio_write(GPIO_SPI4_CSPIN, 1); +#endif +#ifdef CONFIG_GD32F4_SPI5 + /* Configure SPI5 CS GPIO for output */ + + gd32_gpio_config(GPIO_SPI5_CSPIN); + gd32_gpio_write(GPIO_SPI5_CSPIN, 1); +#endif +} + +/**************************************************************************** + * Name: gd32_spi[n]select and gd32_spi[n]status + * + * Description: + * The external functions, gd32_spi0-5select and gd32_spi0-5 status + * must be provided by board-specific logic. They are implementations of the + * select and status methods of the SPI interface defined by struct spi_ops_s + * (see include/nuttx/spi/spi.h). + * All other methods (including gd32_spibus_initialize()) are provided by + * common GD32F4 logic. To use this common SPI logic on your board: + * + * 1. Provide logic in gd32_boardinitialize() to configure SPI chip select + * pins. + * 2. Provide gd32_spi[n]select() and gd32_spi[n]status() functions + * in your board-specific logic. These functions will perform chip + * selection and status operations using GPIOs in the way your board is + * configured. + * 3. Add a calls to gd32_spibus_initialize() in your low level + * application initialization logic + * 4. The handle returned by gd32_spibus_initialize() may then be used to + * bind the SPI driver to higher level logic (e.g., calling + * mmcsd_spislotinitialize(), for example, will bind the SPI driver to + * the SPI MMC/SD driver). + * + ****************************************************************************/ + +#ifdef CONFIG_GD32F4_SPI0 +void gd32_spi0select(struct spi_dev_s *dev, uint32_t devid, + bool selected) +{ + spiinfo("devid: %d CS: %s\n", (int)devid, + selected ? "assert" : "de-assert"); + + gd32_gpio_write(GPIO_SPI0_CSPIN, !selected); +} + +uint8_t gd32_spi0status(struct spi_dev_s *dev, uint32_t devid) +{ + return 0; +} +#endif + +#ifdef CONFIG_GD32F4_SPI1 +void gd32_spi1select(struct spi_dev_s *dev, uint32_t devid, + bool selected) +{ + spiinfo("devid: %d CS: %s\n", (int)devid, + selected ? "assert" : "de-assert"); + + gd32_gpio_write(GPIO_SPI1_CSPIN, !selected); +} + +uint8_t gd32_spi1status(struct spi_dev_s *dev, uint32_t devid) +{ + return 0; +} +#endif + +#ifdef CONFIG_GD32F4_SPI2 +void gd32_spi2select(struct spi_dev_s *dev, uint32_t devid, + bool selected) +{ + spiinfo("devid: %d CS: %s\n", (int)devid, + selected ? "assert" : "de-assert"); + + gd32_gpio_write(GPIO_SPI2_CSPIN, !selected); +} + +uint8_t gd32_spi2status(struct spi_dev_s *dev, uint32_t devid) +{ + return 0; +} +#endif + +#ifdef CONFIG_GD32F4_SPI3 +void gd32_spi3select(struct spi_dev_s *dev, uint32_t devid, + bool selected) +{ + spiinfo("devid: %d CS: %s\n", (int)devid, + selected ? "assert" : "de-assert"); + + gd32_gpio_write(GPIO_SPI3_CSPIN, !selected); +} + +uint8_t gd32_spi3status(struct spi_dev_s *dev, uint32_t devid) +{ + return 0; +} +#endif + +#ifdef CONFIG_GD32F4_SPI4 +void gd32_spi4select(struct spi_dev_s *dev, uint32_t devid, + bool selected) +{ + spiinfo("devid: %d CS: %s\n", (int)devid, + selected ? "assert" : "de-assert"); + + gd32_gpio_write(GPIO_SPI4_CSPIN, !selected); +} + +uint8_t gd32_spi4status(struct spi_dev_s *dev, uint32_t devid) +{ + return 0; +} +#endif + +#ifdef CONFIG_GD32F4_SPI5 +void gd32_spi5select(struct spi_dev_s *dev, uint32_t devid, + bool selected) +{ + spiinfo("devid: %d CS: %s\n", (int)devid, + selected ? "assert" : "de-assert"); + + gd32_gpio_write(GPIO_SPI5_CSPIN, !selected); +} + +uint8_t gd32_spi5status(struct spi_dev_s *dev, uint32_t devid) +{ + return 0; +} +#endif + +/**************************************************************************** + * Name: gd32_spi[n]cmddata + * + * Description: + * Set or clear the SH1101A A0 or SD1306 D/C n bit to select data (true) + * or command (false). This function must be provided by platform-specific + * logic. This is an implementation of the cmddata method of the SPI + * interface defined by struct spi_ops_s (see include/nuttx/spi/spi.h). + * + * Input Parameters: + * + * spi - SPI device that controls the bus the device that requires the CMD/ + * DATA selection. + * devid - If there are multiple devices on the bus, this selects which one + * to select cmd or data. NOTE: This design restricts, for example, + * one one SPI display per SPI bus. + * cmd - true: select command; false: select data + * + * Returned Value: + * None + * + ****************************************************************************/ + +#ifdef CONFIG_SPI_CMDDATA +#ifdef CONFIG_GD32F4_SPI0 +int gd32_spi0cmddata(struct spi_dev_s *dev, uint32_t devid, bool cmd) +{ + return -ENODEV; +} +#endif + +#ifdef CONFIG_GD32F4_SPI1 +int gd32_spi1cmddata(struct spi_dev_s *dev, uint32_t devid, bool cmd) +{ + return -ENODEV; +} +#endif + +#ifdef CONFIG_GD32F4_SPI2 +int gd32_spi2cmddata(struct spi_dev_s *dev, uint32_t devid, bool cmd) +{ + return -ENODEV; +} +#endif + +#ifdef CONFIG_GD32F4_SPI3 +int gd32_spi3cmddata(struct spi_dev_s *dev, uint32_t devid, bool cmd) +{ + return -ENODEV; +} +#endif + +#ifdef CONFIG_GD32F4_SPI5 +int gd32_spi4cmddata(struct spi_dev_s *dev, uint32_t devid, bool cmd) +{ + return -ENODEV; +} +#endif + +#ifdef CONFIG_GD32F4_SPI5 +int gd32_spi5cmddata(struct spi_dev_s *dev, uint32_t devid, bool cmd) +{ + return -ENODEV; +} +#endif + +#endif /* CONFIG_SPI_CMDDATA */ + +#endif /* defined(CONFIG_SPI) */ diff --git a/boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_userleds.c b/boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_userleds.c new file mode 100644 index 00000000000..554f3de9c32 --- /dev/null +++ b/boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_userleds.c @@ -0,0 +1,149 @@ +/**************************************************************************** + * boards/arm/gd32f4/gd32f450zk-aiotbox/src/gd32f4xx_userleds.c + * + * 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 + +#include +#include + +#include + +#include +#include + +#include "gd32f4xx_gpio.h" +#include "gd32f450z_aiotbox.h" + +#ifndef CONFIG_ARCH_LEDS + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* LED index */ + +static const uint32_t g_led_map[BOARD_LEDS] = +{ + LED1, + LED2, + LED3 +}; + +static const uint32_t g_led_setmap[BOARD_LEDS] = +{ + BOARD_LED1_BIT, + BOARD_LED2_BIT, + BOARD_LED3_BIT +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/* Turn on selected led */ + +static void gd32_aiotbox_led_on(led_typedef_enum led_num) +{ + gd32_gpio_write(g_led_map[led_num], true); +} + +/* Turn off selected led */ + +static void gd32_aiotbox_led_off(led_typedef_enum led_num) +{ + gd32_gpio_write(g_led_map[led_num], false); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_userled_initialize + * + * Description: + * If CONFIG_ARCH_LEDS is defined, then NuttX will control the on-board + * LEDs. If CONFIG_ARCH_LEDS is not defined, then the + * board_userled_initialize() is available to initialize the LED from user + * application logic. + * + ****************************************************************************/ + +uint32_t board_userled_initialize(void) +{ + int i; + + /* Configure the LED GPIO for output. */ + + for (i = 0; i < nitems(g_led_map); i++) + { + gd32_gpio_config(g_led_map[i]); + } + + return BOARD_LEDS; +} + +/**************************************************************************** + * Name: board_userled + * + * Description: + * If CONFIG_ARCH_LEDS is defined, then NuttX will control the on-board + * LEDs. If CONFIG_ARCH_LEDS is not defined, then the board_userled() is + * available to control the LED from user application logic. + * + ****************************************************************************/ + +void board_userled(int led, bool ledon) +{ + if ((unsigned)led < nitems(g_led_map)) + { + gd32_gpio_write(g_led_map[led], ledon); + } +} + +/**************************************************************************** + * Name: board_userled_all + * + * Description: + * If CONFIG_ARCH_LEDS is defined, then NuttX will control the on-board + * LEDs. If CONFIG_ARCH_LEDS is not defined, then the board_userled_all() + * is available to control the LED from user application logic. + * NOTE: since there is only a single LED on-board, this is function + * is not very useful. + * + ****************************************************************************/ + +void board_userled_all(uint32_t ledset) +{ + int i; + + /* Configure LED1-3 GPIOs for output */ + + for (i = 0; i < nitems(g_led_map); i++) + { + gd32_gpio_write(g_led_map[i], (ledset & g_led_setmap[i]) != 0); + } +} + +#endif /* !CONFIG_ARCH_LEDS */ diff --git a/boards/arm/gd32f4/gd32f470zk-aiotbox/Kconfig b/boards/arm/gd32f4/gd32f470zk-aiotbox/Kconfig new file mode 100644 index 00000000000..0b2870d2ba4 --- /dev/null +++ b/boards/arm/gd32f4/gd32f470zk-aiotbox/Kconfig @@ -0,0 +1,143 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +if ARCH_BOARD_GD32F470ZK_AIOTBOX + +choice + prompt "Select Console wiring." + default GD32F470ZK_AIOTBOX_CONSOLE_BOARD + ---help--- + Select where you will connect the console. + + Virtual COM Port: + + Advantage: Use the ST-Link as a console. No Extra wiring + needed. + + Disadvantage: Not the best choice for initial bring up. + + BOARD USART Connector: + + Advantage: You have a shield so it is easy. + + Disadvantage: You loose the use of the + other functions on PA9, PA10 + + GD32F470ZK_AIOTBOX + USART0 GPIO + -- ----- --------- ---- + RX USART0_RX PA10 + TX USART0_TX PA9 + -- ----- --------- --- + +config GD32F470ZK_AIOTBOX_CONSOLE_BOARD + bool "Aiotbox Com Connector" + select GD32_USART0 + select USART0_SERIALDRIVER + +config GD32F470ZK_AIOTBOX_CONSOLE_VIRTUAL + bool "Virtual ComPort" + select GD32_USART3 + select USART3_SERIALDRIVER + +config GD32F470ZK_AIOTBOX_CONSOLE_NONE + bool "No Serial Console" + +endchoice # "Select Console wiring" + + +choice + prompt "GD32F470Z MCU Crystal Selected" + default GD32F470Z_BOARD_USE_HXTAL_AIOTBOX + +config GD32F470Z_BOARD_USE_HXTAL_AIOTBOX + bool "Use Hxtal as clock source" + # select GD32F470Z_BOARD_HXTAL_VALUE + +config GD32F470Z_BOARD_USE_IRC16_AIOTBOX + bool "Use IRC16M as clock source" + +endchoice # CPU Frequency + +config GD32F470Z_BOARD_HXTAL_VALUE + int "GD32F470Z Eval Board Hxtal Value" + default 25000000 + depends on GD32F470Z_BOARD_USE_HXTAL + ---help--- + GD32F470Z Eval Board Hxtal Value, default is 25MHz. + +choice + prompt "GD32F470 MCU System Frequency" + default GD32F470_200MHZ_AIOTBOX + +config GD32F470_240MHZ_AIOTBOX + bool "240 MHz" + +config GD32F470_200MHZ_AIOTBOX + bool "200 MHz" + +config GD32F470_168MHZ_AIOTBOX + bool "168 MHz" + +config GD32F470_120MHZ_AIOTBOX + bool "120 MHz" + +endchoice # CPU Frequency + + +config GD32F470ZK_AIOTBOX_GD25_BLOCKMOUNT + bool "GD25 serial FLASH auto-mount" + default n + depends on GD32F4_SPI5 && MTD_GD25 + ---help--- + Automatically initialize the GD25 SPI FLASH driver when NSH starts. + +choice + prompt "GD25 SPI FLASH configuration" + default GD32F470ZK_AIOTBOX_GD25_NXFFS + depends on GD32F470ZK_AIOTBOX_GD25_BLOCKMOUNT + +config GD32F470ZK_AIOTBOX_GD25_FTL + bool "Create GD25 SPI FLASH block driver" + ---help--- + Create the MTD driver for the GD25 and "wrap" the GD25 as a standard + block driver that could then, for example, be mounted using FAT or + any other file system. Any file system may be used, but there will + be no wear-leveling. + +config GD32F470ZK_AIOTBOX_GD25_NXFFS + bool "Create GD25 serial FLASH NXFFS file system" + depends on FS_NXFFS + ---help--- + Create the MTD driver for the GD25 and mount the GD25 device as + a wear-leveling, NuttX FLASH file system (NXFFS). The downside of + NXFFS is that it can be very slow. + +config GD32F470ZK_AIOTBOX_GD25_LITTLEFS + bool "Create GD25 serial FLASH LFS file system" + depends on FS_LITTLEFS + ---help--- + Create the MTD driver for the GD25 and mount the GD25 device as + a wear-leveling, LittleFS FLASH file system (LFS). + +endchoice # GD25 serial FLASH configuration + +config GD32F470ZK_AIOTBOX_AT24_TEST + bool "I2C0 EEPROM AT2402 write and read test" + default n + depends on NSH_ARCHINIT && GD32F4_I2C0 && MTD_AT24XX + ---help--- + Automatically initialize and test the AT24 I2C EEPROM driver when + NSH starts. After test the I2C0 will be released. + +config AT24XX_MTD_BLOCKSIZE + int "AT24xx MTD block size" + default 8 + depends on GD32F470ZK_AIOTBOX_AT24_TEST + ---help--- + The block size must be an even multiple of the pages. + The page size of AT2402 on the board is 8 Byte. + +endif # ARCH_BOARD_GD32F470ZK_AIOTBOX diff --git a/boards/arm/gd32f4/gd32f470zk-aiotbox/configs/aiotboxnsh/defconfig b/boards/arm/gd32f4/gd32f470zk-aiotbox/configs/aiotboxnsh/defconfig new file mode 100644 index 00000000000..2c4654e8850 --- /dev/null +++ b/boards/arm/gd32f4/gd32f470zk-aiotbox/configs/aiotboxnsh/defconfig @@ -0,0 +1,61 @@ +# +# 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_FPU is not set +CONFIG_ARCH="arm" +CONFIG_ARCH_BOARD="gd32f470zk-aiotbox" +CONFIG_ARCH_BOARD_GD32F470ZK_AIOTBOX=y +CONFIG_ARCH_BUTTONS=y +CONFIG_ARCH_CHIP="gd32f4" +CONFIG_ARCH_CHIP_GD32F470ZK=y +CONFIG_ARCH_CHIP_GD32F4=y +CONFIG_ARCH_INTERRUPTSTACK=256 +CONFIG_ARCH_STACKDUMP=y +CONFIG_BOARD_LOOPSPERMSEC=16717 +CONFIG_BUILTIN=y +CONFIG_DEBUG_CUSTOMOPT=y +CONFIG_DEBUG_FEATURES=y +CONFIG_DEBUG_IRQ=y +CONFIG_DEBUG_LEDS=y +CONFIG_DEBUG_OPTLEVEL="-O0" +CONFIG_DEBUG_SCHED=y +CONFIG_DEBUG_SYMBOLS=y +CONFIG_GD32F4_DISABLE_IDLE_SLEEP_DURING_DEBUG=y +CONFIG_GD32F4_FLASH_CONFIG_K=y +CONFIG_GD32F4_I2C0=y +CONFIG_GD32F4_I2C1=y +CONFIG_GD32F4_SPI4=y +CONFIG_GD32F4_UART6=y +CONFIG_GD32F4_UART7=y +CONFIG_GD32F4_USART1=y +CONFIG_GD32F4_USART2=y +CONFIG_GD32F4_USART5=y +CONFIG_HAVE_CXX=y +CONFIG_HAVE_CXXINITIALIZE=y +CONFIG_I2C=y +CONFIG_I2C_POLLED=y +CONFIG_I2C_RESET=y +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_INTELHEX_BINARY=y +CONFIG_MM_REGIONS=2 +CONFIG_NSH_ARCHINIT=y +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_FILEIOSIZE=512 +CONFIG_NSH_LINELEN=64 +CONFIG_NSH_READLINE=y +CONFIG_RAM_SIZE=114688 +CONFIG_RAM_START=0x20000000 +CONFIG_RAW_BINARY=y +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_WAITPID=y +CONFIG_START_DAY=6 +CONFIG_START_MONTH=12 +CONFIG_START_YEAR=2011 +CONFIG_SYSTEM_I2CTOOL=y +CONFIG_SYSTEM_NSH=y +CONFIG_TASK_NAME_SIZE=0 +CONFIG_USART0_SERIAL_CONSOLE=y diff --git a/boards/arm/gd32f4/gd32f470zk-aiotbox/include/board.h b/boards/arm/gd32f4/gd32f470zk-aiotbox/include/board.h new file mode 100644 index 00000000000..c2821e9657e --- /dev/null +++ b/boards/arm/gd32f4/gd32f470zk-aiotbox/include/board.h @@ -0,0 +1,460 @@ +/**************************************************************************** + * boards/arm/gd32f4/gd32f470zk-aiotbox/include/board.h + * + * 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_GD32F470ZK_AIOTBOX_INCLUDE_BOARD_H +#define __BOARDS_ARM_GD32F470ZK_AIOTBOX_INCLUDE_BOARD_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#ifndef __ASSEMBLY__ +# include +#endif + +#define GD32_BOARD_SYSCLK_PLL_HXTAL + +/* Do not include GD32F4 header files here */ + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Clocking *****************************************************************/ + +/* The GD32F470ZK-EVAL board features a single 25MHz crystal. + * + * This is the default configuration: + * System clock source : PLL (HXTAL) + * SYSCLK(Hz) : 200000000 Determined by PLL config + * HCLK(Hz) : 200000000 (GD32_SYSCLK_FREQUENCY) + * AHB Prescaler : 1 (GD32_RCU_CFG0_AHB_PSC) + * APB2 Prescaler : 2 (GD32_RCU_CFG0_APB2_PSC) + * APB1 Prescaler : 4 (GD32_RCU_CFG0_APB1_PSC) + * HXTAL value(Hz) : 25000000 (GD32_BOARD_XTAL) + * PLLM : 25 (GD32_PLL_PLLM) + * PLLN : 400 (RCU_PLL_PLLN) + * PLLP : 2 (GD32_PLL_PLLP) + * PLLQ : 7 (GD32_PLL_PLLQ) + */ + +/* IRC16M - 16 MHz RC factory-trimmed + * IRC32K - 32 KHz RC + * HXTAL - On-board crystal frequency is 25MHz + * LXTAL - 32.768 kHz + */ + +#ifndef CONFIG_GD32F470_BOARD_HXTAL_VALUE +# define GD32_BOARD_HXTAL 25000000ul +#else +# define GD32_BOARD_HXTAL CONFIG_GD32F470_BOARD_HXTAL_VALUE +#endif + +#define GD32_IRC16M_VALUE 16000000ul +#define GD32_IRC32K_VALUE 32000u +#define GD32_HXTAL_VALUE GD32_BOARD_HXTAL +#define GD32_LXTAL_VALUE 32768u + +#if defined(CONFIG_GD32F470_200MHZ_AIOTBOX) + +/* Main PLL Configuration. + * + * PLL source is HXTAL + * PLL_VCO = (GD32_HXTAL_VALUE / PLLM) * PLLN + * = (25,000,000 / 25) * 400 + * = 400,000,000 + * SYSCLK = PLL_VCO / PLLP + * = 400,000,000 / 2 = 168,000,000 + * USB, SDIO and RNG Clock + * = PLL_VCO / PLLQ + * = 48,000,000 + */ + +#define GD32_PLL_PLLPSC RCU_PLL_PLLPSC(25) +#define GD32_PLL_PLLN RCU_PLL_PLLN(400) +#define GD32_PLL_PLLP RCU_PLL_PLLP(2) +#define GD32_PLL_PLLQ RCU_PLL_PLLQ(7) + +#define GD32_SYSCLK_FREQUENCY 200000000ul + +#elif defined(CONFIG_GD32F470_168MHZ_AIOTBOX) + +/* Main PLL Configuration. + * + * PLL source is HXTAL + * PLL_VCO = (GD32_HXTAL_VALUE / PLLM) * PLLN + * = (25,000,000 / 25) * 336 + * = 336,000,000 + * SYSCLK = PLL_VCO / PLLP + * = 336,000,000 / 2 = 168,000,000 + * USB, SDIO and RNG Clock + * = PLL_VCO / PLLQ + * = 48,000,000 + */ + +#define GD32_PLL_PLLPSC RCU_PLL_PLLPSC(25) +#define GD32_PLL_PLLN RCU_PLL_PLLN(336) +#define GD32_PLL_PLLP RCU_PLL_PLLP(2) +#define GD32_PLL_PLLQ RCU_PLL_PLLQ(7) + +#define GD32_SYSCLK_FREQUENCY 168000000ul + +#elif defined(CONFIG_GD32F470_240MHZ_AIOTBOX) + +/* Main PLL Configuration. + * + * PLL source is HXTAL + * PLL_VCO = (GD32_HXTAL_VALUE / PLLM) * PLLN + * = (25,000,000 / 25) * 336 + * = 336,000,000 + * SYSCLK = PLL_VCO / PLLP + * = 336,000,000 / 2 = 168,000,000 + * USB, SDIO and RNG Clock + * = PLL_VCO / PLLQ + * = 48,000,000 + */ + +#define GD32_PLL_PLLPSC RCU_PLL_PLLPSC(25) +#define GD32_PLL_PLLN RCU_PLL_PLLN(480) +#define GD32_PLL_PLLP RCU_PLL_PLLP(2) +#define GD32_PLL_PLLQ RCU_PLL_PLLQ(7) + +#define GD32_SYSCLK_FREQUENCY 240000000ul + +#endif + +/* AHB clock (HCLK) is SYSCLK */ + +#define GD32_RCU_CFG0_AHB_PSC RCU_CFG0_AHBPSC_CKSYS_DIV1 /* HCLK = SYSCLK / 1 */ +#define GD32_HCLK_FREQUENCY GD32_SYSCLK_FREQUENCY + +/* APB2 clock (PCLK2) is HCLK/2 */ + +#define GD32_RCU_CFG0_APB2_PSC RCU_CFG0_APB2PSC_CKAHB_DIV2 /* PCLK2 = HCLK / 2 */ +#define GD32_PCLK2_FREQUENCY (GD32_HCLK_FREQUENCY/2) + +/* APB1 clock (PCLK1) is HCLK/4 */ + +#define GD32_RCU_CFG0_APB1_PSC RCU_CFG0_APB1PSC_CKAHB_DIV4 /* PCLK1 = HCLK / 4 */ +#define GD32_PCLK1_FREQUENCY (GD32_HCLK_FREQUENCY / 4) + +/* Timers driven from APB1 will be twice PCLK1 */ + +#define GD32_APB1_TIMER2_CLKIN (2*GD32_PCLK1_FREQUENCY) +#define GD32_APB1_TIMER3_CLKIN (2*GD32_PCLK1_FREQUENCY) +#define GD32_APB1_TIMER4_CLKIN (2*GD32_PCLK1_FREQUENCY) +#define GD32_APB1_TIMER5_CLKIN (2*GD32_PCLK1_FREQUENCY) +#define GD32_APB1_TIMER6_CLKIN (2*GD32_PCLK1_FREQUENCY) +#define GD32_APB1_TIMER7_CLKIN (2*GD32_PCLK1_FREQUENCY) +#define GD32_APB1_TIMER12_CLKIN (2*GD32_PCLK1_FREQUENCY) +#define GD32_APB1_TIMER13_CLKIN (2*GD32_PCLK1_FREQUENCY) +#define GD32_APB1_TIMER14_CLKIN (2*GD32_PCLK1_FREQUENCY) + +/* Timers driven from APB2 will be twice PCLK2 */ + +#define GD32_APB2_TIMER1_CLKIN (2*GD32_PCLK2_FREQUENCY) +#define GD32_APB2_TIMER8_CLKIN (2*GD32_PCLK2_FREQUENCY) +#define GD32_APB2_TIMER9_CLKIN (2*GD32_PCLK2_FREQUENCY) +#define GD32_APB2_TIMER10_CLKIN (2*GD32_PCLK2_FREQUENCY) +#define GD32_APB2_TIMER11_CLKIN (2*GD32_PCLK2_FREQUENCY) + +/* Timer Frequencies, if APBx is set to 1, frequency is same to APBx + * otherwise frequency is 2xAPBx. + * Note: TIMER1,8 are on APB2, others on APB1 + */ + +#define BOARD_TIMER1_FREQUENCY GD32_HCLK_FREQUENCY +#define BOARD_TIMER2_FREQUENCY (GD32_HCLK_FREQUENCY/2) +#define BOARD_TIMER3_FREQUENCY (GD32_HCLK_FREQUENCY/2) +#define BOARD_TIMER4_FREQUENCY (GD32_HCLK_FREQUENCY/2) +#define BOARD_TIMER5_FREQUENCY (GD32_HCLK_FREQUENCY/2) +#define BOARD_TIMER6_FREQUENCY (GD32_HCLK_FREQUENCY/2) +#define BOARD_TIMER7_FREQUENCY (GD32_HCLK_FREQUENCY/2) +#define BOARD_TIMER8_FREQUENCY GD32_HCLK_FREQUENCY + +/* LED definitions **********************************************************/ + +/* The GD32F470ZK_EVAL board has board has three LEDs. The LED1, LED2 and + * LED3 are controlled by GPIO. LED1 is connected to PD4, LED2 is connected + * to PD5, LED3 is connected to PG3 + * + * If CONFIG_ARCH_LEDS is not defined, then the user can control the LEDs + * in any way. + * The following definitions are used to access individual LEDs. + */ + +/* LED index values */ + +typedef enum +{ + BOARD_LED1 = 0, + BOARD_LED2 = 1, + BOARD_LED3 = 2, + BOARD_LEDS +} led_typedef_enum; + +/* LED bits */ + +#define BOARD_LED1_BIT (1 << BOARD_LED1) +#define BOARD_LED2_BIT (1 << BOARD_LED2) +#define BOARD_LED3_BIT (1 << BOARD_LED3) + +/* If CONFIG_ARCH_LEDS is defined, the usage by the board port is defined in + * include/board.h and src/gd32f4xx_autoleds.c. The LEDs are used to encode + * OS-related events as follows: + * + * + * SYMBOL Meaning LED state + * LED1 LED2 LED3 + * ---------------------- -------------------------- ------ ------ --- + */ + +#define LED_STARTED 0 /* NuttX has been started OFF OFF OFF */ +#define LED_HEAPALLOCATE 1 /* Heap has been allocated ON OFF OFF */ +#define LED_IRQSENABLED 2 /* Interrupts enabled OFF ON OFF */ +#define LED_STACKCREATED 3 /* Idle stack created OFF OFF ON */ +#define LED_INIRQ 4 /* In an interrupt ON ON OFF */ +#define LED_SIGNAL 5 /* In a signal handler ON OFF ON */ +#define LED_ASSERTION 6 /* An assertion failed OFF ON ON */ +#define LED_PANIC 7 /* The system has crashed FLASH ON ON */ +#define LED_IDLE 8 /* MCU is is sleep mode OFF FLASH OFF */ + +/* Button definitions *******************************************************/ + +/* The GD32F470Z Eval supports three user buttons: Wakeup, Tamper and + * User key, they are connected to GPIO PA0, PC13, PB14. + * A low value will be sensed when the button is depressed. + */ + +typedef enum +{ + BUTTON_WAKEUP = 0, + BUTTON_TAMPER = 1, + BUTTON_USER = 2, + NUM_BUTTONS +} key_typedef_enum; + +#define BUTTON_WAKEUP_BIT (1 << BUTTON_WAKEUP) +#define BUTTON_TAMPER_BIT (1 << BUTTON_TAMPER) +#define BUTTON_USER_BIT (1 << BUTTON_USER) + +/* Alternate function pin selections ****************************************/ + +#if defined(CONFIG_GD32F470ZK_AIOTBOX_CONSOLE_BOARD) + +/* USART0: + * + * These configurations assume that you are using a standard RS-232 + * shield with the serial interface with RX on PA10 and TX on PA10: + * + * -------- --------------- + * GD32F470ZK-EVAL + * -- ----- --------- ----- + * RX USART0_RX PA10 + * TX USART0_TX PA9 + * -- ----- --------- ----- + */ + +# define GPIO_USART0_RX GPIO_USART0_RX_1 +# define GPIO_USART0_TX GPIO_USART0_TX_1 + +#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_USART0_IFLOWCONTROL) +# define GPIO_USART0_RTS GPIO_USART0_RTS_1 +# endif +#if defined(CONFIG_SERIAL_OFLOWCONTROL) && defined(CONFIG_USART0_OFLOWCONTROL) +# define GPIO_USART0_CTS GPIO_USART0_CTS_1 +# endif +#endif + +#if CONFIG_GD32F4_USART0_TXDMA +# define DMA_CHANNEL_USART0_TX DMA_REQ_USART0_TX +#endif +#if CONFIG_GD32F4_USART0_RXDMA +# define DMA_CHANNEL_USART0_RX DMA_REQ_USART0_RX_1 +#endif + +#if defined(CONFIG_GD32F4_USART_RXDMA) || defined(CONFIG_GD32F4_USART_TXDMA) +# define USART_DMA_INTEN (DMA_CHXCTL_SDEIE | DMA_CHXCTL_TAEIE | DMA_CHXCTL_FTFIE) +#endif + +/* USART3: + * Use USART3 and the USB virtual COM port + */ + +#if defined(GD32F470ZK_AIOTBOX_CONSOLE_VIRTUAL) +# define GPIO_USART3_RX GPIO_USART3_RX_3 +# define GPIO_USART3_TX GPIO_USART3_TX_3 +#endif + +/* USART1 + * + * RX USART1_RX PD6 + * TX USART1_TX PD5 + */ +# define GPIO_USART1_RX GPIO_USART1_RX_2 +# define GPIO_USART1_TX GPIO_USART1_TX_2 + +/* USART2->RS485 + * + * RX USART2_RX PD9 + * TX USART2_TX PD8 + */ +# define GPIO_USART2_RX GPIO_USART2_RX_4 +# define GPIO_USART2_TX GPIO_USART2_TX_3 + +/* USART5 + * + * RX USART5_RX PC7 + * TX USART5_TX PC6 + */ +# define GPIO_USART5_RX GPIO_USART5_RX_2 +# define GPIO_USART5_TX GPIO_USART5_TX_2 + +/* UART6 + * + * RX UART6_RX PE8 + * TX UART6_TX PE7 + */ +# define GPIO_UART6_RX GPIO_UART6_RX_1 +# define GPIO_UART6_TX GPIO_UART6_TX_1 + +/* UART7 + * + * RX UART7_RX PE0 + * TX UART7_TX PE1 + */ + +/* I2C0 gpios: + * + * PB8 I2C0_SCL + * PB9 I2C0_SDA + */ + +#define GPIO_I2C0_SCL GPIO_I2C0_SCL_2 +#define GPIO_I2C0_SDA GPIO_I2C0_SDA_2 + +/* I2C1 gpios: + * + * PF1 I2C0_SCL + * PF0 I2C0_SDA + */ +#define GPIO_I2C1_SCL GPIO_I2C1_SCL_2 +#define GPIO_I2C1_SDA GPIO_I2C1_SDA_4 + +/* SPI -> FPC + * + * PF8 SPI4_MISO + * PF9 SPI4_MOSI + * PF7 SPI4_SCK + * PF6 SPI4_CS + */ + +#define GPIO_SPI4_CSPIN (GPIO_CFG_PORT_F | GPIO_PIN6_OUTPUT) +#define GPIO_SPI4_MISO_PIN ((GPIO_SPI4_MISO_3& ~GPIO_CFG_SPEED_MASK) | GPIO_CFG_SPEED_25MHZ) +#define GPIO_SPI4_MOSI_PIN ((GPIO_SPI4_MOSI_4 & ~GPIO_CFG_SPEED_MASK) | GPIO_CFG_SPEED_25MHZ) +#define GPIO_SPI4_SCK_PIN ((GPIO_SPI4_SCK_3 & ~GPIO_CFG_SPEED_MASK) | GPIO_CFG_SPEED_25MHZ) + +/* SPI flash + * + * PG12 SPI5_MISO + * PG14 SPI5_MOSI + * PG13 SPI5_SCK + * PG9 SPI5_CS + */ + +#define GPIO_SPI5_CSPIN (GPIO_CFG_PORT_G | GPIO_PIN9_OUTPUT) + +#define GPIO_SPI5_MISO_PIN ((GPIO_SPI5_MISO & ~GPIO_CFG_SPEED_MASK) | GPIO_CFG_SPEED_25MHZ) +#define GPIO_SPI5_MOSI_PIN ((GPIO_SPI5_MOSI & ~GPIO_CFG_SPEED_MASK) | GPIO_CFG_SPEED_25MHZ) +#define GPIO_SPI5_SCK_PIN ((GPIO_SPI5_SCK & ~GPIO_CFG_SPEED_MASK) | GPIO_CFG_SPEED_25MHZ) + +#define GPIO_SPI5_IO2_PIN ((GPIO_SPI5_IO2 & ~GPIO_CFG_SPEED_MASK) | GPIO_CFG_SPEED_25MHZ) +#define GPIO_SPI5_IO3_PIN ((GPIO_SPI5_IO3 & ~GPIO_CFG_SPEED_MASK) | GPIO_CFG_SPEED_25MHZ) + +#ifdef CONFIG_GD32F4_SPI0 +# define GPIO_SPI0_CSPIN (GPIO_CFG_PORT_B | GPIO_PIN9_OUTPUT) +# define GPIO_SPI0_MISO_PIN ((GPIO_SPI0_MISO_1 & ~GPIO_CFG_SPEED_MASK) | GPIO_CFG_SPEED_25MHZ) +# define GPIO_SPI0_MOSI_PIN ((GPIO_SPI0_MOSI_1 & ~GPIO_CFG_SPEED_MASK) | GPIO_CFG_SPEED_25MHZ) +# define GPIO_SPI0_SCK_PIN ((GPIO_SPI0_SCK_1 & ~GPIO_CFG_SPEED_MASK) | GPIO_CFG_SPEED_25MHZ) +#endif + +#ifdef CONFIG_GD32F4_SPI0_DMA +# define DMA_CHANNEL_SPI0_TX DMA_REQ_SPI0_TX_1 +# define DMA_CHANNEL_SPI0_RX DMA_REQ_SPI0_RX_1 +#endif + +#ifdef CONFIG_GD32F4_SPI_DMA +# define SPI_DMA_INTEN (DMA_CHXCTL_SDEIE | DMA_CHXCTL_TAEIE | DMA_CHXCTL_FTFIE) +#endif + +/* The GD32 F4 connects to a DP83848 PHY using these pins: + * + * GD32F470Z Eval BOARD DP83848 + * GPIO SIGNAL PIN NAME + * -------- ------------ ------------- + * PB11 RMII_TX_EN TXEN + * PB12 RMII_TXD0 TXD0 + * PB13 RMII_TXD1 TXD1 + * PC4 RMII_RXD0 RXD_0/PHYAD1 + * PC5 RMII_RXD1 RXD_1/PHYAD2 + * PA7 RMII_CRS_DV RX_DV/MII_MODE + * PC1 RMII_MDC MDC + * PA2 RMII_MDIO MDIO + * NRST NRST RESET_N + * PA1 RMII_REF_CLK X1 + * PB15 RMII_INT PWR_DOWN/INT + * + * The PHY address is 1. + */ + +#define GPIO_ENET_RMII_TX_EN GPIO_ENET_RMII_TX_EN_1 +#define GPIO_ENET_RMII_TXD0 GPIO_ENET_RMII_TXD0_1 +#define GPIO_ENET_RMII_TXD1 GPIO_ENET_RMII_TXD1_1 + +#ifdef CONFIG_GD32F4_ENET_PTP + /* Enable pulse-per-second (PPS) output signal */ + +# define GPIO_ENET_PPS_OUT GPIO_ENET_PPS_OUT_1 +#endif + +/* SDIO gpios + * + * PD2 SDIO_CMD + * PC12 SDIO_CLK + * PC8 SDIO_DAT0 + * PC9 SDIO_DAT1 + * PC10 SDIO_DAT2 + * PC11 SDIO_DAT3 + */ + +#define GPIO_SDIO_CMD_PIN GPIO_SDIO_CMD_2 +#define GPIO_SDIO_CLK_PIN GPIO_SDIO_CK_2 +#define GPIO_SDIO_DAT0_PIN GPIO_SDIO_D0_2 +#define GPIO_SDIO_DAT1_PIN GPIO_SDIO_D1_3 +#define GPIO_SDIO_DAT2_PIN GPIO_SDIO_D2_3 +#define GPIO_SDIO_DAT3_PIN GPIO_SDIO_D3 + +#ifdef CONFIG_GD32F4_SDIO_DMA +# define SDIO_DMA_INTEN (DMA_CHXCTL_SDEIE | DMA_CHXCTL_TAEIE | DMA_CHXCTL_FTFIE) +#endif + +#endif /* __BOARDS_ARM_GD32F470ZK_AIOTBOX_INCLUDE_BOARD_H */ diff --git a/boards/arm/gd32f4/gd32f470zk-aiotbox/scripts/Make.defs b/boards/arm/gd32f4/gd32f470zk-aiotbox/scripts/Make.defs new file mode 100644 index 00000000000..068515ee40c --- /dev/null +++ b/boards/arm/gd32f4/gd32f470zk-aiotbox/scripts/Make.defs @@ -0,0 +1,41 @@ +############################################################################ +# boards/arm/gd32f4/gd32f470zk-eval/scripts/Make.defs +# +# 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 + +LDSCRIPT = ld.script +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 + +EXEEXT = .elf diff --git a/boards/arm/gd32f4/gd32f470zk-aiotbox/scripts/gnu-elf.ld b/boards/arm/gd32f4/gd32f470zk-aiotbox/scripts/gnu-elf.ld new file mode 100644 index 00000000000..a0895eb3e5f --- /dev/null +++ b/boards/arm/gd32f4/gd32f470zk-aiotbox/scripts/gnu-elf.ld @@ -0,0 +1,116 @@ +/**************************************************************************** + * boards/arm/gd32f4/gd32f470zk-eval/scripts/gnu-elf.ld + * + * 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. + * + ****************************************************************************/ + +SECTIONS +{ + .text 0x00000000 : + { + _stext = . ; + *(.text) + *(.text.*) + *(.gnu.warning) + *(.stub) + *(.glue_7) + *(.glue_7t) + *(.jcr) + + /* C++ support: The .init and .fini sections contain specific logic + * to manage static constructors and destructors. + */ + + *(.gnu.linkonce.t.*) + *(.init) /* Old ABI */ + *(.fini) /* Old ABI */ + _etext = . ; + } + + .rodata : + { + _srodata = . ; + *(.rodata) + *(.rodata1) + *(.rodata.*) + *(.gnu.linkonce.r*) + _erodata = . ; + } + + .data : + { + _sdata = . ; + *(.data) + *(.data1) + *(.data.*) + *(.gnu.linkonce.d*) + . = ALIGN(4); + _edata = . ; + } + + /* C++ support. For each global and static local C++ object, + * GCC creates a small subroutine to construct the object. Pointers + * to these routines (not the routines themselves) are stored as + * simple, linear arrays in the .ctors section of the object file. + * Similarly, pointers to global/static destructor routines are + * stored in .dtors. + */ + + .ctors : + { + _sctors = . ; + *(.ctors) /* Old ABI: Unallocated */ + *(.init_array) /* New ABI: Allocated */ + _edtors = . ; + } + + .dtors : + { + _sdtors = . ; + *(.dtors) /* Old ABI: Unallocated */ + *(.fini_array) /* New ABI: Allocated */ + _edtors = . ; + } + + .bss : + { + _sbss = . ; + *(.bss) + *(.bss.*) + *(.sbss) + *(.sbss.*) + *(.gnu.linkonce.b*) + *(COMMON) + . = ALIGN(4); + _ebss = . ; + } + + /* 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) } +} diff --git a/boards/arm/gd32f4/gd32f470zk-aiotbox/scripts/kernel-space.ld b/boards/arm/gd32f4/gd32f470zk-aiotbox/scripts/kernel-space.ld new file mode 100644 index 00000000000..8377a8e028e --- /dev/null +++ b/boards/arm/gd32f4/gd32f470zk-aiotbox/scripts/kernel-space.ld @@ -0,0 +1,98 @@ +/**************************************************************************** + * boards/arm/gd32f4/gd32f470zk-eval/scripts/kernel-space.ld + * + * 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. + * + ****************************************************************************/ + +/* NOTE: This depends on the memory.ld script having been included prior to + * this script. + */ + +OUTPUT_ARCH(arm) +EXTERN(_vectors) +ENTRY(_stext) +SECTIONS +{ + .text : { + _stext = ABSOLUTE(.); + *(.vectors) + *(.text .text.*) + *(.fixup) + *(.gnu.warning) + *(.rodata .rodata.*) + *(.gnu.linkonce.t.*) + *(.glue_7) + *(.glue_7t) + *(.got) + *(.gcc_except_table) + *(.gnu.linkonce.r.*) + _etext = ABSOLUTE(.); + } > kflash + + .init_section : { + _sinit = ABSOLUTE(.); + KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*))) + KEEP(*(.init_array .ctors)) + _einit = ABSOLUTE(.); + } > kflash + + .ARM.extab : { + *(.ARM.extab*) + } > kflash + + __exidx_start = ABSOLUTE(.); + .ARM.exidx : { + *(.ARM.exidx*) + } > kflash + + __exidx_end = ABSOLUTE(.); + + _eronly = ABSOLUTE(.); + + .data : { + _sdata = ABSOLUTE(.); + *(.data .data.*) + *(.gnu.linkonce.d.*) + CONSTRUCTORS + . = ALIGN(4); + _edata = ABSOLUTE(.); + } > ksram AT > kflash + + .bss : { + _sbss = ABSOLUTE(.); + *(.bss .bss.*) + *(.gnu.linkonce.b.*) + *(COMMON) + . = ALIGN(4); + _ebss = ABSOLUTE(.); + } > ksram + + /* 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) } +} diff --git a/boards/arm/gd32f4/gd32f470zk-aiotbox/scripts/ld.script b/boards/arm/gd32f4/gd32f470zk-aiotbox/scripts/ld.script new file mode 100644 index 00000000000..5061f61d2b7 --- /dev/null +++ b/boards/arm/gd32f4/gd32f470zk-aiotbox/scripts/ld.script @@ -0,0 +1,131 @@ +/**************************************************************************** + * boards/arm/gd32f4/gd32f470zk-eval/scripts/ld.script + * + * 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. + * + ****************************************************************************/ + +/* The GD32F470ZKT6 has 3072Kb of FLASH beginning at address 0x0800:0000 and + * 256Kb of SRAM. SRAM is split up into four blocks: + * + * 1) 112Kb of SRAM beginning at address 0x2000:0000 + * 2) 16Kb of SRAM beginning at address 0x2001:c000 + * 3) 64Kb of SRAM beginning at address 0x2002:0000 + * 4) 64Kb of TCMSRAM beginning at address 0x1000:0000 + * + * When booting from FLASH, FLASH memory is aliased to address 0x0000:0000 + * where the code expects to begin execution by jumping to the entry point in + * the 0x0800:0000 address + * range. + */ + +MEMORY +{ + flash (rx) : ORIGIN = 0x08000000, LENGTH = 3072K + sram (rwx) : ORIGIN = 0x20000000, LENGTH = 112K +} + +OUTPUT_ARCH(arm) +EXTERN(_vectors) +ENTRY(_stext) +SECTIONS +{ + .text : { + _stext = ABSOLUTE(.); + *(.vectors) + *(.text .text.*) + *(.fixup) + *(.gnu.warning) + *(.rodata .rodata.*) + *(.gnu.linkonce.t.*) + *(.glue_7) + *(.glue_7t) + *(.got) + *(.gcc_except_table) + *(.gnu.linkonce.r.*) + _etext = ABSOLUTE(.); + } > flash + + .init_section : ALIGN(4) { + _sinit = ABSOLUTE(.); + KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*))) + KEEP(*(.init_array .ctors)) + _einit = ABSOLUTE(.); + } > flash + + .ARM.extab : ALIGN(4) { + *(.ARM.extab*) + } > flash + + .ARM.exidx : ALIGN(4) { + __exidx_start = ABSOLUTE(.); + *(.ARM.exidx*) + __exidx_end = ABSOLUTE(.); + } > flash + + .tdata : { + _stdata = ABSOLUTE(.); + *(.tdata .tdata.* .gnu.linkonce.td.*); + _etdata = ABSOLUTE(.); + } > flash + + .tbss : { + _stbss = ABSOLUTE(.); + *(.tbss .tbss.* .gnu.linkonce.tb.* .tcommon); + _etbss = ABSOLUTE(.); + } > flash + + _eronly = ABSOLUTE(.); + + /* The RAM vector table (if present) should lie at the beginning of SRAM */ + + .ram_vectors : { + *(.ram_vectors) + } > sram + + .data : ALIGN(4) { + _sdata = ABSOLUTE(.); + *(.data .data.*) + *(.gnu.linkonce.d.*) + CONSTRUCTORS + . = ALIGN(4); + _edata = ABSOLUTE(.); + } > sram AT > flash + + .bss : ALIGN(4) { + _sbss = ABSOLUTE(.); + *(.bss .bss.*) + *(.gnu.linkonce.b.*) + *(COMMON) + . = ALIGN(4); + _ebss = ABSOLUTE(.); + } > sram + + /* 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) } +} diff --git a/boards/arm/gd32f4/gd32f470zk-aiotbox/scripts/memory.ld b/boards/arm/gd32f4/gd32f470zk-aiotbox/scripts/memory.ld new file mode 100644 index 00000000000..756f9879aed --- /dev/null +++ b/boards/arm/gd32f4/gd32f470zk-aiotbox/scripts/memory.ld @@ -0,0 +1,85 @@ +/**************************************************************************** + * boards/arm/gd32f4/gd32f470zk-eval/scripts/memory.ld + * + * 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. + * + ****************************************************************************/ + +/* The GD32F470ZKT6 has 3072Kb of FLASH beginning at address 0x0800:0000 and + * 256Kb of SRAM. SRAM is split up into four blocks: + * + * 1) 112KB of SRAM beginning at address 0x2000:0000 + * 2) 16KB of SRAM beginning at address 0x2001:c000 + * 3) 64KB of SRAM beginning at address 0x2002:0000 + * 4) 64KB of TCMSRAM beginning at address 0x1000:0000 + * + * When booting from FLASH, FLASH memory is aliased to address 0x0000:0000 + * where the code expects to begin execution by jumping to the entry point in + * the 0x0800:0000 address range. + * + * For MPU support, the kernel-mode NuttX section is assumed to be 128Kb of + * FLASH and 4Kb of SRAM. That is an excessive amount for the kernel which + * should fit into 64KB and, of course, can be optimized as needed. Allowing the + * additional does permit addition debug instrumentation to be added to the + * kernel space without overflowing the partition. + * + * Alignment of the user space FLASH partition is also a critical factor: + * The user space FLASH partition will be spanned with a single region of + * size 2**n bytes. The alignment of the user-space region must be the same. + * As a consequence, as the user-space increases in size, the alignment + * requirement also increases. + * + * This alignment requirement means that the largest user space FLASH region + * you can have will be 512KB at it would have to be positioned at + * 0x08800000. If you change this address, don't forget to change the + * CONFIG_NUTTX_USERSPACE configuration setting to match and to modify + * the check in kernel/userspace.c. + * + * For the same reasons, the maximum size of the SRAM mapping is limited to + * 4KB. Both of these alignment limitations could be reduced by using + * multiple regions to map the FLASH/SDRAM range or perhaps with some + * clever use of subregions. + * + * A detailed memory map for the 112KB SRAM region is as follows: + * + * 0x20000 0000: Kernel .data region. Typical size: 0.1KB + * ------- ---- Kernel .bss region. Typical size: 1.8KB + * 0x20000 0800: Kernel IDLE thread stack (approximate). Size is + * determined by CONFIG_IDLETHREAD_STACKSIZE and + * adjustments for alignment. Typical is 1KB. + * ------- ---- Padded to 4KB + * 0x20000 1000: User .data region. Size is variable. + * ------- ---- User .bss region Size is variable. + * 0x20000 2000: Beginning of kernel heap. Size determined by + * CONFIG_MM_KERNEL_HEAPSIZE. + * ------- ---- Beginning of user heap. Can vary with other settings. + * 0x20001 c000: End+1 of CPU RAM + */ + +MEMORY +{ + /* 1024Kb FLASH */ + + kflash (rx) : ORIGIN = 0x08000000, LENGTH = 128K + uflash (rx) : ORIGIN = 0x08020000, LENGTH = 128K + xflash (rx) : ORIGIN = 0x08040000, LENGTH = 768K + + /* 112Kb of contiguous SRAM */ + + ksram (rwx) : ORIGIN = 0x20000000, LENGTH = 4K + usram (rwx) : ORIGIN = 0x20001000, LENGTH = 4K + xsram (rwx) : ORIGIN = 0x20002000, LENGTH = 104K +} diff --git a/boards/arm/gd32f4/gd32f470zk-aiotbox/scripts/user-space.ld b/boards/arm/gd32f4/gd32f470zk-aiotbox/scripts/user-space.ld new file mode 100644 index 00000000000..5005e08f182 --- /dev/null +++ b/boards/arm/gd32f4/gd32f470zk-aiotbox/scripts/user-space.ld @@ -0,0 +1,112 @@ +/**************************************************************************** + * boards/arm/gd32f4/gd32f470zk-eval/scripts/user-space.ld + * + * 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. + * + ****************************************************************************/ + +/* NOTE: This depends on the memory.ld script having been included prior to + * this script. + */ + +/* Make sure that the critical memory management functions are in user-space. + * the user heap memory manager will reside in user-space but be usable both + * by kernel- and user-space code + */ + +EXTERN(umm_initialize) +EXTERN(umm_addregion) + +EXTERN(malloc) +EXTERN(realloc) +EXTERN(zalloc) +EXTERN(free) + +OUTPUT_ARCH(arm) +SECTIONS +{ + .userspace : { + *(.userspace) + } > uflash + + .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(.); + } > uflash + + .init_section : { + _sinit = ABSOLUTE(.); + KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*))) + KEEP(*(.init_array .ctors)) + _einit = ABSOLUTE(.); + } > uflash + + .ARM.extab : { + *(.ARM.extab*) + } > uflash + + __exidx_start = ABSOLUTE(.); + .ARM.exidx : { + *(.ARM.exidx*) + } > uflash + + __exidx_end = ABSOLUTE(.); + + _eronly = ABSOLUTE(.); + + .data : { + _sdata = ABSOLUTE(.); + *(.data .data.*) + *(.gnu.linkonce.d.*) + CONSTRUCTORS + . = ALIGN(4); + _edata = ABSOLUTE(.); + } > usram AT > uflash + + .bss : { + _sbss = ABSOLUTE(.); + *(.bss .bss.*) + *(.gnu.linkonce.b.*) + *(COMMON) + . = ALIGN(4); + _ebss = ABSOLUTE(.); + } > usram + + /* 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) } +} diff --git a/boards/arm/gd32f4/gd32f470zk-aiotbox/src/Makefile b/boards/arm/gd32f4/gd32f470zk-aiotbox/src/Makefile new file mode 100644 index 00000000000..a8e28f8b1e6 --- /dev/null +++ b/boards/arm/gd32f4/gd32f470zk-aiotbox/src/Makefile @@ -0,0 +1,77 @@ +############################################################################ +# boards/arm/gd32f4/gd32f470zk-eval/src/Make.defs +# +# 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 = gd32f4xx_boot.c + +# ifeq ($(CONFIG_BOARDCTL),y) +# CSRCS += gd32f4xx_appinit.c +# endif + +ifeq ($(CONFIG_BOARDCTL),y) +CSRCS += gd32f4xx_appinit.c gd32f4xx_bringup.c +else ifeq ($(CONFIG_BOARD_LATE_INITIALIZE),y) +CSRCS += gd32f4xx_bringup.c +endif + +ifeq ($(CONFIG_ARCH_LEDS),y) +CSRCS += gd32f4xx_autoleds.c +else +CSRCS += gd32f4xx_userleds.c +endif + +ifeq ($(CONFIG_DEV_GPIO),y) +CSRCS += gd32f4xx_gpio.c +endif + +ifeq ($(CONFIG_ARCH_BUTTONS),y) +CSRCS += gd32f4xx_buttons.c +endif + +ifeq ($(CONFIG_SPI),y) +CSRCS += gd32f4xx_spi.c +endif + +ifeq ($(CONFIG_MMCSD),y) +CSRCS += gd32f4xx_sdio.c +endif + +ifeq ($(CONFIG_MTD_GD25),y) +CSRCS += gd32f4xx_gd25.c +endif + +ifeq ($(CONFIG_MTD_AT24XX), y) +CSRCS += gd32f4xx_at24.c +endif + +ifeq ($(CONFIG_BOARDCTL_RESET), y) +CSRCS += gd32f4xx_reset.c +endif + +ifeq ($(CONFIG_ETC_ROMFS), y) +CSRCS += etc_romfs.c +endif + +ifeq ($(CONFIG_I2C), y) +CSRCS += gd32f4xx_i2c.c +endif + +include $(TOPDIR)/boards/Board.mk diff --git a/boards/arm/gd32f4/gd32f470zk-aiotbox/src/etc_romfs.c b/boards/arm/gd32f4/gd32f470zk-aiotbox/src/etc_romfs.c new file mode 100644 index 00000000000..ff6452f680e --- /dev/null +++ b/boards/arm/gd32f4/gd32f470zk-aiotbox/src/etc_romfs.c @@ -0,0 +1,119 @@ +/*************************************************************************** + * boards/arm/gd32f4/gd32f470zk-aiotbox/src/etc_romfs.c + * + * 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. + * + ***************************************************************************/ + +/*************************************************************************** + * Public Data + ***************************************************************************/ + +const unsigned char romfs_img[] = +{ + 0x2d, 0x72, 0x6f, 0x6d, 0x31, 0x66, 0x73, 0x2d, 0x00, 0x00, 0x01, 0x50, + 0x9f, 0x13, 0x82, 0x87, 0x4e, 0x53, 0x48, 0x49, 0x6e, 0x69, 0x74, 0x56, + 0x6f, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49, + 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0xd1, 0xff, 0xff, 0x97, + 0x2e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x20, + 0x00, 0x00, 0x00, 0x00, 0xd1, 0xd1, 0xff, 0x80, 0x2e, 0x2e, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, + 0x68, 0x2d, 0x96, 0x03, 0x69, 0x6e, 0x69, 0x74, 0x2e, 0x64, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa0, + 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0xd1, 0xff, 0xff, 0x00, + 0x2e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x3a, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x6e, 0x8d, 0x9c, 0xab, 0x58, 0x72, 0x63, 0x53, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x23, 0x20, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x20, 0x61, 0x20, 0x52, + 0x41, 0x4d, 0x44, 0x49, 0x53, 0x4b, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6d, + 0x6f, 0x75, 0x6e, 0x74, 0x20, 0x69, 0x74, 0x20, 0x61, 0x74, 0x20, 0x2f, + 0x74, 0x6d, 0x70, 0x0a, 0x0a, 0x6d, 0x6b, 0x72, 0x64, 0x20, 0x2d, 0x6d, + 0x20, 0x32, 0x20, 0x2d, 0x73, 0x20, 0x35, 0x31, 0x32, 0x20, 0x31, 0x30, + 0x32, 0x34, 0x0a, 0x6d, 0x6b, 0x66, 0x61, 0x74, 0x66, 0x73, 0x20, 0x2f, + 0x64, 0x65, 0x76, 0x2f, 0x72, 0x61, 0x6d, 0x32, 0x0a, 0x6d, 0x6f, 0x75, + 0x6e, 0x74, 0x20, 0x2d, 0x74, 0x20, 0x76, 0x66, 0x61, 0x74, 0x20, 0x2f, + 0x64, 0x65, 0x76, 0x2f, 0x72, 0x61, 0x6d, 0x32, 0x20, 0x2f, 0x74, 0x6d, + 0x70, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, + 0x00, 0x00, 0x00, 0x00, 0xd1, 0xd1, 0xff, 0xe0, 0x2e, 0x2e, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 +}; + +const unsigned int romfs_img_len = 1024; + +/*************************************************************************** + * Public Functions + ***************************************************************************/ diff --git a/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f470z_aiotbox.h b/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f470z_aiotbox.h new file mode 100644 index 00000000000..0e45012f5ad --- /dev/null +++ b/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f470z_aiotbox.h @@ -0,0 +1,297 @@ +/**************************************************************************** + * boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f470z_aiotbox.h + * + * 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_GD32F4_GD32F470ZK_AIOTBOX_SRC_GD32F470Z_AIOTBOX_H +#define __BOARDS_ARM_GD32F4_GD32F470ZK_AIOTBOX_SRC_GD32F470Z_AIOTBOX_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Configuration ************************************************************/ + +/* procfs File System */ + +#ifdef CONFIG_FS_PROCFS +# ifdef CONFIG_NSH_PROC_MOUNTPOINT +# define GD32_PROCFS_MOUNTPOINT CONFIG_NSH_PROC_MOUNTPOINT +# else +# define GD32_PROCFS_MOUNTPOINT "/proc" +# endif +#endif + +#ifdef CONFIG_FS_NXFFS +# ifndef CONFIG_GD32F4_NXFFS_MOUNTPT +# define CONFIG_GD32F4_NXFFS_MOUNTPT "/mnt/gd32nxffs" +# endif +#endif + +/* GD32F470ZK GPIO Pin Definitions ******************************************/ + +/* LED + * + * The GD32F470ZK board has three LEDs, LED1, LED2 and LED3, that can be + * controlled by software. + * The following definitions assume the default Solder Bridges are installed. + */ + +#define GPIO_LED1 (GPIO_CFG_PORT_D | GPIO_CFG_OUTPUT_RESET | GPIO_PIN4_OUTPUT) +#define GPIO_LED2 (GPIO_CFG_PORT_D | GPIO_CFG_OUTPUT_RESET | GPIO_PIN5_OUTPUT) +#define GPIO_LED3 (GPIO_CFG_PORT_G | GPIO_CFG_OUTPUT_RESET | GPIO_PIN3_OUTPUT) + +#define LED1 GPIO_LED1 +#define LED2 GPIO_LED2 +#define LED3 GPIO_LED3 + +#define LED_DRIVER_PATH "/dev/userleds" + +/* BUTTONS + * + * The GD32F470Z AIOTBOX board has User, Tamper, and Wakeup key, the are + * connected to GPIO PB14, PC13 and PA0. + * A low value will be sensed when the button is depressed. + * + * Note: + * That the EXTI is included in the definition to enable + * an interrupt on this IO. + */ + +#define GPIO_BTN_USER (GPIO_CFG_PORT_B | GPIO_CFG_EXTI | GPIO_PIN14_INPUT) +#define GPIO_BTN_TAMPER (GPIO_CFG_PORT_C | GPIO_CFG_EXTI | GPIO_PIN13_INPUT) +#define GPIO_BTN_WAKEUP (GPIO_CFG_PORT_A | GPIO_CFG_EXTI | GPIO_PIN0_INPUT) + +/* SPI Flash ****************************************************************/ + +/* SPI FLASH (GD25Q40) + * + * PG12 SPI5_MISO + * PG14 SPI5_MOSI + * PG13 SPI5_SCK + * + * PG9 SPI5_CS + */ + +#define GPIO_SPI5_CS (GPIO_CFG_PORT_G | GPIO_PIN9_OUTPUT) +#define SPI_FLASH_CSNUM 5 + +#define HAVE_GD25 1 + +#if !defined(CONFIG_MTD_GD25) || !defined(CONFIG_GD32F4_SPI5) +# undef HAVE_GD25 +#endif + +/* Can't support AT24 features if mountpoints are disabled or if we were not + * asked to mount the AT25 part + */ + +#if defined(CONFIG_DISABLE_MOUNTPOINT) || \ + !defined(CONFIG_GD32F470ZK_AIOTBOX_GD25_BLOCKMOUNT) +# undef HAVE_GD25 +#endif + +#define HAVE_AT24 1 + +/* AT24 Serial EEPROM + * + * A AT24C02C Serial EEPPROM was used for tested I2C0. + */ + +#define AT24_BUS 0 +#define AT24_MINOR 0 + +#if !defined(CONFIG_MTD_AT24XX) || !defined(CONFIG_GD32F4_I2C0) +# undef HAVE_AT24 +#endif + +/* Can't support AT24 features if mountpoints are disabled or if we were not + * asked to mount the AT25 part + */ + +#ifndef CONFIG_GD32F470ZK_AIOTBOX_AT24_TEST +# undef HAVE_AT24 +#endif + +/* GPIO pins used by the GPIO Subsystem */ + +#define BOARD_NGPIOIN 1 /* Amount of GPIO Input pins */ +#define BOARD_NGPIOOUT 1 /* Amount of GPIO Output pins */ +#define BOARD_NGPIOINT 1 /* Amount of GPIO Input w/ Interruption pins */ + +#define GPIO_IN1 (GPIO_CFG_MODE_INPUT | GPIO_CFG_PUPD_NONE | GPIO_CFG_PORT_B | GPIO_CFG_PIN_0) +#define GPIO_OUT1 (GPIO_CFG_MODE_OUTPUT | GPIO_CFG_OUTPUT_SET | GPIO_CFG_SPEED_50MHZ | \ + GPIO_CFG_PORT_B | GPIO_CFG_PIN_1) +#define GPIO_INT1 (GPIO_CFG_MODE_INPUT | GPIO_CFG_PUPD_NONE | GPIO_CFG_PORT_B | GPIO_CFG_PIN_2) + +/* Can't support MMC/SD features if mountpoints are disabled or if SDIO + * support is not enabled. + */ + +#if defined(CONFIG_DISABLE_MOUNTPOINT) || !defined(CONFIG_GD32_SDIO) +# undef HAVE_SDIO +#endif + +#define SDIO_MINOR 0 /* Any minor number, default 0 */ +#define SDIO_SLOTNO 0 /* Only one slot */ + +#ifdef HAVE_SDIO +# if !defined(CONFIG_NSH_MMCSDSLOTNO) +# define CONFIG_NSH_MMCSDSLOTNO SDIO_SLOTNO +# elif CONFIG_NSH_MMCSDSLOTNO != 0 +# warning "Only one MMC/SD slot, slot 0" +# undef CONFIG_NSH_MMCSDSLOTNO +# define CONFIG_NSH_MMCSDSLOTNO SDIO_SLOTNO +# endif + +# if defined(CONFIG_NSH_MMCSDMINOR) +# define SDIO_MINOR CONFIG_NSH_MMCSDMINOR +# else +# define SDIO_MINOR 0 +# endif +#endif + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifndef __ASSEMBLY__ + +/**************************************************************************** + * Name: gd32_bringup + * + * Description: + * Perform architecture specific initialization + * + * CONFIG_BOARDCTL=y: + * If CONFIG_NSH_ARCHINITIALIZE=y: + * Called from the NSH library (or other application) + * Otherwise, assumed to be called from some other application. + * + * Otherwise CONFIG_BOARD_LATE_INITIALIZE=y: + * Called from board_late_initialize(). + * + * Otherwise, bad news: Never called + * + ****************************************************************************/ + +int gd32_bringup(void); + +/**************************************************************************** + * Name: gd32_spidev_initialize + * + * Description: + * Called to configure SPI chip select GPIO pins for the GD32F470Z + * AIOTBOX board. + * + ****************************************************************************/ + +#if defined(CONFIG_SPI) +void gd32_spidev_initialize(void); +#endif + +/**************************************************************************** + * Name: gd32_i2c_initialize + * + * Description: + * Called to configure i2c chip initialize for the GD32F470Z + * AIOTBOX board. + * + ****************************************************************************/ + +#if defined(CONFIG_I2C) +void gd32_i2c_initialize(void); +#endif + +/**************************************************************************** + * Name: gd32_gd25_automount + * + * Description: + * Initialize, configure, and mount the GD25 SPI FLASH. The FLASH will + * be mounted at /dev/gd25. + * + ****************************************************************************/ + +#ifdef HAVE_GD25 +int gd32_gd25_automount(int minor); +#endif + +/**************************************************************************** + * Name: gd32_at24_wr_test + * + * Description: + * Write and read the AT24 serial EEPROM test. + * + ****************************************************************************/ + +#ifdef HAVE_AT24 +int gd32_at24_wr_test(int minor); +#endif + +/**************************************************************************** + * Name: gd32_gpio_initialize + * + * Description: + * Initialize GPIO drivers for use with /apps/examples/gpio + * + ****************************************************************************/ + +#ifdef CONFIG_DEV_GPIO +int gd32_gpio_initialize(void); +#endif + +/**************************************************************************** + * Name: gd32_dma_alloc_init + * + * Description: + * Called to create a FAT DMA allocator + * + * Returned Value: + * 0 on success or -ENOMEM + * + ****************************************************************************/ + +void gd32_dma_alloc_init(void); + +#if defined (CONFIG_FAT_DMAMEMORY) +int gd32_dma_alloc_init(void); +#endif + +/**************************************************************************** + * Name: gd32_sdio_initialize + * + * Description: + * Called at application startup time to initialize the SCMMC + * functionality. + * + ****************************************************************************/ + +#ifdef CONFIG_MMCSD +int gd32_sdio_initialize(void); +#endif + +#endif /* __ASSEMBLY__ */ +#endif /* __BOARDS_ARM_GD32F4_GD32F470ZK_AIOTBOX_SRC_GD32F470Z_AIOTBOX_H */ diff --git a/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_appinit.c b/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_appinit.c new file mode 100644 index 00000000000..5e18d067e3c --- /dev/null +++ b/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_appinit.c @@ -0,0 +1,71 @@ +/**************************************************************************** + * boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_appinit.c + * + * 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 + +#include +#include +#include +#include + +#include + +#include "gd32f4xx.h" +#include "gd32f470z_aiotbox.h" + +/**************************************************************************** + * 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) +{ + /* Perform board initialization here */ + + return gd32_bringup(); +} diff --git a/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_at24.c b/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_at24.c new file mode 100644 index 00000000000..1e98c610a0e --- /dev/null +++ b/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_at24.c @@ -0,0 +1,155 @@ +/**************************************************************************** + * boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_at24.c + * + * 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 + +#include +#include +#include +#include + +#include +#include +#include + +#include "gd32f4xx.h" +#include "gd32f470z_aiotbox.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: gd32_at24_wr_test + * + * Description: + * Write and read the AT24 serial EEPROM test. + * + ****************************************************************************/ + +#ifdef HAVE_AT24 + +#define BUFFSIZE 16 +#define START_BLOCK 0 + +#if BUFFSIZE>=CONFIG_AT24XX_MTD_BLOCKSIZE +# define NBLOCK (BUFFSIZE/CONFIG_AT24XX_MTD_BLOCKSIZE) +#else +# error "BUFFSIZE should bigger than CONFIG_AT24XX_MTD_BLOCKSIZE" +#endif + +const uint8_t write_buf[BUFFSIZE] = +{ + 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, + 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf +}; + +int gd32_at24_wr_test(int minor) +{ + struct i2c_master_s *i2c; + struct mtd_dev_s *at24; + static bool initialized = false; + int ret; + ssize_t nblocks; + uint8_t *read_buf; + + /* Have we already initialized? */ + + if (!initialized) + { + /* No.. Get the I2C port driver */ + + finfo("Initialize TWI%d\n", AT24_BUS); + i2c = gd32_i2cbus_initialize(AT24_BUS); + if (!i2c) + { + ferr("ERROR: Failed to initialize TWI%d\n", AT24_BUS); + return -ENODEV; + } + + /* Now bind the I2C interface to the AT24 I2C EEPROM driver */ + + finfo("Bind the AT24 EEPROM driver to TWI%d\n", AT24_BUS); + at24 = at24c_initialize(i2c); + if (!at24) + { + ferr("ERROR: Failed to bind TWI%d to the AT24 EEPROM driver\n", + AT24_BUS); + return -ENODEV; + } + + /* Now we are initializeed */ + + initialized = true; + } + + /* Write start block is START_BLOCK, number of block is 2 */ + + nblocks = at24->bwrite(at24, START_BLOCK, NBLOCK, write_buf); + if (nblocks < NBLOCK) + { + ferr("ERROR: AT24 write failed: %zd\n", nblocks); + gd32_i2cbus_uninitialize(i2c); + return (int)nblocks; + } + + read_buf = kmm_malloc(BUFFSIZE); + + /* Read the data write before */ + + nblocks = at24->bread(at24, START_BLOCK, NBLOCK, read_buf); + if (nblocks < NBLOCK) + { + ferr("ERROR: AT24 read failed: %zd\n", nblocks); + gd32_i2cbus_uninitialize(i2c); + return (int)nblocks; + } + + if (memcmp(read_buf, write_buf, BUFFSIZE) != 0) + { + ferr("ERROR: Read buffer does not match write buffer\n"); + return -1; + } + + /* Release the I2C instance. + * REVISIT: Need an interface to release the AT24 instance too + */ + + ret = gd32_i2cbus_uninitialize(i2c); + if (ret < 0) + { + ferr("ERROR: Failed to release the I2C interface: %d\n", ret); + } + + syslog(LOG_INFO, "INFO: I2C EEPROM write and read success: \ + %d\n", ret); + + return OK; +} + +#endif /* HAVE_AT24 */ diff --git a/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_autoleds.c b/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_autoleds.c new file mode 100644 index 00000000000..88ee47ac826 --- /dev/null +++ b/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_autoleds.c @@ -0,0 +1,177 @@ +/**************************************************************************** + * boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_autoleds.c + * + * 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 + +#include +#include + +#include + +#include +#include + +#include "gd32f4xx_gpio.h" +#include "gd32f470z_aiotbox.h" +#ifdef CONFIG_ARCH_LEDS + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* LED index */ + +static const uint32_t g_led_map[BOARD_LEDS] = +{ + LED1, + LED2, + LED3 +}; + +static bool g_initialized; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/* Turn on selected led */ + +static void gd32_aiotbox_led_on(led_typedef_enum led_num) +{ + gd32_gpio_write(g_led_map[led_num], true); +} + +/* Turn off selected led */ + +static void gd32_aiotbox_led_off(led_typedef_enum led_num) +{ + gd32_gpio_write(g_led_map[led_num], false); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_autoled_initialize + ****************************************************************************/ + +void board_autoled_initialize(void) +{ + int i; + + /* Configure the LED GPIO for output. */ + + for (i = 0; i < nitems(g_led_map); i++) + { + gd32_gpio_config(g_led_map[i]); + } +} + +/**************************************************************************** + * Name: board_autoled_on + ****************************************************************************/ + +void board_autoled_on(int led) +{ + switch (led) + { + default: + break; + + case LED_HEAPALLOCATE: + gd32_aiotbox_led_on(BOARD_LED1); + break; + + case LED_IRQSENABLED: + gd32_aiotbox_led_on(BOARD_LED2); + break; + + case LED_STACKCREATED: + gd32_aiotbox_led_on(BOARD_LED3); + g_initialized = true; + break; + + case LED_INIRQ: + gd32_aiotbox_led_on(BOARD_LED1); + gd32_aiotbox_led_on(BOARD_LED2); + break; + + case LED_SIGNAL: + gd32_aiotbox_led_on(BOARD_LED1); + gd32_aiotbox_led_on(BOARD_LED3); + break; + + case LED_ASSERTION: + gd32_aiotbox_led_on(BOARD_LED2); + gd32_aiotbox_led_on(BOARD_LED3); + break; + + case LED_PANIC: + gd32_aiotbox_led_on(BOARD_LED1); + break; + + case LED_IDLE : /* IDLE */ + gd32_aiotbox_led_on(BOARD_LED2); + break; + } +} + +/**************************************************************************** + * Name: board_autoled_off + ****************************************************************************/ + +void board_autoled_off(int led) +{ + switch (led) + { + default: + break; + + case LED_SIGNAL: + gd32_aiotbox_led_off(BOARD_LED1); + gd32_aiotbox_led_off(BOARD_LED3); + break; + + case LED_INIRQ: + gd32_aiotbox_led_off(BOARD_LED1); + gd32_aiotbox_led_off(BOARD_LED2); + break; + + case LED_ASSERTION: + gd32_aiotbox_led_off(BOARD_LED2); + gd32_aiotbox_led_off(BOARD_LED3); + break; + + case LED_PANIC: + gd32_aiotbox_led_off(BOARD_LED1); + break; + + case LED_IDLE : /* IDLE */ + gd32_aiotbox_led_off(BOARD_LED2); + break; + } +} + +#endif /* CONFIG_ARCH_LEDS */ diff --git a/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_boot.c b/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_boot.c new file mode 100644 index 00000000000..1012be3a09d --- /dev/null +++ b/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_boot.c @@ -0,0 +1,85 @@ +/**************************************************************************** + * boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_boot.c + * + * 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 + +#include + +#include +#include + +#include "gd32f470z_aiotbox.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: gd32_boardinitialize + * + * Description: + * All GD32F4xx architectures must provide the following entry point. + * This entry point is called early in the initialization + * after all memory has been configured and mapped but + * before any devices have been initialized. + * + ****************************************************************************/ + +void gd32_boardinitialize(void) +{ +#ifdef CONFIG_ARCH_LEDS + /* Configure on-board LEDs if LED support has been selected. */ + + board_autoled_initialize(); +#endif + +#if defined(CONFIG_SPI) + /* Configure SPI chip selects */ + + gd32_spidev_initialize(); +#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_initialize() 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-specific initialization */ + + gd32_bringup(); +} +#endif diff --git a/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_bringup.c b/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_bringup.c new file mode 100644 index 00000000000..7a34d65772f --- /dev/null +++ b/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_bringup.c @@ -0,0 +1,363 @@ +/**************************************************************************** + * boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_bringup.c + * + * 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 + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "gd32f4xx.h" + +#ifdef CONFIG_USERLED +# include +#endif + +#ifdef CONFIG_INPUT_BUTTONS +# include +#endif + +#ifdef CONFIG_GD32F4_ROMFS +#include "gd32f4xx_romfs.h" +#endif + +#include "gd32f470z_aiotbox.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: gd32_bringup + * + * Description: + * Perform architecture-specific initialization + * + * CONFIG_BOARD_LATE_INITIALIZE=y : + * Called from board_late_initialize(). + * + * CONFIG_BOARD_LATE_INITIALIZE=n && CONFIG_BOARDCTL=y : + * Called from the NSH library via boardctl() + * + ****************************************************************************/ + +int gd32_bringup(void) +{ +#ifdef CONFIG_RAMMTD + uint8_t *ramstart; +#endif + + int ret = OK; + +#ifdef CONFIG_FS_PROCFS + /* Mount the procfs file system */ + + ret = nx_mount(NULL, GD32_PROCFS_MOUNTPOINT, "procfs", 0, NULL); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to mount procfs at %s: %d\n", + GD32_PROCFS_MOUNTPOINT, ret); + } +#endif + +#ifdef CONFIG_RAMMTD + /* Create a RAM MTD device if configured */ + + ramstart = kmm_malloc(64 * 1024); + if (ramstart == NULL) + { + syslog(LOG_ERR, "ERROR: Allocation for RAM MTD failed\n"); + } + else + { + /* Initialized the RAM MTD */ + + struct mtd_dev_s *mtd = rammtd_initialize(ramstart, 64 * 1024); + if (mtd == NULL) + { + syslog(LOG_ERR, "ERROR: rammtd_initialize failed\n"); + kmm_free(ramstart); + } + else + { + /* Erase the RAM MTD */ + + ret = mtd->ioctl(mtd, MTDIOC_BULKERASE, 0); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: IOCTL MTDIOC_BULKERASE failed\n"); + } + +#if defined(CONFIG_MTD_SMART) && defined(CONFIG_FS_SMARTFS) + /* Initialize a SMART Flash block device and bind it to the MTD + * device. + */ + + smart_initialize(0, mtd, NULL); + +#elif defined(CONFIG_FS_SPIFFS) + /* Register the MTD driver so that it can be accessed from the + * VFS. + */ + + ret = register_mtddriver("/dev/rammtd", mtd, 0755, NULL); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to register MTD driver: %d\n", + ret); + } + + /* Mount the SPIFFS file system */ + + ret = nx_mount("/dev/rammtd", "/mnt/spiffs", "spiffs", 0, NULL); + if (ret < 0) + { + syslog(LOG_ERR, + "ERROR: Failed to mount SPIFFS at /mnt/spiffs: %d\n", + ret); + } + +#elif defined(CONFIG_FS_LITTLEFS) + /* Register the MTD driver so that it can be accessed from the + * VFS. + */ + + ret = register_mtddriver("/dev/rammtd", mtd, 0755, NULL); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to register MTD driver: %d\n", + ret); + } + + /* Mount the LittleFS file system */ + + ret = nx_mount("/dev/rammtd", "/mnt/lfs", "littlefs", 0, + "forceformat"); + if (ret < 0) + { + syslog(LOG_ERR, + "ERROR: Failed to mount LittleFS at /mnt/lfs: %d\n", + ret); + } + +#elif defined(CONFIG_FS_NXFFS) + /* Initialize to provide NXFFS on the MTD interface */ + + ret = nxffs_initialize(mtd); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: NXFFS initialization failed: %d\n", + ret); + } +#endif + } + } +#endif + +#if defined(CONFIG_INPUT_BUTTONS_LOWER) + ret = btn_lower_initialize("/dev/buttons"); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: btn_lower_initialize() failed: %d\n", ret); + } +#endif + +#ifdef CONFIG_GD32F4_ROMFS + /* Mount the romfs partition */ + + ret = gd32_romfs_initialize(); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to mount romfs at %s: %d\n", + CONFIG_GD32F4_ROMFS_MOUNTPOINT, ret); + } +#endif + +#ifndef CONFIG_DISABLE_MOUNTPOINT + +# ifdef CONFIG_GD32F4_PROGMEM + + /* Create an instance of the GD32F4 FLASH program memory + * device driver + */ + + struct mtd_dev_s *mtd = progmem_initialize(); + if (!mtd) + { + syslog(LOG_ERR, "ERROR: progmem_initialize failed\n"); + } + +# if defined(CONFIG_FS_NXFFS) + /* Initialize to provide NXFFS on the MTD interface */ + + ret = nxffs_initialize(mtd); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: NXFFS initialization failed: %d\n", + ret); + } + + /* Mount the file system */ + + ret = nx_mount(NULL, CONFIG_GD32F4_NXFFS_MOUNTPT, "nxffs", 0, NULL); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to mount the NXFFS volume: %d\n", + ret); + } +# elif defined(CONFIG_FS_LITTLEFS) + /* Initialize to provide LittleFS on the MTD interface */ + + ret = register_mtddriver("/dev/fmc", mtd, 0755, NULL); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to register MTD: %d\n", ret); + return ret; + } + + /* Mount the file system at /mnt/fmc */ + + ret = nx_mount("/dev/fmc", "/mnt/fmc", "littlefs", 0, NULL); + if (ret < 0) + { + ret = nx_mount("/dev/fmc", "/mnt/fmc", "littlefs", 0, + "forceformat"); + if (ret < 0) + { + ferr("ERROR: Failed to mount the FS volume: %d\n", ret); + return ret; + } + } + + syslog(LOG_INFO, "INFO: LittleFS volume /mnt/fmc mount " + "on chip flash success: %d\n", ret); +# endif +# endif + +#ifdef CONFIG_I2C + gd32_i2c_initialize(); +#endif + +# ifdef HAVE_GD25 + + ret = gd32_gd25_automount(0); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to mount the NXFFS \ + volume on spi flash: %d\n", ret); + } + +# endif + +# ifdef HAVE_AT24 + + ret = gd32_at24_wr_test(AT24_MINOR); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: I2C EEPROM write and read test fail: \ + %d\n", ret); + } + +# endif + +#endif /* CONFIG_FS_NXFFS */ + +#ifdef CONFIG_DEV_GPIO + /* Register the GPIO driver */ + + ret = gd32_gpio_initialize(); + if (ret < 0) + { + syslog(LOG_ERR, "Failed to initialize GPIO Driver: %d\n", ret); + return ret; + } +#endif + +#ifdef CONFIG_INPUT_BUTTONS +#ifdef CONFIG_INPUT_BUTTONS_LOWER + /* Register the BUTTON driver */ + + ret = btn_lower_initialize("/dev/buttons"); + if (ret != OK) + { + syslog(LOG_ERR, "ERROR: btn_lower_initialize() failed: %d\n", ret); + return ret; + } +#else + /* Enable BUTTON support for some other purpose */ + + board_button_initialize(); +#endif /* CONFIG_INPUT_BUTTONS_LOWER */ +#endif /* CONFIG_INPUT_BUTTONS */ + +#if !defined(CONFIG_ARCH_LEDS) && defined(CONFIG_USERLED_LOWER) + /* Register the LED driver */ + + ret = userled_lower_initialize(LED_DRIVER_PATH); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: userled_lower_initialize() failed: %d\n", + ret); + } +#endif + + /* Configure SDIO chip selects */ + +#ifdef CONFIG_ARCH_HAVE_SDIO + ret = gd32_sdio_initialize(); + if (ret != OK) + { + syslog(LOG_ERR, "ERROR: gd32_sdio_initialize() failed: %d\n", ret); + return ret; + } + + /* Mount the file system at /mnt/sd */ + + ret = nx_mount("/dev/mmcsd0", "/mnt/sd", "vfat", 0, NULL); + if (ret < 0) + { + ret = nx_mount("/dev/mmcsd0", "/mnt/sd", "vfat", 0, + "forceformat"); + if (ret < 0) + { + ferr("ERROR: Failed to mount the SD card: %d\n", ret); + return ret; + } + } + + syslog(LOG_INFO, "INFO: FAT volume /mnt/sd mount " + "sd card success: %d\n", ret); +#endif + return ret; +} diff --git a/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_buttons.c b/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_buttons.c new file mode 100644 index 00000000000..0352373c004 --- /dev/null +++ b/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_buttons.c @@ -0,0 +1,190 @@ +/**************************************************************************** + * boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_buttons.c + * + * 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 + +#include +#include + +#include +#include + +#include + +#include "gd32f4xx.h" +#include "gd32f470z_aiotbox.h" + +#ifdef CONFIG_ARCH_BUTTONS + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const uint32_t g_button_boards[NUM_BUTTONS] = +{ + GPIO_BTN_USER, GPIO_BTN_TAMPER, GPIO_BTN_WAKEUP +}; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_button_initialize + * + * Description: + * board_button_initialize() must be called to initialize button resources. + * After that, board_buttons() may be called to collect the current state + * of all buttons or board_button_irq() may be called to register button + * interrupt handlers. + * + ****************************************************************************/ + +uint32_t board_button_initialize(void) +{ + int i; + + /* Configure each button */ + + for (i = 0; i < NUM_BUTTONS; i++) + { + gd32_gpio_config(g_button_boards[i]); + } + + return NUM_BUTTONS; +} + +/**************************************************************************** + * Name: board_buttons + * After board_button_initialize() has been called, board_buttons() may be + * called to collect the state of all buttons. board_buttons() returns an + * 32-bit bit set with each bit associated with a button. See the BUTTON* + * definitions above for the meaning of each bit in the returned value. + * + ****************************************************************************/ + +uint32_t board_buttons(void) +{ + uint32_t ret; + int i; + + /* Check each button */ + + for (i = 0, ret = 0; i < NUM_BUTTONS; i++) + { + /* The low value is sensed when the button is pressed */ + + if (!gd32_gpio_read(g_button_boards[i])) + { + ret |= (1 << i); + } + } + + return ret; +} + +/**************************************************************************** + * Button support. + * + * Description: + * board_button_initialize() must be called to initialize button resources. + * After that, board_buttons() may be called to collect the current + * state of all buttons or board_button_irq() may be called to register + * button interrupt handlers. + * + * After board_button_initialize() has been called, board_buttons() + * may be called to collect the state of all buttons. board_buttons() + * returns an 32-bit bit set with each bit associated with a button. + * See the BUTTON_*_BIT definitions in board.h for the meaning of each + * bit. + * + * board_button_irq() may be called to register an interrupt handler that + * will be called when a button is depressed or released. The ID value + * is a button enumeration value that uniquely identifies a button + * resource. See the BUTTON_* definitions in board.h for the meaning of + * enumeration value. + * + ****************************************************************************/ + +#ifdef CONFIG_ARCH_IRQBUTTONS +int board_button_irq(int id, xcpt_t irqhandler, void *arg) +{ + if (id >= 0 && id < NUM_BUTTONS) + { + uint8_t gpio_irq; + uint8_t gpio_irqnum; + irqstate_t flags; + int ret; + + /* Disable interrupts until we are done. This guarantees that the + * following operations are atomic. + */ + + flags = enter_critical_section(); + + /* Get gpio irq numbers */ + + ret = gd32_gpio_exti_irqnum_get(g_button_boards[id], &gpio_irqnum); + + if (ret < 0) + { + leave_critical_section(flags); + return ret; + } + + /* Are we attaching or detaching? */ + + if (irqhandler != NULL) + { + ret = gd32_exti_gpioirq_init(g_button_boards[id], EXTI_INTERRUPT, + EXTI_TRIG_RISING, &gpio_irq); + + if (ret < 0) + { + leave_critical_section(flags); + return ret; + } + + /* Attach and enable the interrupt */ + + gd32_exti_gpio_irq_attach(gpio_irq, irqhandler, arg); + up_enable_irq(gpio_irqnum); + } + else + { + /* Disable and detach the interrupt */ + + up_disable_irq(gpio_irqnum); + irq_detach(gpio_irqnum); + } + + leave_critical_section(flags); + } + + /* Return the old button handler (so that it can be restored) */ + + return OK; +} +#endif +#endif /* CONFIG_ARCH_BUTTONS */ diff --git a/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_gd25.c b/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_gd25.c new file mode 100644 index 00000000000..d5db8faf42e --- /dev/null +++ b/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_gd25.c @@ -0,0 +1,164 @@ +/**************************************************************************** + * boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_gd25.c + * + * 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 + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "gd32f4xx.h" +#include "gd32f470z_aiotbox.h" + +#ifdef HAVE_GD25 + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: gd32_gd25_automount + * + * Description: + * Initialize, configure, and mount the GD25 SPI FLASH. The FLASH will + * be mounted at /dev/gd25. + * + ****************************************************************************/ + +int gd32_gd25_automount(int minor) +{ + struct spi_dev_s *spi; + struct mtd_dev_s *mtd; + static bool initialized = false; + int ret; + + /* Have we already initialized? */ + + if (!initialized) + { + /* No.. Get the SPI port driver */ + + spi = gd32_spibus_initialize(SPI_FLASH_CSNUM); + if (!spi) + { + syslog(LOG_ERR, "ERROR: Failed to initialize SPI port %d\n", + SPI_FLASH_CSNUM); + return -ENODEV; + } + + /* Now bind the SPI interface to the GD25 SPI FLASH driver */ + + mtd = gd25_initialize(spi, 0); + if (!mtd) + { + syslog(LOG_ERR, "ERROR: Failed to bind SPI port to the \ + GD25 FLASH driver\n"); + return -ENODEV; + } + +#if defined(CONFIG_GD32F470ZK_EVAL_GD25_FTL) + /* And finally, use the FTL layer to wrap the MTD driver as a block + * driver at /dev/mtdblockN, where N=minor device number. + */ + + ret = ftl_initialize(minor, mtd); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to initialize the FTL layer: %d\n", + ret); + return ret; + } + +#elif defined(CONFIG_GD32F470ZK_EVAL_GD25_NXFFS) + /* Initialize to provide NXFFS on the MTD interface */ + + ret = nxffs_initialize(mtd); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: NXFFS initialization failed: %d\n", ret); + return ret; + } + + /* Mount the file system at /mnt/gd25 */ + + ret = nx_mount(NULL, "/mnt/gd25", "nxffs", 0, NULL); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to mount the NXFFS volume: %d\n", + ret); + return ret; + } + + syslog(LOG_INFO, "INFO: NXFFS volume /mnt/gd25 mount \ + spi flash success: %d\n", ret); + +#elif defined(CONFIG_GD32F470ZK_EVAL_GD25_LITTLEFS) + /* Initialize to provide LittleFS on the MTD interface */ + + ret = register_mtddriver("/dev/spiflash", mtd, 0755, NULL); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to register MTD: %d\n", ret); + return ret; + } + + /* Mount the file system at /mnt/gd25 */ + + ret = nx_mount("/dev/spiflash", "/mnt/gd25", "littlefs", 0, NULL); + if (ret < 0) + { + ret = nx_mount("/dev/spiflash", "/mnt/gd25", "littlefs", 0, + "forceformat"); + if (ret < 0) + { + ferr("ERROR: Failed to mount the FS volume: %d\n", ret); + return ret; + } + } + + syslog(LOG_INFO, "INFO: LittleFS volume /mnt/gd25 mount \ + spi flash success: %d\n", ret); +#endif + + /* Now we are initialized */ + + initialized = true; + } + + UNUSED(ret); + + return OK; +} + +#endif /* HAVE_GD25 */ diff --git a/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_gpio.c b/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_gpio.c new file mode 100644 index 00000000000..464242d95fe --- /dev/null +++ b/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_gpio.c @@ -0,0 +1,492 @@ +/**************************************************************************** + * boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_gpio.c + * + * 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 + +#include +#include +#include + +#include +#include +#include + +#include + +#include "chip.h" + +#include "gd32f4xx.h" +#include "gd32f470z_aiotbox.h" + +#if defined(CONFIG_DEV_GPIO) && !defined(CONFIG_GPIO_LOWER_HALF) + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct gd32gpio_dev_s +{ + struct gpio_dev_s gpio; + uint32_t pinconfig; + uint8_t id; +}; + +struct gd32gpint_dev_s +{ + struct gd32gpio_dev_s gd32gpio; + pin_interrupt_t callback; +}; + +irqstate_t flags; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static int gpio_setpintype(struct gpio_dev_s *dev, + enum gpio_pintype_e gp_pintype); + +#if BOARD_NGPIOIN > 0 +static int gpin_read(struct gpio_dev_s *dev, bool *value); +#endif + +#if BOARD_NGPIOOUT > 0 +static int gpout_read(struct gpio_dev_s *dev, bool *value); +static int gpout_write(struct gpio_dev_s *dev, bool value); +#endif + +#if BOARD_NGPIOINT > 0 +static int gpint_read(struct gpio_dev_s *dev, bool *value); +static int gpint_attach(struct gpio_dev_s *dev, + pin_interrupt_t callback); +static int gpint_enable(struct gpio_dev_s *dev, bool enable); +#endif + +/**************************************************************************** + * Private Data + ****************************************************************************/ + + #if BOARD_NGPIOIN > 0 +static const struct gpio_operations_s gpin_ops = +{ + .go_read = gpin_read, + .go_write = NULL, + .go_attach = NULL, + .go_enable = NULL, + .go_setpintype = gpio_setpintype, +}; + +/* This array maps the GPIO pins used as INPUT */ + +static const uint32_t g_gpioinputs[BOARD_NGPIOIN] = +{ + GPIO_IN1, +}; + +static struct gd32gpio_dev_s g_gpin[BOARD_NGPIOIN]; +#endif + +#if BOARD_NGPIOOUT > 0 + +static const struct gpio_operations_s gpout_ops = +{ + .go_read = gpout_read, + .go_write = gpout_write, + .go_attach = NULL, + .go_enable = NULL, + .go_setpintype = gpio_setpintype, +}; + +/* This array maps the GPIO pins used as OUTPUT */ + +static const uint32_t g_gpiooutputs[BOARD_NGPIOOUT] = +{ + GPIO_OUT1, +}; + +static struct gd32gpio_dev_s g_gpout[BOARD_NGPIOOUT]; +#endif + +#if BOARD_NGPIOINT > 0 + +static const struct gpio_operations_s gpint_ops = +{ + .go_read = gpint_read, + .go_write = NULL, + .go_attach = gpint_attach, + .go_enable = gpint_enable, + .go_setpintype = gpio_setpintype, +}; + +/* This array maps the GPIO pins used as INTERRUPT INPUTS */ + +static const uint32_t g_gpiointinputs[BOARD_NGPIOINT] = +{ + GPIO_INT1, +}; + +static struct gd32gpint_dev_s g_gpint[BOARD_NGPIOINT]; +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: gpio_setpintype + * + * Description: + * set gpio pintype. + * + ****************************************************************************/ + +static int gpio_setpintype(struct gpio_dev_s *dev, + enum gpio_pintype_e gpio_pintype) +{ + int ret = OK; + uint32_t pinconfig; + const struct gpio_operations_s *gpio_ops; + struct gd32gpint_dev_s *gd32gpint = (struct gd32gpint_dev_s *)dev; + + DEBUGASSERT(gd32gpint != NULL); + gpioinfo("Setpintype...\n"); + + /* Check if the new pintype is actually different from the old pintype */ + + if (gd32gpint->gd32gpio.gpio.gp_pintype == gpio_pintype) + { + /* Pintype has not changed. We're done already. */ + + return ret; + } + + if (gd32gpint->gd32gpio.gpio.gp_pintype >= GPIO_NPINTYPES) + { + gpioerr("pintype error\n"); + return -1; + } + + pinconfig = (gd32gpint->gd32gpio.pinconfig & + (GPIO_CFG_PIN_MASK | GPIO_CFG_PORT_MASK)); + + switch (gpio_pintype) + { + case GPIO_INPUT_PIN: + gd32_gpio_config(GPIO_CFG_MODE_INPUT | GPIO_CFG_PUPD_NONE | + pinconfig); + gpio_ops = &gpin_ops; + break; + case GPIO_INPUT_PIN_PULLUP: + gd32_gpio_config(GPIO_CFG_MODE_INPUT | GPIO_CFG_PUPD_PULLUP | + pinconfig); + gpio_ops = &gpin_ops; + break; + case GPIO_INPUT_PIN_PULLDOWN: + gd32_gpio_config(GPIO_CFG_MODE_INPUT | GPIO_CFG_PUPD_PULLDOWN | + pinconfig); + gpio_ops = &gpin_ops; + break; + case GPIO_OUTPUT_PIN: + gd32_gpio_config(GPIO_CFG_MODE_OUTPUT | GPIO_CFG_PP | + GPIO_CFG_SPEED_50MHZ | pinconfig); + gpio_ops = &gpout_ops; + break; + case GPIO_OUTPUT_PIN_OPENDRAIN: + gd32_gpio_config(GPIO_CFG_MODE_OUTPUT | GPIO_CFG_OD | + GPIO_CFG_SPEED_50MHZ | pinconfig); + gpio_ops = &gpout_ops; + break; + case GPIO_INTERRUPT_PIN: + case GPIO_INTERRUPT_RISING_PIN: + case GPIO_INTERRUPT_FALLING_PIN: + case GPIO_INTERRUPT_BOTH_PIN: + gd32_gpio_config(GPIO_CFG_MODE_INPUT | GPIO_PUPD_NONE | + pinconfig); + gpio_ops = &gpint_ops; + break; + default: + + /* Not support! */ + + return -EINVAL; + break; + } + + /* If the pin previously had an interrupt pintype... */ + + if ((gd32gpint->gd32gpio.gpio.gp_pintype >= GPIO_INTERRUPT_PIN) && + (gd32gpint->gd32gpio.gpio.gp_pintype < GPIO_NPINTYPES)) + { + /* ...disable the interrupt... */ + + ret = gpint_enable(dev, false); + if (ret < 0) + { + return ret; + } + + /* ...and detach the old callback. */ + + ret = gpint_attach(dev, NULL); + if (ret < 0) + { + return ret; + } + } + + /* Change the pintype and set of operations */ + + gd32gpint->gd32gpio.gpio.gp_pintype = gpio_pintype; + gd32gpint->gd32gpio.gpio.gp_ops = gpio_ops; + gd32gpint->gd32gpio.pinconfig = pinconfig; + + return 0; +} + +#if BOARD_NGPIOIN > 0 +static int gpin_read(struct gpio_dev_s *dev, bool *value) +{ + struct gd32gpio_dev_s *gd32gpio = (struct gd32gpio_dev_s *)dev; + + DEBUGASSERT(gd32gpio != NULL && value != NULL); + gpioinfo("Reading...\n"); + + *value = gd32_gpio_read(gd32gpio->pinconfig); + + return OK; +} +#endif + +#if BOARD_NGPIOOUT > 0 +static int gpout_read(struct gpio_dev_s *dev, bool *value) +{ + struct gd32gpio_dev_s *gd32gpio = (struct gd32gpio_dev_s *)dev; + + DEBUGASSERT(gd32gpio != NULL && value != NULL); + gpioinfo("Reading...\n"); + + *value = gd32_gpio_read(gd32gpio->pinconfig); + + return OK; +} + +static int gpout_write(struct gpio_dev_s *dev, bool value) +{ + struct gd32gpio_dev_s *gd32gpio = (struct gd32gpio_dev_s *)dev; + + DEBUGASSERT(gd32gpio != NULL); + gpioinfo("Writing %d\n", (int)value); + + gd32_gpio_write(gd32gpio->pinconfig, value); + + return OK; +} +#endif + +#if BOARD_NGPIOINT > 0 + +static int gd32gpio_interrupt(int irq, void *context, void *arg) +{ + struct gd32gpint_dev_s *gd32gpint = (struct gd32gpint_dev_s *)arg; + + DEBUGASSERT(gd32gpint != NULL && gd32gpint->callback != NULL); + gpioinfo("Interrupt! callback=%p\n", gd32gpint->callback); + + gd32gpint->callback(&gd32gpint->gd32gpio.gpio, gd32gpint->gd32gpio.id); + return OK; +} + +static int gpint_read(struct gpio_dev_s *dev, bool *value) +{ + struct gd32gpint_dev_s *gd32gpint = (struct gd32gpint_dev_s *)dev; + + DEBUGASSERT(gd32gpint != NULL && value != NULL); + DEBUGASSERT(gd32gpint->gd32gpio.id < BOARD_NGPIOINT); + gpioinfo("Reading int pin...\n"); + + *value = gd32_gpio_read(gd32gpint->gd32gpio.pinconfig); + + return OK; +} + +static int gpint_attach(struct gpio_dev_s *dev, pin_interrupt_t callback) +{ + struct gd32gpint_dev_s *gd32gpint = (struct gd32gpint_dev_s *)dev; + int ret; + uint8_t gpio_irq; + uint8_t gpio_irqnum; + + gpioinfo("Attaching the callback\n"); + + flags = enter_critical_section(); + + /* Make sure the interrupt is disabled */ + + ret = gd32_exti_gpioirq_init(g_gpiointinputs[gd32gpint->gd32gpio.id], + EXTI_INTERRUPT, EXTI_TRIG_RISING, &gpio_irq); + + if (ret < 0) + { + leave_critical_section(flags); + return ret; + } + + gd32_gpio_exti_irqnum_get(g_gpiointinputs[gd32gpint->gd32gpio.id], + &gpio_irqnum); + + /* Attach and disable the interrupt */ + + gd32_exti_gpio_irq_attach(gpio_irq, gd32gpio_interrupt, + &g_gpint[gd32gpint->gd32gpio.id]); + + /* Disable and the interrupt */ + + up_disable_irq(gpio_irqnum); + + leave_critical_section(flags); + gpioinfo("Attach %p\n", callback); + gd32gpint->callback = callback; + return OK; +} + +static int gpint_enable(struct gpio_dev_s *dev, bool enable) +{ + struct gd32gpint_dev_s *gd32gpint = (struct gd32gpint_dev_s *)dev; + int ret; + uint8_t gpio_irqnum; + + flags = enter_critical_section(); + + /* Get gpio irq numbers */ + + ret = gd32_gpio_exti_irqnum_get(g_gpiointinputs[gd32gpint->gd32gpio.id], + &gpio_irqnum); + if (ret < 0) + { + leave_critical_section(flags); + return ret; + } + + if (enable) + { + if (gd32gpint->callback != NULL) + { + gpioinfo("Enabling the interrupt\n"); + + /* Enable the interrupt */ + + up_disable_irq(gpio_irqnum); + } + } + else + { + up_disable_irq(gpio_irqnum); + gpioinfo("Disable the interrupt\n"); + } + + leave_critical_section(flags); + return OK; +} +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: gd32_gpio_initialize + * + * Description: + * Initialize GPIO drivers for use with /apps/examples/gpio + * + ****************************************************************************/ + +int gd32_gpio_initialize(void) +{ + int pincount = 0; + int i; + +#if BOARD_NGPIOIN > 0 + for (i = 0; i < BOARD_NGPIOIN; i++) + { + /* Setup and register the GPIO pin */ + + g_gpin[i].gpio.gp_pintype = GPIO_INPUT_PIN; + g_gpin[i].gpio.gp_ops = &gpin_ops; + g_gpin[i].pinconfig = g_gpioinputs[i]; + g_gpin[i].id = i; + + gpio_pin_register(&g_gpin[i].gpio, pincount); + + /* Configure the pin that will be used as input */ + + gd32_gpio_config(g_gpioinputs[i]); + + pincount++; + } +#endif + +#if BOARD_NGPIOOUT > 0 + for (i = 0; i < BOARD_NGPIOOUT; i++) + { + /* Setup and register the GPIO pin */ + + g_gpout[i].gpio.gp_pintype = GPIO_OUTPUT_PIN; + g_gpout[i].gpio.gp_ops = &gpout_ops; + g_gpout[i].pinconfig = g_gpiooutputs[i]; + g_gpout[i].id = i; + + gpio_pin_register(&g_gpout[i].gpio, pincount); + + /* Configure the pin that will be used as output */ + + gd32_gpio_write(g_gpiooutputs[i], 0); + gd32_gpio_config(g_gpiooutputs[i]); + + pincount++; + } +#endif + +#if BOARD_NGPIOINT > 0 + for (i = 0; i < BOARD_NGPIOINT; i++) + { + /* Setup and register the GPIO pin */ + + g_gpint[i].gd32gpio.gpio.gp_pintype = GPIO_INTERRUPT_PIN; + g_gpint[i].gd32gpio.gpio.gp_ops = &gpint_ops; + g_gpint[i].gd32gpio.pinconfig = g_gpiointinputs[i]; + g_gpint[i].gd32gpio.id = i; + (void)gpio_pin_register(&g_gpint[i].gd32gpio.gpio, pincount); + + /* Configure the pin that will be used as interrupt input */ + + gd32_gpio_config(g_gpiointinputs[i]); + + pincount++; + } +#endif + + return 0; +} +#endif /* CONFIG_DEV_GPIO && !CONFIG_GPIO_LOWER_HALF */ diff --git a/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_i2c.c b/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_i2c.c new file mode 100644 index 00000000000..26169f9f2f5 --- /dev/null +++ b/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_i2c.c @@ -0,0 +1,95 @@ +/**************************************************************************** + * boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_i2c.c + * + * 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 +#include +#include +#include +#include + +#include + +#include"gd32f4xx.h" +#include "gd32f470z_aiotbox.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#ifdef CONFIG_I2C +void gd32_i2c_initialize(void) +{ + FAR struct i2c_master_s *i2c; + int ret; + i2cinfo("Initialize I2c\n"); + +#ifdef CONFIG_GD32F4_I2C0 + i2c = gd32_i2cbus_initialize(0); + + if (i2c == NULL) + { + i2cerr("init i2c0 faild.\n"); + return; + } + else + { + ret = i2c_register(i2c, 0); + + if (ret < 0) + { + i2cerr("registering i2c0 faild.\n"); + } + else + { + i2cinfo("registering i2c0 successed.\n"); + } + } + + i2c = NULL; +#endif +#ifdef CONFIG_GD32F4_I2C1 + i2c = gd32_i2cbus_initialize(1); + + if (i2c == NULL) + { + i2cerr("init i2c1 faild.\n"); + return; + } + else + { + ret = i2c_register(i2c, 1); + + if (ret < 0) + { + i2cerr("registering i2c1 faild.\n"); + } + else + { + i2cinfo("registering i2c1 successed.\n"); + } + } + +#endif +} + +#endif \ No newline at end of file diff --git a/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_reset.c b/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_reset.c new file mode 100644 index 00000000000..a5607896f3d --- /dev/null +++ b/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_reset.c @@ -0,0 +1,62 @@ +/**************************************************************************** + * boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_reset.c + * + * 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 + +#include +#include + +#ifdef CONFIG_BOARDCTL_RESET + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_reset + * + * Description: + * Reset board. Support for this function is required by board-level + * logic if CONFIG_BOARDCTL_RESET is selected. + * + * Input Parameters: + * status - Status information provided with the reset event. This + * meaning of this status information is board-specific. If not + * used by a board, the value zero may be provided in calls to + * board_reset(). + * + * Returned Value: + * If this function returns, then it was not possible to power-off the + * board due to some constraints. The return value int this case is a + * board-specific reason for the failure to shutdown. + * + ****************************************************************************/ + +int board_reset(int status) +{ + up_systemreset(); + return 0; +} + +#endif /* CONFIG_BOARDCTL_RESET */ diff --git a/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_romfs.c b/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_romfs.c new file mode 100644 index 00000000000..a5b77da4470 --- /dev/null +++ b/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_romfs.c @@ -0,0 +1,137 @@ +/**************************************************************************** + * boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_romfs.c + * + * 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 + +#include +#include +#include +#include +#include + +#include +#include +#include "gd32f4xx_romfs.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifndef CONFIG_GD32F4_ROMFS +# error "CONFIG_GD32F4_ROMFS must be defined" +#else + +#ifndef CONFIG_GD32F4_ROMFS_IMAGEFILE +# error "CONFIG_GD32F4_ROMFS_IMAGEFILE must be defined" +#endif + +#ifndef CONFIG_GD32F4_ROMFS_DEV_MINOR +# error "CONFIG_GD32F4_ROMFS_DEV_MINOR must be defined" +#endif + +#ifndef CONFIG_GD32F4_ROMFS_MOUNTPOINT +# error "CONFIG_GD32F4_ROMFS_MOUNTPOINT must be defined" +#endif + +#define NSECTORS(size) (((size) + ROMFS_SECTOR_SIZE - 1)/ROMFS_SECTOR_SIZE) + +#define STR2(m) #m +#define STR(m) STR2(m) + +#define MKMOUNT_DEVNAME(m) "/dev/ram" STR(m) +#define MOUNT_DEVNAME MKMOUNT_DEVNAME(CONFIG_GD32F4_ROMFS_DEV_MINOR) + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +__asm__ ( + " .section .rodata \n" + " .balign 16 \n" + " .globl romfs_data_begin \n" + "romfs_data_begin: \n" + " .incbin " STR(CONFIG_GD32F4_ROMFS_IMAGEFILE)"\n" + " .balign " STR(ROMFS_SECTOR_SIZE) "\n" + " .globl romfs_data_end \n" + "romfs_data_end: \n" + ); + +extern const uint8_t romfs_data_begin[]; +extern const uint8_t romfs_data_end[]; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: gd32_romfs_initialize + * + * Description: + * Registers the aboveincluded binary file as block device. + * Then mounts the block device as ROMFS filesystems. + * + * Returned Value: + * Zero (OK) on success, a negated errno value on error. + * + * Assumptions/Limitations: + * Memory addresses [romfs_data_begin .. romfs_data_end) should contain + * ROMFS volume data, as included in the assembly snippet above. + * + ****************************************************************************/ + +int gd32_romfs_initialize(void) +{ + uintptr_t romfs_data_len; + int ret; + + /* Create a ROM disk for the /etc filesystem */ + + romfs_data_len = romfs_data_end - romfs_data_begin; + + ret = romdisk_register(CONFIG_GD32F4_ROMFS_DEV_MINOR, romfs_data_begin, + NSECTORS(romfs_data_len), ROMFS_SECTOR_SIZE); + if (ret < 0) + { + ferr("ERROR: romdisk_register failed: %d\n", -ret); + return ret; + } + + /* Mount the file system */ + + finfo("Mounting ROMFS filesystem at target=%s with source=%s\n", + CONFIG_GD32F4_ROMFS_MOUNTPOINT, MOUNT_DEVNAME); + + ret = nx_mount(MOUNT_DEVNAME, CONFIG_GD32F4_ROMFS_MOUNTPOINT, + "romfs", MS_RDONLY, NULL); + if (ret < 0) + { + ferr("ERROR: nx_mount(%s,%s,romfs) failed: %d\n", + MOUNT_DEVNAME, CONFIG_GD32F4_ROMFS_MOUNTPOINT, ret); + return ret; + } + + return OK; +} + +#endif /* CONFIG_GD32F4_ROMFS */ diff --git a/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_romfs.h b/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_romfs.h new file mode 100644 index 00000000000..658ad1e38ba --- /dev/null +++ b/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_romfs.h @@ -0,0 +1,62 @@ +/**************************************************************************** + * boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_romfs.h + * + * 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_GD32F4_GD32F470ZK_AIOTBOX_SRC_GD32F4XX_ROMFS_H +#define __BOARDS_ARM_GD32F4_GD32F470ZK_AIOTBOX_SRC_GD32F4XX_ROMFS_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#ifdef CONFIG_GD32F4_ROMFS + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define ROMFS_SECTOR_SIZE 64 + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: gd32_romfs_initialize + * + * Description: + * Registers built-in ROMFS image as block device and mounts it. + * + * Returned Value: + * Zero (OK) on success, a negated errno value on error. + * + * Assumptions/Limitations: + * Memory addresses [romfs_data_begin .. romfs_data_end) should contain + * ROMFS volume data, as included in the assembly snippet in + * gd32f4xx_romfs.c. + * + ****************************************************************************/ + +int gd32_romfs_initialize(void); + +#endif /* CONFIG_GD32F4_ROMFS */ + +#endif /* __BOARDS_ARM_GD32F4_GD32F470ZK_EVAL_SRC_GD32F4XX_ROMFS_H */ diff --git a/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_sdio.c b/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_sdio.c new file mode 100644 index 00000000000..3150f3f2fb5 --- /dev/null +++ b/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_sdio.c @@ -0,0 +1,149 @@ +/**************************************************************************** + * boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_sdio.c + * + * 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 + +#include +#include +#include +#include + +#include +#include + +#include "chip.h" +#include "gd32f4xx.h" +#include "gd32f470z_aiotbox.h" + +#ifdef CONFIG_MMCSD + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Configuration ************************************************************/ + +/* Card detections requires card support and a card detection GPIO */ + +#define HAVE_NCD 1 +#if !defined(GPIO_SDMMC1_NCD) +# undef HAVE_NCD +#endif + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static struct sdio_dev_s *g_sdio_dev; +#ifdef HAVE_NCD +static bool g_sd_inserted; +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: gd32_ncd_interrupt + * + * Description: + * Card detect interrupt handler. + * + ****************************************************************************/ + +#ifdef HAVE_NCD +static int gd32_ncd_interrupt(int irq, void *context) +{ + bool present; + + present = !gd32_gpio_read(GPIO_SDMMC1_NCD); + if (g_sdio_dev && present != g_sd_inserted) + { + sdio_mediachange(g_sdio_dev, present); + g_sd_inserted = present; + } + + return OK; +} +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: gd32_sdio_initialize + * + * Description: + * Initialize SDIO-based MMC/SD card support + * + ****************************************************************************/ + +int gd32_sdio_initialize(void) +{ + int ret; + + /* Mount the SDIO-based MMC/SD block driver + * First, get an instance of the SDIO interface + */ + + finfo("Initializing SDIO slot %d\n", SDIO_SLOTNO); + + g_sdio_dev = sdio_initialize(SDIO_SLOTNO); + if (!g_sdio_dev) + { + ferr("ERROR: Failed to initialize SDIO slot %d\n", SDIO_SLOTNO); + return -ENODEV; + } + + /* Now bind the SDIO interface to the MMC/SD driver */ + + finfo("Bind SDIO to the MMC/SD driver, minor=%d\n", SDIO_MINOR); + + ret = mmcsd_slotinitialize(SDIO_MINOR, g_sdio_dev); + if (ret != OK) + { + ferr("ERROR: Failed to bind SDIO to the MMC/SD driver: %d\n", ret); + return ret; + } + + finfo("Successfully bound SDIO to the MMC/SD driver\n"); + +#ifdef HAVE_NCD + /* Use SD card detect pin to check if a card is g_sd_inserted */ + + g_sd_inserted = !gd32_gpio_read(GPIO_SDMMC1_NCD); + finfo("Card detect : %d\n", g_sd_inserted); + + sdio_mediachange(g_sdio_dev, g_sd_inserted); +#else + /* Assume that the SD card is inserted. What choice do we have? */ + + sdio_mediachange(g_sdio_dev, true); +#endif + + return OK; +} + +#endif /* CONFIG_MMCSD */ diff --git a/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_spi.c b/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_spi.c new file mode 100644 index 00000000000..9b83fcd01aa --- /dev/null +++ b/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_spi.c @@ -0,0 +1,283 @@ +/**************************************************************************** + * boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_spi.c + * + * 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 + +#include +#include +#include +#include + +#include +#include + +#include "chip.h" +#include "gd32f4xx.h" +#include "gd32f470z_aiotbox.h" + +#if defined(CONFIG_SPI) + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: gd32_spidev_initialize + * + * Description: + * Called to configure SPI chip select GPIO pins for the GD32F470Z-EVAL. + * + ****************************************************************************/ + +void weak_function gd32_spidev_initialize(void) +{ +#ifdef CONFIG_GD32F4_SPI0 + /* Configure SPI0 CS GPIO for output */ + + gd32_gpio_config(GPIO_SPI0_CSPIN); + gd32_gpio_write(GPIO_SPI0_CSPIN, 1); +#endif +#ifdef CONFIG_GD32F4_SPI1 + /* Configure SPI1 CS GPIO for output */ + + gd32_gpio_config(GPIO_SPI1_CSPIN); + gd32_gpio_write(GPIO_SPI1_CSPIN, 1); +#endif +#ifdef CONFIG_GD32F4_SPI2 + /* Configure SPI2 CS GPIO for output */ + + gd32_gpio_config(GPIO_SPI2_CSPIN); + gd32_gpio_write(GPIO_SPI2_CSPIN, 1); +#endif +#ifdef CONFIG_GD32F4_SPI3 + /* Configure SPI3 CS GPIO for output */ + + gd32_gpio_config(GPIO_SPI3_CSPIN); + gd32_gpio_write(GPIO_SPI3_CSPIN, 1); +#endif +#ifdef CONFIG_GD32F4_SPI4 + /* Configure SPI4 CS GPIO for output */ + + gd32_gpio_config(GPIO_SPI4_CSPIN); + gd32_gpio_write(GPIO_SPI4_CSPIN, 1); +#endif +#ifdef CONFIG_GD32F4_SPI5 + /* Configure SPI5 CS GPIO for output */ + + gd32_gpio_config(GPIO_SPI5_CSPIN); + gd32_gpio_write(GPIO_SPI5_CSPIN, 1); +#endif +} + +/**************************************************************************** + * Name: gd32_spi[n]select and gd32_spi[n]status + * + * Description: + * The external functions, gd32_spi0-5select and gd32_spi0-5 status + * must be provided by board-specific logic. They are implementations of the + * select and status methods of the SPI interface defined by struct spi_ops_s + * (see include/nuttx/spi/spi.h). + * All other methods (including gd32_spibus_initialize()) are provided by + * common GD32F4 logic. To use this common SPI logic on your board: + * + * 1. Provide logic in gd32_boardinitialize() to configure SPI chip select + * pins. + * 2. Provide gd32_spi[n]select() and gd32_spi[n]status() functions + * in your board-specific logic. These functions will perform chip + * selection and status operations using GPIOs in the way your board is + * configured. + * 3. Add a calls to gd32_spibus_initialize() in your low level + * application initialization logic + * 4. The handle returned by gd32_spibus_initialize() may then be used to + * bind the SPI driver to higher level logic (e.g., calling + * mmcsd_spislotinitialize(), for example, will bind the SPI driver to + * the SPI MMC/SD driver). + * + ****************************************************************************/ + +#ifdef CONFIG_GD32F4_SPI0 +void gd32_spi0select(struct spi_dev_s *dev, uint32_t devid, + bool selected) +{ + spiinfo("devid: %d CS: %s\n", (int)devid, + selected ? "assert" : "de-assert"); + + gd32_gpio_write(GPIO_SPI0_CSPIN, !selected); +} + +uint8_t gd32_spi0status(struct spi_dev_s *dev, uint32_t devid) +{ + return 0; +} +#endif + +#ifdef CONFIG_GD32F4_SPI1 +void gd32_spi1select(struct spi_dev_s *dev, uint32_t devid, + bool selected) +{ + spiinfo("devid: %d CS: %s\n", (int)devid, + selected ? "assert" : "de-assert"); + + gd32_gpio_write(GPIO_SPI1_CSPIN, !selected); +} + +uint8_t gd32_spi1status(struct spi_dev_s *dev, uint32_t devid) +{ + return 0; +} +#endif + +#ifdef CONFIG_GD32F4_SPI2 +void gd32_spi2select(struct spi_dev_s *dev, uint32_t devid, + bool selected) +{ + spiinfo("devid: %d CS: %s\n", (int)devid, + selected ? "assert" : "de-assert"); + + gd32_gpio_write(GPIO_SPI2_CSPIN, !selected); +} + +uint8_t gd32_spi2status(struct spi_dev_s *dev, uint32_t devid) +{ + return 0; +} +#endif + +#ifdef CONFIG_GD32F4_SPI3 +void gd32_spi3select(struct spi_dev_s *dev, uint32_t devid, + bool selected) +{ + spiinfo("devid: %d CS: %s\n", (int)devid, + selected ? "assert" : "de-assert"); + + gd32_gpio_write(GPIO_SPI3_CSPIN, !selected); +} + +uint8_t gd32_spi3status(struct spi_dev_s *dev, uint32_t devid) +{ + return 0; +} +#endif + +#ifdef CONFIG_GD32F4_SPI4 +void gd32_spi4select(struct spi_dev_s *dev, uint32_t devid, + bool selected) +{ + spiinfo("devid: %d CS: %s\n", (int)devid, + selected ? "assert" : "de-assert"); + + gd32_gpio_write(GPIO_SPI4_CSPIN, !selected); +} + +uint8_t gd32_spi4status(struct spi_dev_s *dev, uint32_t devid) +{ + return 0; +} +#endif + +#ifdef CONFIG_GD32F4_SPI5 +void gd32_spi5select(struct spi_dev_s *dev, uint32_t devid, + bool selected) +{ + spiinfo("devid: %d CS: %s\n", (int)devid, + selected ? "assert" : "de-assert"); + + gd32_gpio_write(GPIO_SPI5_CSPIN, !selected); +} + +uint8_t gd32_spi5status(struct spi_dev_s *dev, uint32_t devid) +{ + return 0; +} +#endif + +/**************************************************************************** + * Name: gd32_spi[n]cmddata + * + * Description: + * Set or clear the SH1101A A0 or SD1306 D/C n bit to select data (true) + * or command (false). This function must be provided by platform-specific + * logic. This is an implementation of the cmddata method of the SPI + * interface defined by struct spi_ops_s (see include/nuttx/spi/spi.h). + * + * Input Parameters: + * + * spi - SPI device that controls the bus the device that requires the CMD/ + * DATA selection. + * devid - If there are multiple devices on the bus, this selects which one + * to select cmd or data. NOTE: This design restricts, for example, + * one one SPI display per SPI bus. + * cmd - true: select command; false: select data + * + * Returned Value: + * None + * + ****************************************************************************/ + +#ifdef CONFIG_SPI_CMDDATA +#ifdef CONFIG_GD32F4_SPI0 +int gd32_spi0cmddata(struct spi_dev_s *dev, uint32_t devid, bool cmd) +{ + return -ENODEV; +} +#endif + +#ifdef CONFIG_GD32F4_SPI1 +int gd32_spi1cmddata(struct spi_dev_s *dev, uint32_t devid, bool cmd) +{ + return -ENODEV; +} +#endif + +#ifdef CONFIG_GD32F4_SPI2 +int gd32_spi2cmddata(struct spi_dev_s *dev, uint32_t devid, bool cmd) +{ + return -ENODEV; +} +#endif + +#ifdef CONFIG_GD32F4_SPI3 +int gd32_spi3cmddata(struct spi_dev_s *dev, uint32_t devid, bool cmd) +{ + return -ENODEV; +} +#endif + +#ifdef CONFIG_GD32F4_SPI5 +int gd32_spi4cmddata(struct spi_dev_s *dev, uint32_t devid, bool cmd) +{ + return -ENODEV; +} +#endif + +#ifdef CONFIG_GD32F4_SPI5 +int gd32_spi5cmddata(struct spi_dev_s *dev, uint32_t devid, bool cmd) +{ + return -ENODEV; +} +#endif + +#endif /* CONFIG_SPI_CMDDATA */ + +#endif /* defined(CONFIG_SPI) */ diff --git a/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_userleds.c b/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_userleds.c new file mode 100644 index 00000000000..04395e01c0c --- /dev/null +++ b/boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_userleds.c @@ -0,0 +1,149 @@ +/**************************************************************************** + * boards/arm/gd32f4/gd32f470zk-aiotbox/src/gd32f4xx_userleds.c + * + * 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 + +#include +#include + +#include + +#include +#include + +#include "gd32f4xx_gpio.h" +#include "gd32f470z_aiotbox.h" + +#ifndef CONFIG_ARCH_LEDS + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* LED index */ + +static const uint32_t g_led_map[BOARD_LEDS] = +{ + LED1, + LED2, + LED3 +}; + +static const uint32_t g_led_setmap[BOARD_LEDS] = +{ + BOARD_LED1_BIT, + BOARD_LED2_BIT, + BOARD_LED3_BIT +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/* Turn on selected led */ + +static void gd32_aiotbox_led_on(led_typedef_enum led_num) +{ + gd32_gpio_write(g_led_map[led_num], true); +} + +/* Turn off selected led */ + +static void gd32_aiotbox_led_off(led_typedef_enum led_num) +{ + gd32_gpio_write(g_led_map[led_num], false); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_userled_initialize + * + * Description: + * If CONFIG_ARCH_LEDS is defined, then NuttX will control the on-board + * LEDs. If CONFIG_ARCH_LEDS is not defined, then the + * board_userled_initialize() is available to initialize the LED from user + * application logic. + * + ****************************************************************************/ + +uint32_t board_userled_initialize(void) +{ + int i; + + /* Configure the LED GPIO for output. */ + + for (i = 0; i < nitems(g_led_map); i++) + { + gd32_gpio_config(g_led_map[i]); + } + + return BOARD_LEDS; +} + +/**************************************************************************** + * Name: board_userled + * + * Description: + * If CONFIG_ARCH_LEDS is defined, then NuttX will control the on-board + * LEDs. If CONFIG_ARCH_LEDS is not defined, then the board_userled() is + * available to control the LED from user application logic. + * + ****************************************************************************/ + +void board_userled(int led, bool ledon) +{ + if ((unsigned)led < nitems(g_led_map)) + { + gd32_gpio_write(g_led_map[led], ledon); + } +} + +/**************************************************************************** + * Name: board_userled_all + * + * Description: + * If CONFIG_ARCH_LEDS is defined, then NuttX will control the on-board + * LEDs. If CONFIG_ARCH_LEDS is not defined, then the board_userled_all() + * is available to control the LED from user application logic. + * NOTE: since there is only a single LED on-board, this is function + * is not very useful. + * + ****************************************************************************/ + +void board_userled_all(uint32_t ledset) +{ + int i; + + /* Configure LED1-3 GPIOs for output */ + + for (i = 0; i < nitems(g_led_map); i++) + { + gd32_gpio_write(g_led_map[i], (ledset & g_led_setmap[i]) != 0); + } +} + +#endif /* !CONFIG_ARCH_LEDS */