Browse Source

Merge branch 'develop' into RF

# Conflicts:
#	MDK-ARM/Project.uvoptx
#	MDK-ARM/Project.uvprojx
#	Src/main.c
Neluji 3 years ago
parent
commit
b8e0d2bcd8
5 changed files with 216 additions and 4 deletions
  1. 3
    4
      MyDrivers/MyPWM.h
  2. 71
    0
      MyDrivers/MyUSART.c
  3. 44
    0
      MyDrivers/MyUSART.h
  4. 80
    0
      Services/Moteur.c
  5. 18
    0
      Services/Moteur.h

+ 3
- 4
MyDrivers/MyPWM.h View File

@@ -1,8 +1,7 @@
1
-#ifndef MYPWM_H
2
-#define MYPWM_H
1
+#ifndef PWM_H
2
+#define PWM_H
3 3
 
4
-#include "stm32f1xx_ll_bus.h" // Pour l'activation des horloges
5
-#include "stm32f1xx_ll_tim.h"
4
+#include "stm32f103xb.h"
6 5
 
7 6
 
8 7
 void MyPWM_Conf_Output(TIM_TypeDef * Timer, int channel);

+ 71
- 0
MyDrivers/MyUSART.c View File

@@ -0,0 +1,71 @@
1
+#include "MyUSART.h"
2
+#include "stm32f1xx_ll_bus.h" // Pour l'activation des horloges
3
+#include "stm32f1xx_ll_usart.h"
4
+
5
+
6
+/**
7
+	* @brief  Active l'horloge et règle les paramètres de transmission
8
+  * @note   Fonction à lancer avant toute autre.
9
+	* @param  USART_TypeDef UsDollar : indique le usart à utiliser par le uC, USART1, USART2 ou USART3
10
+  * @retval None
11
+  */
12
+void MyUSART_Conf(USART_TypeDef * USART, int TransferDir)
13
+{
14
+	LL_USART_InitTypeDef My_LL_USART_Init_Struct;
15
+	LL_USART_ClockInitTypeDef My_LL_USART_Clock;
16
+	
17
+	// Validation horloge locale
18
+	if (USART==USART1) LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1);
19
+	else if (USART==USART2) LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_USART2);
20
+	else LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_USART3);
21
+	
22
+	//Activation clk de l'USART en entrée et sortie
23
+	LL_USART_ClockStructInit(&My_LL_USART_Clock);
24
+	My_LL_USART_Clock.ClockOutput = LL_USART_CLOCK_ENABLE;
25
+	LL_USART_ClockInit(USART, &My_LL_USART_Clock);
26
+	
27
+	//Initialisation de l'USART
28
+	LL_USART_StructInit(&My_LL_USART_Init_Struct);
29
+	
30
+	//My_LL_USART_Init_Struct.TransferDirection = TransferDir;
31
+	
32
+	LL_USART_Init(USART, &My_LL_USART_Init_Struct);
33
+	
34
+	LL_USART_Enable(USART);
35
+}
36
+
37
+/**
38
+	* @brief  Autorise les interruptions de TXE
39
+  * @note   
40
+	* @param  USART_TypeDef UsDollar : indique le usart à utiliser par le uC, USART1, USART2 ou USART3
41
+  * @retval None
42
+  */
43
+void MyUSART_IT_Enable(USART_TypeDef * USART)
44
+{
45
+	LL_USART_EnableIT_TXE(USART);
46
+}
47
+
48
+
49
+/**
50
+	* @brief  Interdit les interruptions de TXE
51
+  * @note   
52
+	* @param  USART_TypeDef UsDollar : indique le usart à utiliser par le uC, USART1, USART2 ou USART3
53
+  * @retval None
54
+  */
55
+void MyUSART_IT_Disable(USART_TypeDef * USART)
56
+{
57
+	LL_USART_DisableIT_TXE(USART);
58
+}
59
+
60
+
61
+/**
62
+	* @brief  Transmet 8bits de donnée
63
+  * @note   
64
+	* @param  USART_TypeDef UsDollar : indique le usart à utiliser par le uC, USART1, USART2 ou USART3
65
+  * @retval None
66
+  */
67
+void MyUSART_Transmit_Data_8b(USART_TypeDef * USART, int data)
68
+{
69
+	LL_USART_TransmitData8(USART, data);
70
+	while (LL_USART_IsActiveFlag_TC(USART) != 1){}
71
+}

+ 44
- 0
MyDrivers/MyUSART.h View File

@@ -0,0 +1,44 @@
1
+#ifndef MY_USART_H
2
+#define MY_USART_H
3
+
4
+/*
5
+Driver pour USART 1 à 3 du STM32F103RB
6
+
7
+*/
8
+
9
+#include "stm32f103xb.h"
10
+
11
+/**
12
+	* @brief  Active l'horloge et règle les paramètres de transmission
13
+  * @note   Fonction à lancer avant toute autre.
14
+	* @param  USART_TypeDef UsDollar : indique le usart à utiliser par le uC, USART1, USART2 ou USART3
15
+  * @retval None
16
+  */
17
+void MyUSART_Conf(USART_TypeDef * USART, int TransferDir);
18
+
19
+/**
20
+	* @brief  Autorise les interruptions de TXE
21
+  * @note   
22
+	* @param  USART_TypeDef UsDollar : indique le usart à utiliser par le uC, USART1, USART2 ou USART3
23
+  * @retval None
24
+  */
25
+void MyUSART_IT_Enable(USART_TypeDef * USART);
26
+
27
+/**
28
+	* @brief  Interdit les interruptions de TXE
29
+  * @note   
30
+	* @param  USART_TypeDef UsDollar : indique le usart à utiliser par le uC, USART1, USART2 ou USART3
31
+  * @retval None
32
+  */
33
+void MyUSART_IT_Disable(USART_TypeDef * USART);
34
+
35
+/**
36
+	* @brief  Transmet 8bits de donnée
37
+  * @note   
38
+	* @param  USART_TypeDef UsDollar : indique le usart à utiliser par le uC, USART1, USART2 ou USART3
39
+  * @retval None
40
+  */
41
+void MyUSART_Transmit_Data_8b(USART_TypeDef * USART, int data);
42
+
43
+
44
+#endif

+ 80
- 0
Services/Moteur.c View File

@@ -0,0 +1,80 @@
1
+
2
+#include "Moteur.h"
3
+#include "MyPWM.h"
4
+#include "MyTimer.h"
5
+
6
+#include "stm32f1xx_ll_bus.h"
7
+#include "stm32f1xx_ll_gpio.h"
8
+#include "stm32f1xx_ll_tim.h"
9
+
10
+
11
+void Moteur_Conf(void) {
12
+	
13
+	//Fpwm = 10kHz = 72Mhz/(7200 = 0x1C20)
14
+	int Arr = 0x1C1F;
15
+	int Psc = 0x0;
16
+	
17
+	//Activation horloge GPIO
18
+	LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA);
19
+	
20
+	//Config broche PA2 -> Sens
21
+	LL_GPIO_InitTypeDef My_GPIO_Init_Struct;
22
+	
23
+	LL_GPIO_StructInit(&My_GPIO_Init_Struct);
24
+	
25
+	My_GPIO_Init_Struct.Pin = PinSens;
26
+	My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_OUTPUT;
27
+	My_GPIO_Init_Struct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
28
+	
29
+	LL_GPIO_Init(GPIOPins, &My_GPIO_Init_Struct);
30
+	
31
+	//Config broche PA1 -> PWM
32
+	LL_GPIO_StructInit(&My_GPIO_Init_Struct);
33
+	
34
+	My_GPIO_Init_Struct.Pin = LL_GPIO_PIN_1;
35
+	My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_ALTERNATE;
36
+	My_GPIO_Init_Struct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
37
+	
38
+	LL_GPIO_Init(GPIOA, &My_GPIO_Init_Struct);
39
+	
40
+	
41
+	
42
+	//Activation horloge Timer
43
+	LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2);
44
+	
45
+	//Configuration initiale du Timer
46
+	MyTimer_Conf(TimerPWM, Arr, Psc);
47
+	//Configuration du Timer en PWM Output
48
+	MyPWM_Conf_Output(TimerPWM, channelPWM);
49
+	
50
+	Moteur_Speed(0);
51
+	Moteur_Sens(0);
52
+	
53
+}
54
+
55
+
56
+
57
+void Moteur_Speed(int speedPercentage) {
58
+	int Arr = 0x1C1F;
59
+	
60
+	if(speedPercentage == 0) {
61
+		MyTimer_Stop(TimerPWM);
62
+	}
63
+	else {
64
+		MyTimer_Start(TimerPWM);
65
+		MyPWM_Set_Impulse_Duration(TimerPWM, Arr*speedPercentage/100, channelPWM);
66
+	}
67
+	
68
+}
69
+
70
+
71
+void Moteur_Sens(int sens) {
72
+	
73
+	if(sens == 0) {
74
+		LL_GPIO_ResetOutputPin(GPIOPins, PinSens);
75
+	}
76
+	else {
77
+		LL_GPIO_SetOutputPin(GPIOPins, PinSens);
78
+	}
79
+	
80
+}

+ 18
- 0
Services/Moteur.h View File

@@ -0,0 +1,18 @@
1
+#ifndef MOTEUR_H
2
+#define MOTEUR_H
3
+
4
+#include "stm32f103xb.h" 
5
+
6
+#define PinSens LL_GPIO_PIN_2
7
+#define PinPWM LL_GPIO_PIN_1
8
+#define GPIOPins GPIOA
9
+#define TimerPWM TIM2
10
+#define channelPWM LL_TIM_CHANNEL_CH2
11
+
12
+void Moteur_Conf(void);
13
+
14
+void Moteur_Speed(int speedPercentage);
15
+
16
+void Moteur_Sens(int sens);
17
+
18
+#endif

Loading…
Cancel
Save