Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions bsp/stm32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ STM32 系列 BSP 目前支持情况如下表所示:
| [stm32f407-atk-explorer](stm32f407-atk-explorer/) | 正点原子 F407 探索者开发板 |
| [stm32f429-atk-apollo](stm32f429-atk-apollo/) | 正点原子 F429 阿波罗开发板 |
| [stm32f429-fire-challenger](stm32f429-fire-challenger/) | 野火 F429 挑战者开发板 |
| [stm32f767-fire-challenger](stm32f767-fire-challenger/) | 野火 F767 挑战者开发板 |

了解每个 BSP 的详细情况可以阅读该 BSP 下的 readme 文件,如需使用 BSP 更多功能可参考 docs 文件夹下提供的说明文档:

Expand Down
1 change: 1 addition & 0 deletions bsp/stm32/docs/STM32系列BSP添加教程.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ STM32 BSP 由三部分组成,分别是 (1) 通用库、(2) BSP 模板和 (3)
| ------- | ---- |
| libraries/templates/stm32f10x | F1系列芯片模板 |
| libraries/templates/stm32f4xx | F4系列芯片模板 |
| libraries/templates/stm32f7xx | F7系列芯片模板 |
| libraries/templates/stm32l4xx | L4系列芯片模板 |

拷贝 `stm32/libraries/templates/stm32f10x` 文件夹并改名为 `stm32/stm32f103-atk-nano` 。如下图所示:
Expand Down
3 changes: 3 additions & 0 deletions bsp/stm32/libraries/HAL_Drivers/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ if GetDepend(['BSP_USING_ON_CHIP_FLASH', 'SOC_SERIES_STM32F1']):
if GetDepend(['BSP_USING_ON_CHIP_FLASH', 'SOC_SERIES_STM32F4']):
src += ['drv_flash/drv_flash_f4.c']

if GetDepend(['BSP_USING_ON_CHIP_FLASH', 'SOC_SERIES_STM32F7']):
src += ['drv_flash/drv_flash_f7.c']

if GetDepend(['BSP_USING_ON_CHIP_FLASH', 'SOC_SERIES_STM32L4']):
src += ['drv_flash/drv_flash_l4.c']

Expand Down
79 changes: 79 additions & 0 deletions bsp/stm32/libraries/HAL_Drivers/config/f7/adc_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-12-06 zylx first version
*/

#ifndef __ADC_CONFIG_H__
#define __ADC_CONFIG_H__

#include <rtthread.h>

#ifdef BSP_USING_ADC1
#ifndef ADC1_CONFIG
#define ADC1_CONFIG \
{ \
.Instance = ADC1, \
.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4, \
.Init.Resolution = ADC_RESOLUTION_12B, \
.Init.DataAlign = ADC_DATAALIGN_RIGHT, \
.Init.ScanConvMode = DISABLE, \
.Init.EOCSelection = DISABLE, \
.Init.ContinuousConvMode = DISABLE, \
.Init.NbrOfConversion = 1, \
.Init.DiscontinuousConvMode = DISABLE, \
.Init.NbrOfDiscConversion = 0, \
.Init.ExternalTrigConv = ADC_SOFTWARE_START, \
.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE, \
.Init.DMAContinuousRequests = DISABLE, \
}
#endif /* ADC1_CONFIG */
#endif /* BSP_USING_ADC1 */

#ifdef BSP_USING_ADC2
#ifndef ADC2_CONFIG
#define ADC2_CONFIG \
{ \
.Instance = ADC2, \
.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4, \
.Init.Resolution = ADC_RESOLUTION_12B, \
.Init.DataAlign = ADC_DATAALIGN_RIGHT, \
.Init.ScanConvMode = DISABLE, \
.Init.EOCSelection = DISABLE, \
.Init.ContinuousConvMode = DISABLE, \
.Init.NbrOfConversion = 1, \
.Init.DiscontinuousConvMode = DISABLE, \
.Init.NbrOfDiscConversion = 0, \
.Init.ExternalTrigConv = ADC_SOFTWARE_START, \
.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE, \
.Init.DMAContinuousRequests = DISABLE, \
}
#endif /* ADC2_CONFIG */
#endif /* BSP_USING_ADC2 */

#ifdef BSP_USING_ADC3
#ifndef ADC3_CONFIG
#define ADC3_CONFIG \
{ \
.Instance = ADC3, \
.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4, \
.Init.Resolution = ADC_RESOLUTION_12B, \
.Init.DataAlign = ADC_DATAALIGN_RIGHT, \
.Init.ScanConvMode = DISABLE, \
.Init.EOCSelection = DISABLE, \
.Init.ContinuousConvMode = DISABLE, \
.Init.NbrOfConversion = 1, \
.Init.DiscontinuousConvMode = DISABLE, \
.Init.NbrOfDiscConversion = 0, \
.Init.ExternalTrigConv = ADC_SOFTWARE_START, \
.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE, \
.Init.DMAContinuousRequests = DISABLE, \
}
#endif /* ADC3_CONFIG */
#endif /* BSP_USING_ADC3 */

#endif /* __ADC_CONFIG_H__ */
133 changes: 133 additions & 0 deletions bsp/stm32/libraries/HAL_Drivers/config/f7/spi_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-11-06 SummerGift change to new framework
*/

#ifndef __SPI_CONFIG_H__
#define __SPI_CONFIG_H__

#include <rtthread.h>

#ifdef BSP_USING_SPI1
#define SPI1_BUS_CONFIG \
{ \
.Instance = SPI1, \
.bus_name = "spi1", \
.dma_rx.dma_rcc = RCC_AHB1ENR_DMA2EN, \
.dma_tx.dma_rcc = RCC_AHB1ENR_DMA2EN, \
.dma_rx.Instance = DMA2_Stream2, \
.dma_rx.channel = DMA_CHANNEL_3, \
.dma_rx.dma_irq = DMA2_Stream2_IRQn, \
.dma_tx.Instance = DMA2_Stream3, \
.dma_tx.channel = DMA_CHANNEL_3, \
.dma_tx.dma_irq = DMA2_Stream3_IRQn, \
}

#define SPI1_DMA_RX_IRQHandler DMA2_Stream2_IRQHandler
#define SPI1_DMA_TX_IRQHandler DMA2_Stream3_IRQHandler
#endif

#ifdef BSP_USING_SPI2
#define SPI2_BUS_CONFIG \
{ \
.Instance = SPI2, \
.bus_name = "spi2", \
.dma_rx.dma_rcc = RCC_AHB1ENR_DMA1EN, \
.dma_tx.dma_rcc = RCC_AHB1ENR_DMA1EN, \
.dma_rx.Instance = DMA1_Stream3, \
.dma_rx.channel = DMA_CHANNEL_0, \
.dma_rx.dma_irq = DMA1_Stream3_IRQn, \
.dma_tx.Instance = DMA1_Stream4, \
.dma_tx.channel = DMA_CHANNEL_0, \
.dma_tx.dma_irq = DMA1_Stream4_IRQn, \
}

#define SPI2_DMA_RX_IRQHandler DMA1_Stream3_IRQHandler
#define SPI2_DMA_TX_IRQHandler DMA1_Stream4_IRQHandler
#endif

#ifdef BSP_USING_SPI3
#define SPI3_BUS_CONFIG \
{ \
.Instance = SPI3, \
.bus_name = "spi3", \
.dma_rx.dma_rcc = RCC_AHB1ENR_DMA1EN, \
.dma_tx.dma_rcc = RCC_AHB1ENR_DMA1EN, \
.dma_rx.Instance = DMA1_Stream0, \
.dma_rx.channel = DMA_CHANNEL_0, \
.dma_rx.dma_irq = DMA1_Stream0_IRQn, \
.dma_tx.Instance = DMA1_Stream7, \
.dma_tx.channel = DMA_CHANNEL_0, \
.dma_tx.dma_irq = DMA1_Stream7_IRQn, \
}

#define SPI3_DMA_RX_IRQHandler DMA1_Stream0_IRQHandler
#define SPI3_DMA_TX_IRQHandler DMA1_Stream7_IRQHandler
#endif

#ifdef BSP_USING_SPI4
#define SPI4_BUS_CONFIG \
{ \
.Instance = SPI4, \
.bus_name = "spi4", \
.dma_rx.dma_rcc = RCC_AHB1ENR_DMA2EN, \
.dma_tx.dma_rcc = RCC_AHB1ENR_DMA2EN, \
.dma_rx.Instance = DMA2_Stream0, \
.dma_rx.channel = DMA_CHANNEL_4, \
.dma_rx.dma_irq = DMA2_Stream0_IRQn, \
.dma_tx.Instance = DMA2_Stream1, \
.dma_tx.channel = DMA_CHANNEL_4, \
.dma_tx.dma_irq = DMA2_Stream1_IRQn, \
}

#define SPI4_DMA_RX_IRQHandler DMA2_Stream0_IRQHandler
#define SPI4_DMA_TX_IRQHandler DMA2_Stream1_IRQHandler
#endif

#ifdef BSP_USING_SPI5
#define SPI5_BUS_CONFIG \
{ \
.Instance = SPI5, \
.bus_name = "spi5", \
.dma_rx.dma_rcc = RCC_AHB1ENR_DMA2EN, \
.dma_tx.dma_rcc = RCC_AHB1ENR_DMA2EN, \
.dma_rx.Instance = DMA2_Stream3, \
.dma_rx.channel = DMA_CHANNEL_2, \
.dma_rx.dma_irq = DMA2_Stream3_IRQn, \
.dma_tx.Instance = DMA2_Stream4, \
.dma_tx.channel = DMA_CHANNEL_2, \
.dma_tx.dma_irq = DMA2_Stream4_IRQn, \
}

#define SPI5_DMA_RX_IRQHandler DMA2_Stream3_IRQHandler
#define SPI5_DMA_TX_IRQHandler DMA2_Stream4_IRQHandler
#endif

#ifdef BSP_USING_SPI6
#define SPI5_BUS_CONFIG \
{ \
.Instance = SPI6, \
.bus_name = "spi6", \
.dma_rx.dma_rcc = RCC_AHB1ENR_DMA2EN, \
.dma_tx.dma_rcc = RCC_AHB1ENR_DMA2EN, \
.dma_rx.Instance = DMA2_Stream6, \
.dma_rx.channel = DMA_CHANNEL_1, \
.dma_rx.dma_irq = DMA2_Stream6_IRQn, \
.dma_tx.Instance = DMA2_Stream5, \
.dma_tx.channel = DMA_CHANNEL_1, \
.dma_tx.dma_irq = DMA2_Stream5_IRQn, \
}

#define SPI6_DMA_RX_IRQHandler DMA2_Stream6_IRQHandler
#define SPI6_DMA_TX_IRQHandler DMA2_Stream5_IRQHandler
#endif

#endif /*__SPI_CONFIG_H__ */



91 changes: 91 additions & 0 deletions bsp/stm32/libraries/HAL_Drivers/config/f7/uart_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-10-30 SummerGift change to new framework
*/

#ifndef __UART_CONFIG_H__
#define __UART_CONFIG_H__

#include <rtthread.h>

#if defined(BSP_USING_UART1)
#define UART1_CONFIG \
{ \
.name = "uart1", \
.Instance = USART1, \
.irq_type = USART1_IRQn, \
.dma.stream_channel.Instance = DMA2_Stream5, \
.dma.stream_channel.channel = DMA_CHANNEL_4, \
.dma_rcc = RCC_AHB1ENR_DMA2EN, \
.dma_irq = DMA2_Stream5_IRQn, \
}

#define USART1_RX_DMA_ISR DMA2_Stream5_IRQHandler
#endif

#if defined(BSP_USING_UART2)
#define UART2_CONFIG \
{ \
.name = "uart2", \
.Instance = USART2, \
.irq_type = USART2_IRQn, \
.dma.stream_channel.Instance = DMA1_Stream5, \
.dma.stream_channel.channel = DMA_CHANNEL_4, \
.dma_rcc = RCC_AHB1ENR_DMA1EN, \
.dma_irq = DMA1_Stream5_IRQn, \
}

#define USART2_RX_DMA_ISR DMA1_Stream5_IRQHandler
#endif

#if defined(BSP_USING_UART3)
#define UART3_CONFIG \
{ \
.name = "uart3", \
.Instance = USART3, \
.irq_type = USART3_IRQn, \
.dma.stream_channel.Instance = DMA1_Stream1, \
.dma.stream_channel.channel = DMA_CHANNEL_4, \
.dma_rcc = RCC_AHB1ENR_DMA1EN, \
.dma_irq = DMA1_Stream1_IRQn, \
}

#define USART3_RX_DMA_ISR DMA1_Stream1_IRQHandler
#endif

#if defined(BSP_USING_UART4)
#define UART4_CONFIG \
{ \
.name = "uart4", \
.Instance = UART4, \
.irq_type = UART4_IRQn, \
.dma.stream_channel.Instance = DMA1_Stream2, \
.dma.stream_channel.channel = DMA_CHANNEL_4, \
.dma_rcc = RCC_AHB1ENR_DMA1EN, \
.dma_irq = DMA1_Stream2_IRQn, \
}

#define USART4_RX_DMA_ISR DMA1_Stream2_IRQHandler
#endif

#if defined(BSP_USING_UART5)
#define UART5_CONFIG \
{ \
.name = "uart5", \
.Instance = UART5, \
.irq_type = UART5_IRQn, \
.dma.stream_channel.Instance = DMA1_Stream0, \
.dma.stream_channel.channel = DMA_CHANNEL_4, \
.dma_rcc = RCC_AHB1ENR_DMA1EN, \
.dma_irq = DMA1_Stream0_IRQn, \
}

#define USART5_RX_DMA_ISR DMA1_Stream0_IRQHandler
#endif

#endif
11 changes: 6 additions & 5 deletions bsp/stm32/libraries/HAL_Drivers/drv_adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Change Logs:
* Date Author Notes
* 2018-12-05 zylx first version
* 2018-12-12 greedyhao Porting for stm32f7xx
*/

#include <board.h>
Expand Down Expand Up @@ -126,7 +127,7 @@ static rt_uint32_t stm32_adc_get_channel(rt_uint32_t channel)
case 17:
stm32_channel = ADC_CHANNEL_17;
break;
#if defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32L4)
#if defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7) || defined(SOC_SERIES_STM32L4)
case 18:
stm32_channel = ADC_CHANNEL_18;
break;
Expand All @@ -148,7 +149,7 @@ static rt_err_t stm32_get_adc_value(struct rt_adc_device *device, rt_uint32_t ch

#if defined(SOC_SERIES_STM32F1)
if (channel <= 17)
#elif defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32L4)
#elif defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7) || defined(SOC_SERIES_STM32L4)
if (channel <= 18)
#endif
{
Expand All @@ -159,20 +160,20 @@ static rt_err_t stm32_get_adc_value(struct rt_adc_device *device, rt_uint32_t ch
{
#if defined(SOC_SERIES_STM32F1)
LOG_E("ADC channel must be between 0 and 17.");
#elif defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32L4)
#elif defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7) || defined(SOC_SERIES_STM32L4)
LOG_E("ADC channel must be between 0 and 18.");
#endif
return -RT_ERROR;
}
ADC_ChanConf.Rank = 1;
#if defined(SOC_SERIES_STM32F1)
ADC_ChanConf.SamplingTime = ADC_SAMPLETIME_55CYCLES_5;
#elif defined(SOC_SERIES_STM32F4)
#elif defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7)
ADC_ChanConf.SamplingTime = ADC_SAMPLETIME_112CYCLES;
#elif defined(SOC_SERIES_STM32L4)
ADC_ChanConf.SamplingTime = ADC_SAMPLETIME_247CYCLES_5;
#endif
#if defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32L4)
#if defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7) || defined(SOC_SERIES_STM32L4)
ADC_ChanConf.Offset = 0;
#endif
#ifdef SOC_SERIES_STM32L4
Expand Down
4 changes: 4 additions & 0 deletions bsp/stm32/libraries/HAL_Drivers/drv_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
#include "f4/uart_config.h"
#include "f4/spi_config.h"
#include "f4/adc_config.h"
#elif defined(SOC_SERIES_STM32F7)
#include "f7/uart_config.h"
#include "f7/spi_config.h"
#include "f7/adc_config.h"
#elif defined(SOC_SERIES_STM32L4)
#include "l4/uart_config.h"
#include "l4/spi_config.h"
Expand Down
Loading