diff --git a/MDK-ARM/Project.uvoptx b/MDK-ARM/Project.uvoptx
index 542aa50..2a464ad 100644
--- a/MDK-ARM/Project.uvoptx
+++ b/MDK-ARM/Project.uvoptx
@@ -345,7 +345,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=-1,-1,-1,-1,0)(110=-1,-1,-1,-1,0)(111=-1,-1,-1,-1,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=-1,-1,-1,-1,0)(121=-1,-1,-1,-1,0)(122=-1,-1,-1,-1,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=-1,-1,-1,-1,0)(131=-1,-1,-1,-1,0)(132=-1,-1,-1,-1,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=2156,213,2522,450,0)(1009=-1,-1,-1,-1,0)(100=-1,-1,-1,-1,0)(110=-1,-1,-1,-1,0)(111=-1,-1,-1,-1,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=-1,-1,-1,-1,0)(121=2124,217,2535,660,0)(122=-1,-1,-1,-1,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=-1,-1,-1,-1,0)(131=-1,-1,-1,-1,0)(132=2076,105,2660,897,0)(133=2592,151,3176,943,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
@@ -382,9 +382,9 @@
0
0
- 46
+ 65
1
- 134219406
+ 134223216
0
0
0
@@ -393,9 +393,32 @@
1
../Src/main.c
- \\NUCLEO_F103RB\../Src/main.c\46
+ \\NUCLEO_F103RB\../Src/main.c\65
+
+
+ 1
+ 0
+ 69
+ 1
+ 134223230
+ 0
+ 0
+ 0
+ 0
+ 0
+ 1
+ ../Src/main.c
+
+ \\NUCLEO_F103RB\../Src/main.c\69
+
+
+ 0
+ 1
+ counter,0x10
+
+
0
@@ -416,7 +439,7 @@
0
0
0
- 0
+ 1
0
0
0
@@ -438,6 +461,13 @@
+
+
+ 0
+ ((PORTB & 0x00000100) >> 8 & 0x100) >> 8
+ FF000000000000000000000000000000E0FFEF400100000000000000000000000000000028504F5254422026203078303030303031303029203E3E2038000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000001000000000000000000F03F1400000000000000000000000000000000000000AE110008
+
+
1
0
@@ -618,6 +648,18 @@
0
0
+
+ 2
+ 14
+ 1
+ 0
+ 0
+ 0
+ ..\Services\Scheduler.c
+ Scheduler.c
+ 0
+ 0
+
@@ -628,7 +670,7 @@
0
3
- 14
+ 15
1
0
0
@@ -640,7 +682,7 @@
3
- 15
+ 16
1
0
0
@@ -652,7 +694,7 @@
3
- 16
+ 17
1
0
0
@@ -664,7 +706,7 @@
3
- 17
+ 18
1
0
0
@@ -684,7 +726,7 @@
0
4
- 18
+ 19
1
0
0
@@ -696,7 +738,7 @@
4
- 19
+ 20
1
0
0
@@ -708,7 +750,7 @@
4
- 20
+ 21
1
0
0
@@ -718,17 +760,29 @@
0
0
+
+ 4
+ 22
+ 1
+ 0
+ 0
+ 0
+ ..\LLDrivers\src\stm32f1xx_ll_gpio.c
+ stm32f1xx_ll_gpio.c
+ 0
+ 0
+
Doc
- 1
+ 0
0
0
0
5
- 21
+ 23
5
0
0
@@ -742,13 +796,13 @@
Drivers/CMSIS
- 0
+ 1
0
0
0
6
- 22
+ 24
1
0
0
@@ -768,7 +822,7 @@
0
7
- 23
+ 25
2
0
0
diff --git a/MDK-ARM/Project.uvprojx b/MDK-ARM/Project.uvprojx
index 881272c..01a437b 100644
--- a/MDK-ARM/Project.uvprojx
+++ b/MDK-ARM/Project.uvprojx
@@ -453,6 +453,11 @@
1
..\Services\Voltage.c
+
+ Scheduler.c
+ 1
+ ..\Services\Scheduler.c
+
@@ -498,6 +503,11 @@
1
..\LLDrivers\src\stm32f1xx_ll_tim.c
+
+ stm32f1xx_ll_gpio.c
+ 1
+ ..\LLDrivers\src\stm32f1xx_ll_gpio.c
+
@@ -982,6 +992,11 @@
1
..\Services\Voltage.c
+
+ Scheduler.c
+ 1
+ ..\Services\Scheduler.c
+
@@ -1027,6 +1042,11 @@
1
..\LLDrivers\src\stm32f1xx_ll_tim.c
+
+ stm32f1xx_ll_gpio.c
+ 1
+ ..\LLDrivers\src\stm32f1xx_ll_gpio.c
+
diff --git a/MyDrivers/ADC.c b/MyDrivers/ADC.c
index e305f04..7fbd2d0 100644
--- a/MyDrivers/ADC.c
+++ b/MyDrivers/ADC.c
@@ -1 +1,52 @@
#include "ADC.h"
+#include "stm32f1xx_ll_bus.h" // Pour horloge
+
+void ADC_conf(ADC_TypeDef *adc, uint32_t voie)
+{
+ if (adc == ADC1) {
+ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_ADC1);
+ } else if (adc == ADC2) {
+ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_ADC2);
+ }
+
+ // Division de la frequence
+ RCC->CFGR |= RCC_CFGR_ADCPRE_DIV6;
+
+ // Fixe le nombre de conversion à 1
+ adc->SQR1&= ADC_SQR1_L;
+
+ // Indique la voie a convertir
+ adc->SQR3|= voie;
+
+ // Calibration
+ adc->CR2 |= ADC_CR2_CAL_Msk;
+ while ((adc->CR2 & ADC_CR2_CAL_Msk));
+}
+
+
+void ADC_start(ADC_TypeDef *adc)
+{
+ adc->CR2 |= ADC_CR2_ADON;
+}
+
+
+uint16_t ADC_readRaw(ADC_TypeDef *adc)
+{
+ // Lancement de la conversion
+ adc->CR2 |= ADC_CR2_ADON;
+ while(!(ADC1->SR & ADC_SR_EOC)) {}
+
+ return ADC1->DR & ADC_DR_DATA_Msk;
+}
+
+
+double ADC_convertToVolt(uint16_t value)
+{
+ return ((double) value) / 4095.0 * 3.3;
+}
+
+
+double ADC_readVolt(ADC_TypeDef *adc)
+{
+ return ADC_convertToVolt(ADC_readRaw(adc));
+}
diff --git a/MyDrivers/ADC.h b/MyDrivers/ADC.h
index c4ee01e..b73929d 100644
--- a/MyDrivers/ADC.h
+++ b/MyDrivers/ADC.h
@@ -1,4 +1,15 @@
#ifndef ADC_H
#define ADC_H
+#include "stm32f1xx_ll_adc.h"
+
+void ADC_conf(ADC_TypeDef *adc, uint32_t voie);
+void ADC_start(ADC_TypeDef *adc);
+
+uint16_t ADC_readRaw(ADC_TypeDef *adc);
+double ADC_readVolt(ADC_TypeDef *adc);
+
+double ADC_convertToVolt(uint16_t value);
+
+
#endif
diff --git a/MyDrivers/Timer.c b/MyDrivers/Timer.c
index 55bf6d8..b0b5cad 100644
--- a/MyDrivers/Timer.c
+++ b/MyDrivers/Timer.c
@@ -173,7 +173,7 @@ void Timer_conf(TIM_TypeDef * timer, int arr, int psc)
int getArrFromFreq(float freq)
{
- return (72000000 / freq) - 1;
+ return (72000 / freq) - 1;
}
void Timer_pwmo_conf(TIM_TypeDef * timer, int channel, float freq, float dutyCycle)
diff --git a/MyDrivers/USART.c b/MyDrivers/USART.c
index 1273ce3..54706c1 100644
--- a/MyDrivers/USART.c
+++ b/MyDrivers/USART.c
@@ -1 +1,58 @@
#include "USART.h"
+#include "GPIO.h"
+#include "stm32f1xx_ll_bus.h" // Pour horloge
+
+
+void Usart_conf(USART_TypeDef *USARTx) {
+ int txPin;
+ GPIO_TypeDef *usartGpio;
+
+ if (USARTx == USART1) {
+ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1);
+ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA);
+ txPin = LL_GPIO_PIN_9;
+ usartGpio = GPIOA;
+ } else if (USARTx == USART2) {
+ LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_USART2);
+ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA);
+ txPin = LL_GPIO_PIN_2;
+ usartGpio = GPIOA;
+ } else if (USARTx == USART3) {
+ LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_USART3);
+ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOB);
+ txPin = LL_GPIO_PIN_10;
+ usartGpio = GPIOB;
+ }
+
+ LL_USART_InitTypeDef usartInit;
+ LL_USART_StructInit(&usartInit);
+ usartInit.DataWidth = LL_USART_DATAWIDTH_8B;
+ usartInit.BaudRate = 9600;
+ usartInit.TransferDirection = LL_USART_DIRECTION_TX_RX;
+ LL_USART_Init(USARTx, &usartInit);
+
+ GPIO_conf(usartGpio, txPin, LL_GPIO_MODE_ALTERNATE, LL_GPIO_OUTPUT_PUSHPULL, LL_GPIO_PULL_UP);
+}
+
+
+
+void Usart_enable(USART_TypeDef *USARTx) {
+ LL_USART_Enable(USARTx);
+}
+
+
+void sendChar(USART_TypeDef *USARTx, char c) {
+ LL_USART_TransmitData8(USARTx, c);
+ while (!LL_USART_IsActiveFlag_TXE(USARTx)) {}
+}
+
+
+void Usart_send(USART_TypeDef *USARTx, char *msg, int length) {
+ for (int i = 0; i < length; i++) {
+ sendChar(USARTx, msg[i]);
+ }
+}
+
+
+
+
diff --git a/MyDrivers/USART.h b/MyDrivers/USART.h
index b72fa38..3c81502 100644
--- a/MyDrivers/USART.h
+++ b/MyDrivers/USART.h
@@ -1,5 +1,10 @@
#ifndef USART_H
#define USART_H
+#include "stm32f1xx_ll_usart.h"
+
+void Usart_conf(USART_TypeDef *USARTx);
+void Usart_enable(USART_TypeDef *USARTx);
+void Usart_send(USART_TypeDef *USARTx, char *msg, int length);
#endif
diff --git a/Services/IncrementalEncoder.c b/Services/IncrementalEncoder.c
index cefd96c..b963f52 100644
--- a/Services/IncrementalEncoder.c
+++ b/Services/IncrementalEncoder.c
@@ -1,11 +1,12 @@
#include "IncrementalEncoder.h"
#include "Timer.h"
+#include "GPIO.h"
-void IncrementalEncoder_conf(TIM_TypeDef * timer)
+void IncrementalEncoder_conf(TIM_TypeDef * timer, GPIO_TypeDef * gpio, int pin)
{
Timer_encoder_conf(timer);
- // TODO GPIO config
+ GPIO_conf(gpio, pin, LL_GPIO_MODE_INPUT, LL_GPIO_OUTPUT_PUSHPULL, LL_GPIO_PULL_UP);
}
void IncrementalEncoder_start(TIM_TypeDef * timer)
diff --git a/Services/IncrementalEncoder.h b/Services/IncrementalEncoder.h
index 3137432..5882333 100644
--- a/Services/IncrementalEncoder.h
+++ b/Services/IncrementalEncoder.h
@@ -9,7 +9,7 @@
* @param TIM_TypeDef Timer : indique le timer à utiliser : TIM1, TIM2, TIM3 ou TIM4
* @retval None
*/
-void IncrementalEncoder_conf(TIM_TypeDef * timer);
+void IncrementalEncoder_conf(TIM_TypeDef * timer, GPIO_TypeDef * gpio, int pin);
/**
* @brief Démarre le codeur incrémental associé au timer donné
diff --git a/Services/Scheduler.c b/Services/Scheduler.c
new file mode 100644
index 0000000..1d89dfc
--- /dev/null
+++ b/Services/Scheduler.c
@@ -0,0 +1,23 @@
+#include "Scheduler.h"
+#include "Timer.h"
+#include "stm32f1xx_ll_utils.h"
+
+void (*it_callback_SysTick)(void);
+
+void SysTick_Handler(void)
+{
+ (*it_callback_SysTick)();
+}
+
+void Scheduler_conf(void (*it_callback) (void))
+{
+ it_callback_SysTick = it_callback;
+ SysTick->CTRL &= ~(SysTick_CTRL_CLKSOURCE_Msk);
+ SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk;
+ SysTick->LOAD = 9000;
+}
+
+void Scheduler_start(void)
+{
+ SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
+}
diff --git a/Services/Scheduler.h b/Services/Scheduler.h
new file mode 100644
index 0000000..06e7349
--- /dev/null
+++ b/Services/Scheduler.h
@@ -0,0 +1,22 @@
+#ifndef SCHEDULER_H
+#define SCHEDULER_H
+
+#include "stm32f103xb.h"
+
+/**
+ * @brief Configure l'horloge interne comme ordonanceur toutes les 1ms
+ * @note
+ * @param (void)* it_callback : Tache de fond à executer
+ * @retval None
+ */
+void Scheduler_conf(void (*it_callback) (void));
+
+/**
+ * @brief Démarre ordonanceur
+ * @note
+ * @param None
+ * @retval None
+ */
+void Scheduler_start(void);
+
+#endif
diff --git a/Services/ServoMotor.c b/Services/ServoMotor.c
index d006b26..70e636c 100644
--- a/Services/ServoMotor.c
+++ b/Services/ServoMotor.c
@@ -1,11 +1,11 @@
#include "ServoMotor.h"
-#include "Timer.h"
#define SERVO_MOTO_FREQ 50
-void ServoMotor_conf(TIM_TypeDef * timer, int channel)
+void ServoMotor_conf(TIM_TypeDef * timer, int channel, GPIO_TypeDef * gpio, int pin)
{
- Timer_pwmo_conf(timer, channel, SERVO_MOTO_FREQ, 0);
+ Timer_pwmo_conf(timer, channel, SERVO_MOTO_FREQ, 0.5);
+ GPIO_conf(gpio, pin, LL_GPIO_MODE_ALTERNATE, LL_GPIO_OUTPUT_PUSHPULL, LL_GPIO_PULL_UP);
}
void ServoMotor_start(TIM_TypeDef * timer)
diff --git a/Services/ServoMotor.h b/Services/ServoMotor.h
index 65561b8..794dbdf 100644
--- a/Services/ServoMotor.h
+++ b/Services/ServoMotor.h
@@ -2,15 +2,19 @@
#define SERVO_MOTOR_H
#include "stm32f103xb.h"
+#include "Timer.h"
+#include "GPIO.h"
/**
* @brief Configure le servo moteur associé au timer donné
* @note
* @param TIM_TypeDef Timer : indique le timer à utiliser : TIM1, TIM2, TIM3 ou TIM4
* int channel : Le channel utilisé par le servo moteur
+ * GPIO_TypeDef gpio : Le GPIO à utiliser pour la sortie de la PWM
+ * int pin : Le PIN associé au GPIO
* @retval None
*/
-void ServoMotor_conf(TIM_TypeDef * timer, int channel);
+void ServoMotor_conf(TIM_TypeDef * timer, int channel, GPIO_TypeDef * gpio, int pin);
/**
* @brief Démarre les servo moteurs associés au timer donné
diff --git a/Src/Sail.c b/Src/Sail.c
index 250165b..5b0ae95 100644
--- a/Src/Sail.c
+++ b/Src/Sail.c
@@ -1 +1,35 @@
#include "Sail.h"
+#include "ServoMotor.h"
+#include "IncrementalEncoder.h"
+
+TIM_TypeDef * MOTOR_TIMER = TIM4;
+const int MOTOR_CHANNEL = LL_TIM_CHANNEL_CH3;
+GPIO_TypeDef * MOTOR_GPIO = GPIOB;
+const int MOTOR_PIN = LL_GPIO_PIN_8;
+
+TIM_TypeDef * ENCODER_TIMER = TIM3;
+GPIO_TypeDef * ENCODER_GPIO = GPIOA;
+const int ENCODER_PIN = LL_GPIO_PIN_5;
+
+void Sail_conf()
+{
+ ServoMotor_conf(MOTOR_TIMER, MOTOR_CHANNEL, MOTOR_GPIO, MOTOR_PIN);
+ IncrementalEncoder_conf(ENCODER_TIMER, ENCODER_GPIO, ENCODER_PIN);
+}
+
+void Sail_background()
+{
+
+}
+
+void Sail_reset()
+{
+
+}
+
+
+void Sail_start()
+{
+ Timer_start(MOTOR_TIMER);
+ Timer_start(ENCODER_TIMER);
+}
diff --git a/Src/Sail.h b/Src/Sail.h
index a847a15..cc49ef0 100644
--- a/Src/Sail.h
+++ b/Src/Sail.h
@@ -7,7 +7,7 @@
* @param None
* @retval None
*/
-void Sail_conf();
+void Sail_conf(void);
/**
* @brief Execute la tache de fond des voiles en fonction des valeurs récupérées par les drivers
@@ -15,7 +15,7 @@ void Sail_conf();
* @param None
* @retval None
*/
-void Sail_background();
+void Sail_background(void);
/**
* @brief Mets la voile à 90 degres
@@ -23,7 +23,7 @@ void Sail_background();
* @param None
* @retval None
*/
-void Sail_reset();
+void Sail_reset(void);
/**
* @brief Réinitialise la voile à sa position initiale
@@ -31,6 +31,6 @@ void Sail_reset();
* @param None
* @retval None
*/
-void Sail_start();
+void Sail_start(void);
#endif
diff --git a/Src/main.c b/Src/main.c
index c78ee5f..77bdaaf 100644
--- a/Src/main.c
+++ b/Src/main.c
@@ -20,20 +20,45 @@
#include "stm32f1xx_ll_utils.h" // utile dans la fonction SystemClock_Config
#include "stm32f1xx_ll_system.h" // utile dans la fonction SystemClock_Config
-#include "Chrono.h"
+#include "Sail.h"
+#include "Scheduler.h"
+#include "ADC.h"
+#include "GPIO.h"
void SystemClock_Config(void);
/* Private functions ---------------------------------------------------------*/
+int counter = 1;
+int adcRaw = 0;
+double adcVolt = 0.0;
+
+void backgroundTask()
+{
+ counter++;
+ Sail_background();
+ adcRaw = ADC_readRaw(ADC1);
+ adcVolt = ADC_convertToVolt(adcRaw);
+}
+
+
+void configurePeripherals()
+{
+ Sail_conf();
+ ADC_conf(ADC1, 12);
+}
+
+void startPeripherals()
+{
+ Sail_start();
+ ADC_start(ADC1);
+}
+
/**
* @brief Main program
* @param None
* @retval None
*/
-
-Time * time;
-
int main(void)
{
/* Configure the system clock to 72 MHz */
@@ -41,14 +66,16 @@ int main(void)
/* Add your application code here */
// Configuration chronomètre
- Chrono_Conf(TIM3);
-
+ // Chrono_Conf(TIM3);
// Lancement chronomètre
- Chrono_Start();
+ // Chrono_Start();
+ // time = Chrono_Read();
+ configurePeripherals();
+ startPeripherals();
- time = Chrono_Read();
-
- /* Infinite loop */
+ Scheduler_conf(backgroundTask);
+ Scheduler_start();
+
while (1)
{
}