CPU temperature readout
This commit is contained in:
parent
fb8ee5b355
commit
884d949dfa
File diff suppressed because one or more lines are too long
@ -36,6 +36,8 @@ extern SPI_HandleTypeDef hspi1;
|
||||
static Flash flash = Flash(&hspi1, FLASH_CS_GPIO_Port, FLASH_CS_Pin);
|
||||
#endif
|
||||
|
||||
extern ADC_HandleTypeDef hadc1;
|
||||
|
||||
#define FLAG_USB_PACKET 0x01
|
||||
#define FLAG_DATAPOINT 0x02
|
||||
#define FLAG_WORK_REQUIRED 0x04
|
||||
@ -59,6 +61,7 @@ static void HardwareWorkRequired() {
|
||||
}
|
||||
|
||||
void App_Start() {
|
||||
HAL_ADCEx_Calibration_Start(&hadc1, ADC_SINGLE_ENDED);
|
||||
handle = xTaskGetCurrentTaskHandle();
|
||||
usb_init(communication_usb_input);
|
||||
Log_Init();
|
||||
|
@ -3,10 +3,28 @@
|
||||
#include "stm32g431xx.h"
|
||||
#include "stm32g4xx_hal.h"
|
||||
|
||||
extern ADC_HandleTypeDef hadc1;
|
||||
|
||||
namespace STM {
|
||||
|
||||
static inline bool InInterrupt() {
|
||||
return (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) != 0;
|
||||
}
|
||||
|
||||
static inline int8_t getTemperature() {
|
||||
HAL_ADC_Start(&hadc1);
|
||||
HAL_ADC_PollForConversion(&hadc1, 100);
|
||||
int16_t adc = HAL_ADC_GetValue(&hadc1);
|
||||
int16_t rangeFrom = *TEMPSENSOR_CAL2_ADDR - *TEMPSENSOR_CAL1_ADDR;
|
||||
int16_t rangeTo = TEMPSENSOR_CAL2_TEMP - TEMPSENSOR_CAL1_TEMP;
|
||||
adc -= *TEMPSENSOR_CAL1_ADDR;
|
||||
int16_t result = ((int32_t) adc * rangeTo) / rangeFrom + TEMPSENSOR_CAL1_TEMP;
|
||||
if(result < -128) {
|
||||
result = -128;
|
||||
} else if(result > 127) {
|
||||
result = 127;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -243,7 +243,7 @@ void HW::fillDeviceInfo(Protocol::DeviceInfo *info) {
|
||||
info->extRefInUse = extRefInUse;
|
||||
info->temperatures.LO1 = tempLO;
|
||||
info->temperatures.source = tempSource;
|
||||
info->temperatures.MCU = 0;
|
||||
info->temperatures.MCU = STM::getTemperature();
|
||||
FPGA::ResetADCLimits();
|
||||
}
|
||||
|
||||
|
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
@ -35,7 +35,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 */
|
||||
|
@ -44,6 +44,8 @@
|
||||
/* USER CODE END PM */
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
ADC_HandleTypeDef hadc1;
|
||||
|
||||
I2C_HandleTypeDef hi2c2;
|
||||
|
||||
SPI_HandleTypeDef hspi1;
|
||||
@ -77,6 +79,7 @@ static void MX_USART3_UART_Init(void);
|
||||
static void MX_USB_PCD_Init(void);
|
||||
static void MX_TIM1_Init(void);
|
||||
static void MX_TIM2_Init(void);
|
||||
static void MX_ADC1_Init(void);
|
||||
void StartDefaultTask(void const * argument);
|
||||
|
||||
/* USER CODE BEGIN PFP */
|
||||
@ -126,6 +129,7 @@ int main(void)
|
||||
MX_USB_PCD_Init();
|
||||
MX_TIM1_Init();
|
||||
MX_TIM2_Init();
|
||||
MX_ADC1_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
/* USER CODE END 2 */
|
||||
@ -218,16 +222,82 @@ void SystemClock_Config(void)
|
||||
/** Initializes the peripherals clocks
|
||||
*/
|
||||
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART3|RCC_PERIPHCLK_I2C2
|
||||
|RCC_PERIPHCLK_USB;
|
||||
|RCC_PERIPHCLK_USB|RCC_PERIPHCLK_ADC12;
|
||||
PeriphClkInit.Usart3ClockSelection = RCC_USART3CLKSOURCE_PCLK1;
|
||||
PeriphClkInit.I2c2ClockSelection = RCC_I2C2CLKSOURCE_PCLK1;
|
||||
PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLL;
|
||||
PeriphClkInit.Adc12ClockSelection = RCC_ADC12CLKSOURCE_SYSCLK;
|
||||
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ADC1 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static 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_DIV1;
|
||||
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_SOFTWARE_START;
|
||||
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
|
||||
hadc1.Init.DMAContinuousRequests = DISABLE;
|
||||
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_TEMPSENSOR_ADC1;
|
||||
sConfig.Rank = ADC_REGULAR_RANK_1;
|
||||
sConfig.SamplingTime = ADC_SAMPLETIME_92CYCLES_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 */
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief I2C2 Initialization Function
|
||||
* @param None
|
||||
|
@ -84,6 +84,50 @@ void HAL_MspInit(void)
|
||||
/* USER CODE END MspInit 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ADC MSP Initialization
|
||||
* This function configures the hardware resources used in this example
|
||||
* @param hadc: ADC handle pointer
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
|
||||
{
|
||||
if(hadc->Instance==ADC1)
|
||||
{
|
||||
/* USER CODE BEGIN ADC1_MspInit 0 */
|
||||
|
||||
/* USER CODE END ADC1_MspInit 0 */
|
||||
/* Peripheral clock enable */
|
||||
__HAL_RCC_ADC12_CLK_ENABLE();
|
||||
/* USER CODE BEGIN ADC1_MspInit 1 */
|
||||
|
||||
/* USER CODE END ADC1_MspInit 1 */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ADC MSP De-Initialization
|
||||
* This function freeze the hardware resources used in this example
|
||||
* @param hadc: ADC handle pointer
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
|
||||
{
|
||||
if(hadc->Instance==ADC1)
|
||||
{
|
||||
/* USER CODE BEGIN ADC1_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END ADC1_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_ADC12_CLK_DISABLE();
|
||||
/* USER CODE BEGIN ADC1_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END ADC1_MspDeInit 1 */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief I2C MSP Initialization
|
||||
* This function configures the hardware resources used in this example
|
||||
|
@ -1,4 +1,11 @@
|
||||
#MicroXplorer Configuration settings - do not modify
|
||||
ADC1.Channel-0\#ChannelRegularConversion=ADC_CHANNEL_TEMPSENSOR_ADC1
|
||||
ADC1.IPParameters=Rank-0\#ChannelRegularConversion,master,Channel-0\#ChannelRegularConversion,SamplingTime-0\#ChannelRegularConversion,OffsetNumber-0\#ChannelRegularConversion,NbrOfConversionFlag
|
||||
ADC1.NbrOfConversionFlag=1
|
||||
ADC1.OffsetNumber-0\#ChannelRegularConversion=ADC_OFFSET_NONE
|
||||
ADC1.Rank-0\#ChannelRegularConversion=1
|
||||
ADC1.SamplingTime-0\#ChannelRegularConversion=ADC_SAMPLETIME_92CYCLES_5
|
||||
ADC1.master=1
|
||||
Dma.Request0=UCPD1_RX
|
||||
Dma.Request1=UCPD1_TX
|
||||
Dma.Request2=SPI1_RX
|
||||
@ -90,21 +97,22 @@ I2C2.IPParameters=Timing,I2C_Speed_Mode
|
||||
I2C2.Timing=0x00E057FD
|
||||
KeepUserPlacement=false
|
||||
Mcu.Family=STM32G4
|
||||
Mcu.IP0=DMA
|
||||
Mcu.IP1=FREERTOS
|
||||
Mcu.IP10=UCPD1
|
||||
Mcu.IP11=USART3
|
||||
Mcu.IP12=USB
|
||||
Mcu.IP13=USBPD
|
||||
Mcu.IP2=I2C2
|
||||
Mcu.IP3=NVIC
|
||||
Mcu.IP4=RCC
|
||||
Mcu.IP5=SPI1
|
||||
Mcu.IP6=SPI2
|
||||
Mcu.IP7=SYS
|
||||
Mcu.IP8=TIM1
|
||||
Mcu.IP9=TIM2
|
||||
Mcu.IPNb=14
|
||||
Mcu.IP0=ADC1
|
||||
Mcu.IP1=DMA
|
||||
Mcu.IP10=TIM2
|
||||
Mcu.IP11=UCPD1
|
||||
Mcu.IP12=USART3
|
||||
Mcu.IP13=USB
|
||||
Mcu.IP14=USBPD
|
||||
Mcu.IP2=FREERTOS
|
||||
Mcu.IP3=I2C2
|
||||
Mcu.IP4=NVIC
|
||||
Mcu.IP5=RCC
|
||||
Mcu.IP6=SPI1
|
||||
Mcu.IP7=SPI2
|
||||
Mcu.IP8=SYS
|
||||
Mcu.IP9=TIM1
|
||||
Mcu.IPNb=15
|
||||
Mcu.Name=STM32G431C(6-8-B)Ux
|
||||
Mcu.Package=UFQFPN48
|
||||
Mcu.Pin0=PF1-OSC_OUT
|
||||
@ -129,20 +137,21 @@ Mcu.Pin25=PB4
|
||||
Mcu.Pin26=PB5
|
||||
Mcu.Pin27=PB6
|
||||
Mcu.Pin28=PB9
|
||||
Mcu.Pin29=VP_FREERTOS_VS_CMSIS_V1
|
||||
Mcu.Pin29=VP_ADC1_TempSens_Input
|
||||
Mcu.Pin3=PA3
|
||||
Mcu.Pin30=VP_SYS_VS_tim17
|
||||
Mcu.Pin31=VP_TIM1_VS_ClockSourceINT
|
||||
Mcu.Pin32=VP_TIM2_VS_ClockSourceINT
|
||||
Mcu.Pin33=VP_USBPD_VS_USBPD1
|
||||
Mcu.Pin34=VP_USBPD_VS_usbpd_tim3
|
||||
Mcu.Pin30=VP_FREERTOS_VS_CMSIS_V1
|
||||
Mcu.Pin31=VP_SYS_VS_tim17
|
||||
Mcu.Pin32=VP_TIM1_VS_ClockSourceINT
|
||||
Mcu.Pin33=VP_TIM2_VS_ClockSourceINT
|
||||
Mcu.Pin34=VP_USBPD_VS_USBPD1
|
||||
Mcu.Pin35=VP_USBPD_VS_usbpd_tim3
|
||||
Mcu.Pin4=PA4
|
||||
Mcu.Pin5=PA5
|
||||
Mcu.Pin6=PA6
|
||||
Mcu.Pin7=PA7
|
||||
Mcu.Pin8=PC4
|
||||
Mcu.Pin9=PB0
|
||||
Mcu.PinsNb=35
|
||||
Mcu.PinsNb=36
|
||||
Mcu.ThirdPartyNb=0
|
||||
Mcu.UserConstants=
|
||||
Mcu.UserName=STM32G431CBUx
|
||||
@ -374,6 +383,8 @@ TIM2.Prescaler=143
|
||||
USART3.IPParameters=WordLength,VirtualMode-Asynchronous
|
||||
USART3.VirtualMode-Asynchronous=VM_ASYNC
|
||||
USART3.WordLength=WORDLENGTH_8B
|
||||
VP_ADC1_TempSens_Input.Mode=IN-TempSens
|
||||
VP_ADC1_TempSens_Input.Signal=ADC1_TempSens_Input
|
||||
VP_FREERTOS_VS_CMSIS_V1.Mode=CMSIS_V1
|
||||
VP_FREERTOS_VS_CMSIS_V1.Signal=FREERTOS_VS_CMSIS_V1
|
||||
VP_SYS_VS_tim17.Mode=TIM17
|
||||
|
Loading…
Reference in New Issue
Block a user