[AJOUT] premier commit + ajout des fonctions init_Timer_RoueGauche et init_Timer_RoueDroite prochaine étape controle du capteur Ultrasons

This commit is contained in:
2026-05-31 11:47:48 +02:00
parent 319a81a969
commit 6b58baf717
49 changed files with 73518 additions and 1 deletions

134
Code/Src/config.c Normal file
View File

@@ -0,0 +1,134 @@
/*
* config.c
*
* Created on: 28 mai 2026
* Author: innotex
*/
#include <config.h>
#include <stdint.h>
void motor_init(void)
{
// Init des clks sur portB et A
RCC->AHB1ENR |= (RCC_AHB1ENR_GPIOAEN | RCC_AHB1ENR_GPIOBEN);
GPIOA->MODER &= ~INIT_MODDER_MOTOR_PBA_MSK;
GPIOA->MODER |= INIT_MODDER_MOTOR_PBA;
GPIOB->MODER &= ~INIT_MODDER_MOTOR_PBB_MSK;
GPIOB->MODER |= INIT_MODDER_MOTOR_PBB;
GPIOA->OSPEEDR &= ~INIT_OSPEEDR_MOTOR_PBA_MSK;
GPIOA->OSPEEDR |= INIT_OSPEEDR_MOTOR_PBA;
GPIOB->OSPEEDR &= ~INIT_OSPEEDR_MOTOR_PBB_MSK;
GPIOB->OSPEEDR |= INIT_OSPEEDR_MOTOR_PBB;
GPIOA->PUPDR &= ~INIT_PUPDR_MOTOR_PBA_MSK;
GPIOA->PUPDR &= ~INIT_PUPDR_MOTOR_PBB_MSK;
GPIOA->ODR &= ~(GPIO_ODR_ODR_10);
GPIOB->ODR &= ~(GPIO_ODR_ODR_10 | GPIO_ODR_ODR_5 | GPIO_ODR_ODR_4);
}
void init_Timer_RoueDroit(char sens, uint8_t vitesse)
{
RCC->APB1ENR |= (RCC_APB1ENR_TIM2EN | RCC_APB1ENR_TIM3EN);
GPIOB->MODER &= ~(GPIO_MODER_MODER5 | GPIO_MODER_MODER10);
GPIOB->MODER |= (GPIO_MODER_MODER5_1 | GPIO_MODER_MODER10_1); // PB5 et PB10 configuré en alterned function
// Configuration du TIM3 CH2 sur PB5 sur AF02.
GPIOB->AFR[0] &= ~GPIO_AFRL_AFSEL5; // Nettoyage des 4 bits
GPIOB->AFR[0] |= (2 << GPIO_AFRL_AFSEL5_Pos); // Application de AF2
// PB10 -> AF01 (TIM2). En binaire AF01 s'écrit "0001". On active donc le bit 0.
GPIOB->AFR[1] &= ~GPIO_AFRH_AFSEL10; // Nettoyage des 4 bits
GPIOB->AFR[1] |= (1 << GPIO_AFRH_AFSEL10_Pos); // Application de AF1
TIM2->PSC = 35; //PSC = f_horloge/f_tick - 1
TIM2->ARR = 99; // résolution - 1
TIM3->PSC = 35; //PSC = f_horloge/f_tick - 1
TIM3->ARR = 99; // résolution - 1
TIM2->CR1 &= ~TIM_CR1_CMS; // Edge-aligned mode compteur compte de à -> 99 puis retourne à 0
TIM2->CR1 &= ~TIM_CR1_DIR; // Counter used as upcounter
TIM3->CR1 &= ~TIM_CR1_CMS; // Edge-aligned mode compteur compte de à -> 99 puis retourne à 0
TIM3->CR1 &= ~TIM_CR1_DIR; // Counter used as upcounter
TIM2->CR1 |= TIM_CR1_ARPE;
TIM3->CR1 |= TIM_CR1_ARPE;
TIM2->CCMR2 &= ~TIM_CCMR2_CC3S;
TIM3->CCMR1 &= ~TIM_CCMR1_CC1S;
TIM2->CCMR2 &= ~TIM_CCMR2_OC3M;
TIM2->CCMR2 |= (6 << TIM_CCMR2_OC3M_Pos);
TIM3->CCMR1 &= ~TIM_CCMR1_OC2M;
TIM3->CCMR1 |= (6 << TIM_CCMR1_OC2M_Pos);
// Activation du Preload pour le Canal 2 du Timer 3
TIM3->CCMR1 |= TIM_CCMR1_OC2PE;
// Activation du Preload pour le Canal 3 du Timer 2
TIM2->CCMR2 |= TIM_CCMR2_OC3PE;
TIM2->CCER |= TIM_CCER_CC3E; // Activer la sortie du Canal 3
TIM2->CCR3 = vitesse; // Vitesse initiale à 0
TIM2->CR1 |= TIM_CR1_CEN; // Démarrer le Timer 2
TIM3->CCER |= TIM_CCER_CC2E; // Activer la sortie du Canal 2 (Capture/Compare 2 Enable)
TIM3->CCR2 = 0; // Vitesse initiale à 0
TIM3->CR1 |= TIM_CR1_CEN; // Démarrer le Timer 3 (Counter ENable)
}
void init_Timer_RoueGauche(char sens, uint8_t vitesse)
{
// Activation des horloges
RCC->AHB1ENR |= (RCC_AHB1ENR_GPIOAEN | RCC_AHB1ENR_GPIOBEN);
RCC->APB1ENR |= RCC_APB1ENR_TIM3EN;
RCC->APB2ENR |= RCC_APB2ENR_TIM1EN;
// Configuration des MODER
GPIOB->MODER &= ~GPIO_MODER_MODER4;
GPIOB->MODER |= GPIO_MODER_MODER4_1; // PB4 en AF
GPIOA->MODER &= ~GPIO_MODER_MODER10;
GPIOA->MODER |= GPIO_MODER_MODER10_1; // PA10 en AF
// Configuration des AFR
// PB4 -> TIM3 CH1 (AF02)
GPIOB->AFR[0] &= ~GPIO_AFRL_AFSEL4;
GPIOB->AFR[0] |= (2 << GPIO_AFRL_AFSEL4_Pos);
// PA10 -> TIM1 CH3 (AF01)
GPIOA->AFR[1] &= ~GPIO_AFRH_AFSEL10;
GPIOA->AFR[1] |= (1 << GPIO_AFRH_AFSEL10_Pos);
// Paramétrage Timers
TIM3->PSC = 35; TIM3->ARR = 99; TIM3->CR1 |= TIM_CR1_ARPE;
TIM1->PSC = 35; TIM1->ARR = 99; TIM1->CR1 |= TIM_CR1_ARPE;
// --- TIM3 CH1 (PB4) ---
TIM3->CCMR1 &= ~TIM_CCMR1_OC1M;
TIM3->CCMR1 |= (6 << TIM_CCMR1_OC1M_Pos) | TIM_CCMR1_OC1PE;
TIM3->CCER |= TIM_CCER_CC1E; // Activer le Canal 1
// --- TIM1 CH3 (PA10) ---
TIM1->CCMR2 &= ~TIM_CCMR2_OC3M;
TIM1->CCMR2 |= (6 << TIM_CCMR2_OC3M_Pos) | TIM_CCMR2_OC3PE;
TIM1->CCER |= TIM_CCER_CC3E; // Activer le Canal 3
TIM1->BDTR |= TIM_BDTR_MOE; // OBLIGATOIRE POUR TIM1
// Initialisation vitesses
TIM3->CCR1 = 0; // Utilise CCR1 pour canal 1
TIM1->CCR3 = vitesse; // Utilise CCR3 pour canal 3
// Démarrage
TIM3->CR1 |= TIM_CR1_CEN;
TIM1->CR1 |= TIM_CR1_CEN;
}

33
Code/Src/main.c Normal file
View File

@@ -0,0 +1,33 @@
/**
******************************************************************************
* @file : main.c
* @author : Auto-generated by STM32CubeIDE
* @brief : Main program body
******************************************************************************
* @attention
*
* Copyright (c) 2026 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
#include <stdint.h>
#include <config.h>
#if !defined(__SOFT_FP__) && defined(__ARM_FP)
#warning "FPU is not initialized, but the project is compiling for an FPU. Please initialize the FPU before use."
#endif
int main(void)
{
motor_init();
init_Timer_RoueDroit(AVANCE, 0);
init_Timer_RoueGauche(AVANCE, 0);
/* Loop forever */
for(;;);
}

176
Code/Src/syscalls.c Normal file
View File

@@ -0,0 +1,176 @@
/**
******************************************************************************
* @file syscalls.c
* @author Auto-generated by STM32CubeIDE
* @brief STM32CubeIDE Minimal System calls file
*
* For more information about which c-functions
* need which of these lowlevel functions
* please consult the Newlib libc-manual
******************************************************************************
* @attention
*
* Copyright (c) 2020-2026 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Includes */
#include <sys/stat.h>
#include <stdlib.h>
#include <errno.h>
#include <stdio.h>
#include <signal.h>
#include <time.h>
#include <sys/time.h>
#include <sys/times.h>
/* Variables */
extern int __io_putchar(int ch) __attribute__((weak));
extern int __io_getchar(void) __attribute__((weak));
char *__env[1] = { 0 };
char **environ = __env;
/* Functions */
void initialise_monitor_handles()
{
}
int _getpid(void)
{
return 1;
}
int _kill(int pid, int sig)
{
(void)pid;
(void)sig;
errno = EINVAL;
return -1;
}
void _exit (int status)
{
_kill(status, -1);
while (1) {} /* Make sure we hang here */
}
__attribute__((weak)) int _read(int file, char *ptr, int len)
{
(void)file;
int DataIdx;
for (DataIdx = 0; DataIdx < len; DataIdx++)
{
*ptr++ = __io_getchar();
}
return len;
}
__attribute__((weak)) int _write(int file, char *ptr, int len)
{
(void)file;
int DataIdx;
for (DataIdx = 0; DataIdx < len; DataIdx++)
{
__io_putchar(*ptr++);
}
return len;
}
int _close(int file)
{
(void)file;
return -1;
}
int _fstat(int file, struct stat *st)
{
(void)file;
st->st_mode = S_IFCHR;
return 0;
}
int _isatty(int file)
{
(void)file;
return 1;
}
int _lseek(int file, int ptr, int dir)
{
(void)file;
(void)ptr;
(void)dir;
return 0;
}
int _open(char *path, int flags, ...)
{
(void)path;
(void)flags;
/* Pretend like we always fail */
return -1;
}
int _wait(int *status)
{
(void)status;
errno = ECHILD;
return -1;
}
int _unlink(char *name)
{
(void)name;
errno = ENOENT;
return -1;
}
int _times(struct tms *buf)
{
(void)buf;
return -1;
}
int _stat(char *file, struct stat *st)
{
(void)file;
st->st_mode = S_IFCHR;
return 0;
}
int _link(char *old, char *new)
{
(void)old;
(void)new;
errno = EMLINK;
return -1;
}
int _fork(void)
{
errno = EAGAIN;
return -1;
}
int _execve(char *name, char **argv, char **env)
{
(void)name;
(void)argv;
(void)env;
errno = ENOMEM;
return -1;
}

79
Code/Src/sysmem.c Normal file
View File

@@ -0,0 +1,79 @@
/**
******************************************************************************
* @file sysmem.c
* @author Generated by STM32CubeIDE
* @brief STM32CubeIDE System Memory calls file
*
* For more information about which C functions
* need which of these lowlevel functions
* please consult the newlib libc manual
******************************************************************************
* @attention
*
* Copyright (c) 2026 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Includes */
#include <errno.h>
#include <stdint.h>
/**
* Pointer to the current high watermark of the heap usage
*/
static uint8_t *__sbrk_heap_end = NULL;
/**
* @brief _sbrk() allocates memory to the newlib heap and is used by malloc
* and others from the C library
*
* @verbatim
* ############################################################################
* # .data # .bss # newlib heap # MSP stack #
* # # # # Reserved by _Min_Stack_Size #
* ############################################################################
* ^-- RAM start ^-- _end _estack, RAM end --^
* @endverbatim
*
* This implementation starts allocating at the '_end' linker symbol
* The '_Min_Stack_Size' linker symbol reserves a memory for the MSP stack
* The implementation considers '_estack' linker symbol to be RAM end
* NOTE: If the MSP stack, at any point during execution, grows larger than the
* reserved size, please increase the '_Min_Stack_Size'.
*
* @param incr Memory size
* @return Pointer to allocated memory
*/
void *_sbrk(ptrdiff_t incr)
{
extern uint8_t _end; /* Symbol defined in the linker script */
extern uint8_t _estack; /* Symbol defined in the linker script */
extern uint32_t _Min_Stack_Size; /* Symbol defined in the linker script */
const uint32_t stack_limit = (uint32_t)&_estack - (uint32_t)&_Min_Stack_Size;
const uint8_t *max_heap = (uint8_t *)stack_limit;
uint8_t *prev_heap_end;
/* Initialize heap end at first call */
if (NULL == __sbrk_heap_end)
{
__sbrk_heap_end = &_end;
}
/* Protect heap from growing into the reserved MSP stack */
if (__sbrk_heap_end + incr > max_heap)
{
errno = ENOMEM;
return (void *)-1;
}
prev_heap_end = __sbrk_heap_end;
__sbrk_heap_end += incr;
return (void *)prev_heap_end;
}