Merge branch 'develop' into RF
# Conflicts: # MDK-ARM/Project.uvoptx # MDK-ARM/Project.uvprojx # Src/main.c
This commit is contained in:
commit
b8e0d2bcd8
5 changed files with 216 additions and 4 deletions
|
@ -1,8 +1,7 @@
|
|||
#ifndef MYPWM_H
|
||||
#define MYPWM_H
|
||||
#ifndef PWM_H
|
||||
#define PWM_H
|
||||
|
||||
#include "stm32f1xx_ll_bus.h" // Pour l'activation des horloges
|
||||
#include "stm32f1xx_ll_tim.h"
|
||||
#include "stm32f103xb.h"
|
||||
|
||||
|
||||
void MyPWM_Conf_Output(TIM_TypeDef * Timer, int channel);
|
||||
|
|
71
MyDrivers/MyUSART.c
Normal file
71
MyDrivers/MyUSART.c
Normal file
|
@ -0,0 +1,71 @@
|
|||
#include "MyUSART.h"
|
||||
#include "stm32f1xx_ll_bus.h" // Pour l'activation des horloges
|
||||
#include "stm32f1xx_ll_usart.h"
|
||||
|
||||
|
||||
/**
|
||||
* @brief Active l'horloge et règle les paramètres de transmission
|
||||
* @note Fonction à lancer avant toute autre.
|
||||
* @param USART_TypeDef UsDollar : indique le usart à utiliser par le uC, USART1, USART2 ou USART3
|
||||
* @retval None
|
||||
*/
|
||||
void MyUSART_Conf(USART_TypeDef * USART, int TransferDir)
|
||||
{
|
||||
LL_USART_InitTypeDef My_LL_USART_Init_Struct;
|
||||
LL_USART_ClockInitTypeDef My_LL_USART_Clock;
|
||||
|
||||
// Validation horloge locale
|
||||
if (USART==USART1) LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1);
|
||||
else if (USART==USART2) LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_USART2);
|
||||
else LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_USART3);
|
||||
|
||||
//Activation clk de l'USART en entrée et sortie
|
||||
LL_USART_ClockStructInit(&My_LL_USART_Clock);
|
||||
My_LL_USART_Clock.ClockOutput = LL_USART_CLOCK_ENABLE;
|
||||
LL_USART_ClockInit(USART, &My_LL_USART_Clock);
|
||||
|
||||
//Initialisation de l'USART
|
||||
LL_USART_StructInit(&My_LL_USART_Init_Struct);
|
||||
|
||||
//My_LL_USART_Init_Struct.TransferDirection = TransferDir;
|
||||
|
||||
LL_USART_Init(USART, &My_LL_USART_Init_Struct);
|
||||
|
||||
LL_USART_Enable(USART);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Autorise les interruptions de TXE
|
||||
* @note
|
||||
* @param USART_TypeDef UsDollar : indique le usart à utiliser par le uC, USART1, USART2 ou USART3
|
||||
* @retval None
|
||||
*/
|
||||
void MyUSART_IT_Enable(USART_TypeDef * USART)
|
||||
{
|
||||
LL_USART_EnableIT_TXE(USART);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Interdit les interruptions de TXE
|
||||
* @note
|
||||
* @param USART_TypeDef UsDollar : indique le usart à utiliser par le uC, USART1, USART2 ou USART3
|
||||
* @retval None
|
||||
*/
|
||||
void MyUSART_IT_Disable(USART_TypeDef * USART)
|
||||
{
|
||||
LL_USART_DisableIT_TXE(USART);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Transmet 8bits de donnée
|
||||
* @note
|
||||
* @param USART_TypeDef UsDollar : indique le usart à utiliser par le uC, USART1, USART2 ou USART3
|
||||
* @retval None
|
||||
*/
|
||||
void MyUSART_Transmit_Data_8b(USART_TypeDef * USART, int data)
|
||||
{
|
||||
LL_USART_TransmitData8(USART, data);
|
||||
while (LL_USART_IsActiveFlag_TC(USART) != 1){}
|
||||
}
|
44
MyDrivers/MyUSART.h
Normal file
44
MyDrivers/MyUSART.h
Normal file
|
@ -0,0 +1,44 @@
|
|||
#ifndef MY_USART_H
|
||||
#define MY_USART_H
|
||||
|
||||
/*
|
||||
Driver pour USART 1 à 3 du STM32F103RB
|
||||
|
||||
*/
|
||||
|
||||
#include "stm32f103xb.h"
|
||||
|
||||
/**
|
||||
* @brief Active l'horloge et règle les paramètres de transmission
|
||||
* @note Fonction à lancer avant toute autre.
|
||||
* @param USART_TypeDef UsDollar : indique le usart à utiliser par le uC, USART1, USART2 ou USART3
|
||||
* @retval None
|
||||
*/
|
||||
void MyUSART_Conf(USART_TypeDef * USART, int TransferDir);
|
||||
|
||||
/**
|
||||
* @brief Autorise les interruptions de TXE
|
||||
* @note
|
||||
* @param USART_TypeDef UsDollar : indique le usart à utiliser par le uC, USART1, USART2 ou USART3
|
||||
* @retval None
|
||||
*/
|
||||
void MyUSART_IT_Enable(USART_TypeDef * USART);
|
||||
|
||||
/**
|
||||
* @brief Interdit les interruptions de TXE
|
||||
* @note
|
||||
* @param USART_TypeDef UsDollar : indique le usart à utiliser par le uC, USART1, USART2 ou USART3
|
||||
* @retval None
|
||||
*/
|
||||
void MyUSART_IT_Disable(USART_TypeDef * USART);
|
||||
|
||||
/**
|
||||
* @brief Transmet 8bits de donnée
|
||||
* @note
|
||||
* @param USART_TypeDef UsDollar : indique le usart à utiliser par le uC, USART1, USART2 ou USART3
|
||||
* @retval None
|
||||
*/
|
||||
void MyUSART_Transmit_Data_8b(USART_TypeDef * USART, int data);
|
||||
|
||||
|
||||
#endif
|
80
Services/Moteur.c
Normal file
80
Services/Moteur.c
Normal file
|
@ -0,0 +1,80 @@
|
|||
|
||||
#include "Moteur.h"
|
||||
#include "MyPWM.h"
|
||||
#include "MyTimer.h"
|
||||
|
||||
#include "stm32f1xx_ll_bus.h"
|
||||
#include "stm32f1xx_ll_gpio.h"
|
||||
#include "stm32f1xx_ll_tim.h"
|
||||
|
||||
|
||||
void Moteur_Conf(void) {
|
||||
|
||||
//Fpwm = 10kHz = 72Mhz/(7200 = 0x1C20)
|
||||
int Arr = 0x1C1F;
|
||||
int Psc = 0x0;
|
||||
|
||||
//Activation horloge GPIO
|
||||
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA);
|
||||
|
||||
//Config broche PA2 -> Sens
|
||||
LL_GPIO_InitTypeDef My_GPIO_Init_Struct;
|
||||
|
||||
LL_GPIO_StructInit(&My_GPIO_Init_Struct);
|
||||
|
||||
My_GPIO_Init_Struct.Pin = PinSens;
|
||||
My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_OUTPUT;
|
||||
My_GPIO_Init_Struct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
||||
|
||||
LL_GPIO_Init(GPIOPins, &My_GPIO_Init_Struct);
|
||||
|
||||
//Config broche PA1 -> PWM
|
||||
LL_GPIO_StructInit(&My_GPIO_Init_Struct);
|
||||
|
||||
My_GPIO_Init_Struct.Pin = LL_GPIO_PIN_1;
|
||||
My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_ALTERNATE;
|
||||
My_GPIO_Init_Struct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
||||
|
||||
LL_GPIO_Init(GPIOA, &My_GPIO_Init_Struct);
|
||||
|
||||
|
||||
|
||||
//Activation horloge Timer
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2);
|
||||
|
||||
//Configuration initiale du Timer
|
||||
MyTimer_Conf(TimerPWM, Arr, Psc);
|
||||
//Configuration du Timer en PWM Output
|
||||
MyPWM_Conf_Output(TimerPWM, channelPWM);
|
||||
|
||||
Moteur_Speed(0);
|
||||
Moteur_Sens(0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Moteur_Speed(int speedPercentage) {
|
||||
int Arr = 0x1C1F;
|
||||
|
||||
if(speedPercentage == 0) {
|
||||
MyTimer_Stop(TimerPWM);
|
||||
}
|
||||
else {
|
||||
MyTimer_Start(TimerPWM);
|
||||
MyPWM_Set_Impulse_Duration(TimerPWM, Arr*speedPercentage/100, channelPWM);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Moteur_Sens(int sens) {
|
||||
|
||||
if(sens == 0) {
|
||||
LL_GPIO_ResetOutputPin(GPIOPins, PinSens);
|
||||
}
|
||||
else {
|
||||
LL_GPIO_SetOutputPin(GPIOPins, PinSens);
|
||||
}
|
||||
|
||||
}
|
18
Services/Moteur.h
Normal file
18
Services/Moteur.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
#ifndef MOTEUR_H
|
||||
#define MOTEUR_H
|
||||
|
||||
#include "stm32f103xb.h"
|
||||
|
||||
#define PinSens LL_GPIO_PIN_2
|
||||
#define PinPWM LL_GPIO_PIN_1
|
||||
#define GPIOPins GPIOA
|
||||
#define TimerPWM TIM2
|
||||
#define channelPWM LL_TIM_CHANNEL_CH2
|
||||
|
||||
void Moteur_Conf(void);
|
||||
|
||||
void Moteur_Speed(int speedPercentage);
|
||||
|
||||
void Moteur_Sens(int sens);
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue