trying some wacky ways to determine speeds and direction. eventually ill look up some algorithms to do this properly. for now im goofin

stable
Penguin 2 years ago
parent 807f7c29e8
commit ce63792708

@ -54,6 +54,7 @@ void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
void Error_Handler(void);
/* USER CODE BEGIN EFP */
void setPWM(TIM_HandleTypeDef *timer, uint32_t channel, uint8_t dc_percent);
/* USER CODE END EFP */

@ -21,11 +21,11 @@
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "putil.h"
#include "motor_controller.h"
#include "putil.h"
#include "stm32l4xx_hal_uart.h"
#include <stdio.h>
#include <stdbool.h>
#include <stdio.h>
/* USER CODE END Includes */
@ -44,7 +44,7 @@
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
TIM_HandleTypeDef htim2;
TIM_HandleTypeDef htim2;
TIM_HandleTypeDef htim6;
UART_HandleTypeDef huart2;
@ -54,6 +54,8 @@ volatile uint8_t huart2_rxc;
static volatile uint32_t sys_time = 0;
static volatile bool b_timer_struck = false;
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
@ -63,7 +65,6 @@ static void MX_TIM2_Init(void);
static void MX_USART2_UART_Init(void);
static void MX_TIM6_Init(void);
/* USER CODE BEGIN PFP */
void setPWM(TIM_HandleTypeDef *timer, uint32_t channel, uint8_t dc_percent);
/* USER CODE END PFP */
@ -114,20 +115,22 @@ int main(void)
HAL_GPIO_WritePin(m1_dir_GPIO_Port, m1_dir_Pin, 1);
HAL_GPIO_WritePin(m2_dir_GPIO_Port, m2_dir_Pin, 1);
mc_init();
mc_init(&htim2);
HAL_UART_Receive_IT(&huart2, &huart2_rxc, 1);
HAL_TIM_Base_Start_IT(&htim6);
uint16_t motor_degrees = 0;
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
mc_service();
if(b_timer_struck)
if (b_timer_struck)
{
// PDEBUG("%d\n", sys_time);
b_timer_struck = false;
PDEBUG("%d\n", sys_time);
motor_degrees = (motor_degrees + 1) % 360;
mc_service(motor_degrees, 50);
}
/* USER CODE END WHILE */
@ -270,7 +273,7 @@ static void MX_TIM6_Init(void)
htim6.Instance = TIM6;
htim6.Init.Prescaler = 127;
htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
htim6.Init.Period = 999;
htim6.Init.Period = 249;
htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
if (HAL_TIM_Base_Init(&htim6) != HAL_OK)
{
@ -360,16 +363,19 @@ static void MX_GPIO_Init(void)
}
/* USER CODE BEGIN 4 */
void HAL_UART_RxCpltCallback(UART_HandleTypeDef* huart)
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
HAL_UART_Transmit(&huart2, &huart2_rxc, 1, 100);
HAL_UART_Receive_IT(&huart2, &huart2_rxc, 1);
}
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef* htim)
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
sys_time += 4;
b_timer_struck = true;
sys_time += 1;
if(++sys_time % 250 == 0)
{
b_timer_struck = true;
}
}
void setPWM(TIM_HandleTypeDef *timer, uint32_t channel, uint8_t dc_percent)

@ -1,5 +1,5 @@
##########################################################################################################################
# File automatically-generated by tool: [projectgenerator] version: [3.16.0] date: [Fri Apr 01 16:10:25 CDT 2022]
# File automatically-generated by tool: [projectgenerator] version: [3.16.0] date: [Fri Apr 01 16:19:23 CDT 2022]
##########################################################################################################################
# ------------------------------------------------
@ -151,7 +151,7 @@ LDSCRIPT = STM32L432KCUx_FLASH.ld
# libraries
LIBS = -lc -lm -lnosys
LIBDIR =
LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections
LDFLAGS = $(MCU) -specs=nosys.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections -u _print_float
# default action: build all
all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin

@ -1,4 +1,810 @@
[
{
"arguments": [
"arm-none-eabi-gcc",
"-c",
"-mcpu=cortex-m4",
"-mthumb",
"-mfpu=fpv4-sp-d16",
"-mfloat-abi=hard",
"-DUSE_HAL_DRIVER",
"-DSTM32L432xx",
"-ICore/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc/Legacy",
"-IDrivers/CMSIS/Device/ST/STM32L4xx/Include",
"-IDrivers/CMSIS/Include",
"-Ishared",
"-Ishared/devices",
"-Ishared/drivers",
"-Ishared/util",
"-Og",
"-Wall",
"-fdata-sections",
"-ffunction-sections",
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/stm32l4xx_it.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_it.lst",
"-o",
"build/stm32l4xx_it.o",
"Core/Src/stm32l4xx_it.c"
],
"directory": "/storage/Shared/Projects/stm32_projects/motor_controller",
"file": "Core/Src/stm32l4xx_it.c"
},
{
"arguments": [
"arm-none-eabi-gcc",
"-c",
"-mcpu=cortex-m4",
"-mthumb",
"-mfpu=fpv4-sp-d16",
"-mfloat-abi=hard",
"-DUSE_HAL_DRIVER",
"-DSTM32L432xx",
"-ICore/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc/Legacy",
"-IDrivers/CMSIS/Device/ST/STM32L4xx/Include",
"-IDrivers/CMSIS/Include",
"-Ishared",
"-Ishared/devices",
"-Ishared/drivers",
"-Ishared/util",
"-Og",
"-Wall",
"-fdata-sections",
"-ffunction-sections",
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/stm32l4xx_hal_gpio.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_gpio.lst",
"-o",
"build/stm32l4xx_hal_gpio.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_gpio.c"
],
"directory": "/storage/Shared/Projects/stm32_projects/motor_controller",
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_gpio.c"
},
{
"arguments": [
"arm-none-eabi-gcc",
"-c",
"-mcpu=cortex-m4",
"-mthumb",
"-mfpu=fpv4-sp-d16",
"-mfloat-abi=hard",
"-DUSE_HAL_DRIVER",
"-DSTM32L432xx",
"-ICore/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc/Legacy",
"-IDrivers/CMSIS/Device/ST/STM32L4xx/Include",
"-IDrivers/CMSIS/Include",
"-Ishared",
"-Ishared/devices",
"-Ishared/drivers",
"-Ishared/util",
"-Og",
"-Wall",
"-fdata-sections",
"-ffunction-sections",
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/stm32l4xx_hal_dma_ex.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_dma_ex.lst",
"-o",
"build/stm32l4xx_hal_dma_ex.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma_ex.c"
],
"directory": "/storage/Shared/Projects/stm32_projects/motor_controller",
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma_ex.c"
},
{
"arguments": [
"arm-none-eabi-gcc",
"-c",
"-mcpu=cortex-m4",
"-mthumb",
"-mfpu=fpv4-sp-d16",
"-mfloat-abi=hard",
"-DUSE_HAL_DRIVER",
"-DSTM32L432xx",
"-ICore/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc/Legacy",
"-IDrivers/CMSIS/Device/ST/STM32L4xx/Include",
"-IDrivers/CMSIS/Include",
"-Ishared",
"-Ishared/devices",
"-Ishared/drivers",
"-Ishared/util",
"-Og",
"-Wall",
"-fdata-sections",
"-ffunction-sections",
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/motor_controller.d",
"-Wa,-a,-ad,-alms=build/motor_controller.lst",
"-o",
"build/motor_controller.o",
"shared/devices/motor_controller.c"
],
"directory": "/storage/Shared/Projects/stm32_projects/motor_controller",
"file": "shared/devices/motor_controller.c"
},
{
"arguments": [
"arm-none-eabi-gcc",
"-c",
"-mcpu=cortex-m4",
"-mthumb",
"-mfpu=fpv4-sp-d16",
"-mfloat-abi=hard",
"-DUSE_HAL_DRIVER",
"-DSTM32L432xx",
"-ICore/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc/Legacy",
"-IDrivers/CMSIS/Device/ST/STM32L4xx/Include",
"-IDrivers/CMSIS/Include",
"-Ishared",
"-Ishared/devices",
"-Ishared/drivers",
"-Ishared/util",
"-Og",
"-Wall",
"-fdata-sections",
"-ffunction-sections",
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/stm32l4xx_hal_msp.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_msp.lst",
"-o",
"build/stm32l4xx_hal_msp.o",
"Core/Src/stm32l4xx_hal_msp.c"
],
"directory": "/storage/Shared/Projects/stm32_projects/motor_controller",
"file": "Core/Src/stm32l4xx_hal_msp.c"
},
{
"arguments": [
"arm-none-eabi-gcc",
"-c",
"-mcpu=cortex-m4",
"-mthumb",
"-mfpu=fpv4-sp-d16",
"-mfloat-abi=hard",
"-DUSE_HAL_DRIVER",
"-DSTM32L432xx",
"-ICore/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc/Legacy",
"-IDrivers/CMSIS/Device/ST/STM32L4xx/Include",
"-IDrivers/CMSIS/Include",
"-Ishared",
"-Ishared/devices",
"-Ishared/drivers",
"-Ishared/util",
"-Og",
"-Wall",
"-fdata-sections",
"-ffunction-sections",
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/stm32l4xx_hal_i2c.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_i2c.lst",
"-o",
"build/stm32l4xx_hal_i2c.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_i2c.c"
],
"directory": "/storage/Shared/Projects/stm32_projects/motor_controller",
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_i2c.c"
},
{
"arguments": [
"arm-none-eabi-gcc",
"-c",
"-mcpu=cortex-m4",
"-mthumb",
"-mfpu=fpv4-sp-d16",
"-mfloat-abi=hard",
"-DUSE_HAL_DRIVER",
"-DSTM32L432xx",
"-ICore/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc/Legacy",
"-IDrivers/CMSIS/Device/ST/STM32L4xx/Include",
"-IDrivers/CMSIS/Include",
"-Ishared",
"-Ishared/devices",
"-Ishared/drivers",
"-Ishared/util",
"-Og",
"-Wall",
"-fdata-sections",
"-ffunction-sections",
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/stm32l4xx_hal.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal.lst",
"-o",
"build/stm32l4xx_hal.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal.c"
],
"directory": "/storage/Shared/Projects/stm32_projects/motor_controller",
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal.c"
},
{
"arguments": [
"arm-none-eabi-gcc",
"-c",
"-mcpu=cortex-m4",
"-mthumb",
"-mfpu=fpv4-sp-d16",
"-mfloat-abi=hard",
"-DUSE_HAL_DRIVER",
"-DSTM32L432xx",
"-ICore/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc/Legacy",
"-IDrivers/CMSIS/Device/ST/STM32L4xx/Include",
"-IDrivers/CMSIS/Include",
"-Ishared",
"-Ishared/devices",
"-Ishared/drivers",
"-Ishared/util",
"-Og",
"-Wall",
"-fdata-sections",
"-ffunction-sections",
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/stm32l4xx_hal_tim_ex.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_tim_ex.lst",
"-o",
"build/stm32l4xx_hal_tim_ex.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_tim_ex.c"
],
"directory": "/storage/Shared/Projects/stm32_projects/motor_controller",
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_tim_ex.c"
},
{
"arguments": [
"arm-none-eabi-gcc",
"-c",
"-mcpu=cortex-m4",
"-mthumb",
"-mfpu=fpv4-sp-d16",
"-mfloat-abi=hard",
"-DUSE_HAL_DRIVER",
"-DSTM32L432xx",
"-ICore/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc/Legacy",
"-IDrivers/CMSIS/Device/ST/STM32L4xx/Include",
"-IDrivers/CMSIS/Include",
"-Ishared",
"-Ishared/devices",
"-Ishared/drivers",
"-Ishared/util",
"-Og",
"-Wall",
"-fdata-sections",
"-ffunction-sections",
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/stm32l4xx_hal_pwr.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_pwr.lst",
"-o",
"build/stm32l4xx_hal_pwr.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_pwr.c"
],
"directory": "/storage/Shared/Projects/stm32_projects/motor_controller",
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_pwr.c"
},
{
"arguments": [
"arm-none-eabi-gcc",
"-c",
"-x",
"assembler-with-cpp",
"-mcpu=cortex-m4",
"-mthumb",
"-mfpu=fpv4-sp-d16",
"-mfloat-abi=hard",
"-DUSE_HAL_DRIVER",
"-DSTM32L432xx",
"-ICore/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc/Legacy",
"-IDrivers/CMSIS/Device/ST/STM32L4xx/Include",
"-IDrivers/CMSIS/Include",
"-Ishared",
"-Ishared/devices",
"-Ishared/drivers",
"-Ishared/util",
"-Og",
"-Wall",
"-fdata-sections",
"-ffunction-sections",
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/startup_stm32l432xx.d",
"-o",
"build/startup_stm32l432xx.o",
"startup_stm32l432xx.s"
],
"directory": "/storage/Shared/Projects/stm32_projects/motor_controller",
"file": "startup_stm32l432xx.s"
},
{
"arguments": [
"arm-none-eabi-gcc",
"-c",
"-mcpu=cortex-m4",
"-mthumb",
"-mfpu=fpv4-sp-d16",
"-mfloat-abi=hard",
"-DUSE_HAL_DRIVER",
"-DSTM32L432xx",
"-ICore/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc/Legacy",
"-IDrivers/CMSIS/Device/ST/STM32L4xx/Include",
"-IDrivers/CMSIS/Include",
"-Ishared",
"-Ishared/devices",
"-Ishared/drivers",
"-Ishared/util",
"-Og",
"-Wall",
"-fdata-sections",
"-ffunction-sections",
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/stm32l4xx_hal_uart.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_uart.lst",
"-o",
"build/stm32l4xx_hal_uart.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_uart.c"
],
"directory": "/storage/Shared/Projects/stm32_projects/motor_controller",
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_uart.c"
},
{
"arguments": [
"arm-none-eabi-gcc",
"-c",
"-mcpu=cortex-m4",
"-mthumb",
"-mfpu=fpv4-sp-d16",
"-mfloat-abi=hard",
"-DUSE_HAL_DRIVER",
"-DSTM32L432xx",
"-ICore/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc/Legacy",
"-IDrivers/CMSIS/Device/ST/STM32L4xx/Include",
"-IDrivers/CMSIS/Include",
"-Ishared",
"-Ishared/devices",
"-Ishared/drivers",
"-Ishared/util",
"-Og",
"-Wall",
"-fdata-sections",
"-ffunction-sections",
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/stm32l4xx_hal_flash_ramfunc.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_flash_ramfunc.lst",
"-o",
"build/stm32l4xx_hal_flash_ramfunc.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash_ramfunc.c"
],
"directory": "/storage/Shared/Projects/stm32_projects/motor_controller",
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash_ramfunc.c"
},
{
"arguments": [
"arm-none-eabi-gcc",
"-c",
"-mcpu=cortex-m4",
"-mthumb",
"-mfpu=fpv4-sp-d16",
"-mfloat-abi=hard",
"-DUSE_HAL_DRIVER",
"-DSTM32L432xx",
"-ICore/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc/Legacy",
"-IDrivers/CMSIS/Device/ST/STM32L4xx/Include",
"-IDrivers/CMSIS/Include",
"-Ishared",
"-Ishared/devices",
"-Ishared/drivers",
"-Ishared/util",
"-Og",
"-Wall",
"-fdata-sections",
"-ffunction-sections",
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/stm32l4xx_hal_rcc.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_rcc.lst",
"-o",
"build/stm32l4xx_hal_rcc.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rcc.c"
],
"directory": "/storage/Shared/Projects/stm32_projects/motor_controller",
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rcc.c"
},
{
"arguments": [
"arm-none-eabi-gcc",
"-c",
"-mcpu=cortex-m4",
"-mthumb",
"-mfpu=fpv4-sp-d16",
"-mfloat-abi=hard",
"-DUSE_HAL_DRIVER",
"-DSTM32L432xx",
"-ICore/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc/Legacy",
"-IDrivers/CMSIS/Device/ST/STM32L4xx/Include",
"-IDrivers/CMSIS/Include",
"-Ishared",
"-Ishared/devices",
"-Ishared/drivers",
"-Ishared/util",
"-Og",
"-Wall",
"-fdata-sections",
"-ffunction-sections",
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/stm32l4xx_hal_flash_ex.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_flash_ex.lst",
"-o",
"build/stm32l4xx_hal_flash_ex.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash_ex.c"
],
"directory": "/storage/Shared/Projects/stm32_projects/motor_controller",
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash_ex.c"
},
{
"arguments": [
"arm-none-eabi-gcc",
"-c",
"-mcpu=cortex-m4",
"-mthumb",
"-mfpu=fpv4-sp-d16",
"-mfloat-abi=hard",
"-DUSE_HAL_DRIVER",
"-DSTM32L432xx",
"-ICore/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc/Legacy",
"-IDrivers/CMSIS/Device/ST/STM32L4xx/Include",
"-IDrivers/CMSIS/Include",
"-Ishared",
"-Ishared/devices",
"-Ishared/drivers",
"-Ishared/util",
"-Og",
"-Wall",
"-fdata-sections",
"-ffunction-sections",
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/stm32l4xx_hal_cortex.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_cortex.lst",
"-o",
"build/stm32l4xx_hal_cortex.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_cortex.c"
],
"directory": "/storage/Shared/Projects/stm32_projects/motor_controller",
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_cortex.c"
},
{
"arguments": [
"arm-none-eabi-gcc",
"-c",
"-mcpu=cortex-m4",
"-mthumb",
"-mfpu=fpv4-sp-d16",
"-mfloat-abi=hard",
"-DUSE_HAL_DRIVER",
"-DSTM32L432xx",
"-ICore/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc/Legacy",
"-IDrivers/CMSIS/Device/ST/STM32L4xx/Include",
"-IDrivers/CMSIS/Include",
"-Ishared",
"-Ishared/devices",
"-Ishared/drivers",
"-Ishared/util",
"-Og",
"-Wall",
"-fdata-sections",
"-ffunction-sections",
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/stm32l4xx_hal_pwr_ex.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_pwr_ex.lst",
"-o",
"build/stm32l4xx_hal_pwr_ex.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_pwr_ex.c"
],
"directory": "/storage/Shared/Projects/stm32_projects/motor_controller",
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_pwr_ex.c"
},
{
"arguments": [
"arm-none-eabi-gcc",
"-c",
"-mcpu=cortex-m4",
"-mthumb",
"-mfpu=fpv4-sp-d16",
"-mfloat-abi=hard",
"-DUSE_HAL_DRIVER",
"-DSTM32L432xx",
"-ICore/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc/Legacy",
"-IDrivers/CMSIS/Device/ST/STM32L4xx/Include",
"-IDrivers/CMSIS/Include",
"-Ishared",
"-Ishared/devices",
"-Ishared/drivers",
"-Ishared/util",
"-Og",
"-Wall",
"-fdata-sections",
"-ffunction-sections",
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/stm32l4xx_hal_dma.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_dma.lst",
"-o",
"build/stm32l4xx_hal_dma.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma.c"
],
"directory": "/storage/Shared/Projects/stm32_projects/motor_controller",
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma.c"
},
{
"arguments": [
"arm-none-eabi-gcc",
"-c",
"-mcpu=cortex-m4",
"-mthumb",
"-mfpu=fpv4-sp-d16",
"-mfloat-abi=hard",
"-DUSE_HAL_DRIVER",
"-DSTM32L432xx",
"-ICore/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc/Legacy",
"-IDrivers/CMSIS/Device/ST/STM32L4xx/Include",
"-IDrivers/CMSIS/Include",
"-Ishared",
"-Ishared/devices",
"-Ishared/drivers",
"-Ishared/util",
"-Og",
"-Wall",
"-fdata-sections",
"-ffunction-sections",
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/stm32l4xx_hal_uart_ex.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_uart_ex.lst",
"-o",
"build/stm32l4xx_hal_uart_ex.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_uart_ex.c"
],
"directory": "/storage/Shared/Projects/stm32_projects/motor_controller",
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_uart_ex.c"
},
{
"arguments": [
"arm-none-eabi-gcc",
"-c",
"-mcpu=cortex-m4",
"-mthumb",
"-mfpu=fpv4-sp-d16",
"-mfloat-abi=hard",
"-DUSE_HAL_DRIVER",
"-DSTM32L432xx",
"-ICore/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc/Legacy",
"-IDrivers/CMSIS/Device/ST/STM32L4xx/Include",
"-IDrivers/CMSIS/Include",
"-Ishared",
"-Ishared/devices",
"-Ishared/drivers",
"-Ishared/util",
"-Og",
"-Wall",
"-fdata-sections",
"-ffunction-sections",
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/stm32l4xx_hal_exti.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_exti.lst",
"-o",
"build/stm32l4xx_hal_exti.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_exti.c"
],
"directory": "/storage/Shared/Projects/stm32_projects/motor_controller",
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_exti.c"
},
{
"arguments": [
"arm-none-eabi-gcc",
"-c",
"-mcpu=cortex-m4",
"-mthumb",
"-mfpu=fpv4-sp-d16",
"-mfloat-abi=hard",
"-DUSE_HAL_DRIVER",
"-DSTM32L432xx",
"-ICore/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc/Legacy",
"-IDrivers/CMSIS/Device/ST/STM32L4xx/Include",
"-IDrivers/CMSIS/Include",
"-Ishared",
"-Ishared/devices",
"-Ishared/drivers",
"-Ishared/util",
"-Og",
"-Wall",
"-fdata-sections",
"-ffunction-sections",
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/putil.d",
"-Wa,-a,-ad,-alms=build/putil.lst",
"-o",
"build/putil.o",
"shared/util/putil.c"
],
"directory": "/storage/Shared/Projects/stm32_projects/motor_controller",
"file": "shared/util/putil.c"
},
{
"arguments": [
"arm-none-eabi-gcc",
"-c",
"-mcpu=cortex-m4",
"-mthumb",
"-mfpu=fpv4-sp-d16",
"-mfloat-abi=hard",
"-DUSE_HAL_DRIVER",
"-DSTM32L432xx",
"-ICore/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc/Legacy",
"-IDrivers/CMSIS/Device/ST/STM32L4xx/Include",
"-IDrivers/CMSIS/Include",
"-Ishared",
"-Ishared/devices",
"-Ishared/drivers",
"-Ishared/util",
"-Og",
"-Wall",
"-fdata-sections",
"-ffunction-sections",
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/stm32l4xx_hal_tim.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_tim.lst",
"-o",
"build/stm32l4xx_hal_tim.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_tim.c"
],
"directory": "/storage/Shared/Projects/stm32_projects/motor_controller",
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_tim.c"
},
{
"arguments": [
"arm-none-eabi-gcc",
"-c",
"-mcpu=cortex-m4",
"-mthumb",
"-mfpu=fpv4-sp-d16",
"-mfloat-abi=hard",
"-DUSE_HAL_DRIVER",
"-DSTM32L432xx",
"-ICore/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc/Legacy",
"-IDrivers/CMSIS/Device/ST/STM32L4xx/Include",
"-IDrivers/CMSIS/Include",
"-Ishared",
"-Ishared/devices",
"-Ishared/drivers",
"-Ishared/util",
"-Og",
"-Wall",
"-fdata-sections",
"-ffunction-sections",
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/stm32l4xx_hal_i2c_ex.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_i2c_ex.lst",
"-o",
"build/stm32l4xx_hal_i2c_ex.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_i2c_ex.c"
],
"directory": "/storage/Shared/Projects/stm32_projects/motor_controller",
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_i2c_ex.c"
},
{
"arguments": [
"arm-none-eabi-gcc",
"-c",
"-mcpu=cortex-m4",
"-mthumb",
"-mfpu=fpv4-sp-d16",
"-mfloat-abi=hard",
"-DUSE_HAL_DRIVER",
"-DSTM32L432xx",
"-ICore/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc/Legacy",
"-IDrivers/CMSIS/Device/ST/STM32L4xx/Include",
"-IDrivers/CMSIS/Include",
"-Ishared",
"-Ishared/devices",
"-Ishared/drivers",
"-Ishared/util",
"-Og",
"-Wall",
"-fdata-sections",
"-ffunction-sections",
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/stm32l4xx_hal_rcc_ex.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_rcc_ex.lst",
"-o",
"build/stm32l4xx_hal_rcc_ex.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rcc_ex.c"
],
"directory": "/storage/Shared/Projects/stm32_projects/motor_controller",
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rcc_ex.c"
},
{
"arguments": [
"arm-none-eabi-gcc",
@ -33,5 +839,75 @@
],
"directory": "/storage/Shared/Projects/stm32_projects/motor_controller",
"file": "Core/Src/main.c"
},
{
"arguments": [
"arm-none-eabi-gcc",
"-c",
"-mcpu=cortex-m4",
"-mthumb",
"-mfpu=fpv4-sp-d16",
"-mfloat-abi=hard",
"-DUSE_HAL_DRIVER",
"-DSTM32L432xx",
"-ICore/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc/Legacy",
"-IDrivers/CMSIS/Device/ST/STM32L4xx/Include",
"-IDrivers/CMSIS/Include",
"-Ishared",
"-Ishared/devices",
"-Ishared/drivers",
"-Ishared/util",
"-Og",
"-Wall",
"-fdata-sections",
"-ffunction-sections",
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/system_stm32l4xx.d",
"-Wa,-a,-ad,-alms=build/system_stm32l4xx.lst",
"-o",
"build/system_stm32l4xx.o",
"Core/Src/system_stm32l4xx.c"
],
"directory": "/storage/Shared/Projects/stm32_projects/motor_controller",
"file": "Core/Src/system_stm32l4xx.c"
},
{
"arguments": [
"arm-none-eabi-gcc",
"-c",
"-mcpu=cortex-m4",
"-mthumb",
"-mfpu=fpv4-sp-d16",
"-mfloat-abi=hard",
"-DUSE_HAL_DRIVER",
"-DSTM32L432xx",
"-ICore/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc",
"-IDrivers/STM32L4xx_HAL_Driver/Inc/Legacy",
"-IDrivers/CMSIS/Device/ST/STM32L4xx/Include",
"-IDrivers/CMSIS/Include",
"-Ishared",
"-Ishared/devices",
"-Ishared/drivers",
"-Ishared/util",
"-Og",
"-Wall",
"-fdata-sections",
"-ffunction-sections",
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/stm32l4xx_hal_flash.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_flash.lst",
"-o",
"build/stm32l4xx_hal_flash.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash.c"
],
"directory": "/storage/Shared/Projects/stm32_projects/motor_controller",
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash.c"
}
]

1553
gdb.txt

File diff suppressed because it is too large Load Diff

@ -193,7 +193,7 @@ TIM2.Pulse-PWM\ Generation2\ CH2=250
TIM2.Pulse-PWM\ Generation4\ CH4=125
TIM6.AutoReloadPreload=TIM_AUTORELOAD_PRELOAD_ENABLE
TIM6.IPParameters=Prescaler,AutoReloadPreload,Period
TIM6.Period=999
TIM6.Period=249
TIM6.Prescaler=127
USART2.IPParameters=VirtualMode-Asynchronous
USART2.VirtualMode-Asynchronous=VM_ASYNC

@ -1,11 +1,28 @@
#include "motor_controller.h"
#include <math.h>
#include "putil.h"
#include "stm32l4xx_hal_tim.h"
void mc_init()
static TIM_HandleTypeDef* _motor_timer = NULL;
void mc_init(TIM_HandleTypeDef* tim)
{
//
_motor_timer = tim;
}
void mc_service()
// degrees is anything from 0-359
// speed is anything from 0-99
void mc_service(uint16_t degrees, uint8_t speed)
{
float right_pwm = cos(((float)degrees*(3.1415 / 180.0f)));
float left_pwm = right_pwm;
PDEBUG("| DEGREES | COS | SIN | \n");
PDEBUG("| %7d | %-5.3f | %-5.3f | \n",
(int)degrees,
right_pwm,
right_pwm);
HAL_GPIO_WritePin(m1_dir_GPIO_Port, m1_dir_Pin, right_pwm >= 0 ? 0 : 1);
HAL_GPIO_WritePin(m2_dir_GPIO_Port, m2_dir_Pin, left_pwm >= 0 ? 0 : 1);
setPWM(_motor_timer, TIM_CHANNEL_2, abs((int)(right_pwm * 100.0)));
setPWM(_motor_timer, TIM_CHANNEL_4, abs((int)(left_pwm * 100.0)));
}

@ -3,8 +3,8 @@
#include "main.h"
void mc_init(void);
void mc_init(TIM_HandleTypeDef* tim);
void mc_service(void);
void mc_service(uint16_t degrees, uint8_t speed);
#endif

Loading…
Cancel
Save