Skip to content

Commit

Permalink
VIMDronesL431 working
Browse files Browse the repository at this point in the history
  • Loading branch information
tridge committed Aug 1, 2024
1 parent ff4abc9 commit 181119e
Show file tree
Hide file tree
Showing 20 changed files with 953 additions and 1,490 deletions.
73 changes: 37 additions & 36 deletions Inc/targets.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,14 @@


#ifdef VIMDRONES_L431
#define FIRMWARE_NAME "VM DEV L431 "
#define FIRMWARE_NAME "VimdroneL431"
#define FILE_NAME "VIMDRONES_L431"
#define DEAD_TIME 45
#define HARDWARE_GROUP_L4_A
#define TARGET_VOLTAGE_DIVIDER 65
#define USE_SERIAL_TELEMETRY

#define CURRENT_ADC_CHANNEL LL_ADC_CHANNEL_8
#define VOLTAGE_ADC_CHANNEL LL_ADC_CHANNEL_11
// #define ADC_CHANNEL_TEMP LL_ADC_CHANNEL_6
#define EEPROM_START_ADD (uint32_t)0x0801F800
#define APPLICATION_ADDRESS 0x08001000
#endif

#ifdef REF_G431
Expand Down Expand Up @@ -2638,43 +2636,46 @@

#ifdef HARDWARE_GROUP_L4_A

#define MCU_L431
#define USE_TIMER_15_CHANNEL_1
#define INPUT_PIN LL_GPIO_PIN_2
#define INPUT_PIN_PORT GPIOA
#define IC_TIMER_CHANNEL LL_TIM_CHANNEL_CH1
#define IC_TIMER_REGISTER TIM15
#define IC_TIMER_POINTER htim15
#define MCU_L431
#define USE_TIMER_15_CHANNEL_1
#define INPUT_PIN LL_GPIO_PIN_2
#define INPUT_PIN_PORT GPIOA
#define IC_TIMER_CHANNEL LL_TIM_CHANNEL_CH1
#define IC_TIMER_REGISTER TIM15
#define IC_TIMER_POINTER htim15

#define INPUT_DMA_CHANNEL LL_DMA_CHANNEL_5
#define DMA_HANDLE_TYPE_DEF hdma_tim15_ch1
#define IC_DMA_IRQ_NAME DMA1_Channel5_IRQn
#define INPUT_DMA_CHANNEL LL_DMA_CHANNEL_5
#define DMA_HANDLE_TYPE_DEF hdma_tim15_ch1
#define IC_DMA_IRQ_NAME DMA1_Channel5_IRQn

#define PHASE_A_GPIO_LOW LL_GPIO_PIN_1
#define PHASE_A_GPIO_PORT_LOW GPIOB
#define PHASE_A_GPIO_HIGH LL_GPIO_PIN_10
#define PHASE_A_GPIO_PORT_HIGH GPIOA
#define PHASE_A_GPIO_LOW LL_GPIO_PIN_1
#define PHASE_A_GPIO_PORT_LOW GPIOB
#define PHASE_A_GPIO_HIGH LL_GPIO_PIN_10
#define PHASE_A_GPIO_PORT_HIGH GPIOA

#define PHASE_B_GPIO_LOW LL_GPIO_PIN_0
#define PHASE_B_GPIO_PORT_LOW GPIOB
#define PHASE_B_GPIO_HIGH LL_GPIO_PIN_9
#define PHASE_B_GPIO_PORT_HIGH GPIOA
#define PHASE_B_GPIO_LOW LL_GPIO_PIN_0
#define PHASE_B_GPIO_PORT_LOW GPIOB
#define PHASE_B_GPIO_HIGH LL_GPIO_PIN_9
#define PHASE_B_GPIO_PORT_HIGH GPIOA

#define PHASE_C_GPIO_LOW LL_GPIO_PIN_7
#define PHASE_C_GPIO_PORT_LOW GPIOA
#define PHASE_C_GPIO_HIGH LL_GPIO_PIN_8
#define PHASE_C_GPIO_PORT_HIGH GPIOA
#define PHASE_C_GPIO_LOW LL_GPIO_PIN_7
#define PHASE_C_GPIO_PORT_LOW GPIOA
#define PHASE_C_GPIO_HIGH LL_GPIO_PIN_8
#define PHASE_C_GPIO_PORT_HIGH GPIOA

#define USE_COMP_1
#define PHASE_A_COMP LL_COMP_INPUT_MINUS_IO3 // pa0
#define PHASE_B_COMP LL_COMP_INPUT_MINUS_IO4 // pa4
#define PHASE_C_COMP LL_COMP_INPUT_MINUS_IO5 // pa5
#define PHASE_A_COMP LL_COMP_INPUT_MINUS_IO2 // pb7
#define PHASE_B_COMP LL_COMP_INPUT_MINUS_IO5 // pa5
#define PHASE_C_COMP LL_COMP_INPUT_MINUS_IO4 // pa4
#define PHASE_COM_COMP LL_COMP_INPUT_PLUS_IO1 // pb4

#define CURRENT_SENSE_ADC_PIN LL_GPIO_PIN_3
#define VOLTAGE_SENSE_ADC_PIN LL_GPIO_PIN_6
#define USE_COMP_2

#define CURRENT_ADC_CHANNEL LL_ADC_CHANNEL_8
#define VOLTAGE_ADC_CHANNEL LL_ADC_CHANNEL_11
#define USE_LED_STRIP
#define WS2812_PIN LL_GPIO_PIN_3

#define CURRENT_ADC_CHANNEL LL_ADC_CHANNEL_8
#define VOLTAGE_ADC_CHANNEL LL_ADC_CHANNEL_11
#define ADC_CHANNEL_TEMP LL_ADC_CHANNEL_6

#endif

Expand Down Expand Up @@ -2906,7 +2907,7 @@
#ifdef MCU_L431
#define STMICRO
#define CPU_FREQUENCY_MHZ 80
#define EEPROM_START_ADD (uint32_t)0x0800F800
#define EEPROM_START_ADD (uint32_t)0x0801F800
#define INTERVAL_TIMER TIM2
#define TEN_KHZ_TIMER TIM6
#define UTILITY_TIMER TIM7
Expand Down
10 changes: 10 additions & 0 deletions Mcu/l431/Inc/ADC.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,22 @@
#include "main.h"
#include "targets.h"


#ifndef ADC_H_
#define ADC_H_



void ADC_DMA_Callback();
void enableADC_DMA();
void activateADC();
void ADC_Init(void);

void Configure_DMA();

void Configure_ADC();

void Activate_ADC();


#endif /* ADC_H_ */
11 changes: 4 additions & 7 deletions Mcu/l431/Inc/IO.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#endif /* IO_H_ */


#include "main.h"

void changeToOutput();
Expand All @@ -24,14 +25,10 @@ void setInputPullUp();
void enableHalfTransferInt();
void setInputPullNone();

extern char bi_direction;

extern char inputSet;
extern char dshot;
extern char servoPwm;
extern char send_telemetry;
extern uint8_t degrees_celsius;

extern uint16_t ADC_raw_volts;
extern uint16_t servo_low_threshold; // anything below this point considered 0
extern uint16_t
servo_high_threshold; // anything above this point considered 2000 (max)
extern uint16_t servo_neutral;
extern uint8_t servo_dead_band;
7 changes: 3 additions & 4 deletions Mcu/l431/Inc/comparator.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@

#ifndef COMPARATOR_H_
#define COMPARATOR_H_
#endif /* COMPARATOR_H_ */

#define COMP_PA0 0b1100001
#define COMP_PA4 0b1000001
#define COMP_PA5 0b1010001


#endif /* COMPARATOR_H_ */

#include "main.h"

Expand Down
13 changes: 8 additions & 5 deletions Mcu/l431/Inc/eeprom.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
#ifndef INC_EEPROM_H_
#define INC_EEPROM_H_



#endif /* INC_BOOTLOADER_H_ */

// void save_to_flash(uint8_t *data);
// void read_flash(uint8_t* data, uint32_t address);
// void save_to_flash_bin(uint8_t *data, int length, uint32_t add);
void read_flash_bin(uint8_t* data, uint32_t add, int out_buff_len);
void save_flash_nolib(uint8_t* data, int length, uint32_t add);

//void save_to_flash(uint8_t *data);
//void read_flash(uint8_t* data, uint32_t address);
//void save_to_flash_bin(uint8_t *data, int length, uint32_t add);
void read_flash_bin(uint8_t* data , uint32_t add ,int out_buff_len);
void save_flash_nolib(uint8_t *data, int length, uint32_t add);
83 changes: 28 additions & 55 deletions Mcu/l431/Inc/main.h
Original file line number Diff line number Diff line change
@@ -1,106 +1,80 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.h
* @brief : Header for main.c file.
* This file contains the common defines of the application.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
******************************************************************************
* @file : main.h
* @brief : Header for main.c file.
* This file contains the common defines of the application.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* USER CODE END Header */

/* Define to prevent recursive inclusion
* -------------------------------------*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MAIN_H
#define __MAIN_H

#ifdef __cplusplus
extern "C" {
#endif

/* Includes
* ------------------------------------------------------------------*/
/* Includes ------------------------------------------------------------------*/
#include "stm32l4xx_ll_adc.h"
#include "stm32l4xx_ll_comp.h"
#include "stm32l4xx_ll_exti.h"
#include "stm32l4xx_ll_dma.h"
#include "stm32l4xx_ll_crs.h"
#include "stm32l4xx_ll_iwdg.h"
#include "stm32l4xx_ll_rcc.h"
#include "stm32l4xx_ll_bus.h"
#include "stm32l4xx_ll_system.h"
#include "stm32l4xx_ll_cortex.h"
#include "stm32l4xx_ll_utils.h"
#include "stm32l4xx_ll_pwr.h"
#include "stm32l4xx_ll_tim.h"
#include "stm32l4xx_ll_usart.h"
#include "stm32l4xx_ll_gpio.h"
#include "stm32l4xx_ll_iwdg.h"
#include "stm32l4xx_ll_usart.h"

#if defined(USE_FULL_ASSERT)
#include "stm32_assert.h"
#endif /* USE_FULL_ASSERT */

/* Private includes
* ----------------------------------------------------------*/
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* Exported types
* ------------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */

/* USER CODE END ET */

/* Exported constants
* --------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */

/* USER CODE END EC */

/* Exported macro
* ------------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */

/* USER CODE END EM */

/* Exported functions prototypes
* ---------------------------------------------*/
/* Exported functions prototypes ---------------------------------------------*/
void Error_Handler(void);

/* USER CODE BEGIN EFP */

/* USER CODE END EFP */

/* Private defines
* -----------------------------------------------------------*/
#ifndef NVIC_PRIORITYGROUP_0
#define NVIC_PRIORITYGROUP_0 \
((uint32_t)0x00000007) /*!< 0 bit for pre-emption priority, \
4 bits for subpriority */
#define NVIC_PRIORITYGROUP_1 \
((uint32_t)0x00000006) /*!< 1 bit for pre-emption priority, \
3 bits for subpriority */
#define NVIC_PRIORITYGROUP_2 \
((uint32_t)0x00000005) /*!< 2 bits for pre-emption priority, \
2 bits for subpriority */
#define NVIC_PRIORITYGROUP_3 \
((uint32_t)0x00000004) /*!< 3 bits for pre-emption priority, \
1 bit for subpriority */
#define NVIC_PRIORITYGROUP_4 \
((uint32_t)0x00000003) /*!< 4 bits for pre-emption priority, \
0 bit for subpriority */
#endif
/* Private defines -----------------------------------------------------------*/
/* USER CODE BEGIN Private defines */

/* USER CODE END Private defines */
Expand All @@ -111,5 +85,4 @@ void Error_Handler(void);

#endif /* __MAIN_H */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF
* FILE****/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
28 changes: 10 additions & 18 deletions Mcu/l431/Inc/peripherals.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
#ifndef PERIPHERALS_H_
#define PERIPHERALS_H_



#endif /* PERIPHERALS_H_ */

#include "ADC.h"
#include "main.h"

#define INTERVAL_TIMER_COUNT (INTERVAL_TIMER->CNT)
Expand All @@ -30,30 +33,19 @@ void initCorePeripherals(void);
void SystemClock_Config(void);
void MX_GPIO_Init(void);
void MX_DMA_Init(void);
// static void MX_ADC_Init(void);
void MX_COMP1_Init(void);
void MX_ADC1_Init(void);
void MX_COMP2_Init(void);
void MX_TIM1_Init(void);
void MX_TIM2_Init(void);
void MX_IWDG_Init(void);
void MX_TIM15_Init(void);
void MX_TIM16_Init(void);
void MX_TIM14_Init(void);
void MX_TIM6_Init(void);
void MX_TIM7_Init(void);
// static void MX_USART1_UART_Init(void);
void disableComTimerInt(void);
void enableComTimerInt(void);
void setAndEnableComInt(uint16_t time);
uint16_t getintervaTimerCount();
void setintervaTimerCount(uint16_t intertime);
void setAutoReloadPWM(uint16_t relval);
void setDutyCycleAll(uint16_t newdc);
void MX_TIM6_Init(void);
void MX_IWDG_Init(void);

void resetInputCaptureTimer();
void setPWMCompare1(uint16_t compareone);
void setPWMCompare2(uint16_t comparetwo);
void setPWMCompare3(uint16_t comparethree);
void enableCorePeripherals(void);
void reloadWatchDogCounter(void);
void generatePwmTimerEvent(void);
void UN_TIM_Init(void);
void LED_GPIO_init(void);
void setPrescalerPWM(uint16_t presc);
void generatePwmTimerEvent(void);
2 changes: 1 addition & 1 deletion Mcu/l431/Inc/phaseouts.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "main.h"

void allOff();
void comStep(char newStep);
void comStep(int newStep);
void fullBrake();
void allpwm();
void proportionalBrake();
Expand Down
Loading

0 comments on commit 181119e

Please sign in to comment.