调整驱动
This commit is contained in:
parent
452c229a55
commit
883cf7d530
114
bsp/adcs.c
114
bsp/adcs.c
|
@ -2,7 +2,7 @@
|
||||||
* @file adcs.c
|
* @file adcs.c
|
||||||
* @author xxx
|
* @author xxx
|
||||||
* @date 2023-09-04 15:59:16
|
* @date 2023-09-04 15:59:16
|
||||||
* @brief LL库ADC驱动
|
* @brief LL库ADC驱动 STM32F407
|
||||||
* @copyright Copyright (c) 2023 by xxx, All Rights Reserved.
|
* @copyright Copyright (c) 2023 by xxx, All Rights Reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ static uint8_t adc_get_channels_count(uint32_t channnels); // 通过用户配置
|
||||||
* @return {*}
|
* @return {*}
|
||||||
* @note TCONV(转换时间) = (采样时间 + 12.5 个周期)/(主频/ADC分频系数)
|
* @note TCONV(转换时间) = (采样时间 + 12.5 个周期)/(主频/ADC分频系数)
|
||||||
*/
|
*/
|
||||||
void adc_init(adcs_e num, ADC_TypeDef *adc, DMA_TypeDef *dma, uint32_t dma_channel, uint16_t adc_cct, uint32_t channels)
|
void adc_init(adcs_e num, ADC_TypeDef *adc, DMA_TypeDef *dma, uint32_t dma_stream, uint32_t dma_channel, uint16_t adc_cct, uint32_t channels)
|
||||||
{
|
{
|
||||||
DBG_ASSERT(num < ADCS_MAX __DBG_LINE);
|
DBG_ASSERT(num < ADCS_MAX __DBG_LINE);
|
||||||
DBG_ASSERT(adc != NULL __DBG_LINE);
|
DBG_ASSERT(adc != NULL __DBG_LINE);
|
||||||
|
@ -34,6 +34,7 @@ void adc_init(adcs_e num, ADC_TypeDef *adc, DMA_TypeDef *dma, uint32_t dma_chann
|
||||||
osel_memset((uint8_t *)p, 0, sizeof(adcs_t));
|
osel_memset((uint8_t *)p, 0, sizeof(adcs_t));
|
||||||
p->adc = adc;
|
p->adc = adc;
|
||||||
p->dma = dma;
|
p->dma = dma;
|
||||||
|
p->dma_stream = dma_stream;
|
||||||
p->dma_channel = dma_channel;
|
p->dma_channel = dma_channel;
|
||||||
p->channels.data = channels;
|
p->channels.data = channels;
|
||||||
p->adc_cct = adc_cct;
|
p->adc_cct = adc_cct;
|
||||||
|
@ -49,36 +50,40 @@ void adc_init(adcs_e num, ADC_TypeDef *adc, DMA_TypeDef *dma, uint32_t dma_chann
|
||||||
DBG_ASSERT(p->adc_value != NULL __DBG_LINE);
|
DBG_ASSERT(p->adc_value != NULL __DBG_LINE);
|
||||||
osel_memset((uint8_t *)p->adc_value, 0, sizeof(uint16_t) * p->adc_sum);
|
osel_memset((uint8_t *)p->adc_value, 0, sizeof(uint16_t) * p->adc_sum);
|
||||||
|
|
||||||
uint32_t backup_setting_adc_dma_transfer = 0U;
|
LL_DMA_SetChannelSelection(p->dma, p->dma_stream, p->dma_channel);
|
||||||
backup_setting_adc_dma_transfer = LL_ADC_REG_GetDMATransfer(p->adc);
|
LL_DMA_ConfigTransfer(p->dma, p->dma_stream,
|
||||||
LL_ADC_REG_SetDMATransfer(p->adc, LL_ADC_REG_DMA_TRANSFER_NONE);
|
LL_DMA_DIRECTION_PERIPH_TO_MEMORY |
|
||||||
|
LL_DMA_MODE_CIRCULAR |
|
||||||
|
LL_DMA_PERIPH_NOINCREMENT |
|
||||||
|
LL_DMA_MEMORY_INCREMENT |
|
||||||
|
LL_DMA_PDATAALIGN_HALFWORD |
|
||||||
|
LL_DMA_MDATAALIGN_HALFWORD |
|
||||||
|
LL_DMA_PRIORITY_HIGH);
|
||||||
|
LL_DMA_ConfigAddresses(p->dma, p->dma_stream,
|
||||||
|
LL_ADC_DMA_GetRegAddr(p->adc, LL_ADC_DMA_REG_REGULAR_DATA),
|
||||||
|
(uint32_t)p->adc_value,
|
||||||
|
LL_DMA_GetDataTransferDirection(p->dma, p->dma_stream));
|
||||||
|
|
||||||
// ADC开始校准
|
LL_DMA_SetDataLength(p->dma, p->dma_stream, p->adc_sum);
|
||||||
LL_ADC_StartCalibration(p->adc, LL_ADC_SINGLE_ENDED);
|
LL_DMA_EnableStream(p->dma, p->dma_stream);
|
||||||
// 等待校准完成
|
|
||||||
while (LL_ADC_IsCalibrationOnGoing(p->adc))
|
LL_ADC_REG_SetContinuousMode(p->adc, LL_ADC_REG_CONV_CONTINUOUS);
|
||||||
;
|
LL_ADC_REG_SetDMATransfer(p->adc, LL_ADC_REG_DMA_TRANSFER_UNLIMITED);
|
||||||
LL_ADC_REG_SetDMATransfer(p->adc, backup_setting_adc_dma_transfer);
|
|
||||||
LL_mDelay(10);
|
|
||||||
LL_ADC_EnableIT_OVR(p->adc);
|
|
||||||
LL_ADC_Enable(p->adc);
|
|
||||||
LL_mDelay(10);
|
|
||||||
|
|
||||||
if (BIT_IS_SET(channels, INVREF))
|
if (BIT_IS_SET(channels, INVREF))
|
||||||
{
|
{
|
||||||
// 使能VREFINT
|
// 使能VREFINT
|
||||||
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(p->adc), LL_ADC_PATH_INTERNAL_VREFINT);
|
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(p->adc), LL_ADC_PATH_INTERNAL_VREFINT);
|
||||||
}
|
}
|
||||||
|
if (BIT_IS_SET(channels, INTEMP))
|
||||||
LL_DMA_SetDataLength(p->dma, p->dma_channel, p->adc_sum);
|
|
||||||
LL_DMA_SetPeriphAddress(p->dma, p->dma_channel, LL_ADC_DMA_GetRegAddr(p->adc, LL_ADC_DMA_REG_REGULAR_DATA));
|
|
||||||
LL_DMA_SetMemoryAddress(p->dma, p->dma_channel, (uint32_t)p->adc_value);
|
|
||||||
LL_DMA_EnableChannel(p->dma, p->dma_channel);
|
|
||||||
|
|
||||||
if (backup_setting_adc_dma_transfer == LL_ADC_REG_DMA_TRANSFER_UNLIMITED)
|
|
||||||
{
|
{
|
||||||
LL_ADC_REG_StartConversion(p->adc); // 开始转换
|
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(p->adc), LL_ADC_PATH_INTERNAL_TEMPSENSOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LL_mDelay(10);
|
||||||
|
// 启动 ADC 转换
|
||||||
|
LL_ADC_Enable(p->adc);
|
||||||
|
LL_ADC_REG_StartConversionSWStart(p->adc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -91,18 +96,7 @@ void adc_init(adcs_e num, ADC_TypeDef *adc, DMA_TypeDef *dma, uint32_t dma_chann
|
||||||
void start_sample(adcs_e num)
|
void start_sample(adcs_e num)
|
||||||
{
|
{
|
||||||
DBG_ASSERT(num < ADCS_MAX __DBG_LINE);
|
DBG_ASSERT(num < ADCS_MAX __DBG_LINE);
|
||||||
adcs_t *p = &adcs[num];
|
// adcs_t *p = &adcs[num];
|
||||||
LL_DMA_SetDataLength(p->dma, p->dma_channel, p->adc_sum);
|
|
||||||
LL_DMA_SetPeriphAddress(p->dma, p->dma_channel, LL_ADC_DMA_GetRegAddr(p->adc, LL_ADC_DMA_REG_REGULAR_DATA));
|
|
||||||
LL_DMA_SetMemoryAddress(p->dma, p->dma_channel, (uint32_t)p->adc_value);
|
|
||||||
LL_DMA_EnableChannel(p->dma, p->dma_channel);
|
|
||||||
|
|
||||||
LL_ADC_ClearFlag_OVR(p->adc);
|
|
||||||
LL_ADC_ClearFlag_EOC(p->adc);
|
|
||||||
LL_ADC_REG_StartConversion(p->adc); // 开始转换
|
|
||||||
|
|
||||||
// ADC开始校准
|
|
||||||
LL_ADC_StartCalibration(p->adc, LL_ADC_SINGLE_ENDED);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -115,14 +109,7 @@ void start_sample(adcs_e num)
|
||||||
void stop_sample(adcs_e num)
|
void stop_sample(adcs_e num)
|
||||||
{
|
{
|
||||||
DBG_ASSERT(num < ADCS_MAX __DBG_LINE);
|
DBG_ASSERT(num < ADCS_MAX __DBG_LINE);
|
||||||
adcs_t *p = &adcs[num];
|
// adcs_t *p = &adcs[num];
|
||||||
|
|
||||||
LL_ADC_REG_StopConversion(p->adc);
|
|
||||||
while (LL_ADC_REG_IsConversionOngoing(p->adc) != 0)
|
|
||||||
;
|
|
||||||
LL_DMA_DisableChannel(p->dma, p->dma_channel);
|
|
||||||
DMA_CLEAR_FLAG_TC_CHANNEL(p->dma, p->dma_channel);
|
|
||||||
DMA_CLEAR_FLAG_TE_CHANNEL(p->dma, p->dma_channel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -147,8 +134,6 @@ void adc_dinit(adcs_e num)
|
||||||
{
|
{
|
||||||
DBG_ASSERT(num < ADCS_MAX __DBG_LINE);
|
DBG_ASSERT(num < ADCS_MAX __DBG_LINE);
|
||||||
adcs_t *p = &adcs[num];
|
adcs_t *p = &adcs[num];
|
||||||
LL_ADC_REG_StopConversion(p->adc);
|
|
||||||
LL_DMA_DisableChannel(p->dma, p->dma_channel);
|
|
||||||
LL_ADC_Disable(p->adc);
|
LL_ADC_Disable(p->adc);
|
||||||
if (p->adc_value != NULL)
|
if (p->adc_value != NULL)
|
||||||
{
|
{
|
||||||
|
@ -190,7 +175,7 @@ uint16_t adc_result_median_average(adcs_e num, uint8_t chan)
|
||||||
|
|
||||||
if (p->adc_cct <= 2)
|
if (p->adc_cct <= 2)
|
||||||
return 0; // 如果adc_cct小于等于2,直接返回0
|
return 0; // 如果adc_cct小于等于2,直接返回0
|
||||||
p->median_average_ticks.uticks = sys_get_tick();
|
|
||||||
uint16_t adc_temp[p->adc_cct];
|
uint16_t adc_temp[p->adc_cct];
|
||||||
uint32_t adc_sum = 0;
|
uint32_t adc_sum = 0;
|
||||||
uint16_t count = p->adc_cct >> 2; // 使用位移操作计算n的值
|
uint16_t count = p->adc_cct >> 2; // 使用位移操作计算n的值
|
||||||
|
@ -212,13 +197,6 @@ uint16_t adc_result_median_average(adcs_e num, uint8_t chan)
|
||||||
|
|
||||||
// 计算平均值,确保不会除以0
|
// 计算平均值,确保不会除以0
|
||||||
uint16_t res = adc_sum / (p->adc_cct - (count << 1));
|
uint16_t res = adc_sum / (p->adc_cct - (count << 1));
|
||||||
|
|
||||||
p->median_average_ticks.ticks_current = sys_get_tick() - p->median_average_ticks.uticks;
|
|
||||||
if (p->median_average_ticks.ticks_current > p->median_average_ticks.ticks_max)
|
|
||||||
{
|
|
||||||
p->median_average_ticks.ticks_max = p->median_average_ticks.ticks_current;
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,8 +214,6 @@ uint16_t adc_result_median(adcs_e num, uint8_t chan)
|
||||||
adcs_t *p = &adcs[num];
|
adcs_t *p = &adcs[num];
|
||||||
DBG_ASSERT(p != NULL __DBG_LINE);
|
DBG_ASSERT(p != NULL __DBG_LINE);
|
||||||
|
|
||||||
p->median_ticks.uticks = sys_get_tick();
|
|
||||||
|
|
||||||
uint16_t adc_temp[p->adc_cct];
|
uint16_t adc_temp[p->adc_cct];
|
||||||
// 减少重复计算,计算基础偏移量
|
// 减少重复计算,计算基础偏移量
|
||||||
uint16_t *adc_values = (uint16_t *)p->adc_value + chan;
|
uint16_t *adc_values = (uint16_t *)p->adc_value + chan;
|
||||||
|
@ -247,12 +223,6 @@ uint16_t adc_result_median(adcs_e num, uint8_t chan)
|
||||||
}
|
}
|
||||||
insertion_sort(adc_temp, p->adc_cct);
|
insertion_sort(adc_temp, p->adc_cct);
|
||||||
res = adc_temp[p->adc_cct >> 1];
|
res = adc_temp[p->adc_cct >> 1];
|
||||||
|
|
||||||
p->median_ticks.ticks_current = sys_get_tick() - p->median_ticks.uticks;
|
|
||||||
if (p->median_ticks.ticks_current > p->median_ticks.ticks_max)
|
|
||||||
{
|
|
||||||
p->median_ticks.ticks_max = p->median_ticks.ticks_current;
|
|
||||||
}
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,8 +241,6 @@ uint16_t adc_result_average(adcs_e num, uint8_t chan)
|
||||||
adcs_t *p = &adcs[num];
|
adcs_t *p = &adcs[num];
|
||||||
DBG_ASSERT(p != NULL __DBG_LINE);
|
DBG_ASSERT(p != NULL __DBG_LINE);
|
||||||
|
|
||||||
p->average_ticks.uticks = sys_get_tick();
|
|
||||||
|
|
||||||
// 减少重复计算,计算基础偏移量
|
// 减少重复计算,计算基础偏移量
|
||||||
uint16_t *adc_values = (uint16_t *)p->adc_value + chan;
|
uint16_t *adc_values = (uint16_t *)p->adc_value + chan;
|
||||||
for (uint16_t i = 0; i < p->adc_cct; ++i, adc_values += p->adc_chans_count)
|
for (uint16_t i = 0; i < p->adc_cct; ++i, adc_values += p->adc_chans_count)
|
||||||
|
@ -281,12 +249,6 @@ uint16_t adc_result_average(adcs_e num, uint8_t chan)
|
||||||
}
|
}
|
||||||
res = adc_sum / p->adc_cct;
|
res = adc_sum / p->adc_cct;
|
||||||
|
|
||||||
p->average_ticks.ticks_current = sys_get_tick() - p->average_ticks.uticks;
|
|
||||||
if (p->average_ticks.ticks_current > p->average_ticks.ticks_max)
|
|
||||||
{
|
|
||||||
p->average_ticks.ticks_max = p->average_ticks.ticks_current;
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -336,10 +298,6 @@ void adc_dma_callback(adcs_e num)
|
||||||
if (LL_DMA_IsActiveFlag_TC1(p->dma) != 0)
|
if (LL_DMA_IsActiveFlag_TC1(p->dma) != 0)
|
||||||
{
|
{
|
||||||
LL_DMA_ClearFlag_TC1(p->dma);
|
LL_DMA_ClearFlag_TC1(p->dma);
|
||||||
// 停止ADC转换
|
|
||||||
LL_ADC_REG_StopConversion(p->adc);
|
|
||||||
// 关闭ADC,可以不关闭但是校准无法清除
|
|
||||||
// LL_ADC_Disable(p->adc);
|
|
||||||
}
|
}
|
||||||
// 检查DMA1的传输错误标志是否为1,如果是,则清除该标志
|
// 检查DMA1的传输错误标志是否为1,如果是,则清除该标志
|
||||||
if (LL_DMA_IsActiveFlag_TE1(p->dma) != 0)
|
if (LL_DMA_IsActiveFlag_TE1(p->dma) != 0)
|
||||||
|
@ -361,17 +319,7 @@ void adc_env_callback(adcs_e num)
|
||||||
if (LL_ADC_IsActiveFlag_OVR(p->adc) != 0)
|
if (LL_ADC_IsActiveFlag_OVR(p->adc) != 0)
|
||||||
{
|
{
|
||||||
p->ovr_count++;
|
p->ovr_count++;
|
||||||
LL_ADC_REG_StopConversion(p->adc);
|
|
||||||
LL_DMA_DisableChannel(p->dma, p->dma_channel);
|
|
||||||
|
|
||||||
LL_DMA_SetDataLength(p->dma, p->dma_channel, p->adc_sum);
|
|
||||||
LL_DMA_SetPeriphAddress(p->dma, p->dma_channel, LL_ADC_DMA_GetRegAddr(p->adc, LL_ADC_DMA_REG_REGULAR_DATA));
|
|
||||||
LL_DMA_SetMemoryAddress(p->dma, p->dma_channel, (uint32_t)p->adc_value);
|
|
||||||
LL_DMA_EnableChannel(p->dma, p->dma_channel);
|
|
||||||
|
|
||||||
LL_ADC_ClearFlag_OVR(p->adc);
|
LL_ADC_ClearFlag_OVR(p->adc);
|
||||||
LL_ADC_ClearFlag_EOC(p->adc);
|
|
||||||
LL_ADC_REG_StartConversion(p->adc); // 开始转换
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,9 +17,6 @@
|
||||||
|
|
||||||
#ifndef __ADCS_H__
|
#ifndef __ADCS_H__
|
||||||
#define __ADCS_H__
|
#define __ADCS_H__
|
||||||
|
|
||||||
#include "lib.h"
|
|
||||||
#include "main.h"
|
|
||||||
#include "sys.h"
|
#include "sys.h"
|
||||||
|
|
||||||
#define ADC_CHANNEL_MAX 18 ///< Maximum number of ADC channels
|
#define ADC_CHANNEL_MAX 18 ///< Maximum number of ADC channels
|
||||||
|
@ -85,6 +82,7 @@ typedef struct
|
||||||
{
|
{
|
||||||
ADC_TypeDef *adc; ///< ADC peripheral
|
ADC_TypeDef *adc; ///< ADC peripheral
|
||||||
DMA_TypeDef *dma; ///< DMA peripheral
|
DMA_TypeDef *dma; ///< DMA peripheral
|
||||||
|
uint32_t dma_stream; ///< DMA stream
|
||||||
uint32_t dma_channel; ///< DMA channel
|
uint32_t dma_channel; ///< DMA channel
|
||||||
adcs_channels_u channels; ///< ADC channels
|
adcs_channels_u channels; ///< ADC channels
|
||||||
uint32_t ovr_count; ///< ADC overflow count
|
uint32_t ovr_count; ///< ADC overflow count
|
||||||
|
@ -94,9 +92,6 @@ typedef struct
|
||||||
uint16_t adc_sum; ///< Channel acquisition count
|
uint16_t adc_sum; ///< Channel acquisition count
|
||||||
__IO uint16_t *adc_value; ///< Address to store ADC conversion results
|
__IO uint16_t *adc_value; ///< Address to store ADC conversion results
|
||||||
|
|
||||||
utime_ticks_t median_average_ticks; ///< Median average filtering ticks
|
|
||||||
utime_ticks_t median_ticks; ///< Median filtering ticks
|
|
||||||
utime_ticks_t average_ticks; ///< Average filtering ticks
|
|
||||||
} adcs_t;
|
} adcs_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -111,7 +106,7 @@ typedef struct
|
||||||
* @param adc_cct The ADC continuous conversion mode.
|
* @param adc_cct The ADC continuous conversion mode.
|
||||||
* @param channels The number of ADC channels to be converted.
|
* @param channels The number of ADC channels to be converted.
|
||||||
*/
|
*/
|
||||||
extern void adc_init(adcs_e num, ADC_TypeDef *adc, DMA_TypeDef *dma, uint32_t dma_channel, uint16_t adc_cct, uint32_t channels);
|
extern void adc_init(adcs_e num, ADC_TypeDef *adc, DMA_TypeDef *dma, uint32_t dma_stream, uint32_t dma_channel, uint16_t adc_cct, uint32_t channels);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Starts the ADC conversion.
|
* @brief Starts the ADC conversion.
|
||||||
|
|
45
bsp/bsp.c
45
bsp/bsp.c
|
@ -1,8 +1,5 @@
|
||||||
|
|
||||||
#include "stm32l4xx_ll_pwr.h"
|
#include "main.h"
|
||||||
#include "stm32l4xx_ll_bus.h"
|
|
||||||
#include "stm32l4xx_ll_exti.h"
|
|
||||||
#include "stm32l4xx_ll_system.h"
|
|
||||||
#include "bsp.h"
|
#include "bsp.h"
|
||||||
|
|
||||||
#define EXIT_LINE LL_EXTI_LINE_16
|
#define EXIT_LINE LL_EXTI_LINE_16
|
||||||
|
@ -34,8 +31,8 @@ void pvd_configuration(uint32_t pwr_level, pvd_irq_handle_cb call)
|
||||||
LL_EXTI_EnableFallingTrig_0_31(EXIT_LINE);
|
LL_EXTI_EnableFallingTrig_0_31(EXIT_LINE);
|
||||||
|
|
||||||
// 启用PVD中断向量
|
// 启用PVD中断向量
|
||||||
NVIC_EnableIRQ(PVD_PVM_IRQn);
|
// NVIC_EnableIRQ(PVD_PVM_IRQn);
|
||||||
NVIC_SetPriority(PVD_PVM_IRQn, 0);
|
// NVIC_SetPriority(PVD_PVM_IRQn, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -68,27 +65,27 @@ void pvd_irq_handle(void)
|
||||||
*/
|
*/
|
||||||
void disable_debug_interface(void)
|
void disable_debug_interface(void)
|
||||||
{
|
{
|
||||||
// 使能 SYSCFG 时钟
|
// // 使能 SYSCFG 时钟
|
||||||
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SYSCFG);
|
// LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SYSCFG);
|
||||||
|
|
||||||
// 关闭调试接口
|
// // 关闭调试接口
|
||||||
LL_DBGMCU_DisableDBGStopMode();
|
// LL_DBGMCU_DisableDBGStopMode();
|
||||||
LL_DBGMCU_DisableDBGStandbyMode();
|
// LL_DBGMCU_DisableDBGStandbyMode();
|
||||||
LL_DBGMCU_DisableDBGSleepMode();
|
// LL_DBGMCU_DisableDBGSleepMode();
|
||||||
|
|
||||||
// 关闭 SWD 和 JTAG 接口
|
// // 关闭 SWD 和 JTAG 接口
|
||||||
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
|
// LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
|
|
||||||
// 配置 SWDIO (PA13) 和 SWCLK (PA14) 引脚为普通 GPIO
|
// // 配置 SWDIO (PA13) 和 SWCLK (PA14) 引脚为普通 GPIO
|
||||||
GPIO_InitStruct.Pin = LL_GPIO_PIN_13 | LL_GPIO_PIN_14;
|
// GPIO_InitStruct.Pin = LL_GPIO_PIN_13 | LL_GPIO_PIN_14;
|
||||||
GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
|
// GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
|
||||||
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
// GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
||||||
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
// LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||||
|
|
||||||
// 如果使用的是 JTAG 接口,还需要配置 JTDI (PA15), JTDO (PB3), 和 NJTRST (PB4) 引脚
|
// // 如果使用的是 JTAG 接口,还需要配置 JTDI (PA15), JTDO (PB3), 和 NJTRST (PB4) 引脚
|
||||||
GPIO_InitStruct.Pin = LL_GPIO_PIN_15;
|
// GPIO_InitStruct.Pin = LL_GPIO_PIN_15;
|
||||||
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
// LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||||
|
|
||||||
GPIO_InitStruct.Pin = LL_GPIO_PIN_3 | LL_GPIO_PIN_4;
|
// GPIO_InitStruct.Pin = LL_GPIO_PIN_3 | LL_GPIO_PIN_4;
|
||||||
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
// LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||||
}
|
}
|
||||||
|
|
11
bsp/bsp.h
11
bsp/bsp.h
|
@ -15,13 +15,13 @@
|
||||||
|
|
||||||
#include "gpios.h"
|
#include "gpios.h"
|
||||||
#include "adcs.h"
|
#include "adcs.h"
|
||||||
#include "dacs.h"
|
// #include "dacs.h"
|
||||||
#include "tims.h"
|
#include "tims.h"
|
||||||
#include "pwms.h"
|
// #include "pwms.h"
|
||||||
#include "uarts.h"
|
#include "uarts.h"
|
||||||
#include "eeprom.h"
|
// #include "eeprom.h"
|
||||||
#include "spis.h"
|
// #include "spis.h"
|
||||||
#include "i2cs.h"
|
// #include "i2cs.h"
|
||||||
|
|
||||||
///< 定义回调函数类型
|
///< 定义回调函数类型
|
||||||
typedef void (*pvd_irq_handle_cb)(void);
|
typedef void (*pvd_irq_handle_cb)(void);
|
||||||
|
@ -29,4 +29,5 @@ typedef void (*pvd_irq_handle_cb)(void);
|
||||||
extern void pvd_configuration(uint32_t pwr_level, pvd_irq_handle_cb call); ///< Configures the Programmable Voltage Detector (PVD) module
|
extern void pvd_configuration(uint32_t pwr_level, pvd_irq_handle_cb call); ///< Configures the Programmable Voltage Detector (PVD) module
|
||||||
extern void pvd_irq_handle(void); ///< Handles the PVD interrupt
|
extern void pvd_irq_handle(void); ///< Handles the PVD interrupt
|
||||||
extern void disable_debug_interface(void); ///< Disables the debug interface
|
extern void disable_debug_interface(void); ///< Disables the debug interface
|
||||||
|
|
||||||
#endif ///< __BSP_H__
|
#endif ///< __BSP_H__
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
#include "lib.h"
|
#include "lib.h"
|
||||||
#define hal_int_state_t char
|
#define hal_int_state_t char
|
||||||
#ifdef STM32
|
#ifdef STM32
|
||||||
#include "stm32l4xx.h"
|
#include "main.h"
|
||||||
#define HAL_ENTER_CRITICAL(__HANDLE__) \
|
#define HAL_ENTER_CRITICAL(__HANDLE__) \
|
||||||
do \
|
do \
|
||||||
{ \
|
{ \
|
||||||
|
|
|
@ -26,18 +26,16 @@ BOOL DBG_ASSERT(uint8_t cond _DBG_LINE_)
|
||||||
#else
|
#else
|
||||||
#include "board.h"
|
#include "board.h"
|
||||||
#include "sys.h"
|
#include "sys.h"
|
||||||
#include "leds.h"
|
|
||||||
BOOL DBG_ASSERT(uint8_t cond _DBG_LINE_)
|
BOOL DBG_ASSERT(uint8_t cond _DBG_LINE_)
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if ((cond) == FALSE)
|
if ((cond) == FALSE)
|
||||||
{
|
{
|
||||||
dbg_assert_line = line;
|
// dbg_assert_line = line;
|
||||||
#if DEBUG_ENABLE == FALSE
|
#if DEBUG_ENABLE == FALSE
|
||||||
sys_soft_reset();
|
sys_soft_reset();
|
||||||
#endif
|
#endif
|
||||||
leds_on(LEDS_ORANGE);
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
LOG_ERR("DBG_ASSERT:%d", line);
|
LOG_ERR("DBG_ASSERT:%d", line);
|
||||||
|
|
2
sys.h
2
sys.h
|
@ -14,7 +14,7 @@
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "lib.h"
|
#include "lib.h"
|
||||||
|
|
||||||
#define CLOCK_CHANGE_ENABLE TRUE ///< 时钟切换使能
|
#define CLOCK_CHANGE_ENABLE FALSE ///< 时钟切换使能
|
||||||
#define LOCK() __disable_irq() ///< 系统关全局中断
|
#define LOCK() __disable_irq() ///< 系统关全局中断
|
||||||
#define UNLOCK() __enable_irq() ///< 系统开全局中断
|
#define UNLOCK() __enable_irq() ///< 系统开全局中断
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue