hartmannathan commented on code in PR #10328: URL: https://github.com/apache/nuttx/pull/10328#discussion_r1303100829
########## arch/arm/src/stm32h7/Kconfig: ########## @@ -2086,6 +2138,15 @@ config STM32H7_QSPI_REGDEBUG endmenu +config STM32H7_BYPASS_CLOCKCONFIG + bool "Bypass clock configuration" + depends on ARCH_STM32H7_DUALCORE + default n if ARCH_CHIP_STM32H7_CORTEXM7 + default y if ARCH_CHIP_STM32H7_CORTEXM4 + ---help--- + Bypass clock configuration. For dual core chips only one core + should configure clocks + Review Comment: I'm a little confused by `STM32H7_BYPASS_CLOCKCONFIG`: I understand that only one core should configure clocks, but which core will do that? Maybe the `---help---` text could clarify that a little bit. ########## boards/arm/stm32h7/nucleo-h745zi/src/stm32_userleds.c: ########## @@ -0,0 +1,125 @@ +/**************************************************************************** + * boards/arm/stm32h7/nucleo-h745zi/src/stm32_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 <nuttx/config.h> + +#include <stdbool.h> +#include <debug.h> + +#include <sys/param.h> + +#include <nuttx/board.h> +#include <arch/board/board.h> + +#include "stm32_gpio.h" +#include "nucleo-h745zi.h" + +#ifndef CONFIG_ARCH_LEDS + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* This array maps an LED number to GPIO pin configuration and is indexed by + * BOARD_LED_<color> + */ + +static const uint32_t g_ledcfg[BOARD_NLEDS] = +{ + GPIO_LED_GREEN, + GPIO_LED_BLUE, + GPIO_LED_RED, +}; + +/**************************************************************************** + * 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 LED1-3 GPIOs for output */ + + for (i = 0; i < nitems(g_ledcfg); i++) + { + stm32_configgpio(g_ledcfg[i]); + } + + return BOARD_NLEDS; +} + +/**************************************************************************** + * 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 Review Comment: ```suggestion * LEDs. If CONFIG_ARCH_LEDS is not defined, then the board_userled() is ``` ########## boards/arm/stm32h7/nucleo-h745zi/include/board.h: ########## @@ -0,0 +1,393 @@ +/**************************************************************************** + * boards/arm/stm32h7/nucleo-h745zi/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_STM32H7_NUCLEO_H745ZI_INCLUDE_BOARD_H +#define __BOARDS_ARM_STM32H7_NUCLEO_H745ZI_INCLUDE_BOARD_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#ifndef __ASSEMBLY__ +# include <stdint.h> +#endif + +/* Do not include STM32 H7 header files here */ + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Clocking *****************************************************************/ + +/* The Nucleo-144 board provides the following clock sources: Review Comment: ```suggestion /* The Nucleo-144 board provides the following clock sources: ``` ########## arch/arm/src/stm32h7/stm32_allocateheap.c: ########## @@ -100,11 +108,33 @@ /* Set the start and end of the SRAMs */ -#define SRAM_START STM32_AXISRAM_BASE -#define SRAM_END (SRAM_START + STM32H7_SRAM_SIZE) +# define SRAM_START STM32_AXISRAM_BASE +# define SRAM_END (SRAM_START + STM32H7_SRAM_SIZE) + +# define SRAM123_START STM32_SRAM123_BASE +# define SRAM123_END (SRAM123_START + STM32H7_SRAM123_SIZE) + +#elif defined(CONFIG_ARCH_CHIP_STM32H7_CORTEXM7) && \ + !defined(CONFIG_STM32H7_CORTEXM4_DISABLED) + +/* Configuration for M7 core and M4 core support enabled */ Review Comment: ```suggestion /* Configuration for M7 core when M4 core support enabled */ ``` Again, I _think_ that's the intended message... ########## arch/arm/src/stm32h7/stm32_allocateheap.c: ########## @@ -44,13 +44,21 @@ #include "arm_internal.h" #include "hardware/stm32_memorymap.h" #include "stm32_mpuinit.h" -#include "stm32_dtcm.h" + +#ifdef CONFIG_ARCH_CHIP_STM32H7_CORTEXM7 +# include "stm32_dtcm.h" +#endif #include "stm32_fmc.h" /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ +#if defined(CONFIG_ARCH_CHIP_STM32H7_CORTEXM7) && \ + defined(CONFIG_STM32H7_CORTEXM4_DISABLED) + +/* Configuration for M7 core and M4 core support disabled */ Review Comment: ```suggestion /* Configuration for M7 core when M4 core support disabled */ ``` I think that's the intended message? ########## arch/arm/src/stm32h7/stm32_hsem.c: ########## @@ -0,0 +1,291 @@ +/**************************************************************************** + * arch/arm/src/stm32h7/stm32_hsem.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 <debug.h> + +#include "nvic.h" + +#include "arm_internal.h" +#include "stm32_hsem.h" + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/* HSEM receive channel configuration */ + +struct stm32_hsem_recv_s +{ + hsem_callback_t callback; + void *args; +}; + +/* HSEM device */ + +struct stm32_hsem_s +{ + struct stm32_hsem_recv_s recv[STM32_HSEM_CHANS]; + uint32_t irq; + uint8_t block; +}; + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +struct stm32_hsem_s g_stm32_hsem; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: stm32_hsem_interrupt + ****************************************************************************/ + +static int stm32_hsem_interrupt(int irq, void *context, void *args) +{ + struct stm32_hsem_s *dev = args; + uint32_t regval = 0; + int i = 0; + + regval = getreg32(STM32_HSEM_CXMISR(dev->block)); + + _info("HSEM interrupt 0x%" PRIx32 "\n", regval); + + for (i = 0; i < STM32_HSEM_CHANS; i += 1) Review Comment: ```suggestion for (i = 0; i < STM32_HSEM_CHANS; i++) ``` ########## arch/arm/src/stm32h7/Kconfig: ########## @@ -492,6 +503,39 @@ config STM32H7_AXI_SRAM_CORRUPTION_WAR AXI_TARG7_FN_MOD register. This will reduce the read issuing capability of the SRAM to 1 at AXI interconnect level and avoid data corruption. +if ARCH_STM32H7_DUALCORE + +if ARCH_CHIP_STM32H7_CORTEXM7 + +config STM32H7_CORTEXM4_DISABLED + bool "Disable support for M4 core" + default n + +config STM32H7_CORTEXM7_BOOTM4 + bool "Boot M4 core core" Review Comment: Just minor nit: ```suggestion bool "Boot M4 core" ``` ########## arch/arm/src/stm32h7/stm32_hsem.c: ########## @@ -0,0 +1,291 @@ +/**************************************************************************** + * arch/arm/src/stm32h7/stm32_hsem.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 <debug.h> + +#include "nvic.h" + +#include "arm_internal.h" +#include "stm32_hsem.h" + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/* HSEM receive channel configuration */ + +struct stm32_hsem_recv_s +{ + hsem_callback_t callback; + void *args; +}; + +/* HSEM device */ + +struct stm32_hsem_s +{ + struct stm32_hsem_recv_s recv[STM32_HSEM_CHANS]; + uint32_t irq; + uint8_t block; +}; + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +struct stm32_hsem_s g_stm32_hsem; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: stm32_hsem_interrupt + ****************************************************************************/ + +static int stm32_hsem_interrupt(int irq, void *context, void *args) +{ + struct stm32_hsem_s *dev = args; + uint32_t regval = 0; + int i = 0; + + regval = getreg32(STM32_HSEM_CXMISR(dev->block)); + + _info("HSEM interrupt 0x%" PRIx32 "\n", regval); + + for (i = 0; i < STM32_HSEM_CHANS; i += 1) + { + if (regval & HSEM_CHAN_ID(i)) + { + if (dev->recv[i].callback) + { + dev->recv[i].callback(i, dev->recv[i].args); + } + } + } + + /* Clear events */ + + putreg32(regval, STM32_HSEM_CXICR(dev->block)); + + return 0; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: stm32_hsem_subscribe + * + * Description: + * Subscribe to event on a given semaphore + * + ****************************************************************************/ + +void stm32_hsem_subscribe(uint8_t id, hsem_callback_t callback, void *args) +{ + struct stm32_hsem_s *dev = &g_stm32_hsem; + + DEBUGASSERT(id < STM32_HSEM_CHANS); + + _info("HSEM subscribe %d\n", id); + + /* Register callaback */ + + dev->recv[id].callback = callback; + dev->recv[id].args = args; + + if (callback) + { + /* Clear pending */ + + putreg32(HSEM_CHAN_ID(id), STM32_HSEM_CXICR(dev->block)); + + /* Enable interrupt */ + + modifyreg32(STM32_HSEM_CXIER(dev->block), 0, HSEM_CHAN_ID(id)); + } + else + { + /* Disable interrupts */ + + modifyreg32(STM32_HSEM_CXIER(dev->block), HSEM_CHAN_ID(id), 0); + } +} + +/**************************************************************************** + * Name: stm32_hsem_signal + * + * Description: + * Signal on a semaphore (free and lock again) + * + ****************************************************************************/ + +void stm32_hsem_signal(uint8_t id) +{ + DEBUGASSERT(id < STM32_HSEM_CHANS); + + _info("HSEM signal %d\n", id); + + /* Lock semaphore */ + + while (stm32_hsem_take(id) == 0); + + /* Free semaphore to signal event */ + + stm32_hsem_free(id); +} + +/**************************************************************************** + * Name: stm32_hsem_busywait_lock + * + * Description: + * Busy wait for a semaphore to be locked + * + ****************************************************************************/ + +void stm32_hsem_busywait_lock(uint8_t id) +{ + DEBUGASSERT(id < STM32_HSEM_CHANS); + + _info("HSEM busywait lock %d\n", id); + + /* Wait for semaphore lock */ + + while ((getreg32(STM32_HSEM_RX(id)) & HSEM_SEMX_LOCK) == 0); +} + +/**************************************************************************** + * Name: stm32_hsem_busywait_free + * + * Description: + * Busy wait for a semaphore to be free + * + ****************************************************************************/ + +void stm32_hsem_busywait_free(uint8_t id) +{ + DEBUGASSERT(id < STM32_HSEM_CHANS); + + _info("HSEM busywait free %d\n", id); + + /* Wait for semaphore free */ + + while ((getreg32(STM32_HSEM_RX(id)) & HSEM_SEMX_LOCK) != 0); +} + +/**************************************************************************** + * Name: stm32_hsem_wait_take + * + * Description: + * Take a semaphore (1-step lock) + * + ****************************************************************************/ + +void stm32_hsem_wait_take(uint8_t id) +{ + DEBUGASSERT(id < STM32_HSEM_CHANS); + + _info("HSEM wait take %d\n", id); + + stm32_hsem_busywait_free(id); + while (stm32_hsem_take(id) == 0); +} + +/**************************************************************************** + * Name: stm32_hsem_take + * + * Description: + * Take a semaphore (1-step lock) + * + ****************************************************************************/ + +bool stm32_hsem_take(uint8_t id) +{ + DEBUGASSERT(id < STM32_HSEM_CHANS); + + _info("HSEM take %d\n", id); + + /* Take semaphore */ + +#ifdef CONFIG_ARCH_CHIP_STM32H7_CORTEXM7 + return (getreg32(STM32_HSEM_RLRX(id)) == + ((HSEM_COREID_CPU1 << HSEM_SEMX_COREID_SHIFT) | HSEM_SEMX_LOCK)); +#else + return (getreg32(STM32_HSEM_RLRX(id)) == + ((HSEM_COREID_CPU2 << HSEM_SEMX_COREID_SHIFT) | HSEM_SEMX_LOCK)); +#endif +} + +/**************************************************************************** + * Name: stm32_hsem_free + * + * Description: + * Free a semaphore + * + ****************************************************************************/ + +void stm32_hsem_free(uint8_t id) +{ +#ifdef CONFIG_ARCH_CHIP_STM32H7_CORTEXM7 + putreg32((HSEM_COREID_CPU1 << HSEM_CR_COREID_SHIFT) , STM32_HSEM_RX(id)); +#else + putreg32((HSEM_COREID_CPU2 << HSEM_CR_COREID_SHIFT) , STM32_HSEM_RX(id)); +#endif +} + +/**************************************************************************** + * Name: stm32_hsem_init + * + * Description: + * Intiialize the hardware semaphore driver Review Comment: ```suggestion * Initialize the hardware semaphore driver ``` ########## boards/arm/stm32h7/nucleo-h745zi/src/stm32_userleds.c: ########## @@ -0,0 +1,125 @@ +/**************************************************************************** + * boards/arm/stm32h7/nucleo-h745zi/src/stm32_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 <nuttx/config.h> + +#include <stdbool.h> +#include <debug.h> + +#include <sys/param.h> + +#include <nuttx/board.h> +#include <arch/board/board.h> + +#include "stm32_gpio.h" +#include "nucleo-h745zi.h" + +#ifndef CONFIG_ARCH_LEDS + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* This array maps an LED number to GPIO pin configuration and is indexed by + * BOARD_LED_<color> + */ + +static const uint32_t g_ledcfg[BOARD_NLEDS] = +{ + GPIO_LED_GREEN, + GPIO_LED_BLUE, + GPIO_LED_RED, +}; + +/**************************************************************************** + * 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 LED1-3 GPIOs for output */ + + for (i = 0; i < nitems(g_ledcfg); i++) + { + stm32_configgpio(g_ledcfg[i]); + } + + return BOARD_NLEDS; +} + +/**************************************************************************** + * 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. Review Comment: ```suggestion * available to control the LED from user application logic. ``` ########## arch/arm/src/stm32h7/stm32_mpuinit.c: ########## @@ -42,18 +58,25 @@ * Name: stm32_mpuinitialize * * Description: - * Configure the MPU to permit user-space access to only restricted SAM3U - * resources. + * Configure the MPU. + * + * If PROTETECTED build: Review Comment: ```suggestion * If PROTECTED build: ``` ########## boards/arm/stm32h7/nucleo-h745zi/src/stm32_userleds.c: ########## @@ -0,0 +1,125 @@ +/**************************************************************************** + * boards/arm/stm32h7/nucleo-h745zi/src/stm32_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 <nuttx/config.h> + +#include <stdbool.h> +#include <debug.h> + +#include <sys/param.h> + +#include <nuttx/board.h> +#include <arch/board/board.h> + +#include "stm32_gpio.h" +#include "nucleo-h745zi.h" + +#ifndef CONFIG_ARCH_LEDS + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* This array maps an LED number to GPIO pin configuration and is indexed by + * BOARD_LED_<color> + */ + +static const uint32_t g_ledcfg[BOARD_NLEDS] = +{ + GPIO_LED_GREEN, + GPIO_LED_BLUE, + GPIO_LED_RED, +}; + +/**************************************************************************** + * 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 LED1-3 GPIOs for output */ + + for (i = 0; i < nitems(g_ledcfg); i++) + { + stm32_configgpio(g_ledcfg[i]); + } + + return BOARD_NLEDS; +} + +/**************************************************************************** + * 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_ledcfg)) + { + stm32_gpiowrite(g_ledcfg[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. Review Comment: ```suggestion * 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. ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
