add printf float to makefile
This commit is contained in:
@@ -24,6 +24,7 @@ extern "C" {
|
|||||||
/* USER CODE BEGIN Includes */
|
/* USER CODE BEGIN Includes */
|
||||||
//#include <stdio.h>
|
//#include <stdio.h>
|
||||||
} // end extern "C"
|
} // end extern "C"
|
||||||
|
#include <cstdint>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
/* USER CODE END Includes */
|
/* USER CODE END Includes */
|
||||||
@@ -37,14 +38,6 @@ extern "C" {
|
|||||||
/* USER CODE BEGIN PD */
|
/* USER CODE BEGIN PD */
|
||||||
#define Print2UART1 int __io_putchar(int data) // prints to serial monitor
|
#define Print2UART1 int __io_putchar(int data) // prints to serial monitor
|
||||||
|
|
||||||
int duty;
|
|
||||||
/*
|
|
||||||
* We are going to set this value repeatedly as such:
|
|
||||||
* CCR
|
|
||||||
* DC(%) = ----------- * 100
|
|
||||||
* ARR + 1
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* USER CODE END PD */
|
/* USER CODE END PD */
|
||||||
|
|
||||||
/* Private macro -------------------------------------------------------------*/
|
/* Private macro -------------------------------------------------------------*/
|
||||||
@@ -61,7 +54,16 @@ UART_HandleTypeDef huart1;
|
|||||||
|
|
||||||
/* USER CODE BEGIN PV */
|
/* USER CODE BEGIN PV */
|
||||||
uint16_t rawValue;
|
uint16_t rawValue;
|
||||||
|
float val;
|
||||||
float volts;
|
float volts;
|
||||||
|
float duty;
|
||||||
|
/*
|
||||||
|
* We are going to set this value repeatedly as such:
|
||||||
|
* CCR
|
||||||
|
* DC(%) = ----------- * 100
|
||||||
|
* ARR + 1
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
/* USER CODE END PV */
|
/* USER CODE END PV */
|
||||||
|
|
||||||
@@ -128,21 +130,30 @@ main(void)
|
|||||||
rawValue = HAL_ADC_GetValue(&hadc1);
|
rawValue = HAL_ADC_GetValue(&hadc1);
|
||||||
printf("ADC raw value: %hu\r\n", rawValue);
|
printf("ADC raw value: %hu\r\n", rawValue);
|
||||||
|
|
||||||
HAL_Delay(500);
|
val = (float)rawValue;
|
||||||
|
printf("ADC float value: %f\r\n", val);
|
||||||
|
|
||||||
volts = ((float)rawValue / 4096) * 3; // convert to voltage from 0 to 3.0
|
//HAL_Delay(500);
|
||||||
|
|
||||||
|
//volts = (float)(((float)rawValue / 4096) * 3); // convert to voltage from 0 to 3.0
|
||||||
|
volts = (val/4096)*3;
|
||||||
printf("Voltage: %fV\r\n", volts);
|
printf("Voltage: %fV\r\n", volts);
|
||||||
|
|
||||||
HAL_Delay(500);
|
//HAL_Delay(500);
|
||||||
|
|
||||||
duty = ((float)rawValue / 4096) * 65534;
|
//duty = (((float)rawValue / 4096) * 65534);
|
||||||
|
duty = (val/4096)*65534;
|
||||||
|
printf("Duty: %f\r\n", duty);
|
||||||
|
|
||||||
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, duty);
|
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, duty);
|
||||||
|
|
||||||
HAL_Delay(500);
|
//printf("\r\n");
|
||||||
|
|
||||||
|
HAL_Delay(1000);
|
||||||
/* USER CODE END WHILE */
|
/* USER CODE END WHILE */
|
||||||
|
|
||||||
/* USER CODE BEGIN 3 */
|
/* USER CODE BEGIN 3 */
|
||||||
|
printf("\x1B[2J\x1B[H"); // ANSI: clear tty
|
||||||
}
|
}
|
||||||
/* USER CODE END 3 */
|
/* USER CODE END 3 */
|
||||||
}
|
}
|
||||||
|
|||||||
2
Makefile
2
Makefile
@@ -158,7 +158,7 @@ LDSCRIPT = STM32F429XX_FLASH.ld
|
|||||||
# libraries
|
# libraries
|
||||||
LIBS = -lc -lm -lnosys
|
LIBS = -lc -lm -lnosys
|
||||||
LIBDIR =
|
LIBDIR =
|
||||||
LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections
|
LDFLAGS = $(MCU) -specs=nano.specs -u _printf_float -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections
|
||||||
|
|
||||||
# default action: build all
|
# default action: build all
|
||||||
all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin
|
all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin
|
||||||
|
|||||||
Reference in New Issue
Block a user