From 0935f3d16362ea0aca89d06b94ea41876061de72 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Thu, 30 Nov 2023 22:00:00 +0800 Subject: [PATCH 1/3] [nano][kernel] correct nano Kconfig dependency --- components/Kconfig | 2 +- src/Kconfig | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/components/Kconfig b/components/Kconfig index b9ccece2ded..b1a57b96ba4 100644 --- a/components/Kconfig +++ b/components/Kconfig @@ -33,6 +33,7 @@ source "$RTT_DIR/components/fal/Kconfig" source "$RTT_DIR/components/drivers/Kconfig" source "$RTT_DIR/components/libc/Kconfig" source "$RTT_DIR/components/net/Kconfig" +source "$RTT_DIR/components/mprotect/Kconfig" source "$RTT_DIR/components/utilities/Kconfig" source "$RTT_DIR/components/vbus/Kconfig" endif @@ -40,6 +41,5 @@ endif if RT_USING_SMART source "$RTT_DIR/components/lwp/Kconfig" source "$RTT_DIR/components/mm/Kconfig" -source "$RTT_DIR/components/mprotect/Kconfig" endif endmenu diff --git a/src/Kconfig b/src/Kconfig index d5b789782ad..6430b4675d8 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -400,10 +400,12 @@ endmenu config RT_USING_DEVICE bool "Using device object" + depends on !RT_USING_NANO default y config RT_USING_DEVICE_OPS bool "Using ops for each device object" + depends on RT_USING_DEVICE default n config RT_USING_INTERRUPT_INFO @@ -423,6 +425,7 @@ if RT_USING_CONSOLE config RT_CONSOLE_DEVICE_NAME string "the device name for console" + depends on RT_USING_DEVICE default "uart" endif From 29b39dca79ec36ecc39844b5ed1abfc880270354 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Thu, 30 Nov 2023 22:00:00 +0800 Subject: [PATCH 2/3] [stm32][nano] stm32l475-pandora support nano version --- bsp/stm32/libraries/HAL_Drivers/SConscript | 3 +- bsp/stm32/libraries/HAL_Drivers/drv_common.c | 16 +++-- bsp/stm32/libraries/HAL_Drivers/drv_common.h | 2 +- bsp/stm32/libraries/STM32L4xx_HAL/SConscript | 2 +- bsp/stm32/stm32l475-atk-pandora/Kconfig | 10 +++ .../stm32l475-atk-pandora/applications/main.c | 29 ++++++++- bsp/stm32/stm32l475-atk-pandora/board/Kconfig | 7 -- .../stm32l475-atk-pandora/board/SConscript | 45 ++++++------- bsp/stm32/stm32l475-atk-pandora/board/board.c | 2 +- bsp/stm32/stm32l475-atk-pandora/board/board.h | 6 +- .../board/nano/drv_console.c | 64 +++++++++++++++++++ 11 files changed, 142 insertions(+), 44 deletions(-) create mode 100644 bsp/stm32/stm32l475-atk-pandora/board/nano/drv_console.c diff --git a/bsp/stm32/libraries/HAL_Drivers/SConscript b/bsp/stm32/libraries/HAL_Drivers/SConscript index afc919360ff..a3380da81f3 100644 --- a/bsp/stm32/libraries/HAL_Drivers/SConscript +++ b/bsp/stm32/libraries/HAL_Drivers/SConscript @@ -4,14 +4,13 @@ from building import * cwd = GetCurrentDir() group = [] -src = [] +src = ['drv_common.c'] path = [cwd] if not GetDepend('PKG_CMSIS_CORE'): path += [cwd + '/CMSIS/Include'] if not GetDepend(['RT_USING_NANO']): - src += ['drv_common.c'] if GetDepend(['RT_USING_PIN']): src += ['drv_gpio.c'] diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_common.c b/bsp/stm32/libraries/HAL_Drivers/drv_common.c index 7670b020002..79be0074362 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_common.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_common.c @@ -9,7 +9,7 @@ */ #include "drv_common.h" -#include "board.h" +#include #ifdef RT_USING_SERIAL #ifdef RT_USING_SERIAL_V2 @@ -182,29 +182,31 @@ rt_weak void rt_hw_board_init(void) /* System clock initialization */ SystemClock_Config(); - /* Heap initialization */ #if defined(RT_USING_HEAP) + /* Heap initialization */ rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END); #endif - /* Pin driver initialization is open by default */ #ifdef RT_USING_PIN rt_hw_pin_init(); #endif - /* USART driver initialization is open by default */ #ifdef RT_USING_SERIAL rt_hw_usart_init(); #endif - /* Set the shell console output device */ #if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE) + /* Set the shell console output device */ rt_console_set_device(RT_CONSOLE_DEVICE_NAME); #endif - /* Board underlying hardware initialization */ +#if defined(RT_USING_CONSOLE) && defined(RT_USING_NANO) + extern void rt_hw_console_init(void); + rt_hw_console_init(); +#endif + #ifdef RT_USING_COMPONENTS_INIT + /* Board underlying hardware initialization */ rt_components_board_init(); #endif } - diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_common.h b/bsp/stm32/libraries/HAL_Drivers/drv_common.h index 88a99a4a643..4b9e87aee27 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_common.h +++ b/bsp/stm32/libraries/HAL_Drivers/drv_common.h @@ -15,7 +15,7 @@ #include #ifdef RT_USING_DEVICE #include -#endif +#endif /* RT_USING_DEVICE */ #ifdef __cplusplus extern "C" { diff --git a/bsp/stm32/libraries/STM32L4xx_HAL/SConscript b/bsp/stm32/libraries/STM32L4xx_HAL/SConscript index ebc7c4a01c8..7a073130ce4 100644 --- a/bsp/stm32/libraries/STM32L4xx_HAL/SConscript +++ b/bsp/stm32/libraries/STM32L4xx_HAL/SConscript @@ -26,7 +26,7 @@ STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rng.c STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_gpio.c ''') -if GetDepend(['RT_USING_SERIAL']): +if GetDepend(['RT_USING_SERIAL']) or GetDepend(['RT_USING_NANO', 'RT_USING_CONSOLE']): src += ['STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_uart.c'] src += ['STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_uart_ex.c'] src += ['STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_usart.c'] diff --git a/bsp/stm32/stm32l475-atk-pandora/Kconfig b/bsp/stm32/stm32l475-atk-pandora/Kconfig index 79b160b8567..18ee161f555 100644 --- a/bsp/stm32/stm32l475-atk-pandora/Kconfig +++ b/bsp/stm32/stm32l475-atk-pandora/Kconfig @@ -15,7 +15,17 @@ config PKGS_DIR option env="PKGS_ROOT" default "packages" +config SOC_STM32L475VE + bool + select SOC_SERIES_STM32L4 + select RT_USING_COMPONENTS_INIT + select RT_USING_USER_MAIN + default y + source "$RTT_DIR/Kconfig" source "$PKGS_DIR/Kconfig" + +if !RT_USING_NANO source "../libraries/Kconfig" source "board/Kconfig" +endif diff --git a/bsp/stm32/stm32l475-atk-pandora/applications/main.c b/bsp/stm32/stm32l475-atk-pandora/applications/main.c index 7410e0463ea..7ff30d00595 100644 --- a/bsp/stm32/stm32l475-atk-pandora/applications/main.c +++ b/bsp/stm32/stm32l475-atk-pandora/applications/main.c @@ -9,9 +9,11 @@ */ #include -#include #include +#ifndef RT_USING_NANO +#include + /* defined the LED0 pin: PE7 */ #define LED0_PIN GET_PIN(E, 7) @@ -28,3 +30,28 @@ int main(void) rt_thread_mdelay(500); } } +#else +int main(void) +{ + GPIO_InitTypeDef GPIO_InitStruct = {0}; + + /* GPIO Ports Clock Enable */ + __HAL_RCC_GPIOE_CLK_ENABLE(); + + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(GPIOE, GPIO_PIN_7, GPIO_PIN_SET); + + /*Configure GPIO pin : PE7 */ + GPIO_InitStruct.Pin = GPIO_PIN_7; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_PULLUP; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM; + HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); + + while (1) + { + HAL_GPIO_TogglePin(GPIOE, GPIO_PIN_7); + rt_thread_mdelay(500); + } +} +#endif /* RT_USING_NANO */ diff --git a/bsp/stm32/stm32l475-atk-pandora/board/Kconfig b/bsp/stm32/stm32l475-atk-pandora/board/Kconfig index 61d4f2abfb4..0bc4844a117 100644 --- a/bsp/stm32/stm32l475-atk-pandora/board/Kconfig +++ b/bsp/stm32/stm32l475-atk-pandora/board/Kconfig @@ -1,12 +1,5 @@ menu "Hardware Drivers Config" -config SOC_STM32L475VE - bool - select SOC_SERIES_STM32L4 - select RT_USING_COMPONENTS_INIT - select RT_USING_USER_MAIN - default y - config BOARD_STM32L475_ATK_PANDORA bool default y diff --git a/bsp/stm32/stm32l475-atk-pandora/board/SConscript b/bsp/stm32/stm32l475-atk-pandora/board/SConscript index 513aa8598a3..e1deb74ee5d 100644 --- a/bsp/stm32/stm32l475-atk-pandora/board/SConscript +++ b/bsp/stm32/stm32l475-atk-pandora/board/SConscript @@ -15,35 +15,36 @@ CubeMX_Config/Src/stm32l4xx_hal_msp.c path = [cwd] path += [cwd + '/CubeMX_Config/Inc'] -if GetDepend(['BSP_USING_KEY']): - src += Glob('ports/drv_key.c') +if not GetDepend(['RT_USING_NANO']): + if GetDepend(['BSP_USING_KEY']): + src += os.path.join('ports', 'drv_key.c') -if GetDepend(['BSP_USING_QSPI_FLASH']): - src += Glob('ports/drv_qspi_flash.c') + if GetDepend(['BSP_USING_QSPI_FLASH']): + src += os.path.join('ports', 'drv_qspi_flash.c') -if GetDepend(['BSP_USING_FS']): - src += Glob('ports/drv_filesystem.c') - if GetDepend(['BSP_USING_SPI_FLASH_LITTLEFS']): - src += Glob('ports/fal/fal_spi_flash_sfud_port.c') - path += [cwd + '/ports/fal'] + if GetDepend(['BSP_USING_FS']): + src += os.path.join('ports', 'drv_filesystem.c') + if GetDepend(['BSP_USING_SPI_FLASH_LITTLEFS']): + src += os.path.join('ports', 'fal', 'fal_spi_flash_sfud_port.c') + path += [cwd + os.path.join('ports', 'fal')] -if GetDepend(['RT_USING_SENSOR']): - src += Glob('ports/drv_sensors.c') + if GetDepend(['RT_USING_SENSOR']): + src += os.path.join('ports', 'drv_sensors.c') -if GetDepend(['BSP_USING_AUDIO']): - src += Glob('ports/audio/drv_es8388.c') - src += Glob('ports/audio/drv_sound.c') + if GetDepend(['BSP_USING_AUDIO']): + src += os.path.join('ports', 'audio', 'drv_es8388.c') + src += os.path.join('ports', 'audio', 'drv_sound.c') -if GetDepend(['BSP_USING_AUDIO_RECORD']): - src += Glob('ports/audio/drv_mic.c') + if GetDepend(['BSP_USING_AUDIO_RECORD']): + src += os.path.join('ports', 'audio', 'drv_mic.c') -if GetDepend(['BSP_USING_STM32_SDIO']): - src += Glob('ports/drv_sdio_adapter.c') + if GetDepend(['BSP_USING_STM32_SDIO']): + src += os.path.join('ports', 'drv_sdio_adapter.c') - - -if GetDepend(['BSP_USING_AUDIO']): - path += [cwd + '/ports/audio'] + if GetDepend(['BSP_USING_AUDIO']): + path += [cwd + os.path.join('ports', 'audio')] +else: + src += [os.path.join('nano', 'drv_console.c')] startup_path_prefix = SDK_LIB diff --git a/bsp/stm32/stm32l475-atk-pandora/board/board.c b/bsp/stm32/stm32l475-atk-pandora/board/board.c index 6e2be4bf423..17f1f410102 100644 --- a/bsp/stm32/stm32l475-atk-pandora/board/board.c +++ b/bsp/stm32/stm32l475-atk-pandora/board/board.c @@ -243,4 +243,4 @@ void SystemClock_ReConfig(uint8_t mode) // SystemClock_MSI_OFF(); } -#endif +#endif /* RT_USING_PM */ diff --git a/bsp/stm32/stm32l475-atk-pandora/board/board.h b/bsp/stm32/stm32l475-atk-pandora/board/board.h index c91fb31d238..410d3155e6c 100644 --- a/bsp/stm32/stm32l475-atk-pandora/board/board.h +++ b/bsp/stm32/stm32l475-atk-pandora/board/board.h @@ -13,8 +13,10 @@ #include #include -#include "drv_common.h" -#include "drv_gpio.h" +#include +#ifndef RT_USING_NANO +#include +#endif /* RT_USING_NANO */ #ifdef __cplusplus extern "C" { diff --git a/bsp/stm32/stm32l475-atk-pandora/board/nano/drv_console.c b/bsp/stm32/stm32l475-atk-pandora/board/nano/drv_console.c new file mode 100644 index 00000000000..95a77342277 --- /dev/null +++ b/bsp/stm32/stm32l475-atk-pandora/board/nano/drv_console.c @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2023-11-30 Meco Man First version + */ + +#include + +UART_HandleTypeDef huart1; + +void rt_hw_console_init(void) +{ + huart1.Instance = USART1; + huart1.Init.BaudRate = 115200; + huart1.Init.WordLength = UART_WORDLENGTH_8B; + huart1.Init.StopBits = UART_STOPBITS_1; + huart1.Init.Parity = UART_PARITY_NONE; + huart1.Init.Mode = UART_MODE_TX_RX; + huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; + huart1.Init.OverSampling = UART_OVERSAMPLING_16; + huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; + huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; + if (HAL_UART_Init(&huart1) != HAL_OK) + { + Error_Handler(); + } +} + +void rt_hw_console_output(const char *str) +{ + rt_size_t i = 0, size = 0; + char a = '\r'; + + __HAL_UNLOCK(&huart1); + + size = rt_strlen(str); + for (i = 0; i < size; i++) + { + if (*(str + i) == '\n') + { + HAL_UART_Transmit(&huart1, (uint8_t *)&a, 1, 1); + } + HAL_UART_Transmit(&huart1, (uint8_t *)(str + i), 1, 1); + } +} + +char rt_hw_console_getchar(void) +{ + int ch = -1; + + if (__HAL_UART_GET_FLAG(&huart1, UART_FLAG_RXNE) != RESET) + { + ch = huart1.Instance->RDR & 0xff; + } + else + { + rt_thread_mdelay(10); + } + return ch; +} From f2a8b0b9645107d76c2320f259fb05bfaafaffee Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Thu, 30 Nov 2023 18:55:35 +0800 Subject: [PATCH 3/3] [msh] add dependency of RT_USING_CONSOLE --- components/Kconfig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/components/Kconfig b/components/Kconfig index b1a57b96ba4..cef29589c96 100644 --- a/components/Kconfig +++ b/components/Kconfig @@ -25,7 +25,9 @@ config RT_USING_LEGACY bool "Support legacy version for compatibility" default n +if RT_USING_CONSOLE source "$RTT_DIR/components/finsh/Kconfig" +endif if !RT_USING_NANO source "$RTT_DIR/components/dfs/Kconfig"