Ajout du service USART avec les drivers pour GPIO et Timer harmonisé avec ceux déjà sur cette branche. Ajout de MYGPIO_PinOff et MYGPIO_PinOn dans le driver de GPIO pour une fonction de la PWM. Ajout du service du plateau.

This commit is contained in:
Mygi27 2025-12-16 18:34:11 +01:00
parent 262e198447
commit b53cc78582
7 changed files with 102 additions and 16 deletions

View file

@ -0,0 +1,36 @@
// File: STM32F101_102_103_105_107.dbgconf
// Version: 1.0.0
// Note: refer to STM32F101xx STM32F102xx STM32F103xx STM32F105xx STM32F107xx Reference manual (RM0008)
// STM32F101xx STM32F102xx STM32F103xx STM32F105xx STM32F107xx datasheets
// <<< Use Configuration Wizard in Context Menu >>>
// <h> Debug MCU configuration register (DBGMCU_CR)
// <i> Reserved bits must be kept at reset value
// <o.30> DBG_TIM11_STOP <i> TIM11 counter stopped when core is halted
// <o.29> DBG_TIM10_STOP <i> TIM10 counter stopped when core is halted
// <o.28> DBG_TIM9_STOP <i> TIM9 counter stopped when core is halted
// <o.27> DBG_TIM14_STOP <i> TIM14 counter stopped when core is halted
// <o.26> DBG_TIM13_STOP <i> TIM13 counter stopped when core is halted
// <o.25> DBG_TIM12_STOP <i> TIM12 counter stopped when core is halted
// <o.21> DBG_CAN2_STOP <i> Debug CAN2 stopped when core is halted
// <o.20> DBG_TIM7_STOP <i> TIM7 counter stopped when core is halted
// <o.19> DBG_TIM6_STOP <i> TIM6 counter stopped when core is halted
// <o.18> DBG_TIM5_STOP <i> TIM5 counter stopped when core is halted
// <o.17> DBG_TIM8_STOP <i> TIM8 counter stopped when core is halted
// <o.16> DBG_I2C2_SMBUS_TIMEOUT <i> SMBUS timeout mode stopped when core is halted
// <o.15> DBG_I2C1_SMBUS_TIMEOUT <i> SMBUS timeout mode stopped when core is halted
// <o.14> DBG_CAN1_STOP <i> Debug CAN1 stopped when Core is halted
// <o.13> DBG_TIM4_STOP <i> TIM4 counter stopped when core is halted
// <o.12> DBG_TIM3_STOP <i> TIM3 counter stopped when core is halted
// <o.11> DBG_TIM2_STOP <i> TIM2 counter stopped when core is halted
// <o.10> DBG_TIM1_STOP <i> TIM1 counter stopped when core is halted
// <o.9> DBG_WWDG_STOP <i> Debug window watchdog stopped when core is halted
// <o.8> DBG_IWDG_STOP <i> Debug independent watchdog stopped when core is halted
// <o.2> DBG_STANDBY <i> Debug standby mode
// <o.1> DBG_STOP <i> Debug stop mode
// <o.0> DBG_SLEEP <i> Debug sleep mode
// </h>
DbgMCU_CR = 0x00000007;
// <<< end of configuration section >>>

View file

@ -14,4 +14,6 @@ extern int MyGPIO_Read(GPIO_TypeDef * GPIO, char GPIO_Pin); // renvoie 0 ou autr
extern void MyGPIO_Set(GPIO_TypeDef * GPIO, char GPIO_Pin);
extern void MyGPIO_Reset(GPIO_TypeDef * GPIO, char GPIO_Pin);
extern void MyGPIO_Toggle(GPIO_TypeDef * GPIO, char GPIO_Pin);
void MYGPIO_PinOn (GPIO_TypeDef *GPIO , char GPIO_Pin);
void MYGPIO_PinOff (GPIO_TypeDef *GPIO , char GPIO_Pin);
#endif

View file

@ -77,6 +77,15 @@ void MyGPIO_Reset(GPIO_TypeDef * GPIO, char GPIO_Pin) {
}
void MYGPIO_PinOn (GPIO_TypeDef *GPIO , char GPIO_Pin){
GPIO->ODR |= (1<<GPIO_Pin);
};
void MYGPIO_PinOff (GPIO_TypeDef *GPIO , char GPIO_Pin){
GPIO->ODR &= ~(1<<GPIO_Pin);
};
void MyGPIO_Toggle(GPIO_TypeDef * GPIO, char GPIO_Pin) {
GPIO -> ODR = GPIO -> ODR ^ (0x1 << GPIO_Pin);
}

View file

@ -1,16 +1,17 @@
#include <stm32f10x.h>
#include "stm32f10x.h"
#include "DriverGPIO.h"
void My_USART_Config(USART_TypeDef* USARTx, uint32_t baudrate) { //QUE POUR USART1
// Configuration PA9 (Tx) en Alternate Function Push-Pull
MyGPIO_Init(GPIOA, 9 , 0xB);
MyGPIO_Init(GPIOA, 9 , AltOut_Ppull);
// Configuration PA10 (Rx) en Input Floating
MyGPIO_Init(GPIOA, 10 , 0x4);
MyGPIO_Init(GPIOA, 10 , In_Floating);
NVIC_EnableIRQ(USART1_IRQn);
NVIC_SetPriority(USART1_IRQn, 3<<4);
RCC->APB2ENR |= RCC_APB2ENR_USART1EN;
// USARTx->CR2 |= USART_CR2_CLKEN;
USARTx->CR1 |= USART_CR1_UE;
USARTx->BRR = baudrate;
USARTx->CR1 |= USART_CR1_TE;
@ -19,35 +20,35 @@ void My_USART_Config(USART_TypeDef* USARTx, uint32_t baudrate) { //QUE POUR USAR
void USART_Send_Char(USART_TypeDef* USARTx, char car) {
while ((USARTx->SR & USART_SR_TXE)==0){}
while ((USARTx->SR & USART_SR_TXE)==0){
}
USARTx->DR = car;
};
void USART_Send_String(USART_TypeDef *USARTx, char *pString) {
while (*pString != '\0') {
void USART_Send_String(USART_TypeDef *USARTx, char *pString)
{
while (*pString != '\0')
{
USART_Send_Char(USARTx, *pString);
pString++;
}
};
void (*pFnc_Receive)(char);
void (*pFnc_Receive) (int);
void USART_IT_Receive_Enable(USART_TypeDef* USARTx) {
USARTx->CR1 |= USART_CR1_RXNEIE;
};
void Init_IT_Receive(void (*Receive_IT_function) (char)){
void Init_IT_Receive(void (*Receive_IT_function) (int)){
pFnc_Receive = Receive_IT_function;
};
void USART1_IRQHandler(void){
signed char commande = USART1->DR;
int commande_int = (int) commande;
if (pFnc_Receive != 0) {
pFnc_Receive(commande);
pFnc_Receive(commande_int);
}
};

View file

@ -1,6 +1,6 @@
/*
* UVISION generated file: DO NOT EDIT!
* Generated by: uVision version 5.42.0.0
* Generated by: uVision version 5.43.1.0
*
* Project: 'ProjetVoilier'
* Target: 'Reel'

View file

@ -1,6 +1,6 @@
/*
* UVISION generated file: DO NOT EDIT!
* Generated by: uVision version 5.42.0.0
* Generated by: uVision version 5.43.1.0
*
* Project: 'ProjetVoilier'
* Target: 'Simulation'

38
Services/Source/Plateau.c Normal file
View file

@ -0,0 +1,38 @@
#include "stm32f10x.h"
#include "PWM.h"
#include "DriverGPIO.h"
#include "Horloge.h"
void initPlato(TIM_TypeDef * Timer, int Channel){ // Config du moteur servo
MyGPIO_Init(GPIOB, 5, AltOut_Ppull); //config pin de direction 0 ou 1
if (Timer == TIM3) {
Timer_Init(TIM3, 159, 17); // Pour obtenir fréq de 20kHZ
if (Channel == 3){
MyGPIO_Init(GPIOB, 0, AltOut_Ppull); // Outut push pull alternate, config pin de consigne entre -100 et 100
MyTimer_PWM(TIM3, 3); //TIM3 CH3
}
else{
//printf("Ce pilote n'existe pas");
}
}
else{
//printf("Ce pilote n'existe pas");
}
}
void Update_Motor_PWM(int Consigne, TIM_TypeDef * Timer, int Channel) {
int duty_cycle;
if (Consigne>=0){
MYGPIO_PinOn(GPIOB, 5);
duty_cycle = Consigne;
};
if (Consigne<0){
MYGPIO_PinOff(GPIOB,5);
duty_cycle = -Consigne;
};
Set_DutyCycle_PWM(Timer, Channel, duty_cycle);
}