dac to adc test

This commit is contained in:
2023-12-14 21:32:33 +01:00
parent 9c2f914740
commit e840c1f931
22 changed files with 20707 additions and 58 deletions

File diff suppressed because one or more lines are too long

View File

@@ -6,7 +6,8 @@
"${workspaceFolder}/Core/Inc",
"${workspaceFolder}/Drivers/CMSIS/Include",
"${workspaceFolder}/Drivers/CMSIS/Device/ST/STM32G4xx/Include",
"${workspaceFolder}/Drivers/STM32G4xx_HAL_Driver/Inc"
"${workspaceFolder}/Drivers/STM32G4xx_HAL_Driver/Inc",
"${workspaceFolder}/utils/printf"
],
"defines": [
"_DEBUG",

52
Core/Inc/adc.h Normal file
View File

@@ -0,0 +1,52 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file adc.h
* @brief This file contains all the function prototypes for
* the adc.c file
******************************************************************************
* @attention
*
* Copyright (c) 2023 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __ADC_H__
#define __ADC_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
extern ADC_HandleTypeDef hadc1;
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
void MX_ADC1_Init(void);
/* USER CODE BEGIN Prototypes */
/* USER CODE END Prototypes */
#ifdef __cplusplus
}
#endif
#endif /* __ADC_H__ */

View File

@@ -57,6 +57,7 @@ void Error_Handler(void);
/* USER CODE END EFP */
/* Private defines -----------------------------------------------------------*/
#define ADC_PULSES 1024
#define B1_Pin GPIO_PIN_13
#define B1_GPIO_Port GPIOC
#define B1_EXTI_IRQn EXTI15_10_IRQn

View File

@@ -36,7 +36,7 @@
#define HAL_MODULE_ENABLED
/*#define HAL_ADC_MODULE_ENABLED */
#define HAL_ADC_MODULE_ENABLED
/*#define HAL_COMP_MODULE_ENABLED */
/*#define HAL_CORDIC_MODULE_ENABLED */
/*#define HAL_CRC_MODULE_ENABLED */

View File

@@ -58,6 +58,7 @@ void SysTick_Handler(void);
void DMA1_Channel1_IRQHandler(void);
void EXTI15_10_IRQHandler(void);
void TIM7_DAC_IRQHandler(void);
void DMA2_Channel1_IRQHandler(void);
/* USER CODE BEGIN EFP */
/* USER CODE END EFP */

View File

@@ -34,11 +34,14 @@ extern "C" {
extern TIM_HandleTypeDef htim7;
extern TIM_HandleTypeDef htim20;
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
void MX_TIM7_Init(void);
void MX_TIM20_Init(void);
/* USER CODE BEGIN Prototypes */

176
Core/Src/adc.c Normal file
View File

@@ -0,0 +1,176 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file adc.c
* @brief This file provides code for the configuration
* of the ADC instances.
******************************************************************************
* @attention
*
* Copyright (c) 2023 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "adc.h"
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
ADC_HandleTypeDef hadc1;
DMA_HandleTypeDef hdma_adc1;
/* ADC1 init function */
void MX_ADC1_Init(void)
{
/* USER CODE BEGIN ADC1_Init 0 */
/* USER CODE END ADC1_Init 0 */
ADC_MultiModeTypeDef multimode = {0};
ADC_ChannelConfTypeDef sConfig = {0};
/* USER CODE BEGIN ADC1_Init 1 */
/* USER CODE END ADC1_Init 1 */
/** Common config
*/
hadc1.Instance = ADC1;
hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV4;
hadc1.Init.Resolution = ADC_RESOLUTION_12B;
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc1.Init.GainCompensation = 0;
hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
hadc1.Init.LowPowerAutoWait = DISABLE;
hadc1.Init.ContinuousConvMode = DISABLE;
hadc1.Init.NbrOfConversion = 1;
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.ExternalTrigConv = ADC_EXTERNALTRIG_T20_TRGO;
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING;
hadc1.Init.DMAContinuousRequests = ENABLE;
hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
hadc1.Init.OversamplingMode = DISABLE;
if (HAL_ADC_Init(&hadc1) != HAL_OK)
{
Error_Handler();
}
/** Configure the ADC multi-mode
*/
multimode.Mode = ADC_MODE_INDEPENDENT;
if (HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK)
{
Error_Handler();
}
/** Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_14;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5;
sConfig.SingleDiff = ADC_SINGLE_ENDED;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset = 0;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN ADC1_Init 2 */
/* USER CODE END ADC1_Init 2 */
}
void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
if(adcHandle->Instance==ADC1)
{
/* USER CODE BEGIN ADC1_MspInit 0 */
/* USER CODE END ADC1_MspInit 0 */
/** Initializes the peripherals clocks
*/
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC12;
PeriphClkInit.Adc12ClockSelection = RCC_ADC12CLKSOURCE_SYSCLK;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}
/* ADC1 clock enable */
__HAL_RCC_ADC12_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/**ADC1 GPIO Configuration
PB11 ------> ADC1_IN14
*/
GPIO_InitStruct.Pin = GPIO_PIN_11;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/* ADC1 DMA Init */
/* ADC1 Init */
hdma_adc1.Instance = DMA2_Channel1;
hdma_adc1.Init.Request = DMA_REQUEST_ADC1;
hdma_adc1.Init.Direction = DMA_PERIPH_TO_MEMORY;
hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_adc1.Init.MemInc = DMA_MINC_ENABLE;
hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
hdma_adc1.Init.Mode = DMA_CIRCULAR;
hdma_adc1.Init.Priority = DMA_PRIORITY_LOW;
if (HAL_DMA_Init(&hdma_adc1) != HAL_OK)
{
Error_Handler();
}
__HAL_LINKDMA(adcHandle,DMA_Handle,hdma_adc1);
/* USER CODE BEGIN ADC1_MspInit 1 */
/* USER CODE END ADC1_MspInit 1 */
}
}
void HAL_ADC_MspDeInit(ADC_HandleTypeDef* adcHandle)
{
if(adcHandle->Instance==ADC1)
{
/* USER CODE BEGIN ADC1_MspDeInit 0 */
/* USER CODE END ADC1_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_ADC12_CLK_DISABLE();
/**ADC1 GPIO Configuration
PB11 ------> ADC1_IN14
*/
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_11);
/* ADC1 DMA DeInit */
HAL_DMA_DeInit(adcHandle->DMA_Handle);
/* USER CODE BEGIN ADC1_MspDeInit 1 */
/* USER CODE END ADC1_MspDeInit 1 */
}
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */

View File

@@ -42,11 +42,15 @@ void MX_DMA_Init(void)
/* DMA controller clock enable */
__HAL_RCC_DMAMUX1_CLK_ENABLE();
__HAL_RCC_DMA1_CLK_ENABLE();
__HAL_RCC_DMA2_CLK_ENABLE();
/* DMA interrupt init */
/* DMA1_Channel1_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn);
/* DMA2_Channel1_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DMA2_Channel1_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(DMA2_Channel1_IRQn);
}

View File

@@ -18,6 +18,7 @@
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "adc.h"
#include "dac.h"
#include "dma.h"
#include "usart.h"
@@ -27,7 +28,7 @@
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "printf.h"
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
@@ -37,7 +38,8 @@
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
#define DAC_LENGHT 16
#define DAC_LENGHT 1024
#define ADC_LENGHT ADC_PULSES
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
@@ -48,9 +50,11 @@
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
volatile uint8_t dac_no;
volatile uint32_t soft_timer, data_ready;
uint8_t uart_data[32];
uint16_t dac_data_ch1[DAC_LENGHT];
uint16_t dac_data_ch2[DAC_LENGHT];
uint16_t adc_data[ADC_LENGHT];
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
@@ -98,6 +102,8 @@ int main(void)
MX_LPUART1_UART_Init();
MX_OPAMP4_Init();
MX_TIM7_Init();
MX_ADC1_Init();
MX_TIM20_Init();
/* Initialize interrupts */
MX_NVIC_Init();
@@ -116,32 +122,47 @@ int main(void)
}
}
htim7.Instance->PSC = 0;
htim7.Instance->ARR = 84;
HAL_DAC_Start_DMA(&hdac4, DAC_CHANNEL_1, (uint32_t *)dac_data_ch1, DAC_LENGHT, DAC_ALIGN_12B_R);
HAL_ADC_Start_DMA(&hadc1, (uint32_t *)adc_data, ADC_LENGHT);
// HAL_DAC_Start_DMA(&hdac4, DAC_CHANNEL_2, (uint32_t *)dac_data_ch2, DAC_LENGHT, DAC_ALIGN_12B_R);
// HAL_DAC_Start(&hdac4, DAC_CHANNEL_1);
// HAL_DAC_Start(&hdac4, DAC_CHANNEL_2);
HAL_OPAMP_Start(&hopamp4);
// HAL_OPAMP_Start(&hopamp5);
HAL_TIM_Base_Start_IT(&htim7);
HAL_TIM_OnePulse_Start(&htim20, TIM_CHANNEL_1);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
uint8_t i = 0;
int8_t count = 0;
while (1)
{
// HAL_DAC_SetValue(&hdac4, DAC_CHANNEL_1, DAC_ALIGN_12B_R, dac_data_ch1[i]);
// HAL_DAC_SetValue(&hdac4, DAC_CHANNEL_2, DAC_ALIGN_12B_R, dac_data_ch1[i++]);
if (i >= DAC_LENGHT)
if (data_ready)
{
i = 0;
HAL_UART_Transmit(&hlpuart1, (uint8_t *)"*******************************\n", 32, HAL_MAX_DELAY);
for (size_t i = 0; i < ADC_LENGHT; i++)
{
count = snprintf((char *)uart_data, 32, "%u, %u\n", i, adc_data[i]);
if (count < 0 || count >= 32)
{
Error_Handler();
}
HAL_UART_Transmit(&hlpuart1, uart_data, count, HAL_MAX_DELAY);
adc_data[i] = 0;
}
HAL_UART_Transmit(&hlpuart1, (uint8_t *)"*******************************\n", 32, HAL_MAX_DELAY);
}
// HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);
HAL_Delay(1000);
htim7.Instance->PSC = 100;
htim7.Instance->ARR = 170;
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
@@ -207,14 +228,23 @@ static void MX_NVIC_Init(void)
/* USER CODE BEGIN 4 */
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if (htim->Instance == TIM7)
{
HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);
}
}
void HAL_DAC_ConvHalfCpltCallbackCh1(DAC_HandleTypeDef *hdac)
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hadc)
{
if (hdac->Instance == DAC4)
data_ready++;
}
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if (GPIO_Pin == B1_Pin && soft_timer + 50 < HAL_GetTick())
{
dac_no = 1;
soft_timer = HAL_GetTick();
__HAL_TIM_ENABLE(&htim20);
}
}
/* USER CODE END 4 */

View File

@@ -55,6 +55,7 @@
/* USER CODE END 0 */
/* External variables --------------------------------------------------------*/
extern DMA_HandleTypeDef hdma_adc1;
extern DMA_HandleTypeDef hdma_dac4_ch1;
extern DAC_HandleTypeDef hdac4;
extern TIM_HandleTypeDef htim7;
@@ -243,6 +244,20 @@ void TIM7_DAC_IRQHandler(void)
/* USER CODE END TIM7_DAC_IRQn 1 */
}
/**
* @brief This function handles DMA2 channel1 global interrupt.
*/
void DMA2_Channel1_IRQHandler(void)
{
/* USER CODE BEGIN DMA2_Channel1_IRQn 0 */
/* USER CODE END DMA2_Channel1_IRQn 0 */
HAL_DMA_IRQHandler(&hdma_adc1);
/* USER CODE BEGIN DMA2_Channel1_IRQn 1 */
/* USER CODE END DMA2_Channel1_IRQn 1 */
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */

View File

@@ -25,6 +25,7 @@
/* USER CODE END 0 */
TIM_HandleTypeDef htim7;
TIM_HandleTypeDef htim20;
/* TIM7 init function */
void MX_TIM7_Init(void)
@@ -58,6 +59,52 @@ void MX_TIM7_Init(void)
/* USER CODE END TIM7_Init 2 */
}
/* TIM20 init function */
void MX_TIM20_Init(void)
{
/* USER CODE BEGIN TIM20_Init 0 */
/* USER CODE END TIM20_Init 0 */
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};
/* USER CODE BEGIN TIM20_Init 1 */
/* USER CODE END TIM20_Init 1 */
htim20.Instance = TIM20;
htim20.Init.Prescaler = 0;
htim20.Init.CounterMode = TIM_COUNTERMODE_UP;
htim20.Init.Period = 65535;
htim20.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim20.Init.RepetitionCounter = ADC_PULSES;
htim20.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim20) != HAL_OK)
{
Error_Handler();
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim20, &sClockSourceConfig) != HAL_OK)
{
Error_Handler();
}
if (HAL_TIM_OnePulse_Init(&htim20, TIM_OPMODE_SINGLE) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE;
sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim20, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN TIM20_Init 2 */
/* USER CODE END TIM20_Init 2 */
}
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle)
@@ -74,6 +121,17 @@ void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle)
/* USER CODE END TIM7_MspInit 1 */
}
else if(tim_baseHandle->Instance==TIM20)
{
/* USER CODE BEGIN TIM20_MspInit 0 */
/* USER CODE END TIM20_MspInit 0 */
/* TIM20 clock enable */
__HAL_RCC_TIM20_CLK_ENABLE();
/* USER CODE BEGIN TIM20_MspInit 1 */
/* USER CODE END TIM20_MspInit 1 */
}
}
void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle)
@@ -100,6 +158,17 @@ void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle)
/* USER CODE END TIM7_MspDeInit 1 */
}
else if(tim_baseHandle->Instance==TIM20)
{
/* USER CODE BEGIN TIM20_MspDeInit 0 */
/* USER CODE END TIM20_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_TIM20_CLK_DISABLE();
/* USER CODE BEGIN TIM20_MspDeInit 1 */
/* USER CODE END TIM20_MspDeInit 1 */
}
}
/* USER CODE BEGIN 1 */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,5 @@
##########################################################################################################################
# File automatically-generated by tool: [projectgenerator] version: [4.1.0] date: [Tue Dec 12 23:07:03 CET 2023]
# File automatically-generated by tool: [projectgenerator] version: [4.1.0] date: [Thu Dec 14 20:03:10 CET 2023]
##########################################################################################################################
# ------------------------------------------------
@@ -66,8 +66,13 @@ Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_opamp_ex.c \
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_tim.c \
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_tim_ex.c \
Core/Src/system_stm32g4xx.c \
Core/Src/dma.c
Core/Src/dma.c \
Core/Src/adc.c \
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_adc.c \
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_adc_ex.c \
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_adc.c
C_SOURCES += utils/printf/printf.c
# ASM sources
ASM_SOURCES = \
startup_stm32g474xx.s
@@ -129,11 +134,13 @@ C_INCLUDES = \
-IDrivers/CMSIS/Device/ST/STM32G4xx/Include \
-IDrivers/CMSIS/Include
C_INCLUDES += -Iutils/printf
# compile gcc flags
ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
CFLAGS += $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
CFLAGS += $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections -Werror
ifeq ($(DEBUG), 1)
CFLAGS += -g -gdwarf-2

View File

@@ -1,10 +1,39 @@
#MicroXplorer Configuration settings - do not modify
ADC1.Channel-0\#ChannelRegularConversion=ADC_CHANNEL_14
ADC1.ClockPrescaler=ADC_CLOCK_ASYNC_DIV4
ADC1.CommonPathInternal=null|null|null|null
ADC1.DMAContinuousRequests=ENABLE
ADC1.EnableInjectedConversion=DISABLE
ADC1.ExternalTrigConv=ADC_EXTERNALTRIG_T20_TRGO
ADC1.IPParameters=Rank-0\#ChannelRegularConversion,Channel-0\#ChannelRegularConversion,SamplingTime-0\#ChannelRegularConversion,OffsetNumber-0\#ChannelRegularConversion,NbrOfConversionFlag,ClockPrescaler,DMAContinuousRequests,ExternalTrigConv,EnableInjectedConversion,master,CommonPathInternal
ADC1.NbrOfConversionFlag=1
ADC1.OffsetNumber-0\#ChannelRegularConversion=ADC_OFFSET_NONE
ADC1.Rank-0\#ChannelRegularConversion=1
ADC1.SamplingTime-0\#ChannelRegularConversion=ADC_SAMPLETIME_2CYCLES_5
ADC1.master=1
CAD.formats=
CAD.pinconfig=
CAD.provider=
DAC4.DAC_HighFrequency_OUT1-DAC_OUT1_Int=DAC_HIGH_FREQUENCY_INTERFACE_MODE_AUTOMATIC
DAC4.DAC_Trigger_OUT1-DAC_OUT1_Int=DAC_TRIGGER_T7_TRGO
DAC4.IPParameters=DAC_HighFrequency_OUT1-DAC_OUT1_Int,DAC_Trigger_OUT1-DAC_OUT1_Int
Dma.ADC1.1.Direction=DMA_PERIPH_TO_MEMORY
Dma.ADC1.1.EventEnable=DISABLE
Dma.ADC1.1.Instance=DMA2_Channel1
Dma.ADC1.1.MemDataAlignment=DMA_MDATAALIGN_HALFWORD
Dma.ADC1.1.MemInc=DMA_MINC_ENABLE
Dma.ADC1.1.Mode=DMA_CIRCULAR
Dma.ADC1.1.PeriphDataAlignment=DMA_PDATAALIGN_HALFWORD
Dma.ADC1.1.PeriphInc=DMA_PINC_DISABLE
Dma.ADC1.1.Polarity=HAL_DMAMUX_REQ_GEN_RISING
Dma.ADC1.1.Priority=DMA_PRIORITY_LOW
Dma.ADC1.1.RequestNumber=1
Dma.ADC1.1.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,SignalID,Polarity,RequestNumber,SyncSignalID,SyncPolarity,SyncEnable,EventEnable,SyncRequestNumber
Dma.ADC1.1.SignalID=NONE
Dma.ADC1.1.SyncEnable=DISABLE
Dma.ADC1.1.SyncPolarity=HAL_DMAMUX_SYNC_NO_EVENT
Dma.ADC1.1.SyncRequestNumber=1
Dma.ADC1.1.SyncSignalID=NONE
Dma.DAC4_CH1.0.Direction=DMA_MEMORY_TO_PERIPH
Dma.DAC4_CH1.0.EventEnable=DISABLE
Dma.DAC4_CH1.0.Instance=DMA1_Channel1
@@ -23,7 +52,8 @@ Dma.DAC4_CH1.0.SyncPolarity=HAL_DMAMUX_SYNC_NO_EVENT
Dma.DAC4_CH1.0.SyncRequestNumber=1
Dma.DAC4_CH1.0.SyncSignalID=NONE
Dma.Request0=DAC4_CH1
Dma.RequestsNb=1
Dma.Request1=ADC1
Dma.RequestsNb=2
File.Version=6
KeepUserPlacement=false
LPUART1.BaudRate=115200
@@ -31,41 +61,47 @@ LPUART1.IPParameters=BaudRate,WordLength
LPUART1.WordLength=UART_WORDLENGTH_8B
Mcu.CPN=STM32G474RET6
Mcu.Family=STM32G4
Mcu.IP0=DAC4
Mcu.IP1=DMA
Mcu.IP2=LPUART1
Mcu.IP3=NVIC
Mcu.IP4=OPAMP4
Mcu.IP5=RCC
Mcu.IP6=SYS
Mcu.IP7=TIM7
Mcu.IPNb=8
Mcu.IP0=ADC1
Mcu.IP1=DAC4
Mcu.IP2=DMA
Mcu.IP3=LPUART1
Mcu.IP4=NVIC
Mcu.IP5=OPAMP4
Mcu.IP6=RCC
Mcu.IP7=SYS
Mcu.IP8=TIM7
Mcu.IP9=TIM20
Mcu.IPNb=10
Mcu.Name=STM32G474R(B-C-E)Tx
Mcu.Package=LQFP64
Mcu.Pin0=PC13
Mcu.Pin1=PC14-OSC32_IN
Mcu.Pin10=PA14
Mcu.Pin11=PB3
Mcu.Pin12=VP_DAC4_VS_DACI1
Mcu.Pin13=VP_SYS_VS_Systick
Mcu.Pin14=VP_SYS_VS_DBSignals
Mcu.Pin15=VP_TIM7_VS_ClockSourceINT
Mcu.Pin10=PA13
Mcu.Pin11=PA14
Mcu.Pin12=PB3
Mcu.Pin13=VP_DAC4_VS_DACI1
Mcu.Pin14=VP_SYS_VS_Systick
Mcu.Pin15=VP_SYS_VS_DBSignals
Mcu.Pin16=VP_TIM7_VS_ClockSourceINT
Mcu.Pin17=VP_TIM20_VS_ClockSourceINT
Mcu.Pin18=VP_TIM20_VS_OPM
Mcu.Pin2=PC15-OSC32_OUT
Mcu.Pin3=PF0-OSC_IN
Mcu.Pin4=PF1-OSC_OUT
Mcu.Pin5=PA2
Mcu.Pin6=PA3
Mcu.Pin7=PA5
Mcu.Pin8=PB12
Mcu.Pin9=PA13
Mcu.PinsNb=16
Mcu.Pin8=PB11
Mcu.Pin9=PB12
Mcu.PinsNb=19
Mcu.ThirdPartyNb=0
Mcu.UserConstants=
Mcu.UserConstants=ADC_PULSES,1024
Mcu.UserName=STM32G474RETx
MxCube.Version=6.9.2
MxDb.Version=DB.6.0.92
NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
NVIC.DMA1_Channel1_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true
NVIC.DMA2_Channel1_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true
NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
NVIC.EXTI15_10_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
NVIC.ForceEnableDMAVector=true
@@ -104,6 +140,9 @@ PA5.GPIOParameters=GPIO_Label
PA5.GPIO_Label=LD2 [green led]
PA5.Locked=true
PA5.Signal=GPIO_Output
PB11.Locked=true
PB11.Mode=IN14-Single-Ended
PB11.Signal=ADC1_IN14
PB12.Mode=Follower-DAC_OUT2-INP
PB12.Signal=OPAMP4_VOUT
PB3.GPIOParameters=GPIO_Label
@@ -157,7 +196,7 @@ ProjectManager.ToolChainLocation=
ProjectManager.UAScriptAfterPath=
ProjectManager.UAScriptBeforePath=
ProjectManager.UnderRoot=false
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_DMA_Init-DMA-false-HAL-true,4-MX_DAC4_Init-DAC4-false-HAL-true,5-MX_LPUART1_UART_Init-LPUART1-false-HAL-true,6-MX_OPAMP4_Init-OPAMP4-false-HAL-true,7-MX_TIM7_Init-TIM7-false-HAL-true
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_DMA_Init-DMA-false-HAL-true,4-MX_DAC4_Init-DAC4-false-HAL-true,5-MX_LPUART1_UART_Init-LPUART1-false-HAL-true,6-MX_OPAMP4_Init-OPAMP4-false-HAL-true,7-MX_TIM7_Init-TIM7-false-HAL-true,8-MX_ADC1_Init-ADC1-false-HAL-true,9-MX_TIM20_Init-TIM20-false-HAL-true
RCC.ADC12Freq_Value=170000000
RCC.ADC345Freq_Value=170000000
RCC.AHBFreq_Value=170000000
@@ -211,6 +250,9 @@ RCC.VCOInputFreq_Value=4000000
RCC.VCOOutputFreq_Value=340000000
SH.GPXTI13.0=GPIO_EXTI13
SH.GPXTI13.ConfNb=1
TIM20.IPParameters=TIM_MasterOutputTrigger,RepetitionCounter
TIM20.RepetitionCounter=ADC_PULSES
TIM20.TIM_MasterOutputTrigger=TIM_TRGO_UPDATE
TIM7.AutoReloadPreload=TIM_AUTORELOAD_PRELOAD_ENABLE
TIM7.IPParameters=PeriodNoDither,TIM_MasterOutputTrigger,AutoReloadPreload,Prescaler
TIM7.PeriodNoDither=170-1
@@ -222,6 +264,10 @@ VP_SYS_VS_DBSignals.Mode=DisableDeadBatterySignals
VP_SYS_VS_DBSignals.Signal=SYS_VS_DBSignals
VP_SYS_VS_Systick.Mode=SysTick
VP_SYS_VS_Systick.Signal=SYS_VS_Systick
VP_TIM20_VS_ClockSourceINT.Mode=Internal
VP_TIM20_VS_ClockSourceINT.Signal=TIM20_VS_ClockSourceINT
VP_TIM20_VS_OPM.Mode=OPM_bit
VP_TIM20_VS_OPM.Signal=TIM20_VS_OPM
VP_TIM7_VS_ClockSourceINT.Mode=Enable_Timer
VP_TIM7_VS_ClockSourceINT.Signal=TIM7_VS_ClockSourceINT
board=NUCLEO-G474RE

1043
utils/printf/printf.c Normal file

File diff suppressed because it is too large Load Diff

109
utils/printf/printf.h Normal file
View File

@@ -0,0 +1,109 @@
///////////////////////////////////////////////////////////////////////////////
// \author (c) Marco Paland (info@paland.com)
// 2014-2019, PALANDesign Hannover, Germany
//
// \license The MIT License (MIT)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// \brief Tiny printf, sprintf and snprintf implementation, optimized for speed on
// embedded systems with a very limited resources.
// Use this instead of bloated standard/newlib printf.
// These routines are thread safe and reentrant.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef _PRINTF_H_
#define _PRINTF_H_
#include <stdarg.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C"
{
#endif
/**
* Output a character to a custom device like UART, used by the printf() function
* This function is declared here only. You have to write your custom implementation somewhere
* \param character Character to output
*/
void _putchar(char character);
/**
* Tiny printf implementation
* You have to implement _putchar if you use printf()
* To avoid conflicts with the regular printf() API it is overridden by macro defines
* and internal underscore-appended functions like printf_() are used
* \param format A string that specifies the format of the output
* \return The number of characters that are written into the array, not counting the terminating null character
*/
#define printf printf_
int printf_(const char *format, ...);
/**
* Tiny sprintf implementation
* Due to security reasons (buffer overflow) YOU SHOULD CONSIDER USING (V)SNPRINTF INSTEAD!
* \param buffer A pointer to the buffer where to store the formatted string. MUST be big enough to store the output!
* \param format A string that specifies the format of the output
* \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character
*/
#define sprintf sprintf_
int sprintf_(char *buffer, const char *format, ...);
/**
* Tiny snprintf/vsnprintf implementation
* \param buffer A pointer to the buffer where to store the formatted string
* \param count The maximum number of characters to store in the buffer, including a terminating null character
* \param format A string that specifies the format of the output
* \param va A value identifying a variable arguments list
* \return The number of characters that COULD have been written into the buffer, not counting the terminating
* null character. A value equal or larger than count indicates truncation. Only when the returned value
* is non-negative and less than count, the string has been completely written.
*/
#define snprintf snprintf_
#define vsnprintf vsnprintf_
int snprintf_(char *buffer, size_t count, const char *format, ...);
int vsnprintf_(char *buffer, size_t count, const char *format, va_list va);
/**
* Tiny vprintf implementation
* \param format A string that specifies the format of the output
* \param va A value identifying a variable arguments list
* \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character
*/
#define vprintf vprintf_
int vprintf_(const char *format, va_list va);
/**
* printf with output function
* You may use this as dynamic alternative to printf() with its fixed _putchar() output
* \param out An output function which takes one character and an argument pointer
* \param arg An argument pointer for user data passed to output function
* \param format A string that specifies the format of the output
* \return The number of characters that are sent to the output function, not counting the terminating null character
*/
int fctprintf(void (*out)(char character, void *arg), void *arg, const char *format, ...);
#ifdef __cplusplus
}
#endif
#endif // _PRINTF_H_