From fff46d3a159ed37373d603546a2aa13af62ae62a Mon Sep 17 00:00:00 2001
From: Neluji <38362829+Neluji@users.noreply.github.com>
Date: Wed, 4 Nov 2020 09:27:31 +0100
Subject: [PATCH 1/5] USART init
---
MyDrivers/MyUSART.c | 63 +++++++++++++++++++++++++++++++++++++++++++++
MyDrivers/MyUSART.h | 44 +++++++++++++++++++++++++++++++
2 files changed, 107 insertions(+)
create mode 100644 MyDrivers/MyUSART.c
create mode 100644 MyDrivers/MyUSART.h
diff --git a/MyDrivers/MyUSART.c b/MyDrivers/MyUSART.c
new file mode 100644
index 0000000..57caff4
--- /dev/null
+++ b/MyDrivers/MyUSART.c
@@ -0,0 +1,63 @@
+#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;
+
+ // 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);
+
+ //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);
+
+}
+
+/**
+ * @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);
+}
diff --git a/MyDrivers/MyUSART.h b/MyDrivers/MyUSART.h
new file mode 100644
index 0000000..691a3b3
--- /dev/null
+++ b/MyDrivers/MyUSART.h
@@ -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
From 506c51938668361fd3322595a9ea2b12e4f6e14d Mon Sep 17 00:00:00 2001
From: Neluji <38362829+Neluji@users.noreply.github.com>
Date: Tue, 17 Nov 2020 10:09:04 +0100
Subject: [PATCH 2/5] Moteur_conf(), moteur_speed() et moteur_sens()
---
MDK-ARM/Project.uvoptx | 36 ++++++++++++++-------
MDK-ARM/Project.uvprojx | 14 ++++++++
Services/Moteur.c | 72 +++++++++++++++++++++++++++++++++++++++++
Services/Moteur.h | 6 ++++
Src/main.c | 1 +
5 files changed, 117 insertions(+), 12 deletions(-)
create mode 100644 Services/Moteur.c
create mode 100644 Services/Moteur.h
diff --git a/MDK-ARM/Project.uvoptx b/MDK-ARM/Project.uvoptx
index fc20bbe..633b71e 100644
--- a/MDK-ARM/Project.uvoptx
+++ b/MDK-ARM/Project.uvoptx
@@ -461,6 +461,18 @@
0
0
0
+
+ 2
+ 2
+ 1
+ 1
+ 0
+ 0
+ ..\Services\Moteur.c
+ Moteur.c
+ 0
+ 0
+
@@ -471,9 +483,9 @@
0
3
- 2
+ 3
1
- 1
+ 0
0
0
..\MyDrivers\MyTimer.c
@@ -483,9 +495,9 @@
3
- 3
+ 4
1
- 1
+ 0
0
0
..\MyDrivers\MyPWM.c
@@ -503,7 +515,7 @@
0
4
- 4
+ 5
1
0
0
@@ -515,7 +527,7 @@
4
- 5
+ 6
1
0
0
@@ -527,7 +539,7 @@
4
- 6
+ 7
1
0
0
@@ -539,7 +551,7 @@
4
- 7
+ 8
1
0
0
@@ -551,7 +563,7 @@
4
- 8
+ 9
1
0
0
@@ -571,7 +583,7 @@
0
5
- 9
+ 10
5
0
0
@@ -591,7 +603,7 @@
0
6
- 10
+ 11
1
0
0
@@ -611,7 +623,7 @@
0
7
- 11
+ 12
2
0
0
diff --git a/MDK-ARM/Project.uvprojx b/MDK-ARM/Project.uvprojx
index 8a6b949..59049c2 100644
--- a/MDK-ARM/Project.uvprojx
+++ b/MDK-ARM/Project.uvprojx
@@ -391,6 +391,13 @@
User Services
+
+
+ Moteur.c
+ 1
+ ..\Services\Moteur.c
+
+
MyDrivers
@@ -857,6 +864,13 @@
User Services
+
+
+ Moteur.c
+ 1
+ ..\Services\Moteur.c
+
+
MyDrivers
diff --git a/Services/Moteur.c b/Services/Moteur.c
new file mode 100644
index 0000000..69e5ca8
--- /dev/null
+++ b/Services/Moteur.c
@@ -0,0 +1,72 @@
+#include "Moteur.h"
+#include "MyPWM.h"
+#include "MyTimer.h"
+
+#include "stm32f1xx_ll_bus.h"
+#include "stm32f1xx_ll_gpio.h"
+
+//Fpwm = 10kHz
+static int Arr = 0x1C1F;
+static int Psc = 0x0;
+
+void Moteur_Conf() {
+
+ //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 = PinPWM;
+ My_GPIO_Init_Struct->Mode = LL_GPIO_MODE_ALTERNATE;
+ My_GPIO_Init_Struct->OutputType = LL_GPIO_OUTPUT_PUSHPULL;
+
+ LL_GPIO_Init(GPIOPins, 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);
+ MyPWM_Set_Impulse_Duration(TimerPWM, 0, channelPWM);
+
+}
+
+
+
+void Moteur_Speed(int speedPercentage) {
+
+ 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);
+ }
+
+}
\ No newline at end of file
diff --git a/Services/Moteur.h b/Services/Moteur.h
new file mode 100644
index 0000000..f49a42c
--- /dev/null
+++ b/Services/Moteur.h
@@ -0,0 +1,6 @@
+
+#define PinSens LL_GPIO_PIN_2
+#define PinPWM LL_GPIO_PIN_1
+#define GPIOPins GPIOA
+#define TimerPWM TIM2
+#define channelPWM LL_TIM_CHANNEL_CH2
diff --git a/Src/main.c b/Src/main.c
index a621f57..519f827 100644
--- a/Src/main.c
+++ b/Src/main.c
@@ -22,6 +22,7 @@
#include "stm32f1xx_ll_gpio.h"
#include "MyTimer.h"
#include "MyPWM.h"
+#include "Moteur.h"
void SystemClock_Config(void);
From 7e745ca4f9741f38af83fbf1c8664e4f8dfe8a37 Mon Sep 17 00:00:00 2001
From: Neluji <38362829+Neluji@users.noreply.github.com>
Date: Tue, 17 Nov 2020 11:09:17 +0100
Subject: [PATCH 3/5] =?UTF-8?q?Fin=20s=C3=A9ance=2010=20->=20pb=20conf=20g?=
=?UTF-8?q?pio?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
MDK-ARM/Project.uvoptx | 56 +++++++++++++++++++++++++++++++-----------
Services/Moteur.c | 21 +++++++++-------
Services/Moteur.h | 6 +++++
Services/services.txt | 1 -
Src/main.c | 50 ++++---------------------------------
5 files changed, 65 insertions(+), 69 deletions(-)
delete mode 100644 Services/services.txt
diff --git a/MDK-ARM/Project.uvoptx b/MDK-ARM/Project.uvoptx
index 633b71e..6c5132a 100644
--- a/MDK-ARM/Project.uvoptx
+++ b/MDK-ARM/Project.uvoptx
@@ -305,7 +305,7 @@
- ..\..\inifiles\Simu_Pulse.ini
+
@@ -317,7 +317,7 @@
0
DLGDARM
- (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(100=504,37,1150,710,0)(110=60,88,280,548,0)(111=752,104,972,564,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=533,85,954,512,0)(121=892,96,1313,523,0)(122=674,103,1095,530,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=-1,-1,-1,-1,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=709,11,1303,762,0)(131=150,13,744,764,0)(132=599,17,1193,768,0)(133=-1,-1,-1,-1,0)(160=-1,-1,-1,-1,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(234=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=-1,-1,-1,-1,0)(151=-1,-1,-1,-1,0)
+ (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(100=504,37,1150,710,0)(110=60,88,280,548,0)(111=752,104,972,564,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=864,64,1285,491,0)(121=892,96,1313,523,0)(122=674,103,1095,530,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=-1,-1,-1,-1,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=709,11,1303,762,0)(131=736,17,1330,768,0)(132=599,17,1193,768,0)(133=295,17,889,768,0)(160=-1,-1,-1,-1,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(234=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=-1,-1,-1,-1,0)(151=-1,-1,-1,-1,0)
0
@@ -350,7 +350,40 @@
-U-O142 -O2254 -S0 -C0 -A0 -N00("ARM CoreSight SW-DP") -D00(1BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC800 -FN1 -FF0STM32F10x_128.FLM -FS08000000 -FL020000 -FP0($$Device:STM32F103RB$Flash\STM32F10x_128.FLM)
-
+
+
+ 0
+ 0
+ 38
+ 1
+ 134219162
+ 0
+ 0
+ 0
+ 0
+ 0
+ 1
+ F:\Etudes\4A\µC - Périphériques\Periph-Voilier\Services\Moteur.c
+
+ \\NUCLEO_F103RB\../Services/Moteur.c\38
+
+
+ 1
+ 0
+ 26
+ 1
+ 134219126
+ 0
+ 0
+ 0
+ 0
+ 0
+ 1
+ F:\Etudes\4A\µC - Périphériques\Periph-Voilier\Services\Moteur.c
+
+ \\NUCLEO_F103RB\../Services/Moteur.c\26
+
+
0
@@ -362,7 +395,7 @@
1
0
- porta
+ Psc
0
@@ -411,18 +444,13 @@
0
- ((porta & 0x00000080) >> 7 & 0x80) >> 7
- 00800000000000000000000000000000E0FFEF400100000000000000000000000000000028706F7274612026203078303030303030383029203E3E2037000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000001000000CDCCCCCCCCCCD43F1800000000000000000000000000000000000000540E0008
+ ((porta & 0x00000002) >> 1 & 0x2) >> 1
+ 00800000000000000000000000000000E0FFEF400100000000000000000000000000000028706F7274612026203078303030303030303229203E3E2031000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000001000000000000000000E03F1800000000000000000000000000000000000000320F0008
1
- (porta & 0x00000001)
- 00000000000000000000000000000000E0FFEF400100000000000000000000000000000028706F72746120262030783030303030303031290000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000002000000000000000000D43F1800000000000000000000000000000000000000E20E0008
-
-
- 2
- ((portb & 0x00000040) >> 6 & 0x40) >> 6
- 00008000000000000000000000000000E0FFEF400000000000000000000000000000000028706F7274622026203078303030303030343029203E3E2036000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000003000000333333333333D73F1800000000000000000000000000000000000000440E0008
+ ((porta & 0x00000004) >> 2 & 0x4) >> 2
+ 00008000000000000000000000000000E0FFEF400100000000000000000000000000000028706F7274612026203078303030303030303429203E3E2032000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000002000000000000000000E03F1800000000000000000000000000000000000000320F0008
@@ -465,7 +493,7 @@
2
2
1
- 1
+ 0
0
0
..\Services\Moteur.c
diff --git a/Services/Moteur.c b/Services/Moteur.c
index 69e5ca8..3a7e749 100644
--- a/Services/Moteur.c
+++ b/Services/Moteur.c
@@ -6,10 +6,10 @@
#include "stm32f1xx_ll_gpio.h"
//Fpwm = 10kHz
-static int Arr = 0x1C1F;
-static int Psc = 0x0;
-void Moteur_Conf() {
+void Moteur_Conf(void) {
+ int Arr = 0x1C1F;
+ int Psc = 0x0;
//Activation horloge GPIO
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA);
@@ -19,20 +19,20 @@ void Moteur_Conf() {
LL_GPIO_StructInit(My_GPIO_Init_Struct);
- My_GPIO_Init_Struct->Pin = PinSens;
+ My_GPIO_Init_Struct->Pin = LL_GPIO_PIN_2;
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);
+ LL_GPIO_Init(GPIOA, My_GPIO_Init_Struct);
//Config broche PA1 -> PWM
LL_GPIO_StructInit(My_GPIO_Init_Struct);
- My_GPIO_Init_Struct->Pin = PinPWM;
+ 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(GPIOPins, My_GPIO_Init_Struct);
+ LL_GPIO_Init(GPIOA, My_GPIO_Init_Struct);
//Activation horloge Timer
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2);
@@ -41,13 +41,16 @@ void Moteur_Conf() {
MyTimer_Conf(TimerPWM, Arr, Psc);
//Configuration du Timer en PWM Output
MyPWM_Conf_Output(TimerPWM, channelPWM);
- MyPWM_Set_Impulse_Duration(TimerPWM, 0, channelPWM);
+
+ Moteur_Speed(0);
+ Moteur_Sens(0);
}
void Moteur_Speed(int speedPercentage) {
+ int Arr = 0x1C1F;
if(speedPercentage == 0) {
MyTimer_Stop(TimerPWM);
@@ -69,4 +72,4 @@ void Moteur_Sens(int sens) {
LL_GPIO_SetOutputPin(GPIOPins, PinSens);
}
-}
\ No newline at end of file
+}
diff --git a/Services/Moteur.h b/Services/Moteur.h
index f49a42c..69ccaae 100644
--- a/Services/Moteur.h
+++ b/Services/Moteur.h
@@ -4,3 +4,9 @@
#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);
diff --git a/Services/services.txt b/Services/services.txt
deleted file mode 100644
index 1698ef7..0000000
--- a/Services/services.txt
+++ /dev/null
@@ -1 +0,0 @@
-Mettre les services ici
\ No newline at end of file
diff --git a/Src/main.c b/Src/main.c
index 519f827..bf51d3f 100644
--- a/Src/main.c
+++ b/Src/main.c
@@ -40,53 +40,13 @@ int main(void)
/* Configure the system clock to 72 MHz */
SystemClock_Config();
- /*===Test Output===*/
+ /*===Test Moteur===*/
- TIM_TypeDef *Timer1 = TIM3;
- int Channel1 = LL_TIM_CHANNEL_CH2;
- TIM_TypeDef *Timer2 = TIM4;
- int Channel2 = LL_TIM_CHANNEL_CH4;
+ //INIT GPIO MARCHE PAS->PB PIN
+ Moteur_Conf();
- MyTimer_Conf(Timer1,0xFFFE, 0x72);
- MyTimer_Conf(Timer2,0xFFFE, 0x72);
-
- MyPWM_Conf_Output(Timer1, Channel1);
- MyPWM_Conf_Output(Timer2, Channel2);
-
- MyPWM_Set_Impulse_Duration(Timer1, 25, Channel1);
- MyPWM_Set_Impulse_Duration(Timer2, 75, Channel2);
-
- LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA);
- LL_GPIO_InitTypeDef My_GPIO_Init_Struct;
- My_GPIO_Init_Struct.Pin = LL_GPIO_PIN_7;
- My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_ALTERNATE;
- My_GPIO_Init_Struct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
- My_GPIO_Init_Struct.Speed = LL_GPIO_MODE_OUTPUT_2MHz;
- My_GPIO_Init_Struct.Pull = LL_GPIO_PULL_DOWN;
- LL_GPIO_Init(GPIOA, &My_GPIO_Init_Struct);
-
- LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOB);
- My_GPIO_Init_Struct.Pin = LL_GPIO_PIN_9;
- My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_ALTERNATE;
- My_GPIO_Init_Struct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
- My_GPIO_Init_Struct.Speed = LL_GPIO_MODE_OUTPUT_2MHz;
- My_GPIO_Init_Struct.Pull = LL_GPIO_PULL_DOWN;
- LL_GPIO_Init(GPIOB, &My_GPIO_Init_Struct);
-
- My_GPIO_Init_Struct.Pin = LL_GPIO_PIN_0;
- My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_FLOATING;
- My_GPIO_Init_Struct.Pull = LL_GPIO_PULL_DOWN;
- LL_GPIO_Init(GPIOA, &My_GPIO_Init_Struct);
-
- My_GPIO_Init_Struct.Pin = LL_GPIO_PIN_6;
- My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_FLOATING;
- My_GPIO_Init_Struct.Pull = LL_GPIO_PULL_DOWN;
- LL_GPIO_Init(GPIOB, &My_GPIO_Init_Struct);
-
- MyTimer_Start(Timer1);
- MyTimer_Start(Timer2);
-
-
+ Moteur_Speed(50);
+ Moteur_Sens(1);
/* Infinite loop */
while (1)
From 3aa80037769457c3902ffe3ef78c1ceb81ae66fd Mon Sep 17 00:00:00 2001
From: Neluji <38362829+Neluji@users.noreply.github.com>
Date: Sun, 22 Nov 2020 13:05:16 +0100
Subject: [PATCH 4/5] GPIO configuration fixed - Moteur OK
---
MDK-ARM/Project.uvoptx | 28 ++++++----------------------
MyDrivers/MyPWM.h | 8 ++++++--
Services/Moteur.c | 29 +++++++++++++++++------------
Services/Moteur.h | 6 ++++++
Src/main.c | 13 ++++++++++---
5 files changed, 45 insertions(+), 39 deletions(-)
diff --git a/MDK-ARM/Project.uvoptx b/MDK-ARM/Project.uvoptx
index 6c5132a..aa749d9 100644
--- a/MDK-ARM/Project.uvoptx
+++ b/MDK-ARM/Project.uvoptx
@@ -354,9 +354,9 @@
0
0
- 38
+ 25
1
- 134219162
+ 134219120
0
0
0
@@ -365,23 +365,7 @@
1
F:\Etudes\4A\µC - Périphériques\Periph-Voilier\Services\Moteur.c
- \\NUCLEO_F103RB\../Services/Moteur.c\38
-
-
- 1
- 0
- 26
- 1
- 134219126
- 0
- 0
- 0
- 0
- 0
- 1
- F:\Etudes\4A\µC - Périphériques\Periph-Voilier\Services\Moteur.c
-
- \\NUCLEO_F103RB\../Services/Moteur.c\26
+ \\NUCLEO_F103RB\../Services/Moteur.c\25
@@ -395,7 +379,7 @@
1
0
- Psc
+ My_GPIO_Init_Struct
0
@@ -445,12 +429,12 @@
0
((porta & 0x00000002) >> 1 & 0x2) >> 1
- 00800000000000000000000000000000E0FFEF400100000000000000000000000000000028706F7274612026203078303030303030303229203E3E2031000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000001000000000000000000E03F1800000000000000000000000000000000000000320F0008
+ 00800000000000000000000000000000E0FFEF400100000000000000000000000000000028706F7274612026203078303030303030303229203E3E2031000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000001000000000000000000E03F0B00000000000000000000000000000000000000320F0008
1
((porta & 0x00000004) >> 2 & 0x4) >> 2
- 00008000000000000000000000000000E0FFEF400100000000000000000000000000000028706F7274612026203078303030303030303429203E3E2032000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000002000000000000000000E03F1800000000000000000000000000000000000000320F0008
+ 00008000000000000000000000000000E0FFEF400100000000000000000000000000000028706F7274612026203078303030303030303429203E3E2032000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000002000000000000000000E03F0B00000000000000000000000000000000000000320F0008
diff --git a/MyDrivers/MyPWM.h b/MyDrivers/MyPWM.h
index 6702b92..562cb06 100644
--- a/MyDrivers/MyPWM.h
+++ b/MyDrivers/MyPWM.h
@@ -1,5 +1,7 @@
-#include "stm32f1xx_ll_bus.h" // Pour l'activation des horloges
-#include "stm32f1xx_ll_tim.h"
+#ifndef PWM_H
+#define PWM_H
+
+#include "stm32f103xb.h"
void MyPWM_Conf_Output(TIM_TypeDef * Timer, int channel);
@@ -7,3 +9,5 @@ void MyPWM_Conf_Output(TIM_TypeDef * Timer, int channel);
void MyPWM_Conf_Input(TIM_TypeDef * Timer, int channel1, int channel2);
void MyPWM_Set_Impulse_Duration(TIM_TypeDef * Timer, uint32_t CompareValue, int channel);
+
+#endif
diff --git a/Services/Moteur.c b/Services/Moteur.c
index 3a7e749..19640e9 100644
--- a/Services/Moteur.c
+++ b/Services/Moteur.c
@@ -1,13 +1,16 @@
+
#include "Moteur.h"
#include "MyPWM.h"
#include "MyTimer.h"
#include "stm32f1xx_ll_bus.h"
#include "stm32f1xx_ll_gpio.h"
+#include "stm32f1xx_ll_tim.h"
-//Fpwm = 10kHz
void Moteur_Conf(void) {
+
+ //Fpwm = 10kHz = 72Mhz/(7200 = 0x1C20)
int Arr = 0x1C1F;
int Psc = 0x0;
@@ -15,24 +18,26 @@ void Moteur_Conf(void) {
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA);
//Config broche PA2 -> Sens
- LL_GPIO_InitTypeDef* My_GPIO_Init_Struct;
+ LL_GPIO_InitTypeDef My_GPIO_Init_Struct;
- LL_GPIO_StructInit(My_GPIO_Init_Struct);
+ LL_GPIO_StructInit(&My_GPIO_Init_Struct);
- My_GPIO_Init_Struct->Pin = LL_GPIO_PIN_2;
- My_GPIO_Init_Struct->Mode = LL_GPIO_MODE_OUTPUT;
- My_GPIO_Init_Struct->OutputType = LL_GPIO_OUTPUT_PUSHPULL;
+ 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(GPIOA, My_GPIO_Init_Struct);
+ LL_GPIO_Init(GPIOPins, &My_GPIO_Init_Struct);
//Config broche PA1 -> PWM
- LL_GPIO_StructInit(My_GPIO_Init_Struct);
+ 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);
- 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);
diff --git a/Services/Moteur.h b/Services/Moteur.h
index 69ccaae..32cdb88 100644
--- a/Services/Moteur.h
+++ b/Services/Moteur.h
@@ -1,3 +1,7 @@
+#ifndef MOTEUR_H
+#define MOTEUR_H
+
+#include "stm32f103xb.h"
#define PinSens LL_GPIO_PIN_2
#define PinPWM LL_GPIO_PIN_1
@@ -10,3 +14,5 @@ void Moteur_Conf(void);
void Moteur_Speed(int speedPercentage);
void Moteur_Sens(int sens);
+
+#endif
diff --git a/Src/main.c b/Src/main.c
index bf51d3f..64a2b92 100644
--- a/Src/main.c
+++ b/Src/main.c
@@ -45,13 +45,20 @@ int main(void)
//INIT GPIO MARCHE PAS->PB PIN
Moteur_Conf();
- Moteur_Speed(50);
- Moteur_Sens(1);
+ Moteur_Speed(30);
+ Moteur_Sens(0);
/* Infinite loop */
- while (1)
+ for (int i =0; i<0xFFFF; i++)
{
}
+
+ Moteur_Speed(60);
+ Moteur_Sens(1);
+
+ while (1)
+ {
+ }
}
From 1556c5145f09513d7db2cf50124a92c5d226c002 Mon Sep 17 00:00:00 2001
From: Neluji <38362829+Neluji@users.noreply.github.com>
Date: Sun, 22 Nov 2020 18:49:30 +0100
Subject: [PATCH 5/5] Configuration fonct OK
---
MDK-ARM/Project.uvoptx | 32 ++++++++++++++++++++++----------
MDK-ARM/Project.uvprojx | 10 ++++++++++
MyDrivers/MyUSART.c | 10 +++++++++-
3 files changed, 41 insertions(+), 11 deletions(-)
diff --git a/MDK-ARM/Project.uvoptx b/MDK-ARM/Project.uvoptx
index dad60dc..39ec91c 100644
--- a/MDK-ARM/Project.uvoptx
+++ b/MDK-ARM/Project.uvoptx
@@ -420,7 +420,7 @@
1
1
1
- 1
+ 0
0
0
../Src/main.c
@@ -448,7 +448,7 @@
3
2
1
- 1
+ 0
0
0
..\MyDrivers\MyTimer.c
@@ -456,6 +456,18 @@
0
0
+
+ 3
+ 3
+ 1
+ 1
+ 0
+ 0
+ ..\MyDrivers\MyUSART.c
+ MyUSART.c
+ 0
+ 0
+
@@ -466,7 +478,7 @@
0
4
- 3
+ 4
1
0
0
@@ -478,7 +490,7 @@
4
- 4
+ 5
1
0
0
@@ -490,7 +502,7 @@
4
- 5
+ 6
1
0
0
@@ -502,7 +514,7 @@
4
- 6
+ 7
1
0
0
@@ -514,7 +526,7 @@
4
- 7
+ 8
1
0
0
@@ -534,7 +546,7 @@
0
5
- 8
+ 9
5
0
0
@@ -554,7 +566,7 @@
0
6
- 9
+ 10
1
0
0
@@ -574,7 +586,7 @@
0
7
- 10
+ 11
2
0
0
diff --git a/MDK-ARM/Project.uvprojx b/MDK-ARM/Project.uvprojx
index cd43e32..35d72bc 100644
--- a/MDK-ARM/Project.uvprojx
+++ b/MDK-ARM/Project.uvprojx
@@ -400,6 +400,11 @@
1
..\MyDrivers\MyTimer.c
+
+ MyUSART.c
+ 1
+ ..\MyDrivers\MyUSART.c
+
@@ -861,6 +866,11 @@
1
..\MyDrivers\MyTimer.c
+
+ MyUSART.c
+ 1
+ ..\MyDrivers\MyUSART.c
+
diff --git a/MyDrivers/MyUSART.c b/MyDrivers/MyUSART.c
index 57caff4..5a20a14 100644
--- a/MyDrivers/MyUSART.c
+++ b/MyDrivers/MyUSART.c
@@ -12,19 +12,26 @@
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;
+ //My_LL_USART_Init_Struct.TransferDirection = TransferDir;
LL_USART_Init(USART, &My_LL_USART_Init_Struct);
+ LL_USART_Enable(USART);
}
/**
@@ -60,4 +67,5 @@ void MyUSART_IT_Disable(USART_TypeDef * USART)
void MyUSART_Transmit_Data_8b(USART_TypeDef * USART, int data)
{
LL_USART_TransmitData8(USART, data);
+ while (LL_USART_IsActiveFlag_TC(USART) != 1){}
}