Skip to content

Commit

Permalink
[stm32][nano] stm32l475-pandora support nano version
Browse files Browse the repository at this point in the history
  • Loading branch information
mysterywolf authored and Guozhanxin committed Dec 1, 2023
1 parent 6cd24d4 commit 031a81a
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 44 deletions.
3 changes: 1 addition & 2 deletions bsp/stm32/libraries/HAL_Drivers/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand Down
16 changes: 9 additions & 7 deletions bsp/stm32/libraries/HAL_Drivers/drv_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/

#include "drv_common.h"
#include "board.h"
#include <board.h>

#ifdef RT_USING_SERIAL
#ifdef RT_USING_SERIAL_V2
Expand Down Expand Up @@ -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
}

2 changes: 1 addition & 1 deletion bsp/stm32/libraries/HAL_Drivers/drv_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <rthw.h>
#ifdef RT_USING_DEVICE
#include <rtdevice.h>
#endif
#endif /* RT_USING_DEVICE */

#ifdef __cplusplus
extern "C" {
Expand Down
2 changes: 1 addition & 1 deletion bsp/stm32/libraries/STM32L4xx_HAL/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
10 changes: 10 additions & 0 deletions bsp/stm32/stm32l475-atk-pandora/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
29 changes: 28 additions & 1 deletion bsp/stm32/stm32l475-atk-pandora/applications/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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 */
7 changes: 0 additions & 7 deletions bsp/stm32/stm32l475-atk-pandora/board/Kconfig
Original file line number Diff line number Diff line change
@@ -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
Expand Down
45 changes: 23 additions & 22 deletions bsp/stm32/stm32l475-atk-pandora/board/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion bsp/stm32/stm32l475-atk-pandora/board/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,4 @@ void SystemClock_ReConfig(uint8_t mode)
// SystemClock_MSI_OFF();
}

#endif
#endif /* RT_USING_PM */
6 changes: 4 additions & 2 deletions bsp/stm32/stm32l475-atk-pandora/board/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
64 changes: 64 additions & 0 deletions bsp/stm32/stm32l475-atk-pandora/board/nano/drv_console.c
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 031a81a

Please sign in to comment.