You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ac...@apache.org on 2021/07/28 23:02:46 UTC

[incubator-nuttx] branch master updated: nucleo-g431rb: add CORDIC example

This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 68a345e  nucleo-g431rb: add CORDIC example
68a345e is described below

commit 68a345e248b6ca53b0d830c96d21bbd8de9c036e
Author: raiden00pl <ra...@railab.me>
AuthorDate: Wed Jul 14 14:42:41 2021 +0200

    nucleo-g431rb: add CORDIC example
---
 .../stm32/nucleo-g431rb/configs/cordic/defconfig   | 54 ++++++++++++++
 boards/arm/stm32/nucleo-g431rb/src/Make.defs       |  4 +
 boards/arm/stm32/nucleo-g431rb/src/nucleo-g431rb.h | 12 +++
 boards/arm/stm32/nucleo-g431rb/src/stm32_bringup.c | 10 +++
 boards/arm/stm32/nucleo-g431rb/src/stm32_cordic.c  | 87 ++++++++++++++++++++++
 5 files changed, 167 insertions(+)

diff --git a/boards/arm/stm32/nucleo-g431rb/configs/cordic/defconfig b/boards/arm/stm32/nucleo-g431rb/configs/cordic/defconfig
new file mode 100644
index 0000000..096e281
--- /dev/null
+++ b/boards/arm/stm32/nucleo-g431rb/configs/cordic/defconfig
@@ -0,0 +1,54 @@
+#
+# 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_NSH_ARGCAT is not set
+# CONFIG_NSH_CMDOPT_HEXDUMP is not set
+# CONFIG_NSH_CMDPARMS is not set
+# CONFIG_NSH_DISABLE_IFCONFIG is not set
+# CONFIG_NSH_DISABLE_PS is not set
+CONFIG_ARCH="arm"
+CONFIG_ARCH_BOARD="nucleo-g431rb"
+CONFIG_ARCH_BOARD_NUCLEO_G431RB=y
+CONFIG_ARCH_BUTTONS=y
+CONFIG_ARCH_CHIP="stm32"
+CONFIG_ARCH_CHIP_STM32=y
+CONFIG_ARCH_CHIP_STM32G431R=y
+CONFIG_ARCH_INTERRUPTSTACK=2048
+CONFIG_ARCH_STACKDUMP=y
+CONFIG_BOARD_LOOPSPERMSEC=8499
+CONFIG_BUILTIN=y
+CONFIG_DEBUG_FULLOPT=y
+CONFIG_DEBUG_SYMBOLS=y
+CONFIG_EXAMPLES_CORDIC=y
+CONFIG_HAVE_CXX=y
+CONFIG_HAVE_CXXINITIALIZE=y
+CONFIG_INTELHEX_BINARY=y
+CONFIG_LIBC_FLOATINGPOINT=y
+CONFIG_MATH_CORDIC=y
+CONFIG_NSH_ARCHINIT=y
+CONFIG_NSH_BUILTIN_APPS=y
+CONFIG_NSH_FILEIOSIZE=512
+CONFIG_NSH_LINELEN=64
+CONFIG_NSH_READLINE=y
+CONFIG_PREALLOC_TIMERS=4
+CONFIG_RAM_SIZE=22528
+CONFIG_RAM_START=0x20000000
+CONFIG_RAW_BINARY=y
+CONFIG_RR_INTERVAL=200
+CONFIG_SCHED_WAITPID=y
+CONFIG_SDCLONE_DISABLE=y
+CONFIG_START_DAY=14
+CONFIG_START_MONTH=10
+CONFIG_START_YEAR=2014
+CONFIG_STM32_CORDIC=y
+CONFIG_STM32_JTAG_SW_ENABLE=y
+CONFIG_STM32_USART2=y
+CONFIG_SYSTEM_NSH=y
+CONFIG_TASK_NAME_SIZE=0
+CONFIG_USART2_SERIAL_CONSOLE=y
+CONFIG_USER_ENTRYPOINT="nsh_main"
diff --git a/boards/arm/stm32/nucleo-g431rb/src/Make.defs b/boards/arm/stm32/nucleo-g431rb/src/Make.defs
index 5861195..eb1eef2 100644
--- a/boards/arm/stm32/nucleo-g431rb/src/Make.defs
+++ b/boards/arm/stm32/nucleo-g431rb/src/Make.defs
@@ -51,6 +51,10 @@ ifeq ($(CONFIG_BOARD_STM32_IHM16M1),y)
 CSRCS += stm32_foc_ihm16m1.c
 endif
 
+ifeq ($(CONFIG_MATH_CORDIC),y)
+CSRCS += stm32_cordic.c
+endif
+
 DEPPATH += --dep-path board
 VPATH += :board
 CFLAGS += $(shell $(INCDIR) "$(CC)" $(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board)
diff --git a/boards/arm/stm32/nucleo-g431rb/src/nucleo-g431rb.h b/boards/arm/stm32/nucleo-g431rb/src/nucleo-g431rb.h
index 92154be..1afa58e 100644
--- a/boards/arm/stm32/nucleo-g431rb/src/nucleo-g431rb.h
+++ b/boards/arm/stm32/nucleo-g431rb/src/nucleo-g431rb.h
@@ -143,4 +143,16 @@ int stm32_adc_setup(void);
 int stm32_foc_setup(void);
 #endif
 
+/****************************************************************************
+ * Name: stm32_cordic_setup
+ *
+ * Description:
+ *  Initialize CORDIC peripheral for the board.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_MATH_CORDIC
+int stm32_cordic_setup(void);
+#endif
+
 #endif /* __BOARDS_ARM_STM32_NUCLEO_G431RB_SRC_NUCLEO_G431RB_H */
diff --git a/boards/arm/stm32/nucleo-g431rb/src/stm32_bringup.c b/boards/arm/stm32/nucleo-g431rb/src/stm32_bringup.c
index 7e7ad76..6200a53 100644
--- a/boards/arm/stm32/nucleo-g431rb/src/stm32_bringup.c
+++ b/boards/arm/stm32/nucleo-g431rb/src/stm32_bringup.c
@@ -122,6 +122,16 @@ int stm32_bringup(void)
     }
 #endif
 
+#ifdef CONFIG_MATH_CORDIC
+  /* Initialize CORDIC and register the CORDIC driver. */
+
+  ret = stm32_cordic_setup();
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: stm32_cordic_setup failed: %d\n", ret);
+    }
+#endif
+
   UNUSED(ret);
   return OK;
 }
diff --git a/boards/arm/stm32/nucleo-g431rb/src/stm32_cordic.c b/boards/arm/stm32/nucleo-g431rb/src/stm32_cordic.c
new file mode 100644
index 0000000..ead99fc
--- /dev/null
+++ b/boards/arm/stm32/nucleo-g431rb/src/stm32_cordic.c
@@ -0,0 +1,87 @@
+/****************************************************************************
+ * boards/arm/stm32/nucleo-g431rb/src/stm32_cordic.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 <nuttx/config.h>
+
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/math/cordic.h>
+#include <arch/board/board.h>
+
+#include "stm32_cordic.h"
+
+#include "nucleo-g431rb.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: stm32_cordic_setup
+ *
+ * Description:
+ *   Initialize CORDIC and register the CORDIC device.
+ *
+ ****************************************************************************/
+
+int stm32_cordic_setup(void)
+{
+  FAR struct cordic_lowerhalf_s *cordic      = NULL;
+  static bool                    initialized = false;
+  int                            ret         = OK;
+
+  /* Have we already initialized? */
+
+  if (!initialized)
+    {
+      /* Call stm32_cordicinitialize() to get an instance of the CORDIC
+       * interface
+       */
+
+      cordic = stm32_cordicinitialize();
+      if (!cordic)
+        {
+          tmrerr("Failed to get the STM32 CORDIC lower half\n");
+          ret = -ENODEV;
+          goto errout;
+        }
+
+      /* Register the CORDIC driver at "/dev/cordic0" */
+
+      ret = cordic_register("/dev/cordic0", cordic);
+      if (ret < 0)
+        {
+          tmrerr("cordic_register failed: %d\n", ret);
+          goto errout;
+        }
+
+      /* Now we are initialized */
+
+      initialized = true;
+    }
+
+errout:
+  return ret;
+}