Browse Source

[stm32][nano] stm32l475-pandora support nano version

Meco Man 1 year ago
parent
commit
031a81a98e

+ 1 - 2
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']
 

+ 9 - 7
bsp/stm32/libraries/HAL_Drivers/drv_common.c

@@ -9,7 +9,7 @@
  */
 
 #include "drv_common.h"
-#include "board.h"
+#include <board.h>
 
 #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
 }
-

+ 1 - 1
bsp/stm32/libraries/HAL_Drivers/drv_common.h

@@ -15,7 +15,7 @@
 #include <rthw.h>
 #ifdef RT_USING_DEVICE
 #include <rtdevice.h>
-#endif
+#endif /* RT_USING_DEVICE */
 
 #ifdef __cplusplus
 extern "C" {

+ 1 - 1
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']

+ 10 - 0
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

+ 28 - 1
bsp/stm32/stm32l475-atk-pandora/applications/main.c

@@ -9,9 +9,11 @@
  */
 
 #include <rtthread.h>
-#include <rtdevice.h>
 #include <board.h>
 
+#ifndef RT_USING_NANO
+#include <rtdevice.h>
+
 /* 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 */

+ 0 - 7
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

+ 23 - 22
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
 

+ 1 - 1
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 */

+ 4 - 2
bsp/stm32/stm32l475-atk-pandora/board/board.h

@@ -13,8 +13,10 @@
 
 #include <rtthread.h>
 #include <stm32l4xx.h>
-#include "drv_common.h"
-#include "drv_gpio.h"
+#include <drv_common.h>
+#ifndef RT_USING_NANO
+#include <drv_gpio.h>
+#endif /* RT_USING_NANO */
 
 #ifdef __cplusplus
 extern "C" {

+ 64 - 0
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 <board.h>
+
+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;
+}