From f24d419c1b7ed0ec7c983642792b698bea837d30 Mon Sep 17 00:00:00 2001 From: Arnaud Vergnet Date: Sat, 7 Nov 2020 15:50:57 +0100 Subject: [PATCH 1/7] add sail start and conf functions --- MyDrivers/Timer.c | 2 +- Services/ServoMotor.c | 6 +++--- Services/ServoMotor.h | 6 +++++- Src/Sail.c | 27 +++++++++++++++++++++++++++ Src/Sail.h | 8 ++++---- Src/main.c | 15 ++++++--------- 6 files changed, 46 insertions(+), 18 deletions(-) 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/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..76c5198 100644 --- a/Src/Sail.c +++ b/Src/Sail.c @@ -1 +1,28 @@ #include "Sail.h" +#include "ServoMotor.h" + +TIM_TypeDef * SAIL_TIMER = TIM4; +const int SAIL_CHANNEL = LL_TIM_CHANNEL_CH3; +GPIO_TypeDef * SAIL_GPIO = GPIOB; +const int SAIL_PIN = LL_GPIO_PIN_8; + +void Sail_conf() +{ + ServoMotor_conf(SAIL_TIMER, SAIL_CHANNEL, SAIL_GPIO, SAIL_PIN); +} + +void Sail_background() +{ + +} + +void Sail_reset() +{ + +} + + +void Sail_start() +{ + Timer_start(SAIL_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..c440ba6 100644 --- a/Src/main.c +++ b/Src/main.c @@ -20,7 +20,7 @@ #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" void SystemClock_Config(void); @@ -31,8 +31,6 @@ void SystemClock_Config(void); * @param None * @retval None */ - -Time * time; int main(void) { @@ -41,14 +39,13 @@ int main(void) /* Add your application code here */ // Configuration chronomètre - Chrono_Conf(TIM3); - + // Chrono_Conf(TIM3); // Lancement chronomètre - Chrono_Start(); - - time = Chrono_Read(); + // Chrono_Start(); + // time = Chrono_Read(); - /* Infinite loop */ + Sail_conf(); + Sail_start(); while (1) { } From 6ded190d3d64a70ed8c3e8102c817aa17e1068c5 Mon Sep 17 00:00:00 2001 From: Arnaud Vergnet Date: Mon, 9 Nov 2020 10:01:00 +0100 Subject: [PATCH 2/7] add gpio config --- Services/IncrementalEncoder.c | 5 +++-- Services/IncrementalEncoder.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) 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é From cdcf3a2f9de849364049dc9fe50e38cdd3e52dcf Mon Sep 17 00:00:00 2001 From: Arnaud Vergnet Date: Mon, 9 Nov 2020 10:01:18 +0100 Subject: [PATCH 3/7] add encoder config --- Src/Sail.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Src/Sail.c b/Src/Sail.c index 76c5198..5b0ae95 100644 --- a/Src/Sail.c +++ b/Src/Sail.c @@ -1,14 +1,20 @@ #include "Sail.h" #include "ServoMotor.h" +#include "IncrementalEncoder.h" -TIM_TypeDef * SAIL_TIMER = TIM4; -const int SAIL_CHANNEL = LL_TIM_CHANNEL_CH3; -GPIO_TypeDef * SAIL_GPIO = GPIOB; -const int SAIL_PIN = LL_GPIO_PIN_8; +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(SAIL_TIMER, SAIL_CHANNEL, SAIL_GPIO, SAIL_PIN); + ServoMotor_conf(MOTOR_TIMER, MOTOR_CHANNEL, MOTOR_GPIO, MOTOR_PIN); + IncrementalEncoder_conf(ENCODER_TIMER, ENCODER_GPIO, ENCODER_PIN); } void Sail_background() @@ -24,5 +30,6 @@ void Sail_reset() void Sail_start() { - Timer_start(SAIL_TIMER); + Timer_start(MOTOR_TIMER); + Timer_start(ENCODER_TIMER); } From 7e6eb879f1193ba980a821d6f344c9ad49baf2ee Mon Sep 17 00:00:00 2001 From: Arnaud Vergnet Date: Mon, 9 Nov 2020 10:01:39 +0100 Subject: [PATCH 4/7] add basic scheduler functions --- Services/Scheduler.c | 21 +++++++++++++++++++++ Services/Scheduler.h | 22 ++++++++++++++++++++++ Src/main.c | 30 ++++++++++++++++++++++++++---- 3 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 Services/Scheduler.c create mode 100644 Services/Scheduler.h diff --git a/Services/Scheduler.c b/Services/Scheduler.c new file mode 100644 index 0000000..4c78041 --- /dev/null +++ b/Services/Scheduler.c @@ -0,0 +1,21 @@ +#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; + LL_Init1msTick(1000); +} + +void Scheduler_start(void) +{ + +} diff --git a/Services/Scheduler.h b/Services/Scheduler.h new file mode 100644 index 0000000..13c9c89 --- /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 + * @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/Src/main.c b/Src/main.c index c440ba6..1d6d586 100644 --- a/Src/main.c +++ b/Src/main.c @@ -21,17 +21,36 @@ #include "stm32f1xx_ll_system.h" // utile dans la fonction SystemClock_Config #include "Sail.h" +#include "Scheduler.h" void SystemClock_Config(void); /* Private functions ---------------------------------------------------------*/ +int counter = 1; + +void backgroundTask() +{ + counter++; + Sail_background(); +} + + +void configurePeripherals() +{ + Sail_conf(); +} + +void startPeripherals() +{ + Sail_start(); +} + /** * @brief Main program * @param None * @retval None */ - int main(void) { /* Configure the system clock to 72 MHz */ @@ -43,9 +62,12 @@ int main(void) // Lancement chronomètre // Chrono_Start(); // time = Chrono_Read(); - - Sail_conf(); - Sail_start(); + configurePeripherals(); + startPeripherals(); + + Scheduler_conf(backgroundTask); + Scheduler_start(); + while (1) { } From 84a3fea45017e92ebd760cd13d977f90da6e0577 Mon Sep 17 00:00:00 2001 From: Arnaud Vergnet Date: Mon, 9 Nov 2020 10:17:28 +0100 Subject: [PATCH 5/7] make systick actually work every 1ms --- Services/Scheduler.c | 6 ++++-- Services/Scheduler.h | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Services/Scheduler.c b/Services/Scheduler.c index 4c78041..1d89dfc 100644 --- a/Services/Scheduler.c +++ b/Services/Scheduler.c @@ -12,10 +12,12 @@ void SysTick_Handler(void) void Scheduler_conf(void (*it_callback) (void)) { it_callback_SysTick = it_callback; - LL_Init1msTick(1000); + 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 index 13c9c89..06e7349 100644 --- a/Services/Scheduler.h +++ b/Services/Scheduler.h @@ -4,7 +4,7 @@ #include "stm32f103xb.h" /** - * @brief Configure l'horloge interne comme ordonanceur + * @brief Configure l'horloge interne comme ordonanceur toutes les 1ms * @note * @param (void)* it_callback : Tache de fond à executer * @retval None From 76fd320df4fcd99adb0d6555c6b634e849fbe572 Mon Sep 17 00:00:00 2001 From: Yohan Simard Date: Mon, 9 Nov 2020 12:14:55 +0100 Subject: [PATCH 6/7] implement ADC and USART --- MDK-ARM/Project.uvoptx | 117 ++++++++++++++++++++++++++++++++++------ MDK-ARM/Project.uvprojx | 63 +++++++++++++++------- MyDrivers/ADC.c | 51 ++++++++++++++++++ MyDrivers/ADC.h | 11 ++++ MyDrivers/USART.c | 57 ++++++++++++++++++++ MyDrivers/USART.h | 5 ++ Src/main.c | 10 +++- 7 files changed, 276 insertions(+), 38 deletions(-) diff --git a/MDK-ARM/Project.uvoptx b/MDK-ARM/Project.uvoptx index 542aa50..b46b6c8 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=-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=100,129,658,654,0)(121=-1,-1,-1,-1,0)(122=1005,156,1563,681,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=1238,79,1832,588,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 + 39 1 -
134219406
+
134224104
0 0 0 @@ -393,16 +393,44 @@ 1 ../Src/main.c - \\NUCLEO_F103RB\../Src/main.c\46 + \\NUCLEO_F103RB\../Src/main.c\39 +
+ + 1 + 0 + 40 + 1 +
0
+ 0 + 0 + 0 + 0 + 0 + 0 + ../Src/main.c + +
+ + + 0 + 1 + adcRaw,0x0A + + + 1 + 1 + adcVolt + + 0 0 1 - 1 + 0 0 0 0 @@ -438,6 +466,13 @@ + + + 0 + ((PORTA & 0x00000200) >> 9 & 0x200) >> 9 + 00800000000000000000000000000000E0FFEF400100000000000000000000000000000028504F5254412026203078303030303032303029203E3E2039000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000001000000000000000000F03F170000000000000000000000000000000000000000010008 + + 1 0 @@ -618,6 +653,18 @@ 0 0 + + 2 + 14 + 1 + 0 + 0 + 0 + ..\Services\Scheduler.c + Scheduler.c + 0 + 0 + @@ -628,7 +675,7 @@ 0 3 - 14 + 15 1 0 0 @@ -640,9 +687,9 @@ 3 - 15 + 16 1 - 0 + 1 0 0 ..\MyDrivers\ADC.c @@ -652,7 +699,7 @@ 3 - 16 + 17 1 0 0 @@ -664,9 +711,9 @@ 3 - 17 + 18 1 - 0 + 1 0 0 ..\MyDrivers\USART.c @@ -684,7 +731,7 @@ 0 4 - 18 + 19 1 0 0 @@ -696,7 +743,7 @@ 4 - 19 + 20 1 0 0 @@ -708,7 +755,7 @@ 4 - 20 + 21 1 0 0 @@ -718,6 +765,42 @@ 0 0 + + 4 + 22 + 1 + 0 + 0 + 0 + ..\LLDrivers\src\stm32f1xx_ll_gpio.c + stm32f1xx_ll_gpio.c + 0 + 0 + + + 4 + 23 + 1 + 0 + 0 + 0 + ..\LLDrivers\src\stm32f1xx_ll_usart.c + stm32f1xx_ll_usart.c + 0 + 0 + + + 4 + 24 + 1 + 0 + 0 + 0 + ..\LLDrivers\src\stm32f1xx_ll_adc.c + stm32f1xx_ll_adc.c + 0 + 0 + @@ -728,7 +811,7 @@ 0 5 - 21 + 25 5 0 0 @@ -748,7 +831,7 @@ 0 6 - 22 + 26 1 0 0 @@ -768,7 +851,7 @@ 0 7 - 23 + 27 2 0 0 diff --git a/MDK-ARM/Project.uvprojx b/MDK-ARM/Project.uvprojx index 881272c..254be84 100644 --- a/MDK-ARM/Project.uvprojx +++ b/MDK-ARM/Project.uvprojx @@ -185,7 +185,6 @@ 0 0 0 - 0 0 0 8 @@ -352,7 +351,7 @@ 0 0 0 - 4 + 0 @@ -453,6 +452,11 @@ 1 ..\Services\Voltage.c + + Scheduler.c + 1 + ..\Services\Scheduler.c + @@ -498,6 +502,21 @@ 1 ..\LLDrivers\src\stm32f1xx_ll_tim.c + + stm32f1xx_ll_gpio.c + 1 + ..\LLDrivers\src\stm32f1xx_ll_gpio.c + + + stm32f1xx_ll_usart.c + 1 + ..\LLDrivers\src\stm32f1xx_ll_usart.c + + + stm32f1xx_ll_adc.c + 1 + ..\LLDrivers\src\stm32f1xx_ll_adc.c + @@ -539,7 +558,7 @@ Simulateur 0x4 ARM-ADS - 5060750::V5.06 update 6 (build 750)::.\ARMCC + 5060750::V5.06 update 6 (build 750)::ARMCC 0 @@ -714,7 +733,6 @@ 0 0 0 - 0 0 0 8 @@ -881,7 +899,7 @@ 0 0 0 - 4 + 0 @@ -982,6 +1000,11 @@ 1 ..\Services\Voltage.c + + Scheduler.c + 1 + ..\Services\Scheduler.c + @@ -1027,6 +1050,21 @@ 1 ..\LLDrivers\src\stm32f1xx_ll_tim.c + + stm32f1xx_ll_gpio.c + 1 + ..\LLDrivers\src\stm32f1xx_ll_gpio.c + + + stm32f1xx_ll_usart.c + 1 + ..\LLDrivers\src\stm32f1xx_ll_usart.c + + + stm32f1xx_ll_adc.c + 1 + ..\LLDrivers\src\stm32f1xx_ll_adc.c + @@ -1080,19 +1118,4 @@ - - - - <Project Info> - - - - - - 0 - 1 - - - - 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/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/Src/main.c b/Src/main.c index 1d6d586..77bdaaf 100644 --- a/Src/main.c +++ b/Src/main.c @@ -22,28 +22,36 @@ #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); } /** @@ -67,7 +75,7 @@ int main(void) Scheduler_conf(backgroundTask); Scheduler_start(); - + while (1) { } From f5adb05005c5942569da27154049eb3e04604e0e Mon Sep 17 00:00:00 2001 From: Arnaud Vergnet Date: Tue, 10 Nov 2020 14:14:57 +0100 Subject: [PATCH 7/7] update project files --- MDK-ARM/Project.uvoptx | 69 ++++++++++++----------------------------- MDK-ARM/Project.uvprojx | 43 ++++++++++++------------- 2 files changed, 40 insertions(+), 72 deletions(-) diff --git a/MDK-ARM/Project.uvoptx b/MDK-ARM/Project.uvoptx index b46b6c8..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=100,129,658,654,0)(121=-1,-1,-1,-1,0)(122=1005,156,1563,681,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=1238,79,1832,588,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 - 39 + 65 1 -
134224104
+
134223216
0 0 0 @@ -393,35 +393,30 @@ 1 ../Src/main.c - \\NUCLEO_F103RB\../Src/main.c\39 + \\NUCLEO_F103RB\../Src/main.c\65
1 0 - 40 + 69 1 -
0
+
134223230
0 0 0 0 0 - 0 + 1 ../Src/main.c - + \\NUCLEO_F103RB\../Src/main.c\69
0 1 - adcRaw,0x0A - - - 1 - 1 - adcVolt + counter,0x10 @@ -430,7 +425,7 @@ 0 1 - 0 + 1 0 0 0 @@ -444,7 +439,7 @@ 0 0 0 - 0 + 1 0 0 0 @@ -469,8 +464,8 @@ 0 - ((PORTA & 0x00000200) >> 9 & 0x200) >> 9 - 00800000000000000000000000000000E0FFEF400100000000000000000000000000000028504F5254412026203078303030303032303029203E3E2039000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000001000000000000000000F03F170000000000000000000000000000000000000000010008 + ((PORTB & 0x00000100) >> 8 & 0x100) >> 8 + FF000000000000000000000000000000E0FFEF400100000000000000000000000000000028504F5254422026203078303030303031303029203E3E2038000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000001000000000000000000F03F1400000000000000000000000000000000000000AE110008 @@ -689,7 +684,7 @@ 3 16 1 - 1 + 0 0 0 ..\MyDrivers\ADC.c @@ -713,7 +708,7 @@ 3 18 1 - 1 + 0 0 0 ..\MyDrivers\USART.c @@ -777,41 +772,17 @@ 0 0 - - 4 - 23 - 1 - 0 - 0 - 0 - ..\LLDrivers\src\stm32f1xx_ll_usart.c - stm32f1xx_ll_usart.c - 0 - 0 - - - 4 - 24 - 1 - 0 - 0 - 0 - ..\LLDrivers\src\stm32f1xx_ll_adc.c - stm32f1xx_ll_adc.c - 0 - 0 -
Doc - 1 + 0 0 0 0 5 - 25 + 23 5 0 0 @@ -825,13 +796,13 @@ Drivers/CMSIS - 0 + 1 0 0 0 6 - 26 + 24 1 0 0 @@ -851,7 +822,7 @@ 0 7 - 27 + 25 2 0 0 diff --git a/MDK-ARM/Project.uvprojx b/MDK-ARM/Project.uvprojx index 254be84..01a437b 100644 --- a/MDK-ARM/Project.uvprojx +++ b/MDK-ARM/Project.uvprojx @@ -185,6 +185,7 @@ 0 0 0 + 0 0 0 8 @@ -351,7 +352,7 @@ 0 0 0 - 0 + 4 @@ -507,16 +508,6 @@ 1 ..\LLDrivers\src\stm32f1xx_ll_gpio.c - - stm32f1xx_ll_usart.c - 1 - ..\LLDrivers\src\stm32f1xx_ll_usart.c - - - stm32f1xx_ll_adc.c - 1 - ..\LLDrivers\src\stm32f1xx_ll_adc.c - @@ -558,7 +549,7 @@ Simulateur 0x4 ARM-ADS - 5060750::V5.06 update 6 (build 750)::ARMCC + 5060750::V5.06 update 6 (build 750)::.\ARMCC 0 @@ -733,6 +724,7 @@ 0 0 0 + 0 0 0 8 @@ -899,7 +891,7 @@ 0 0 0 - 0 + 4 @@ -1055,16 +1047,6 @@ 1 ..\LLDrivers\src\stm32f1xx_ll_gpio.c - - stm32f1xx_ll_usart.c - 1 - ..\LLDrivers\src\stm32f1xx_ll_usart.c - - - stm32f1xx_ll_adc.c - 1 - ..\LLDrivers\src\stm32f1xx_ll_adc.c - @@ -1118,4 +1100,19 @@ + + + + <Project Info> + + + + + + 0 + 1 + + + +