diff --git a/DebugConfig/Simulation_STM32F103RB_1.0.0.dbgconf b/DebugConfig/Simulation_STM32F103RB_1.0.0.dbgconf new file mode 100644 index 0000000..66e10b6 --- /dev/null +++ b/DebugConfig/Simulation_STM32F103RB_1.0.0.dbgconf @@ -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 >>> + +// Debug MCU configuration register (DBGMCU_CR) +// Reserved bits must be kept at reset value +// DBG_TIM11_STOP TIM11 counter stopped when core is halted +// DBG_TIM10_STOP TIM10 counter stopped when core is halted +// DBG_TIM9_STOP TIM9 counter stopped when core is halted +// DBG_TIM14_STOP TIM14 counter stopped when core is halted +// DBG_TIM13_STOP TIM13 counter stopped when core is halted +// DBG_TIM12_STOP TIM12 counter stopped when core is halted +// DBG_CAN2_STOP Debug CAN2 stopped when core is halted +// DBG_TIM7_STOP TIM7 counter stopped when core is halted +// DBG_TIM6_STOP TIM6 counter stopped when core is halted +// DBG_TIM5_STOP TIM5 counter stopped when core is halted +// DBG_TIM8_STOP TIM8 counter stopped when core is halted +// DBG_I2C2_SMBUS_TIMEOUT SMBUS timeout mode stopped when core is halted +// DBG_I2C1_SMBUS_TIMEOUT SMBUS timeout mode stopped when core is halted +// DBG_CAN1_STOP Debug CAN1 stopped when Core is halted +// DBG_TIM4_STOP TIM4 counter stopped when core is halted +// DBG_TIM3_STOP TIM3 counter stopped when core is halted +// DBG_TIM2_STOP TIM2 counter stopped when core is halted +// DBG_TIM1_STOP TIM1 counter stopped when core is halted +// DBG_WWDG_STOP Debug window watchdog stopped when core is halted +// DBG_IWDG_STOP Debug independent watchdog stopped when core is halted +// DBG_STANDBY Debug standby mode +// DBG_STOP Debug stop mode +// DBG_SLEEP Debug sleep mode +// +DbgMCU_CR = 0x00000007; + +// <<< end of configuration section >>> diff --git a/Pilotes/Include/DriverGPIO.h b/Pilotes/Include/DriverGPIO.h index b0d7acb..2eae0f8 100644 --- a/Pilotes/Include/DriverGPIO.h +++ b/Pilotes/Include/DriverGPIO.h @@ -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 diff --git a/Pilotes/Source/DriverGPIO.c b/Pilotes/Source/DriverGPIO.c index 54adbab..30c0fb4 100644 --- a/Pilotes/Source/DriverGPIO.c +++ b/Pilotes/Source/DriverGPIO.c @@ -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<ODR &= ~(1< ODR = GPIO -> ODR ^ (0x1 << GPIO_Pin); } diff --git a/Pilotes/Source/MyUart.c b/Pilotes/Source/MyUart.c index 015b3e2..5291f34 100644 --- a/Pilotes/Source/MyUart.c +++ b/Pilotes/Source/MyUart.c @@ -1,16 +1,17 @@ -#include +#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); } }; diff --git a/RTE/_Reel/RTE_Components.h b/RTE/_Reel/RTE_Components.h index f313aca..6b44938 100644 --- a/RTE/_Reel/RTE_Components.h +++ b/RTE/_Reel/RTE_Components.h @@ -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' diff --git a/RTE/_Simulation/RTE_Components.h b/RTE/_Simulation/RTE_Components.h index 0ce3f00..6a369f6 100644 --- a/RTE/_Simulation/RTE_Components.h +++ b/RTE/_Simulation/RTE_Components.h @@ -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' diff --git a/Services/Source/Plateau.c b/Services/Source/Plateau.c new file mode 100644 index 0000000..7020c43 --- /dev/null +++ b/Services/Source/Plateau.c @@ -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); + +}