stm32duino 文件结构分析

GitHub - stm32duino/Arduino_Core_STM32: STM32 core support for Arduino

与arduino 相关的主要涉及 library 与 corel/arduino 

corel/arduino 内的analogWrite analogRead 使用 digital_write() ;内部主要使用  pwm_start(),adc_xxx_() (定义所在地址为 Library的xx文件中 ,详见下方代码,注释*** 头文件处)

帮助 wiki

system:stm32的启动文件

corel/arduino :包含与arduino相关的文件

library:示列,以及于ARDUINO相关的函数(SRCWRAPPER文件)

variant:stm32不同板子的信息

stm32 外设时钟使能与arduino中

目录:corel/arduino 

相关文件:

涉及相应函数 来源于LL

相关文件相关函数
wiring.h主要函数
wring_analog.c

digital_wirte()

digitalPinToPinName()[pins_arduino.h]

wring_digital.c

digitalWriteFast()

digitalReadFast()

#----------WIRING_ANALOG.Cuint32_t analogRead(uint32_t ulPin)   *************
{uint32_t value = 0;
#if defined(HAL_ADC_MODULE_ENABLED) && !defined(HAL_ADC_MODULE_ONLY)PinName p = analogInputToPinName(ulPin);if (p != NC) {value = adc_read_value(p, _internalReadResolution);value = mapResolution(value, _internalReadResolution, _readResolution);}
#elseUNUSED(ulPin);
#endifreturn value;
}void analogWrite(uint32_t ulPin, uint32_t ulValue)   **************
{
#if defined(HAL_DAC_MODULE_ENABLED) && !defined(HAL_DAC_MODULE_ONLY)uint8_t do_init = 0;
#endifPinName p = digitalPinToPinName(ulPin);if (p != NC) {
#if defined(HAL_DAC_MODULE_ENABLED) && !defined(HAL_DAC_MODULE_ONLY)if (pin_in_pinmap(p, PinMap_DAC)) {if (is_pin_configured(p, g_anOutputPinConfigured) == false) {do_init = 1;set_pin_configured(p, g_anOutputPinConfigured);   *****************}ulValue = mapResolution(ulValue, _writeResolution, DACC_RESOLUTION);dac_write_value(p, ulValue, do_init);   *******************} else
#endif //HAL_DAC_MODULE_ENABLED && !HAL_DAC_MODULE_ONLY
#if defined(HAL_TIM_MODULE_ENABLED) && !defined(HAL_TIM_MODULE_ONLY)if (pin_in_pinmap(p, PinMap_TIM)) {if (is_pin_configured(p, g_anOutputPinConfigured) == false) {set_pin_configured(p, g_anOutputPinConfigured);}ulValue = mapResolution(ulValue, _writeResolution, _internalWriteResolution);pwm_start(p, _writeFreq, ulValue, _internalWriteResolution);} else
#endif /* HAL_TIM_MODULE_ENABLED && !HAL_TIM_MODULE_ONLY */{//DIGITAL PIN ONLY// Defaults to digital writepinMode(ulPin, OUTPUT);  // ***************ulValue = mapResolution(ulValue, _writeResolution, 8);if (ulValue < 128) {digitalWrite(ulPin, LOW);   //(********** DIGITALWRITE} else {digitalWrite(ulPin, HIGH);}}}
}------------------------------------------------------------------#WIRING_DIGITAL.Cvoid digitalWrite(uint32_t ulPin, uint32_t ulVal)
{digitalWriteFast(digitalPinToPinName(ulPin), ulVal);  
}int digitalRead(uint32_t ulPin)
{return digitalReadFast(digitalPinToPinName(ulPin));
}void digitalToggle(uint32_t ulPin)
{digitalToggleFast(digitalPinToPinName(ulPin));
}void pinMode(uint32_t ulPin, uint32_t ulMode)
{PinName p = digitalPinToPinName(ulPin);   ***************if (p != NC) {// If the pin that support PWM or DAC output, we need to turn it off
#if (defined(HAL_DAC_MODULE_ENABLED) && !defined(HAL_DAC_MODULE_ONLY)) ||\(defined(HAL_TIM_MODULE_ENABLED) && !defined(HAL_TIM_MODULE_ONLY))if (is_pin_configured(p, g_anOutputPinConfigured)) {
#if defined(HAL_DAC_MODULE_ENABLED) && !defined(HAL_DAC_MODULE_ONLY)if (pin_in_pinmap(p, PinMap_DAC)) {dac_stop(p);       *********主要函数} else
#endif //HAL_DAC_MODULE_ENABLED && !HAL_DAC_MODULE_ONLY
#if defined(HAL_TIM_MODULE_ENABLED) && !defined(HAL_TIM_MODULE_ONLY)if (pin_in_pinmap(p, PinMap_TIM)) {pwm_stop(p);   *******主要函数}
#endif //HAL_TIM_MODULE_ENABLED && !HAL_TIM_MODULE_ONLY{reset_pin_configured(p, g_anOutputPinConfigured);   **********}}
#endifswitch (ulMode) {case INPUT: /* INPUT_FLOATING */pin_function(p, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));break;case INPUT_PULLUP:pin_function(p, STM_PIN_DATA(STM_MODE_INPUT, GPIO_PULLUP, 0));break;case INPUT_PULLDOWN:pin_function(p, STM_PIN_DATA(STM_MODE_INPUT, GPIO_PULLDOWN, 0));break;case INPUT_ANALOG:pin_function(p, STM_PIN_DATA(STM_MODE_ANALOG, GPIO_NOPULL, 0));break;case OUTPUT:pin_function(p, STM_PIN_DATA(STM_MODE_OUTPUT_PP, GPIO_NOPULL, 0));break;case OUTPUT_OPEN_DRAIN:pin_function(p, STM_PIN_DATA(STM_MODE_OUTPUT_OD, GPIO_NOPULL, 0));break;default:Error_Handler();break;}}
}-------------------------------------------------------------
#HARDWARESERIAL.CPPvoid HardwareSerial::begin(unsigned long baud, byte config)
{uint32_t databits = 0;uint32_t stopbits = 0;uint32_t parity = 0;_baud = baud;_config = config;// Manage databitsswitch (config & 0x07) {case 0x02:databits = 6;break;case 0x04:databits = 7;break;case 0x06:databits = 8;break;default:databits = 0;break;}if ((config & 0x30) == 0x30) {parity = UART_PARITY_ODD;databits++;} else if ((config & 0x20) == 0x20) {parity = UART_PARITY_EVEN;databits++;} else {parity = UART_PARITY_NONE;}if ((config & 0x08) == 0x08) {stopbits = UART_STOPBITS_2;} else {stopbits = UART_STOPBITS_1;}switch (databits) {
#ifdef UART_WORDLENGTH_7Bcase 7:databits = UART_WORDLENGTH_7B;break;
#endifcase 8:databits = UART_WORDLENGTH_8B;break;case 9:databits = UART_WORDLENGTH_9B;break;default:case 0:Error_Handler();break;}uart_init(&_serial, (uint32_t)baud, databits, parity, stopbits);   **********enableHalfDuplexRx();uart_attach_rx_callback(&_serial, _rx_complete_irq);
}-------------------------------------------------------------
#PINS_ARDUINO.H
**digitalPinToPinName#define digitalPinToPinName(p)      ((((uint32_t)(p) & PNUM_MASK) < NUM_DIGITAL_PINS) ? \(PinName)(digitalPin[(uint32_t)(p) & PNUM_MASK] | ((p) & ALTX_MASK)) : NC)
#endif /* NUM_ANALOG_INPUTS > 0 */
//***********digitalPin
//主要涉及函数:
digitalPin
dac_stop(p)
pwm_stop(p) #定义在 ANALOG.H
reset_pin_configured
set_pin_configured
dac_write_value
pwm_start  #定义在 ANALOG.H
adc_read_valuE
uart_init--------------------------------------
#ANALOG.H
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __ANALOG_H
#define __ANALOG_H/* Includes ------------------------------------------------------------------*/
#include "stm32_def.h"
#include "PeripheralPins.h"
#include "HardwareTimer.h"#ifdef __cplusplus
extern "C" {
#endif/* Exported functions ------------------------------------------------------- */
#if defined(HAL_ADC_MODULE_ENABLED) && !defined(HAL_ADC_MODULE_ONLY)
uint32_t get_adc_channel(PinName pin, uint32_t *bank);
uint32_t get_adc_internal_channel(PinName pin);
uint16_t adc_read_value(PinName pin, uint32_t resolution);
#endif
#if defined(HAL_DAC_MODULE_ENABLED) && !defined(HAL_DAC_MODULE_ONLY)
uint32_t get_dac_channel(PinName pin);
void dac_write_value(PinName pin, uint32_t value, uint8_t do_init);
void dac_stop(PinName pin);
#endif
#if defined(HAL_TIM_MODULE_ENABLED) && !defined(HAL_TIM_MODULE_ONLY)
void pwm_start(PinName pin, uint32_t clock_freq, uint32_t value, TimerCompareFormat_t resolution);
void pwm_stop(PinName pin);
#endif

PINMAP.H
bool pin_in_pinmap(PinName pin, const PinMap *map);
void pin_function(PinName pin, int function);

PINFUNCTION

主要函数所在地址 :

STMicroelectronics\hardware\stm32\2.4.0\libraries\SrcWrapper\src\stm32

STMicroelectronics\hardware\stm32\2.4.0\libraries\SrcWrapper\src

/********************************************************************************* Copyright (c) 2016-2021, STMicroelectronics* All rights reserved.** This software component is licensed by ST under BSD 3-Clause license,* the "License"; You may not use this file except in compliance with the* License. You may obtain a copy of the License at:*                        opensource.org/licenses/BSD-3-Clause*********************************************************************************/
#include "analog.h"
#include "lock_resource.h"
#include "stm32yyxx_ll_adc.h"
#include "PinAF_STM32F1.h"#ifdef __cplusplus
extern "C" {
#endif/* Private_Variables */
#if (defined(HAL_ADC_MODULE_ENABLED) && !defined(HAL_ADC_MODULE_ONLY)) ||\(defined(HAL_DAC_MODULE_ENABLED) && !defined(HAL_DAC_MODULE_ONLY))
static PinName g_current_pin = NC;
#endif/* Private_Defines */
#if defined(HAL_ADC_MODULE_ENABLED) && !defined(HAL_ADC_MODULE_ONLY)#ifndef ADC_SAMPLINGTIME
#if defined(ADC_SAMPLETIME_8CYCLES_5)
#define ADC_SAMPLINGTIME        ADC_SAMPLETIME_8CYCLES_5;
#elif defined(ADC_SAMPLETIME_12CYCLES)
#define ADC_SAMPLINGTIME        ADC_SAMPLETIME_12CYCLES;
#elif defined(ADC_SAMPLETIME_12CYCLES_5)
#define ADC_SAMPLINGTIME        ADC_SAMPLETIME_12CYCLES_5;
#elif defined(ADC_SAMPLETIME_13CYCLES_5)
#define ADC_SAMPLINGTIME        ADC_SAMPLETIME_13CYCLES_5;
#elif defined(ADC_SAMPLETIME_15CYCLES)
#define ADC_SAMPLINGTIME        ADC_SAMPLETIME_15CYCLES;
#elif defined(ADC_SAMPLETIME_16CYCLES)
#define ADC_SAMPLINGTIME        ADC_SAMPLETIME_16CYCLES;
#elif defined(ADC_SAMPLETIME_19CYCLES_5)
#define ADC_SAMPLINGTIME        ADC_SAMPLETIME_19CYCLES_5;
#endif
#endif /* !ADC_SAMPLINGTIME */#if defined(ADC_VER_V5_V90) && !defined(ADC3_SAMPLINGTIME)
#define ADC3_SAMPLINGTIME       ADC3_SAMPLETIME_24CYCLES_5;
#endif#if defined(ADC4_SAMPLETIME_19CYCLES_5) && !defined(ADC4_SAMPLINGTIME)
#define ADC4_SAMPLINGTIME       ADC4_SAMPLETIME_19CYCLES_5;
#endif/** Minimum ADC sampling time is required when reading* internal channels so set it to max possible value.* It can be defined more precisely by defining:* ADC_SAMPLINGTIME_INTERNAL* to the desired ADC sample time.*/
#ifndef ADC_SAMPLINGTIME_INTERNAL
#if defined(ADC_SAMPLETIME_480CYCLES)
#define ADC_SAMPLINGTIME_INTERNAL ADC_SAMPLETIME_480CYCLES
#elif defined(ADC_SAMPLETIME_384CYCLES)
#define ADC_SAMPLINGTIME_INTERNAL ADC_SAMPLETIME_384CYCLES
#elif defined(ADC_SAMPLETIME_810CYCLES_5)
#define ADC_SAMPLINGTIME_INTERNAL ADC_SAMPLETIME_810CYCLES_5
#elif defined(ADC_SAMPLETIME_814CYCLES)
#define ADC_SAMPLINGTIME_INTERNAL ADC_SAMPLETIME_814CYCLES
#elif defined(ADC_SAMPLETIME_640CYCLES_5)
#define ADC_SAMPLINGTIME_INTERNAL ADC_SAMPLETIME_640CYCLES_5
#elif defined(ADC_SAMPLETIME_601CYCLES_5)
#define ADC_SAMPLINGTIME_INTERNAL ADC_SAMPLETIME_601CYCLES_5
#elif defined(ADC_SAMPLETIME_247CYCLES_5)
#define ADC_SAMPLINGTIME_INTERNAL ADC_SAMPLETIME_247CYCLES_5
#elif defined(ADC_SAMPLETIME_239CYCLES_5)
#define ADC_SAMPLINGTIME_INTERNAL ADC_SAMPLETIME_239CYCLES_5
#elif defined(ADC_SAMPLETIME_160CYCLES_5)
#define ADC_SAMPLINGTIME_INTERNAL ADC_SAMPLETIME_160CYCLES_5
#else
#error "ADC sampling time could not be defined for internal channels!"
#endif
#endif /* !ADC_SAMPLINGTIME_INTERNAL */#ifndef ADC_CLOCK_DIV
#ifdef ADC_CLOCK_SYNC_PCLK_DIV4
#define ADC_CLOCK_DIV       ADC_CLOCK_SYNC_PCLK_DIV4
#elif ADC_CLOCK_SYNC_PCLK_DIV2
#define ADC_CLOCK_DIV       ADC_CLOCK_SYNC_PCLK_DIV2
#elif defined(ADC_CLOCK_ASYNC_DIV4)
#define ADC_CLOCK_DIV       ADC_CLOCK_ASYNC_DIV4
#endif
#endif /* !ADC_CLOCK_DIV */#ifndef ADC_REGULAR_RANK_1
#define ADC_REGULAR_RANK_1  1
#endif/* Exported Functions */
/*** @brief  Return ADC HAL channel linked to a PinName* @param  pin: PinName* @param  bank: pointer to get ADC channel bank if required* @retval Valid HAL channel*/
uint32_t get_adc_channel(PinName pin, uint32_t *bank)
{uint32_t function = pinmap_function(pin, PinMap_ADC);uint32_t channel = 0;switch (STM_PIN_CHANNEL(function)) {
#ifdef ADC_CHANNEL_0case 0:channel = ADC_CHANNEL_0;break;
#endifcase 1:channel = ADC_CHANNEL_1;break;case 2:channel = ADC_CHANNEL_2;break;case 3:channel = ADC_CHANNEL_3;break;case 4:channel = ADC_CHANNEL_4;break;case 5:channel = ADC_CHANNEL_5;break;case 6:channel = ADC_CHANNEL_6;break;case 7:channel = ADC_CHANNEL_7;break;case 8:channel = ADC_CHANNEL_8;break;case 9:channel = ADC_CHANNEL_9;break;case 10:channel = ADC_CHANNEL_10;break;case 11:channel = ADC_CHANNEL_11;break;case 12:channel = ADC_CHANNEL_12;break;case 13:channel = ADC_CHANNEL_13;break;case 14:channel = ADC_CHANNEL_14;break;case 15:channel = ADC_CHANNEL_15;break;
#ifdef ADC_CHANNEL_16case 16:channel = ADC_CHANNEL_16;break;
#endifcase 17:channel = ADC_CHANNEL_17;break;
#ifdef ADC_CHANNEL_18case 18:channel = ADC_CHANNEL_18;break;
#endif
#ifdef ADC_CHANNEL_19case 19:channel = ADC_CHANNEL_19;break;
#endif
#ifdef ADC_CHANNEL_20case 20:channel = ADC_CHANNEL_20;break;case 21:channel = ADC_CHANNEL_21;break;case 22:channel = ADC_CHANNEL_22;break;case 23:channel = ADC_CHANNEL_23;break;
#ifdef ADC_CHANNEL_24case 24:channel = ADC_CHANNEL_24;break;case 25:channel = ADC_CHANNEL_25;break;case 26:channel = ADC_CHANNEL_26;break;
#ifdef ADC_CHANNEL_27case 27:channel = ADC_CHANNEL_27;break;case 28:channel = ADC_CHANNEL_28;break;case 29:channel = ADC_CHANNEL_29;break;case 30:channel = ADC_CHANNEL_30;break;case 31:channel = ADC_CHANNEL_31;break;
#endif
#endif
#endifdefault:_Error_Handler("ADC: Unknown adc channel", (int)(STM_PIN_CHANNEL(function)));break;}
#ifdef ADC_CHANNELS_BANK_Bif (STM_PIN_ANALOG_CHANNEL_BANK_B(function)) {*bank = ADC_CHANNELS_BANK_B;} else {*bank = ADC_CHANNELS_BANK_A;}
#elseUNUSED(bank);
#endifreturn channel;
}/*** @brief  Return ADC HAL internal channel linked to a PinName* @param  pin: specific PinName's for ADC internal. Value can be:*         PADC_TEMP, PADC_TEMP_ADC5, PADC_VREF, PADC_VBAT*         Note that not all of these values 鈥嬧€媘ay be available for all series.* @retval Valid HAL internal channel.*/
uint32_t get_adc_internal_channel(PinName pin)
{uint32_t channel = 0;switch (pin) {
#if defined(ADC_CHANNEL_TEMPSENSOR)case PADC_TEMP:channel = ADC_CHANNEL_TEMPSENSOR;break;
#endif
#if defined(ADC_CHANNEL_TEMPSENSOR_ADC1)case PADC_TEMP:channel = ADC_CHANNEL_TEMPSENSOR_ADC1;break;
#endif
#if defined(ADC5) && defined(ADC_CHANNEL_TEMPSENSOR_ADC5)case PADC_TEMP_ADC5:channel = ADC_CHANNEL_TEMPSENSOR_ADC5;break;
#endif
#ifdef ADC_CHANNEL_VREFINTcase PADC_VREF:channel = ADC_CHANNEL_VREFINT;break;
#endif
#ifdef ADC_CHANNEL_VBATcase PADC_VBAT:channel = ADC_CHANNEL_VBAT;break;
#endifdefault:_Error_Handler("ADC: Unknown adc internal PiName", (int)(pin));break;}return channel;
}
#endif /* HAL_ADC_MODULE_ENABLED && !HAL_ADC_MODULE_ONLY */#if defined(HAL_DAC_MODULE_ENABLED) && !defined(HAL_DAC_MODULE_ONLY)
/*** @brief  Return DAC HAL channel linked to a PinName* @param  pin: specific PinName's for ADC internal.* @retval Valid HAL channel*/
uint32_t get_dac_channel(PinName pin)
{uint32_t function = pinmap_function(pin, PinMap_DAC);uint32_t channel = 0;switch (STM_PIN_CHANNEL(function)) {
#ifdef DAC_CHANNEL_0case 0:channel = DAC_CHANNEL_0;break;
#endifcase 1:channel = DAC_CHANNEL_1;break;
#ifdef DAC_CHANNEL_2case 2:channel = DAC_CHANNEL_2;break;
#endifdefault:_Error_Handler("DAC: Unknown dac channel", (int)(STM_PIN_CHANNEL(function)));break;}return channel;
}// DAC INTERFACE FUNCTIONS //*** @brief DAC MSP Initialization*        This function configures the hardware resources used in this example:*           - Peripheral's clock enable*           - Peripheral's GPIO Configuration* @param hdac: DAC handle pointer* @retval None*/
void HAL_DAC_MspInit(DAC_HandleTypeDef *hdac)
{/* DAC Periph clock enable */if (hdac->Instance == DAC1) {
#ifdef __HAL_RCC_DAC_CLK_ENABLE__HAL_RCC_DAC_CLK_ENABLE();
#endif
#ifdef __HAL_RCC_DAC1_CLK_ENABLE__HAL_RCC_DAC1_CLK_ENABLE();
#endif
#ifdef __HAL_RCC_DAC12_CLK_ENABLE__HAL_RCC_DAC12_CLK_ENABLE();
#endif}
#ifdef DAC2else if (hdac->Instance == DAC2) {
#ifdef __HAL_RCC_DAC2_CLK_ENABLE__HAL_RCC_DAC2_CLK_ENABLE();
#endif
#ifdef __HAL_RCC_DAC12_CLK_ENABLE__HAL_RCC_DAC12_CLK_ENABLE();
#endif}
#endif
#ifdef DAC3else if (hdac->Instance == DAC3) {
#ifdef __HAL_RCC_DAC3_CLK_ENABLE__HAL_RCC_DAC3_CLK_ENABLE();
#endif}
#endif
#ifdef DAC4else if (hdac->Instance == DAC4) {
#ifdef __HAL_RCC_DAC4_CLK_ENABLE__HAL_RCC_DAC4_CLK_ENABLE();
#endif}
#endif/* Configure DAC GPIO pins */pinmap_pinout(g_current_pin, PinMap_DAC);
}/*** @brief  This function will set the DAC to the required value* @param  port : the gpio port to use* @param  pin : the gpio pin to use* @param  value : the value to push on the adc output* @param  do_init : if set to 1 the initialization of the adc is done* @retval None*/
void dac_write_value(PinName pin, uint32_t value, uint8_t do_init)
{DAC_HandleTypeDef DacHandle = {};DAC_ChannelConfTypeDef dacChannelConf = {};uint32_t dacChannel;DacHandle.Instance = (DAC_TypeDef *)pinmap_peripheral(pin, PinMap_DAC);if (DacHandle.Instance == NP) {return;}dacChannel = get_dac_channel(pin);
#if defined(STM32G4xx)if (!IS_DAC_CHANNEL(DacHandle.Instance, dacChannel)) {
#elseif (!IS_DAC_CHANNEL(dacChannel)) {
#endifreturn;}if (do_init == 1) {/*##-1- Configure the DAC peripheral #######################################*/g_current_pin = pin;if (HAL_DAC_Init(&DacHandle) != HAL_OK) {/* Initialization Error */return;}dacChannelConf.DAC_Trigger = DAC_TRIGGER_NONE;dacChannelConf.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
#if defined(DAC_OUTPUTSWITCH_ENABLE)dacChannelConf.DAC_OutputSwitch = DAC_OUTPUTSWITCH_ENABLE;
#endif/*##-2- Configure DAC channel1 #############################################*/if (HAL_DAC_ConfigChannel(&DacHandle, &dacChannelConf, dacChannel) != HAL_OK) {/* Channel configuration Error */return;}}/*##-3- Set DAC Channel1 DHR register ######################################*/if (HAL_DAC_SetValue(&DacHandle, dacChannel, DAC_ALIGN_12B_R, value) != HAL_OK) {/* Setting value Error */return;}/*##-4- Enable DAC Channel1 ################################################*/HAL_DAC_Start(&DacHandle, dacChannel);
}/*** @brief  DeInitialize the DAC MSP.* @param  hdac: pointer to a DAC_HandleTypeDef structure that contains*         the configuration information for the specified DAC.* @retval None*/
void HAL_DAC_MspDeInit(DAC_HandleTypeDef *hdac)
{/* DAC Periph clock disable */if (hdac->Instance == DAC1) {
#ifdef __HAL_RCC_DAC_FORCE_RESET__HAL_RCC_DAC_FORCE_RESET();
#endif
#ifdef __HAL_RCC_DAC1_FORCE_RESET__HAL_RCC_DAC1_FORCE_RESET();
#endif
#ifdef __HAL_RCC_DAC12_FORCE_RESET__HAL_RCC_DAC12_FORCE_RESET();
#endif
#ifdef __HAL_RCC_DAC_RELEASE_RESET__HAL_RCC_DAC_RELEASE_RESET();
#endif
#ifdef __HAL_RCC_DAC1_RELEASE_RESET__HAL_RCC_DAC1_RELEASE_RESET();
#endif
#ifdef __HAL_RCC_DAC12_RELEASE_RESET__HAL_RCC_DAC12_RELEASE_RESET();
#endif
#ifdef __HAL_RCC_DAC_CLK_DISABLE__HAL_RCC_DAC_CLK_DISABLE();
#endif
#ifdef __HAL_RCC_DAC1_CLK_DISABLE__HAL_RCC_DAC1_CLK_DISABLE();
#endif
#ifdef __HAL_RCC_DAC12_CLK_ENABLE__HAL_RCC_DAC12_CLK_ENABLE();
#endif}
#ifdef DAC2else if (hdac->Instance == DAC2) {
#ifdef __HAL_RCC_DAC2_FORCE_RESET__HAL_RCC_DAC2_FORCE_RESET();
#endif
#ifdef __HAL_RCC_DAC12_FORCE_RESET__HAL_RCC_DAC12_FORCE_RESET();
#endif
#ifdef __HAL_RCC_DAC2_RELEASE_RESET__HAL_RCC_DAC2_RELEASE_RESET();
#endif
#ifdef __HAL_RCC_DAC12_RELEASE_RESET__HAL_RCC_DAC12_RELEASE_RESET();
#endif
#ifdef __HAL_RCC_DAC2_CLK_ENABLE__HAL_RCC_DAC2_CLK_ENABLE();
#endif
#ifdef __HAL_RCC_DAC12_CLK_ENABLE__HAL_RCC_DAC12_CLK_ENABLE();
#endif}
#endif
#ifdef DAC3else if (hdac->Instance == DAC3) {
#ifdef __HAL_RCC_DAC3_FORCE_RESET__HAL_RCC_DAC3_FORCE_RESET();
#endif
#ifdef __HAL_RCC_DAC3_RELEASE_RESET__HAL_RCC_DAC3_RELEASE_RESET();
#endif
#ifdef __HAL_RCC_DAC3_CLK_DISABLE__HAL_RCC_DAC3_CLK_DISABLE();
#endif}
#endif
#ifdef DAC4else if (hdac->Instance == DAC4) {
#ifdef __HAL_RCC_DAC4_FORCE_RESET__HAL_RCC_DAC4_FORCE_RESET();
#endif
#ifdef __HAL_RCC_DAC4_RELEASE_RESET__HAL_RCC_DAC4_RELEASE_RESET();
#endif
#ifdef __HAL_RCC_DAC4_CLK_DISABLE__HAL_RCC_DAC4_CLK_DISABLE();
#endif}
#endif
}/*** @brief  This function will stop the DAC* @param  port : the gpio port to use* @param  pin : the gpio pin to use* @retval None*/
void dac_stop(PinName pin)
{DAC_HandleTypeDef DacHandle;uint32_t dacChannel;DacHandle.Instance = (DAC_TypeDef *)pinmap_peripheral(pin, PinMap_DAC);if (DacHandle.Instance == NP) {return;}dacChannel = get_dac_channel(pin);
#if defined(STM32G4xx)if (!IS_DAC_CHANNEL(DacHandle.Instance, dacChannel)) {
#elseif (!IS_DAC_CHANNEL(dacChannel)) {
#endifreturn;}HAL_DAC_Stop(&DacHandle, dacChannel);if (HAL_DAC_DeInit(&DacHandle) != HAL_OK) {/* DeInitialization Error */return;}
}
#endif //HAL_DAC_MODULE_ENABLED && !HAL_DAC_MODULE_ONLY#if defined(HAL_ADC_MODULE_ENABLED) && !defined(HAL_ADC_MODULE_ONLY)
// ADC INTERFACE FUNCTIONS //*** @brief ADC MSP Initialization*        This function configures the hardware resources used in this example:*           - Peripheral's clock enable*           - Peripheral's GPIO Configuration* @param hadc: ADC handle pointer* @retval None*/
void HAL_ADC_MspInit(ADC_HandleTypeDef *hadc)
{/*##-1- Enable peripherals and GPIO Clocks #################################*//* ADC Periph clock enable */if (hadc->Instance == ADC1) {
#ifdef __HAL_RCC_ADC1_CLK_ENABLE__HAL_RCC_ADC1_CLK_ENABLE();
#endif
#ifdef __HAL_RCC_ADC12_CLK_ENABLE__HAL_RCC_ADC12_CLK_ENABLE();
#endif}
#ifdef ADC2else if (hadc->Instance == ADC2) {
#ifdef __HAL_RCC_ADC2_CLK_ENABLE__HAL_RCC_ADC2_CLK_ENABLE();
#endif
#ifdef __HAL_RCC_ADC12_CLK_ENABLE__HAL_RCC_ADC12_CLK_ENABLE();
#endif}
#endif
#ifdef ADC3else if (hadc->Instance == ADC3) {
#ifdef __HAL_RCC_ADC3_CLK_ENABLE__HAL_RCC_ADC3_CLK_ENABLE();
#endif
#ifdef __HAL_RCC_ADC34_CLK_ENABLE__HAL_RCC_ADC34_CLK_ENABLE();
#endif
#if defined(ADC345_COMMON)__HAL_RCC_ADC345_CLK_ENABLE();
#endif}
#endif
#ifdef ADC4else if (hadc->Instance == ADC4) {
#ifdef __HAL_RCC_ADC4_CLK_ENABLE__HAL_RCC_ADC4_CLK_ENABLE();
#endif
#ifdef __HAL_RCC_ADC34_CLK_ENABLE__HAL_RCC_ADC34_CLK_ENABLE();
#endif
#if defined(ADC345_COMMON)__HAL_RCC_ADC345_CLK_ENABLE();
#endif}
#endif
#ifdef ADC5else if (hadc->Instance == ADC5) {
#if defined(ADC345_COMMON)__HAL_RCC_ADC345_CLK_ENABLE();
#endif}
#endif
#ifdef __HAL_RCC_ADC_CLK_ENABLE__HAL_RCC_ADC_CLK_ENABLE();
#endif/* For STM32F1xx, STM32H7xx, and STM32MP1xx ADC prescaler is configured inSystemClock_Config (variant.cpp) */
#if defined(__HAL_RCC_ADC_CONFIG) && !defined(STM32F1xx) && \!defined(STM32H7xx) && !defined(STM32MP1xx)hsem_lock(CFG_HW_RCC_CRRCR_CCIPR_SEMID, HSEM_LOCK_DEFAULT_RETRY);/* ADC Periph interface clock configuration */__HAL_RCC_ADC_CONFIG(RCC_ADCCLKSOURCE_SYSCLK);hsem_unlock(CFG_HW_RCC_CRRCR_CCIPR_SEMID);
#endif/* Configure ADC GPIO pin */if (!(g_current_pin & PADC_BASE)) {pinmap_pinout(g_current_pin, PinMap_ADC);}
}/*** @brief  DeInitializes the ADC MSP.* @param  hadc: ADC handle* @retval None*/
void HAL_ADC_MspDeInit(ADC_HandleTypeDef *hadc)
{
#ifdef __HAL_RCC_ADC_FORCE_RESET__HAL_RCC_ADC_FORCE_RESET();
#endif
#ifdef __HAL_RCC_ADC_RELEASE_RESET__HAL_RCC_ADC_RELEASE_RESET();
#endifif (hadc->Instance == ADC1) {
#ifdef __HAL_RCC_ADC1_FORCE_RESET__HAL_RCC_ADC1_FORCE_RESET();
#endif
#ifdef __HAL_RCC_ADC1_RELEASE_RESET__HAL_RCC_ADC1_RELEASE_RESET();
#endif
#ifdef __HAL_RCC_ADC12_FORCE_RESET__HAL_RCC_ADC12_FORCE_RESET();
#endif
#ifdef __HAL_RCC_ADC12_RELEASE_RESET__HAL_RCC_ADC12_RELEASE_RESET();
#endif
#ifdef __HAL_RCC_ADC1_CLK_DISABLE__HAL_RCC_ADC1_CLK_DISABLE();
#endif
#ifdef __HAL_RCC_ADC12_CLK_DISABLE__HAL_RCC_ADC12_CLK_DISABLE();
#endif}
#ifdef ADC2else if (hadc->Instance == ADC2) {
#ifdef __HAL_RCC_ADC2_FORCE_RESET__HAL_RCC_ADC2_FORCE_RESET();
#endif
#ifdef __HAL_RCC_ADC2_RELEASE_RESET__HAL_RCC_ADC2_RELEASE_RESET();
#endif
#ifdef __HAL_RCC_ADC12_FORCE_RESET__HAL_RCC_ADC12_FORCE_RESET();
#endif
#ifdef __HAL_RCC_ADC12_RELEASE_RESET__HAL_RCC_ADC12_RELEASE_RESET();
#endif
#ifdef __HAL_RCC_ADC2_CLK_DISABLE__HAL_RCC_ADC2_CLK_DISABLE();
#endif
#ifdef __HAL_RCC_ADC2_CLK_DISABLE__HAL_RCC_ADC2_CLK_DISABLE();
#endif}
#endif
#ifdef ADC3else if (hadc->Instance == ADC3) {
#ifdef __HAL_RCC_ADC3_FORCE_RESET__HAL_RCC_ADC3_FORCE_RESET();
#endif
#ifdef __HAL_RCC_ADC3_RELEASE_RESET__HAL_RCC_ADC3_RELEASE_RESET();
#endif
#ifdef __HAL_RCC_ADC34_FORCE_RESET__HAL_RCC_ADC34_FORCE_RESET();
#endif
#ifdef __HAL_RCC_ADC34_RELEASE_RESET__HAL_RCC_ADC34_RELEASE_RESET();
#endif
#ifdef __HAL_RCC_ADC3_CLK_DISABLE__HAL_RCC_ADC3_CLK_DISABLE();
#endif
#ifdef __HAL_RCC_ADC34_CLK_DISABLE__HAL_RCC_ADC34_CLK_DISABLE();
#endif
#if defined(ADC345_COMMON)__HAL_RCC_ADC345_FORCE_RESET();__HAL_RCC_ADC345_RELEASE_RESET();__HAL_RCC_ADC345_CLK_DISABLE();
#endif}
#endif
#ifdef ADC4else if (hadc->Instance == ADC4) {
#ifdef __HAL_RCC_ADC4_FORCE_RESET__HAL_RCC_ADC4_FORCE_RESET();
#endif
#ifdef __HAL_RCC_ADC4_RELEASE_RESET__HAL_RCC_ADC4_RELEASE_RESET();
#endif
#ifdef __HAL_RCC_ADC4_CLK_DISABLE__HAL_RCC_ADC4_CLK_DISABLE();
#endif
#ifdef __HAL_RCC_ADC34_FORCE_RESET__HAL_RCC_ADC34_FORCE_RESET();
#endif
#ifdef __HAL_RCC_ADC34_RELEASE_RESET__HAL_RCC_ADC34_RELEASE_RESET();
#endif
#ifdef __HAL_RCC_ADC34_CLK_DISABLE__HAL_RCC_ADC34_CLK_DISABLE();
#endif
#if defined(ADC345_COMMON)__HAL_RCC_ADC345_FORCE_RESET();__HAL_RCC_ADC345_RELEASE_RESET();__HAL_RCC_ADC345_CLK_DISABLE();
#endif}
#endif
#ifdef ADC5else if (hadc->Instance == ADC5) {
#if defined(ADC345_COMMON)__HAL_RCC_ADC345_FORCE_RESET();__HAL_RCC_ADC345_RELEASE_RESET();__HAL_RCC_ADC345_CLK_DISABLE();
#endif}
#endif
#ifdef __HAL_RCC_ADC_CLK_DISABLE__HAL_RCC_ADC_FORCE_RESET();__HAL_RCC_ADC_RELEASE_RESET();__HAL_RCC_ADC_CLK_DISABLE();
#endif
}/*** @brief  This function will set the ADC to the required value* @param  pin : the pin to use* @param  resolution : resolution for converted data: 6/8/10/12/14/16* @retval the value of the adc*/
uint16_t adc_read_value(PinName pin, uint32_t resolution)
{ADC_HandleTypeDef AdcHandle = {};ADC_ChannelConfTypeDef  AdcChannelConf = {};__IO uint16_t uhADCxConvertedValue = 0;uint32_t samplingTime = ADC_SAMPLINGTIME;uint32_t channel = 0;uint32_t bank = 0;if ((pin & PADC_BASE) && (pin < ANA_START)) {
#if defined(STM32H7xx) || defined(STM32MP1xx)
#ifdef ADC3AdcHandle.Instance = ADC3;
#elseAdcHandle.Instance = ADC2;
#endif
#elseAdcHandle.Instance = ADC1;
#if defined(ADC5) && defined(ADC_CHANNEL_TEMPSENSOR_ADC5)if (pin == PADC_TEMP_ADC5) {AdcHandle.Instance = ADC5;}
#endif
#endifchannel = get_adc_internal_channel(pin);samplingTime = ADC_SAMPLINGTIME_INTERNAL;} else {AdcHandle.Instance = (ADC_TypeDef *)pinmap_peripheral(pin, PinMap_ADC);channel = get_adc_channel(pin, &bank);
#if defined(ADC_VER_V5_V90)if (AdcHandle.Instance == ADC3) {samplingTime = ADC3_SAMPLINGTIME;}
#endif
#if defined(ADC4_SAMPLINGTIME)if (AdcHandle.Instance == ADC4) {samplingTime = ADC4_SAMPLINGTIME;}
#endif}if (AdcHandle.Instance == NP) {return 0;}#ifdef ADC_CLOCK_DIVAdcHandle.Init.ClockPrescaler        = ADC_CLOCK_DIV;                 /* (A)synchronous clock mode, input ADC clock divided */
#endif
#ifdef ADC_RESOLUTION_12Bswitch (resolution) {
#ifdef ADC_RESOLUTION_6Bcase 6:AdcHandle.Init.Resolution          = ADC_RESOLUTION_6B;             /* resolution for converted data */break;
#endifcase 8:AdcHandle.Init.Resolution          = ADC_RESOLUTION_8B;             /* resolution for converted data */break;case 10:AdcHandle.Init.Resolution          = ADC_RESOLUTION_10B;            /* resolution for converted data */break;case 12:default:AdcHandle.Init.Resolution          = ADC_RESOLUTION_12B;            /* resolution for converted data */break;
#ifdef ADC_RESOLUTION_14Bcase 14:AdcHandle.Init.Resolution          = ADC_RESOLUTION_14B;            /* resolution for converted data */break;
#endif
#ifdef ADC_RESOLUTION_16Bcase 16:AdcHandle.Init.Resolution          = ADC_RESOLUTION_16B;            /* resolution for converted data */break;
#endif}
#elseUNUSED(resolution);
#endif
#ifdef ADC_DATAALIGN_RIGHTAdcHandle.Init.DataAlign             = ADC_DATAALIGN_RIGHT;           /* Right-alignment for converted data */
#endif
#ifdef ADC_SCAN_SEQ_FIXEDAdcHandle.Init.ScanConvMode          = ADC_SCAN_SEQ_FIXED;            /* Sequencer disabled (ADC conversion on only 1 channel: channel set on rank 1) */
#elseAdcHandle.Init.ScanConvMode          = DISABLE;                       /* Sequencer disabled (ADC conversion on only 1 channel: channel set on rank 1) */
#endif
#ifdef ADC_EOC_SINGLE_CONVAdcHandle.Init.EOCSelection          = ADC_EOC_SINGLE_CONV;           /* EOC flag picked-up to indicate conversion end */
#endif
#if !defined(STM32F1xx) && !defined(STM32F2xx) && !defined(STM32F4xx) && \!defined(STM32F7xx) && !defined(ADC1_V2_5)AdcHandle.Init.LowPowerAutoWait      = DISABLE;                       /* Auto-delayed conversion feature disabled */
#endif
#if !defined(STM32F1xx) && !defined(STM32F2xx) && !defined(STM32F3xx) && \!defined(STM32F4xx) && !defined(STM32F7xx) && !defined(STM32G4xx) && \!defined(STM32H7xx) && !defined(STM32L4xx) && !defined(STM32L5xx) && \!defined(STM32MP1xx) && !defined(STM32WBxx)AdcHandle.Init.LowPowerAutoPowerOff  = DISABLE;                       /* ADC automatically powers-off after a conversion and automatically wakes-up when a new conversion is triggered */
#endif
#ifdef ADC_CHANNELS_BANK_BAdcHandle.Init.ChannelsBank          = bank;
#elif defined(ADC_CHANNELS_BANK_A)AdcHandle.Init.ChannelsBank          = ADC_CHANNELS_BANK_A;
#endifAdcHandle.Init.ContinuousConvMode    = DISABLE;                       /* Continuous mode disabled to have only 1 conversion at each conversion trig */
#if !defined(STM32F0xx) && !defined(STM32L0xx)AdcHandle.Init.NbrOfConversion       = 1;                             /* Specifies the number of ranks that will be converted within the regular group sequencer. */
#endifAdcHandle.Init.DiscontinuousConvMode = DISABLE;                       /* Parameter discarded because sequencer is disabled */
#if !defined(STM32F0xx) && !defined(STM32G0xx) && !defined(STM32L0xx) && \!defined(STM32WLxx)AdcHandle.Init.NbrOfDiscConversion   = 0;                             /* Parameter discarded because sequencer is disabled */
#endifAdcHandle.Init.ExternalTrigConv      = ADC_SOFTWARE_START;            /* Software start to trig the 1st conversion manually, without external event */
#if !defined(STM32F1xx) && !defined(ADC1_V2_5)AdcHandle.Init.ExternalTrigConvEdge  = ADC_EXTERNALTRIGCONVEDGE_NONE; /* Parameter discarded because software trigger chosen */
#endif
#if !defined(STM32F1xx) && !defined(STM32H7xx) && !defined(STM32MP1xx) && \!defined(ADC1_V2_5)AdcHandle.Init.DMAContinuousRequests = DISABLE;                       /* DMA one-shot mode selected (not applied to this example) */
#endif
#ifdef ADC_CONVERSIONDATA_DRAdcHandle.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DR;      /* Regular Conversion data stored in DR register only */
#endif
#ifdef ADC_OVR_DATA_OVERWRITTENAdcHandle.Init.Overrun               = ADC_OVR_DATA_OVERWRITTEN;      /* DR register is overwritten with the last conversion result in case of overrun */
#endif
#ifdef ADC_LEFTBITSHIFT_NONEAdcHandle.Init.LeftBitShift          = ADC_LEFTBITSHIFT_NONE;         /* No bit shift left applied on the final ADC conversion data */
#endif#if defined(STM32F0xx)AdcHandle.Init.SamplingTimeCommon    = samplingTime;
#endif
#if defined(STM32G0xx) || defined(STM32U5xx) || defined(STM32WLxx)AdcHandle.Init.SamplingTimeCommon1   = samplingTime;              /* Set sampling time common to a group of channels. */AdcHandle.Init.SamplingTimeCommon2   = samplingTime;              /* Set sampling time common to a group of channels, second common setting possible.*/
#endif
#if defined(STM32L0xx)AdcHandle.Init.LowPowerFrequencyMode = DISABLE;                       /* To be enabled only if ADC clock < 2.8 MHz */AdcHandle.Init.SamplingTime          = samplingTime;
#endif
#if !defined(STM32F0xx) && !defined(STM32F1xx) && !defined(STM32F2xx) && \!defined(STM32F3xx) && !defined(STM32F4xx) && !defined(STM32F7xx) && \!defined(STM32L1xx)AdcHandle.Init.OversamplingMode      = DISABLE;/* AdcHandle.Init.Oversample ignore for STM32L0xx as oversampling disabled *//* AdcHandle.Init.Oversampling ignored for other as oversampling disabled */
#endif
#if defined(ADC_CFGR_DFSDMCFG) && defined(DFSDM1_Channel0)AdcHandle.Init.DFSDMConfig           = ADC_DFSDM_MODE_DISABLE;        /* ADC conversions are not transferred by DFSDM. */
#endif
#ifdef ADC_TRIGGER_FREQ_HIGHAdcHandle.Init.TriggerFrequencyMode  = ADC_TRIGGER_FREQ_HIGH;
#endif
#ifdef ADC_VREF_PPROT_NONEAdcHandle.Init.VrefProtection = ADC_VREF_PPROT_NONE;
#endifAdcHandle.State = HAL_ADC_STATE_RESET;AdcHandle.DMA_Handle = NULL;AdcHandle.Lock = HAL_UNLOCKED;/* Some other ADC_HandleTypeDef fields exists but not required */g_current_pin = pin; /* Needed for HAL_ADC_MspInit*/if (HAL_ADC_Init(&AdcHandle) != HAL_OK) {return 0;}AdcChannelConf.Channel      = channel;                          /* Specifies the channel to configure into ADC */#if defined(STM32G4xx) || defined(STM32L4xx) || defined(STM32L5xx) || \defined(STM32WBxx)if (!IS_ADC_CHANNEL(&AdcHandle, AdcChannelConf.Channel)) {
#elseif (!IS_ADC_CHANNEL(AdcChannelConf.Channel)) {
#endifreturn 0;}
#if defined(ADC_SCAN_SEQ_FIXED) && defined(ADC_RANK_CHANNEL_NUMBER)AdcChannelConf.Rank         = ADC_RANK_CHANNEL_NUMBER;          /* Enable the rank of the selected channels when not fully configurable */
#elseAdcChannelConf.Rank         = ADC_REGULAR_RANK_1;               /* Specifies the rank in the regular group sequencer */
#endif
#if !defined(STM32L0xx)
#if !defined(STM32G0xx)AdcChannelConf.SamplingTime = samplingTime;                     /* Sampling time value to be set for the selected channel */
#elseAdcChannelConf.SamplingTime = ADC_SAMPLINGTIME_COMMON_1;        /* Sampling time value to be set for the selected channel */
#endif
#endif
#if defined(ADC_DIFFERENTIAL_ENDED) && !defined(ADC1_V2_5)AdcChannelConf.SingleDiff   = ADC_SINGLE_ENDED;                 /* Single-ended input channel */AdcChannelConf.OffsetNumber = ADC_OFFSET_NONE;                  /* No offset subtraction */
#endif
#if !defined(STM32F0xx) && !defined(STM32F1xx) && !defined(STM32F2xx) && \!defined(STM32G0xx) && !defined(STM32L0xx) && !defined(STM32L1xx) && \!defined(STM32WBxx) && !defined(STM32WLxx) && \!defined(ADC1_V2_5)AdcChannelConf.Offset = 0;                                      /* Parameter discarded because offset correction is disabled */
#endif
#if defined (STM32H7xx) || defined(STM32MP1xx)AdcChannelConf.OffsetRightShift = DISABLE;                      /* No Right Offset Shift */AdcChannelConf.OffsetSignedSaturation = DISABLE;                /* Signed saturation feature is not used */
#endif/*##-2- Configure ADC regular channel ######################################*/if (HAL_ADC_ConfigChannel(&AdcHandle, &AdcChannelConf) != HAL_OK) {/* Channel Configuration Error */return 0;}#if defined(ADC_CR_ADCAL) || defined(ADC_CR2_RSTCAL)/*##-2.1- Calibrate ADC then Start the conversion process ####################*/
#if defined(ADC_CALIB_OFFSET)if (HAL_ADCEx_Calibration_Start(&AdcHandle, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED) != HAL_OK)
#elif defined(ADC_SINGLE_ENDED) && !defined(ADC1_V2_5)if (HAL_ADCEx_Calibration_Start(&AdcHandle, ADC_SINGLE_ENDED) !=  HAL_OK)
#elseif (HAL_ADCEx_Calibration_Start(&AdcHandle) !=  HAL_OK)
#endif{/* ADC Calibration Error */return 0;}
#endif/*##-3- Start the conversion process ####################*/if (HAL_ADC_Start(&AdcHandle) != HAL_OK) {/* Start Conversion Error */return 0;}/*##-4- Wait for the end of conversion #####################################*//*  For simplicity reasons, this example is just waiting till the end of theconversion, but application may perform other tasks while conversionoperation is ongoing. */if (HAL_ADC_PollForConversion(&AdcHandle, 10) != HAL_OK) {/* End Of Conversion flag not set on time */return 0;}/* Check if the continuous conversion of regular channel is finished */if ((HAL_ADC_GetState(&AdcHandle) & HAL_ADC_STATE_REG_EOC) == HAL_ADC_STATE_REG_EOC) {/*##-5- Get the converted value of regular channel  ########################*/uhADCxConvertedValue = HAL_ADC_GetValue(&AdcHandle);}if (HAL_ADC_Stop(&AdcHandle) != HAL_OK) {/* Stop Conversation Error */return 0;}if (HAL_ADC_DeInit(&AdcHandle) != HAL_OK) {return 0;}if (__LL_ADC_COMMON_INSTANCE(AdcHandle.Instance) != 0U) {LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(AdcHandle.Instance), LL_ADC_PATH_INTERNAL_NONE);}return uhADCxConvertedValue;
}
#endif /* HAL_ADC_MODULE_ENABLED && !HAL_ADC_MODULE_ONLY*/#if defined(HAL_TIM_MODULE_ENABLED) && !defined(HAL_TIM_MODULE_ONLY)
// PWM INTERFACE FUNCTIONS //*** @brief  This function will set the PWM to the required value* @param  port : the gpio port to use* @param  pin : the gpio pin to use* @param  clock_freq : frequency of the tim clock* @param  value : the value to push on the PWM output* @retval None*/
void pwm_start(PinName pin, uint32_t PWM_freq, uint32_t value, TimerCompareFormat_t resolution)
{TIM_TypeDef *Instance = (TIM_TypeDef *)pinmap_peripheral(pin, PinMap_TIM);HardwareTimer *HT;TimerModes_t previousMode;uint32_t index = get_timer_index(Instance);if (HardwareTimer_Handle[index] == NULL) {HardwareTimer_Handle[index]->__this = new HardwareTimer((TIM_TypeDef *)pinmap_peripheral(pin, PinMap_TIM));}HT = (HardwareTimer *)(HardwareTimer_Handle[index]->__this);uint32_t channel = STM_PIN_CHANNEL(pinmap_function(pin, PinMap_TIM));previousMode = HT->getMode(channel);if (previousMode != TIMER_OUTPUT_COMPARE_PWM1) {HT->setMode(channel, TIMER_OUTPUT_COMPARE_PWM1, pin);}HT->setOverflow(PWM_freq, HERTZ_FORMAT);HT->setCaptureCompare(channel, value, resolution);if (previousMode != TIMER_OUTPUT_COMPARE_PWM1) {HT->resume();}
}
/*** @brief  This function will disable the PWM* @param  port : the gpio port to use* @param  pin : the gpio pin to use* @retval None*/
void pwm_stop(PinName pin)
{TIM_TypeDef *Instance = (TIM_TypeDef *)pinmap_peripheral(pin, PinMap_TIM);HardwareTimer *HT;uint32_t index = get_timer_index(Instance);if (HardwareTimer_Handle[index] == NULL) {HardwareTimer_Handle[index]->__this = new HardwareTimer((TIM_TypeDef *)pinmap_peripheral(pin, PinMap_TIM));}HT = (HardwareTimer *)(HardwareTimer_Handle[index]->__this);if (HT != NULL) {delete (HT);HT = NULL;}
}
#endif /* HAL_TIM_MODULE_ENABLED && !HAL_TIM_MODULE_ONLY */#ifdef __cplusplus
}
#endif/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

TOOLS 

MDK

WINDOWS SEARTH 

arduino中:

analogRead 与analogWrite是不同的,使用adc输入测量,但输出是用pwm 而不是dac

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/56707.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

面试常问:水平居中和垂直居中的方法

水平居中 文本居中 如果元素为行内元素&#xff0c;可以将父元素的text-align属性设置为center&#xff0c;这样子元素就会水平居中对齐 .text{text-align: center; }固定宽度的居中 如果元素宽度已知并固定&#xff0c;可以通过将左右margin设置为auto来实现水平居中。 .…

list【1】介绍与使用(超详解哦)

list的介绍与使用 引言list介绍接口使用默认成员函数迭代器容量元素访问数据修改 list的算法接口总结 引言 继vector之后&#xff0c;我们继续来介绍STL容器&#xff1a;list 对于容器的使用其实有着类似的模式&#xff0c;参考之前vector的使用可以让我们更快的上手&#xff…

【MySQL】2、MySQL数据库的管理

常用 describe user; Field:字段名称 Type:数据类型 Null :是否允许为空 Key :主键 Type:数据类型 Null :是否允许为空key :主键 Default :默认值 Extra :扩展属性&#xff0c;例如:标志符列&#xff08;标识了种子&#xff0c;增量/步长&#xff09;1 2 id&#xff1a;1 3 5 …

Android Jetpack组件的全方位分析

Jetpack是一个用于简化Android应用程序开发的工具包&#xff0c;包含了一系列的组件和工具。Jetpack包含了很多组件&#xff0c;如LiveData、ViewModel、Room、Data Binding、Navigation等。 Jetpack组件是一种更高级别的抽象&#xff0c;它们可以提供更简洁、更易于使用的API。…

self instruct 介绍

《SELF-INSTRUCT: Aligning Language Model with Self Generated Instructions》 github: self-instruct 背景 大模型表现惊人&#xff0c;但是严重依赖于人工编写的指令数据。然而&#xff0c;依靠人工标注数据成本高昂。本文中提出self-instruct框架&#xff1a;一种基于大…

在 React 中如何使用定时器

在React中使用定时器通常有两种方式&#xff1a;使用setInterval和setTimeout函数。 使用setInterval函数&#xff1a; 首先&#xff0c;在组件中导入useEffect和useState函数&#xff1a; import React, { useEffect, useState } from "react";在组件中声明一个状…

ES6-简介、语法

ES6 ES6简介 ​ ECMAScript 6&#xff08;简称ES6&#xff09;是于2015年6月正式发布的JavaScript语言的标准&#xff0c;正式名为ECMAScript 2015&#xff08;ES2015&#xff09;。它的目标是使得JavaScript语言可以用来编写复杂的大型应用程序&#xff0c;成为企业级开发语…

Linux 常用

系统信息 查看CPU信息&#xff08;型号&#xff09; cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c查看物理CPU个数 cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l查看每个物理CPU中core的个数(即核数) cat /proc/cpuinfo | grep "c…

Android创建签名文件,并获取签名文件MD5,SHA1,SHA256值

一、创建Android签名文件 使用Android Studio开发工具&#xff0c;可视化窗口进行创建 第一步&#xff1a;点击AndroidStudio导航栏上的 Build→Generate Signed Bundle / APK 第二步&#xff1a;选择APK选项 第三步&#xff1a;创建签名文件 第四步&#xff1a;输入创建签名的…

如何五分钟设计制作自己的蛋糕店小程序

在现如今的互联网时代&#xff0c;小程序已成为企业推广和销售的重要利器。对于蛋糕店来说&#xff0c;搭建一个小程序可以为其带来更多的品牌曝光和销售渠道。下面&#xff0c;我们将以乔拓云平台为例&#xff0c;来教你如何从零开始搭建自己的蛋糕店小程序。 首先&#xff0c…

2023/8/27周报

目录 摘要 论文阅读 1、标题和现存问题 2、过度平滑和度量方法 3、处理过坡 4、实验结果 深度学习 1、解决可视化问题 2、CART算法 总结 摘要 本周在论文阅读上&#xff0c;阅读了一篇Pairnorm:解决GNNS中的过平滑问题的论文。PairNorm 的核心思想是在图卷积层之间引…

CUDA和C++混合编程及CMakeLists.txt

1. 概要 首先认识一个问题&#xff0c;单从CMakeLists.txt的角度来看&#xff0c;无法同时使用两种编译器编译两种语言。不过直接编写Makefile是可以的&#xff0c;通过设置不同的任务&#xff0c;可以实现一个Makefile编译两个语言。但这不是这里要讨论的重点。 使用CUDA和C进…

7 集群基本测试

1. 上传小文件到集群 在hadoop路径下执行命令创建一个文件夹用于存放即将上传的文件&#xff1a; [atguiguhadoop102 ~]$ hadoop fs -mkdir /input上传&#xff1a; [atguiguhadoop102 hadoop-3.1.3]$ hadoop fs -put wcinput/work.txt /input2.上传大文件 [atguiguhadoop1…

Vue 3 常见面试题汇总

前端面试题库 &#xff08;面试必备&#xff09; 推荐&#xff1a;★★★★★ 地址&#xff1a;前端面试题库 前言 最近两年许多大厂都在实行“降本增效”、“优化组织架构”&#xff0c;然后“为社会输送了大量人才”&#xff0c;今年&#xff08;2023&#xff…

视频云存储/安防监控视频智能分析网关V3:占道经营功能详解

违规占道经营者经常会在人流量大、车辆集中的道路两旁摆摊&#xff0c;导致公路交通堵塞&#xff0c;给居民出行的造成不便&#xff0c;而且违规占路密集的地方都是交通事故频频发生的区域。 TSINGSEE青犀视频云存储/安防监控视频/AI智能分析网关V3运用视频AI智能分析技术&…

10万字智慧政务大数据平台项目建设方案222页[Word]

导读&#xff1a;原文《10万字智慧政务大数据平台项目建设方案222页[Word]》&#xff08;获取来源见文尾&#xff09;&#xff0c;本文精选其中精华及架构部分&#xff0c;逻辑清晰、内容完整&#xff0c;为快速形成售前方案提供参考。 1.1 项目建设目标 推进市一级政府搭建数…

求生之路2社区服务器sourcemod安装配置搭建教程centos

求生之路2社区服务器sourcemod安装配置搭建教程centos 大家好我是艾西&#xff0c;通过上文我们已经成功搭建了求生之路2的服务端。但是这个服务端是纯净的服务端&#xff0c;就是那种最纯粹的原版。如果想要实现插件、sm开头的命令等功能&#xff0c;需要安装这个sourcemod。…

js中的解构赋值

在JavaScript中&#xff0c;解构赋值是一种方便地从数组或对象中提取值并赋给变量的方法。 它允许你使用一种简洁的语法来快速访问和使用数据。 对于数组解构赋值&#xff0c;你可以使用方括号&#xff08;[]&#xff09;来指定变量名&#xff0c;并将其放在赋值语句的左侧。例…

opencv 案例实战02-停车场车牌识别SVM模型训练及验证

1. 整个识别的流程图&#xff1a; 2. 车牌定位中分割流程图&#xff1a; 三、车牌识别中字符分割流程图&#xff1a; 1.准备数据集 下载车牌相关字符样本用于训练和测试&#xff0c;本文使用14个汉字样本和34个数字跟字母样本&#xff0c;每个字符样本数为40&#xff0c;样本尺…

家政服务行业搭建小程序的实用技巧分享

随着移动互联网的发展&#xff0c;小程序成为了各行各业的新宠。对于家政服务行业来说&#xff0c;搭建一个小程序商城可以极大地提升服务的便捷性和用户体验&#xff0c;同时也能提高企业的竞争力。本文将分享家政服务行业搭建小程序的实用技巧&#xff0c;帮助您顺利创建属于…