Fixed battery ADC, use SWO for printf.
continuous-integration/drone/push Build is passing Details

Signed-off-by: Yilin Sun <imi415@imi.moe>
This commit is contained in:
Yilin Sun 2023-07-05 23:17:47 +08:00
parent 0c38ace964
commit 56adb86381
Signed by: imi415
GPG Key ID: 17F01E106F9F5E0A
6 changed files with 36 additions and 26 deletions

View File

@ -158,7 +158,7 @@
/**
* @brief This is the HAL system configuration section
*/
#define VDD_VALUE 3300U /*!< Value of VDD in mv */
#define VDD_VALUE 3372U /*!< Value of VDD in mv */
#define TICK_INT_PRIORITY ((1uL <<__NVIC_PRIO_BITS) - 1uL) /*!< tick interrupt priority (lowest by default) */
#define USE_RTOS 0U
#define PREFETCH_ENABLE 1U

View File

@ -43,7 +43,7 @@ void MX_ADC_Init(void)
/** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
*/
hadc.Instance = ADC;
hadc.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2;
hadc.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV16;
hadc.Init.Resolution = ADC_RESOLUTION_12B;
hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc.Init.ScanConvMode = ADC_SCAN_DISABLE;
@ -57,7 +57,7 @@ void MX_ADC_Init(void)
hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc.Init.DMAContinuousRequests = DISABLE;
hadc.Init.Overrun = ADC_OVR_DATA_PRESERVED;
hadc.Init.SamplingTimeCommon1 = ADC_SAMPLETIME_1CYCLE_5;
hadc.Init.SamplingTimeCommon1 = ADC_SAMPLETIME_39CYCLES_5;
hadc.Init.SamplingTimeCommon2 = ADC_SAMPLETIME_1CYCLE_5;
hadc.Init.OversamplingMode = DISABLE;
hadc.Init.TriggerFrequencyMode = ADC_TRIGGER_FREQ_HIGH;
@ -70,7 +70,7 @@ void MX_ADC_Init(void)
*/
sConfig.Channel = ADC_CHANNEL_8;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLINGTIME_COMMON_2;
sConfig.SamplingTime = ADC_SAMPLINGTIME_COMMON_1;
if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
{
Error_Handler();
@ -85,11 +85,22 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
if(adcHandle->Instance==ADC)
{
/* USER CODE BEGIN ADC_MspInit 0 */
/* USER CODE END ADC_MspInit 0 */
/** Initializes the peripherals clocks
*/
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_ADC;
PeriphClkInitStruct.AdcClockSelection = RCC_ADCCLKSOURCE_SYSCLK;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
{
Error_Handler();
}
/* ADC clock enable */
__HAL_RCC_ADC_CLK_ENABLE();

View File

@ -1,13 +1,15 @@
#MicroXplorer Configuration settings - do not modify
ADC.Channel-0\#ChannelRegularConversion=ADC_CHANNEL_8
ADC.ClockPrescaler=ADC_CLOCK_ASYNC_DIV16
ADC.ContinuousConvMode=DISABLE
ADC.EnableRegularConversion=ENABLE
ADC.IPParameters=NbrOfConversion,SelectedChannel,ContinuousConvMode,EnableRegularConversion,Rank-0\#ChannelRegularConversion,Channel-0\#ChannelRegularConversion,SamplingTime-0\#ChannelRegularConversion,NbrOfConversionFlag,OversamplingMode
ADC.IPParameters=NbrOfConversion,SelectedChannel,ContinuousConvMode,EnableRegularConversion,Rank-0\#ChannelRegularConversion,Channel-0\#ChannelRegularConversion,SamplingTime-0\#ChannelRegularConversion,NbrOfConversionFlag,OversamplingMode,ClockPrescaler,SamplingTimeCommon1
ADC.NbrOfConversion=1
ADC.NbrOfConversionFlag=1
ADC.OversamplingMode=DISABLE
ADC.Rank-0\#ChannelRegularConversion=1
ADC.SamplingTime-0\#ChannelRegularConversion=ADC_SAMPLINGTIME_COMMON_2
ADC.SamplingTime-0\#ChannelRegularConversion=ADC_SAMPLINGTIME_COMMON_1
ADC.SamplingTimeCommon1=ADC_SAMPLETIME_39CYCLES_5
ADC.SelectedChannel=ADC_CHANNEL_8
CAD.formats=
CAD.pinconfig=
@ -178,6 +180,8 @@ ProjectManager.TargetToolchain=Makefile
ProjectManager.ToolChainLocation=
ProjectManager.UnderRoot=false
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_RTC_Init-RTC-false-HAL-true,4-MX_I2C1_Init-I2C1-false-HAL-true,5-MX_ADC_Init-ADC-false-HAL-true
RCC.ADCCLockSelection=RCC_ADCCLKSOURCE_SYSCLK
RCC.ADCFreq_Value=48000000
RCC.AHBFreq_Value=48000000
RCC.APB1Freq_Value=48000000
RCC.APB1TimFreq_Value=48000000
@ -195,7 +199,7 @@ RCC.I2C1Freq_Value=48000000
RCC.I2C2Freq_Value=48000000
RCC.I2C3Freq_Value=48000000
RCC.I2S2Freq_Value=16000000
RCC.IPParameters=AHBFreq_Value,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,APB3Freq_Value,CortexFreq_Value,FCLKCortexFreq_Value,FamilyName,HCLK3Freq_Value,HCLKFreq_Value,HSE_VALUE,HSI_VALUE,I2C1Freq_Value,I2C2Freq_Value,I2C3Freq_Value,I2S2Freq_Value,LPTIM1Freq_Value,LPTIM2Freq_Value,LPTIM3Freq_Value,LPUART1Freq_Value,LSCOPinFreq_Value,LSE_Drive_Capability,LSE_VALUE,MCO1PinFreq_Value,MSIClockRange,PLLM,PLLN,PLLPoutputFreq_Value,PLLQoutputFreq_Value,PLLR,PLLRCLKFreq_Value,PLLSourceVirtual,PREFETCH_ENABLE,PWRFreq_Value,RNGFreq_Value,RTCClockSelection,RTCFreq_Value,SYSCLKFreq_VALUE,SYSCLKSource,USART1Freq_Value,USART2Freq_Value,VCOInputFreq_Value,VCOOutputFreq_Value
RCC.IPParameters=ADCCLockSelection,ADCFreq_Value,AHBFreq_Value,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,APB3Freq_Value,CortexFreq_Value,FCLKCortexFreq_Value,FamilyName,HCLK3Freq_Value,HCLKFreq_Value,HSE_VALUE,HSI_VALUE,I2C1Freq_Value,I2C2Freq_Value,I2C3Freq_Value,I2S2Freq_Value,LPTIM1Freq_Value,LPTIM2Freq_Value,LPTIM3Freq_Value,LPUART1Freq_Value,LSCOPinFreq_Value,LSE_Drive_Capability,LSE_VALUE,MCO1PinFreq_Value,MSIClockRange,PLLM,PLLN,PLLPoutputFreq_Value,PLLQoutputFreq_Value,PLLR,PLLRCLKFreq_Value,PLLSourceVirtual,PREFETCH_ENABLE,PWRFreq_Value,RNGFreq_Value,RTCClockSelection,RTCFreq_Value,SYSCLKFreq_VALUE,SYSCLKSource,USART1Freq_Value,USART2Freq_Value,VCOInputFreq_Value,VCOOutputFreq_Value,VDD_VALUE
RCC.LPTIM1Freq_Value=48000000
RCC.LPTIM2Freq_Value=48000000
RCC.LPTIM3Freq_Value=48000000
@ -223,6 +227,7 @@ RCC.USART1Freq_Value=48000000
RCC.USART2Freq_Value=48000000
RCC.VCOInputFreq_Value=8000000
RCC.VCOOutputFreq_Value=144000000
RCC.VDD_VALUE=3.37234
RTC.BinMode=RTC_BINARY_ONLY
RTC.IPParameters=BinMode
SH.GPXTI0.0=GPIO_EXTI0

View File

@ -11,7 +11,7 @@ set(TARGET_TOOLCHAIN_SIZE arm-none-eabi-size)
set(CMAKE_C_FLAGS_INIT "-mcpu=cortex-m4 -mthumb -mfloat-abi=soft")
set(CMAKE_CXX_FLAGS_INIT "-mcpu=cortex-m4 -mthumb -mfloat-abi=soft")
set(CMAKE_EXE_LINKER_FLAGS_INIT "-specs=nano.specs -specs=nosys.specs -Wl,--print-memory-usage -Wl,--no-warn-rwx-segments")
set(CMAKE_EXE_LINKER_FLAGS_INIT "-specs=nano.specs -specs=nosys.specs -u _printf_float -Wl,--print-memory-usage -Wl,--no-warn-rwx-segments")
# Make CMake happy about those compilers
set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")

View File

@ -2,6 +2,7 @@
int _write(int file, char *ptr, int len) {
for (int i = 0; i < len; i++) {
ITM_SendChar(ptr[i]);
}
return len;
}

View File

@ -92,7 +92,7 @@ int main(void) {
MX_RTC_Init();
MX_I2C1_Init();
printf("Hello world\r\n");
printf("LWNode Functional Test Program:\r\n");
if (ims_bme280_init(&s_dht) != IMS_SUCCESS) {
goto dead_loop;
@ -139,7 +139,7 @@ int main(void) {
VL53L1_SetInterMeasurementPeriodMilliSeconds(&s_ranging, 500);
VL53L1_StartMeasurement(&s_ranging);
if(HAL_ADCEx_Calibration_Start(&hadc) != HAL_OK) {
if (HAL_ADCEx_Calibration_Start(&hadc) != HAL_OK) {
goto dead_loop;
}
@ -147,8 +147,8 @@ int main(void) {
ims_bme280_result_t dht_result;
VL53L1_RangingMeasurementData_t ranging_result;
uint8_t ranging_ready = 0U;
int16_t imu_temp;
uint8_t ranging_ready = 0U;
int16_t imu_temp;
volatile uint16_t vbat;
for (;;) {
@ -177,25 +177,18 @@ int main(void) {
HAL_ADC_Start(&hadc);
HAL_ADC_PollForConversion(&hadc, 1000);
if(HAL_ADC_GetState(&hadc) & HAL_ADC_STATE_EOC_REG) {
if (HAL_ADC_GetState(&hadc) & HAL_ADC_STATE_EOC_REG) {
vbat = HAL_ADC_GetValue(&hadc);
}
HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_SET);
/* clang-format off */
/*
dprintf main:printf_point, "T: %.2fC,\tH: %.2f%%,\tP: %.2fhPa,\tI0: %.2flx,\tI1: %.2flx,\tT_IMU: %.2fC\tR: %dmm\tV: %.2fmV\n",
dht_result.temperature / 100.0, dht_result.humidity / 1024.0, dht_result.pressure / 25600.0,
als_result.ch0_value / 48.0,
als_result.ch1_value / 48.0,
(imu_temp / 256.0) + 25.0,
ranging_result.RangeMilliMeter,
(vbat * 3362.0 / 4096.0)
*/
/* clang-format on */
printf_point:
printf(
"T: %5.2fC,\tH: %6.2f%%,\tP: %6.2fhPa,\tI0: %6.2flx,\tI1: %6.2flx,\tT_IMU: %5.2fC\tR: %4dmm\tV: "
"%6.2fmV\r\n",
dht_result.temperature / 100.0, dht_result.humidity / 1024.0, dht_result.pressure / 25600.0,
als_result.ch0_value / 48.0, als_result.ch1_value / 48.0, (imu_temp / 256.0) + 25.0,
ranging_result.RangeMilliMeter, (vbat * VDD_VALUE / 4096.0));
HAL_Delay(100);
}