Compare commits
44 commits
main
...
Activites_
| Author | SHA1 | Date | |
|---|---|---|---|
| 7b40ab4ffc | |||
| dffc7d50df | |||
| 71e2f55c50 | |||
| a79ec6a59c | |||
| 0ab684fc00 | |||
| a7e2a63ffc | |||
| 2d3fdc0fad | |||
| 01ffdcfb99 | |||
| 078e8384d5 | |||
| cd739176a3 | |||
| 1283e0f110 | |||
| a54c43911f | |||
| 4d895d45b6 | |||
| 5a7f6e10e6 | |||
| d1bcdc3c4f | |||
| dabd3d6c83 | |||
| 1948cb7347 | |||
| e0ca0f4a1b | |||
| b55d936354 | |||
| 757f549365 | |||
| acd2b99fa3 | |||
| 73e79729e0 | |||
| a631dee3e1 | |||
| 5c538d13f6 | |||
| 6b94c43b98 | |||
| cacffbcb3f | |||
| e720a1bc55 | |||
| 1fddb1ed8c | |||
| 1435e10cef | |||
| 7d5b89ff33 | |||
| 35f3cc9da8 | |||
| 59950ca590 | |||
| d9bee1b366 | |||
| c8a9ce32c4 | |||
| aa64344f3b | |||
| 253b63b738 | |||
| 2ad9ce5602 | |||
| fa5194e9bf | |||
| b7a1bb1171 | |||
| d1f7df6251 | |||
| ddf3538d45 | |||
| a7a27d7bb3 | |||
| 869cd02272 | |||
| 5d16703d01 |
31 changed files with 940 additions and 0 deletions
14
CantoOrvikPilotes/Include/DriverGPIO.h
Normal file
14
CantoOrvikPilotes/Include/DriverGPIO.h
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#include "stm32f10x.h"
|
||||
#define In_Floating 0x4
|
||||
#define In_PullDown 0x8
|
||||
#define In_PullUp 0x8
|
||||
#define In_Analog 0x0
|
||||
#define Out_Ppull 0x3
|
||||
#define Out_OD 0x7
|
||||
#define AltOut_Ppull 0xB
|
||||
#define AltOut_OD 0xF
|
||||
extern void MyGPIO_Init(GPIO_TypeDef * GPIO, char pin, char conf );
|
||||
extern int MyGPIO_Read(GPIO_TypeDef * GPIO, char GPIO_Pin); // renvoie 0 ou autre chose different de 0
|
||||
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);
|
||||
8
CantoOrvikPilotes/Include/GPIO.h
Normal file
8
CantoOrvikPilotes/Include/GPIO.h
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
// Gestion des signaux
|
||||
extern int ChercherEtat(GPIO_TypeDef * GPIO, int pin);
|
||||
extern void ResetBroche(uint32_t GPIO, int Broche);
|
||||
extern void SetBroche(uint32_t GPIO, int Broche);
|
||||
extern void TogglePin(GPIO_TypeDef*GPIO, int Broche);
|
||||
// Config des broches
|
||||
extern void ConfigureBroche(uint32_t GPIO, int Broche, int IO, char Mode);
|
||||
|
||||
11
CantoOrvikPilotes/Include/MyTimer.h
Normal file
11
CantoOrvikPilotes/Include/MyTimer.h
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#include "stm32f10x.h"
|
||||
|
||||
//TIMERS start
|
||||
#define MyTimer_Base_Start(Timer) (Timer->CR1 |= TIM_CR1_CEN)
|
||||
#define MyTimer_Base_Stop(Timer) (Timer -> CR1 =(0x0))
|
||||
// IT
|
||||
extern volatile int g_tick_count; // Declara que a variável existe em outro arquivo
|
||||
void Test(void);
|
||||
void ConfigureIT();
|
||||
// PWM
|
||||
void ConfigurePWM();
|
||||
8
CantoOrvikPilotes/Include/Nucleo.h
Normal file
8
CantoOrvikPilotes/Include/Nucleo.h
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#include "stm32f10x.h"
|
||||
// Config
|
||||
extern void ConfigHorloge(void);
|
||||
extern void ConfigBroche(void);
|
||||
// Gestion des IO Spesifiques
|
||||
extern int BoutonAppuye(void);
|
||||
extern void AllumerLED(void);
|
||||
extern void EteindreLED(void);
|
||||
4
CantoOrvikPilotes/Include/PWM.h
Normal file
4
CantoOrvikPilotes/Include/PWM.h
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#include "stm32f10x.h"
|
||||
// Config
|
||||
extern void MyTimer_PWM(TIM_TypeDef *Timer, char Channel);
|
||||
extern void MyTimer_Set_DutyCycle(TIM_TypeDef *Timer, char Channel, float DutyCycle_Percent);
|
||||
12
CantoOrvikPilotes/Include/Timer.h
Normal file
12
CantoOrvikPilotes/Include/Timer.h
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#include "stm32f10x.h"
|
||||
// Config de timer
|
||||
extern void MyTimer_Base_Init(TIM_TypeDef *Timer , unsigned short ValARR , unsigned short ValPSC );
|
||||
extern void MyTimer_ActiveIT(TIM_TypeDef *Timer, char Prio,void(*IT_function)(void));
|
||||
// Fonctions d'interruption
|
||||
extern void TIM2_IRQHandler(void);
|
||||
extern void TIM3_IRQHandler(void);
|
||||
extern void TIM4_IRQHandler(void);
|
||||
extern void TIM1_CC_IRQnHandler(void);
|
||||
extern void TIM1_UP_IRQnHandler(void);
|
||||
// Enable timers
|
||||
extern void EnableTimer();
|
||||
BIN
CantoOrvikPilotes/Include/test.h
Normal file
BIN
CantoOrvikPilotes/Include/test.h
Normal file
Binary file not shown.
BIN
CantoOrvikPilotes/Source/ADC.c
Normal file
BIN
CantoOrvikPilotes/Source/ADC.c
Normal file
Binary file not shown.
80
CantoOrvikPilotes/Source/DriverGPIO.c
Normal file
80
CantoOrvikPilotes/Source/DriverGPIO.c
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
#include "stm32f10x.h"
|
||||
|
||||
#define In_Floating 0x4
|
||||
#define In_PullDown 0x8
|
||||
#define In_PullUp 0x8
|
||||
#define In_Analog 0x0
|
||||
#define Out_Ppull 0x3
|
||||
#define Out_OD 0x7
|
||||
#define AltOut_Ppull 0xB
|
||||
#define AltOut_OD 0xF
|
||||
|
||||
void MyGPIO_Init(GPIO_TypeDef * GPIO, char pin, char conf ){
|
||||
int shift_pin;
|
||||
//Start clock
|
||||
if(GPIO == GPIOA){
|
||||
RCC -> APB2ENR |= RCC_APB2ENR_IOPAEN;
|
||||
}
|
||||
else if(GPIO == GPIOB){
|
||||
RCC -> APB2ENR |= RCC_APB2ENR_IOPBEN;
|
||||
}
|
||||
else if(GPIO == GPIOC){
|
||||
RCC -> APB2ENR |= RCC_APB2ENR_IOPCEN;
|
||||
}
|
||||
else if(GPIO == GPIOD){
|
||||
RCC -> APB2ENR |= RCC_APB2ENR_IOPDEN;
|
||||
}
|
||||
if(pin < 8){//CRL zone
|
||||
shift_pin = pin*4;
|
||||
GPIO -> CRL &= ~(0xF << shift_pin);
|
||||
//PullUp and PullDown have the same conf number, so we need to change the ODR to diferenciate them both
|
||||
if(conf == In_PullUp){
|
||||
GPIO -> CRL |= ( In_PullUp << shift_pin);
|
||||
GPIO -> ODR |= (1<<pin);
|
||||
}
|
||||
else if(conf == In_PullDown){
|
||||
GPIO -> CRL |= ( In_PullDown << shift_pin);
|
||||
GPIO -> ODR &= ~(1<<pin);
|
||||
}
|
||||
else{
|
||||
GPIO -> CRL |= ( conf << shift_pin);
|
||||
}
|
||||
}
|
||||
else{//CRH zone
|
||||
shift_pin = (pin-8)*4;
|
||||
GPIO -> CRH &= ~(0xF << shift_pin);
|
||||
if(conf == In_PullUp){
|
||||
GPIO -> CRH |= ( In_PullUp << shift_pin);
|
||||
GPIO -> ODR |= (1<<pin);
|
||||
}
|
||||
else if(conf == In_PullDown){
|
||||
GPIO -> CRH |= ( In_PullDown << shift_pin);
|
||||
GPIO -> ODR &= ~(1<<pin);
|
||||
}
|
||||
else{
|
||||
GPIO -> CRH |= ( conf << shift_pin);
|
||||
}
|
||||
}
|
||||
}
|
||||
int MyGPIO_Read(GPIO_TypeDef * GPIO, char GPIO_Pin){
|
||||
if(GPIO -> IDR & (1 << GPIO_Pin)){
|
||||
return 1;
|
||||
}
|
||||
else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
void MyGPIO_Set(GPIO_TypeDef * GPIO, char GPIO_Pin){
|
||||
GPIO -> BSRR = (1<<GPIO_Pin);//1 on set zone
|
||||
}
|
||||
void MyGPIO_Reset(GPIO_TypeDef * GPIO, char GPIO_Pin){
|
||||
GPIO -> BSRR = (1<<(GPIO_Pin+16));//1 on reset zone
|
||||
}
|
||||
void MyGPIO_Toggle(GPIO_TypeDef * GPIO, char GPIO_Pin){
|
||||
if((GPIO-> ODR & (1<<GPIO_Pin)) != 0){
|
||||
GPIO -> BSRR = (1<<(GPIO_Pin+16));
|
||||
}
|
||||
else{
|
||||
GPIO -> BSRR = (1<<GPIO_Pin);
|
||||
}
|
||||
}
|
||||
106
CantoOrvikPilotes/Source/GPIO.c
Normal file
106
CantoOrvikPilotes/Source/GPIO.c
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
#include "stm32f10x.h"
|
||||
#include <stdlib.h>
|
||||
#include "../Include/GPIO.h"
|
||||
|
||||
int ChercherEtat(GPIO_TypeDef * GPIO, int pin){ // Trouvons la valeur d'un broche sur un certain GPIO
|
||||
return((GPIO -> IDR & (0x01 << pin)));
|
||||
}
|
||||
|
||||
void ResetBroche(GPIO_TypeDef * GPIO, int Broche){ // Mettre à zero d'un certain broche d'un certain GPIO
|
||||
GPIO -> BSRR |= BS Broche;
|
||||
}
|
||||
|
||||
void SetBroche(uint32_t * GPIO, int Broche){ // Mettre à zero d'un certain broche d'un certain GPIO
|
||||
GPIO -> BSRR |= BSBroche << 16;
|
||||
}
|
||||
|
||||
void TogglePin(GPIO_TypeDef * GPIO, int Broche){ // Inverser la valueur de broche sur GPIO
|
||||
GPIO -> ODR = GPIO -> ODR ^ (0x1 << Broche);
|
||||
}
|
||||
|
||||
void ConfigureGPIO(uint32_t * GPIO, int Broche, int IO, char * Mode){ // Mettre un broche d'un GPIO sur un mode
|
||||
// Possble de améliorer avec des int à la place de string
|
||||
//Start clock pour les GPIO concernés
|
||||
if(GPIO == GPIOA){
|
||||
RCC -> APB2ENR |= RCC_APB2ENR_IOPAEN;
|
||||
}
|
||||
else if(GPIO == GPIOB){
|
||||
RCC -> APB2ENR |= RCC_APB2ENR_IOPBEN;
|
||||
}
|
||||
else if(GPIO == GPIOC){
|
||||
RCC -> APB2ENR |= RCC_APB2ENR_IOPCEN;
|
||||
}
|
||||
else if(GPIO == GPIOD){
|
||||
RCC -> APB2ENR |= RCC_APB2ENR_IOPDEN;
|
||||
}
|
||||
// Cas d'u CRL, broche 0 à 7
|
||||
if (Broche < 8) {
|
||||
GPIO -> CRL &= ~(0x1 << Broche *4) & ~(0x1 << Broche *4 +1) & ~(0x1 << Broche *4 + 2) & ~(0x1 << Broche *4 + 3); // Clean bits
|
||||
if (IO == 0){ //Input
|
||||
if (strcmp(Mode,"Floating")) {
|
||||
GPIO -> CRL |= (0x1 << Broche *4) | (0x1 << Broche * 4 + 1);
|
||||
}
|
||||
else if (strcmp(Mode,"Pull-Up") || strcmp(Mode,"Pull-Down")){
|
||||
GPIO -> CRL |= (0x1 << 6*4 + 1);
|
||||
}
|
||||
else {
|
||||
return; // Mode invalid
|
||||
}
|
||||
}
|
||||
else if ( IO < 5) { // Output
|
||||
GPIO -> CRL |= (0xIO << Broche * 4 + 2); // Frequency mode
|
||||
if (strcmp(Mode, "Open-Drain")){
|
||||
GPIO -> CRL |= (0x1 << Broche *4);
|
||||
}
|
||||
else if (strcmp(Mode, "Push-Pull Alterne")){
|
||||
GPIO -> CRL |= (0x1 << Broche *4 + 1);
|
||||
RCC->APB2ENR |= RCC_APB2ENR_AFIOEN; // Alternate Function I/O clock enable GPIOA
|
||||
}
|
||||
else if (strcmp(Mode, "Open-Drain Alterne")){
|
||||
GPIO -> CRL |= (0x1 << Broche * 4) | (0x1 << Broche * 4 + 1);
|
||||
}
|
||||
else {
|
||||
return; // Mode invalid
|
||||
}
|
||||
}
|
||||
else{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (Broche < 16) {
|
||||
GPIO -> CRH &= ~(0x1 << Broche *4) & ~(0x1 << Broche *4 +1) & ~(0x1 << Broche *4 + 2) & ~(0x1 << Broche *4 + 3); // Clean bits
|
||||
if (IO == 0){ //Input
|
||||
if (strcmp(Mode,"Floating")) {
|
||||
GPIO -> CRH |= (0x1 << Broche *4) | (0x1 << Broche * 4 + 1);
|
||||
}
|
||||
else if (strcmp(Mode,"Pull-Up") || strcmp(Mode,"Pull-Down")){
|
||||
GPIO -> CRH |= (0x1 << 6*4 + 1);
|
||||
}
|
||||
else {
|
||||
return; // Mode invalid or doesn't exist
|
||||
}
|
||||
}
|
||||
else if ( IO < 5) { // Output
|
||||
GPIO -> CRH |= (0xIO << Broche * 4 + 2); // Frequency mode
|
||||
if (strcmp(Mode, "Open-Drain")){
|
||||
GPIO -> CRH |= (0x1 << Broche *4);
|
||||
}
|
||||
else if (strcmp(Mode, "Push-Pull Alterne")){
|
||||
GPIO -> CRH |= (0x1 << Broche *4 + 1);
|
||||
}
|
||||
else if (strcmp(Mode, "Open-Drain Alterne")){
|
||||
GPIO -> CRH |= (0x1 << Broche * 4) | (0x1 << Broche * 4 + 1);
|
||||
}
|
||||
else {
|
||||
return; // Mode invalid or doesn't exits
|
||||
}
|
||||
}
|
||||
else{
|
||||
return; // IO invalid
|
||||
}
|
||||
}
|
||||
else{
|
||||
return; // Pin number invalid
|
||||
}
|
||||
}
|
||||
|
||||
36
CantoOrvikPilotes/Source/MyTimer.c
Normal file
36
CantoOrvikPilotes/Source/MyTimer.c
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
#include "stm32f10x.h"
|
||||
#include "../Include/Timer.h"
|
||||
#include "../Include/PWM.h"
|
||||
#include "../Include/DriverGPIO.h"
|
||||
// Variables
|
||||
#define ARR_TIM1 0xFFAD
|
||||
#define PSC_TIM1 0xFF
|
||||
#define ARR_TIM2 0xFFAD
|
||||
#define PSC_TIM2 0x0225
|
||||
#define ARR_TIM3 0x2CF
|
||||
#define PSC_TIM3 0x0
|
||||
|
||||
volatile int g_tick_count;
|
||||
void Test(void){
|
||||
// Signal
|
||||
g_tick_count++;
|
||||
MyGPIO_Toggle(GPIOA, 8);
|
||||
}
|
||||
|
||||
void ConfigureTimers(){
|
||||
MyTimer_Base_Init(TIM2, ARR_TIM2, PSC_TIM2);
|
||||
MyTimer_Base_Init(TIM1, ARR_TIM1, PSC_TIM1);
|
||||
MyTimer_Base_Init(TIM3, ARR_TIM2, PSC_TIM2);
|
||||
EnableTimer(TIM1);
|
||||
EnableTimer(TIM2);
|
||||
EnableTimer(TIM3);
|
||||
}
|
||||
void ConfigureIT(){
|
||||
//MyTimer_ActiveIT(TIM2, 4, Test); //start interruption with priority 4
|
||||
//MyTimer_ActiveIT(TIM1, 4, Test); //start interruption with priority 4
|
||||
MyTimer_ActiveIT(TIM3, 4, Test); //start interruption with priority 4
|
||||
}
|
||||
void ConfigurePWM(){
|
||||
MyTimer_PWM(TIM1, 1);
|
||||
MyTimer_Set_DutyCycle(TIM1, 1, 20.0);
|
||||
}
|
||||
37
CantoOrvikPilotes/Source/Nucleo.c
Normal file
37
CantoOrvikPilotes/Source/Nucleo.c
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
#include "stm32f10x.h"
|
||||
#include "../Include/Nucleo.h"
|
||||
#include "GPIO.h"
|
||||
|
||||
void ConfigHorloge(void) { // Peut-être redondant ??
|
||||
RCC->APB2ENR |= (0x01 << 2) | (0x01 << 3) | (0x01 << 4) | RCC_APB2ENR_IOPCEN | RCC_APB2ENR_TIM1EN;
|
||||
};
|
||||
|
||||
void ConfigBroche(void){ //
|
||||
//Mettre Broche 5 GPIOA à output push-pull
|
||||
ConfigureGPIO(GPIOA, 5, 4, Push-Pull);
|
||||
// Equivaut à :
|
||||
//GPIOA ->CRL &= ~(0x1 << (5*4 + 2)); //0x44144444;
|
||||
//GPIOA ->CRL |= (0x1 << 5*4); //0x44144444;
|
||||
|
||||
//Mettre broche 8 sur GPIOA à output open drain
|
||||
ConfigureGPIO(GPIOA, 8, 4, Open-Drain);
|
||||
// Equivaut à :
|
||||
//GPIOA ->CRH |= (0x1 );
|
||||
};
|
||||
|
||||
int BoutonAppuye(void){ // Peut être modifié avec ChercherEtat
|
||||
ChercherEtat(GPIOA, 9);
|
||||
// Equivaut à
|
||||
//return((GPIOA -> IDR & (0x01 << 9)));
|
||||
}
|
||||
void AllumerLED(void){
|
||||
SetBroche(GPIOA, 8);
|
||||
// Equivaut à :
|
||||
//GPIOA -> ODR &= ~(0x1 << 8); // Peut être modifié avec SetBroche
|
||||
}
|
||||
void EteindreLED(void){
|
||||
ResetBroche(GPIOA, 8);
|
||||
// Equivaut à :
|
||||
//GPIOA -> ODR |= (0x1 << 8); // Peut être modifié avec ResetBroche
|
||||
}
|
||||
|
||||
67
CantoOrvikPilotes/Source/PWM.c
Normal file
67
CantoOrvikPilotes/Source/PWM.c
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
#include "stm32f10x.h"
|
||||
#include "../Include/PWM.h"
|
||||
|
||||
|
||||
void MyTimer_PWM(TIM_TypeDef *Timer, char Channel) { // Activer PWM sur un output
|
||||
// preload
|
||||
Timer->CR1 |= TIM_CR1_ARPE;
|
||||
|
||||
switch (Channel) {
|
||||
case 1:
|
||||
// Config o channel 1 in "PWM Mode 1" and enable preload of CCR1
|
||||
Timer->CCMR1 &= ~TIM_CCMR1_OC1M; // clean bit modes
|
||||
Timer->CCMR1 |= TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_1; // Mode PWM 1
|
||||
Timer->CCMR1 |= TIM_CCMR1_OC1PE; // enable preload
|
||||
|
||||
// enable exit 1 (Output enable)
|
||||
Timer->CCER |= TIM_CCER_CC1E;
|
||||
break;
|
||||
case 2:
|
||||
Timer->CCMR1 &= ~TIM_CCMR1_OC2M;
|
||||
Timer->CCMR1 |= TIM_CCMR1_OC2M_2 | TIM_CCMR1_OC2M_1;
|
||||
Timer->CCMR1 |= TIM_CCMR1_OC2PE;
|
||||
Timer->CCER |= TIM_CCER_CC2E;
|
||||
break;
|
||||
case 3:
|
||||
Timer->CCMR2 &= ~TIM_CCMR2_OC3M;
|
||||
Timer->CCMR2 |= TIM_CCMR2_OC3M_2 | TIM_CCMR2_OC3M_1;
|
||||
Timer->CCMR2 |= TIM_CCMR2_OC3PE;
|
||||
Timer->CCER |= TIM_CCER_CC3E;
|
||||
break;
|
||||
case 4:
|
||||
Timer->CCMR2 &= ~TIM_CCMR2_OC4M;
|
||||
Timer->CCMR2 |= TIM_CCMR2_OC4M_2 | TIM_CCMR2_OC4M_1;
|
||||
Timer->CCMR2 |= TIM_CCMR2_OC4PE;
|
||||
Timer->CCER |= TIM_CCER_CC4E;
|
||||
break;
|
||||
}
|
||||
|
||||
// special case(specific timers)
|
||||
if (Timer == TIM1 || Timer == TIM8) {
|
||||
Timer->BDTR |= TIM_BDTR_MOE;
|
||||
}
|
||||
}
|
||||
void MyTimer_Set_DutyCycle(TIM_TypeDef *Timer, char Channel, float DutyCycle_Percent) {
|
||||
unsigned short ccr_value;
|
||||
|
||||
// Percentages between 0 and 100
|
||||
if (DutyCycle_Percent > 100.0) DutyCycle_Percent = 100.0;
|
||||
if (DutyCycle_Percent < 0.0) DutyCycle_Percent = 0.0;
|
||||
// calcule of crr
|
||||
ccr_value = (unsigned short)((DutyCycle_Percent / 100.0) * (Timer->ARR));
|
||||
// Assigner le valaur pour le registre de comparison pour le channel qui est pertient
|
||||
switch (Channel) {
|
||||
case 1:
|
||||
Timer->CCR1 = ccr_value;
|
||||
break;
|
||||
case 2:
|
||||
Timer->CCR2 = ccr_value;
|
||||
break;
|
||||
case 3:
|
||||
Timer->CCR3 = ccr_value;
|
||||
break;
|
||||
case 4:
|
||||
Timer->CCR4 = ccr_value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
106
CantoOrvikPilotes/Source/Timer.c
Normal file
106
CantoOrvikPilotes/Source/Timer.c
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
#include "stm32f10x.h"
|
||||
#include "../Include/Timer.h"
|
||||
|
||||
//REMEMBER TO ENALBLE TIMERS
|
||||
//EXAMPLES
|
||||
//RCC -> APB1ENR |= RCC_APB1ENR_TIM2EN | RCC_APB1ENR_TIM3EN; // Enable TIM2
|
||||
//RCC->APB2ENR |= RCC_APB2ENR_TIM1EN; // Enable TIM1
|
||||
|
||||
void MyTimer_Base_Init( TIM_TypeDef * Timer , unsigned short ValARR , unsigned short ValPSC ) { // Configuration du timer
|
||||
Timer -> PSC=(ValPSC);
|
||||
Timer-> ARR = (ValARR);
|
||||
Timer->EGR |= TIM_EGR_UG;
|
||||
};
|
||||
|
||||
|
||||
static void (*p_IT_functions[4])(void); // Pour créer l'array des fonctions
|
||||
|
||||
void MyTimer_ActiveIT(TIM_TypeDef *Timer, char Prio,void(*IT_function)(void)) {
|
||||
//Enable interruption requisition
|
||||
Timer->DIER |= TIM_DIER_UIE; // Update interrupt enable
|
||||
|
||||
//Id the interruption timer routine
|
||||
IRQn_Type IRQn;
|
||||
|
||||
int timer_index = -1; // Indice pour notre array des pointeurs
|
||||
if (Timer == TIM2) {
|
||||
IRQn = TIM2_IRQn;
|
||||
timer_index = 0;
|
||||
} else if (Timer == TIM3) {
|
||||
IRQn = TIM3_IRQn;
|
||||
timer_index = 1;
|
||||
} else if (Timer == TIM4) {
|
||||
IRQn = TIM4_IRQn;
|
||||
timer_index = 2;
|
||||
}
|
||||
// Keep the pointer of the valid timer function
|
||||
if (timer_index != -1) {
|
||||
p_IT_functions[timer_index] = IT_function; // index the function
|
||||
} else {
|
||||
return; // Timer invalid
|
||||
}
|
||||
|
||||
// set interruption priority
|
||||
NVIC_SetPriority(IRQn, Prio);
|
||||
|
||||
// Enable routine
|
||||
NVIC_EnableIRQ(IRQn);
|
||||
};
|
||||
|
||||
|
||||
void TIM2_IRQHandler(void) {
|
||||
// Clean flag
|
||||
TIM2->SR &= ~TIM_SR_UIF; // Drapeau d'interuption
|
||||
//Call function
|
||||
if (p_IT_functions[0] != 0) {
|
||||
p_IT_functions[0](); // Execute fonction
|
||||
}
|
||||
};
|
||||
void TIM3_IRQHandler(void) {
|
||||
// Clean flag
|
||||
TIM3->SR &= ~TIM_SR_UIF;
|
||||
//Call function
|
||||
if (p_IT_functions[1] != 0) {
|
||||
p_IT_functions[1](); // Execute function
|
||||
}
|
||||
};
|
||||
void TIM4_IRQHandler(void) {
|
||||
// Clean flag
|
||||
TIM4->SR &= ~TIM_SR_UIF;
|
||||
//Call function
|
||||
if (p_IT_functions[2] != 0) {
|
||||
p_IT_functions[2](); // Execute function
|
||||
}
|
||||
};
|
||||
// IT PWM
|
||||
void TIM1_CC_IRQHandler(void) {
|
||||
// Clean flag
|
||||
TIM1 -> DIER &= ~TIM_DIER_CC1IE;
|
||||
//Set bit
|
||||
GPIOA -> ODR |= (0x1 << 8);
|
||||
};
|
||||
|
||||
void TIM1_UP_IRQHandler(void) {
|
||||
// Clean flag
|
||||
TIM1-> DIER &= ~TIM_DIER_TIE;
|
||||
|
||||
//Reset bit
|
||||
GPIOA -> ODR &= ~(0x1 << 8);
|
||||
|
||||
};
|
||||
void EnableTimer(TIM_TypeDef *Timer){
|
||||
if(Timer == TIM2){
|
||||
RCC -> APB1ENR |= RCC_APB1ENR_TIM2EN;
|
||||
}
|
||||
else if(Timer == TIM3){
|
||||
RCC -> APB1ENR |= RCC_APB1ENR_TIM3EN;
|
||||
}
|
||||
else if(Timer == TIM4){
|
||||
RCC -> APB1ENR |= RCC_APB1ENR_TIM4EN;
|
||||
}
|
||||
else if(Timer == TIM1){
|
||||
RCC->APB2ENR |= RCC_APB2ENR_TIM1EN;
|
||||
}
|
||||
else{
|
||||
}
|
||||
}
|
||||
BIN
Images/Cible.png
Normal file
BIN
Images/Cible.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 114 KiB |
BIN
Images/RegisterMap_SPI.png
Normal file
BIN
Images/RegisterMap_SPI.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 196 KiB |
39
NicolasYarno/MyGPIO.c
Normal file
39
NicolasYarno/MyGPIO.c
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
#include "stm32f10x.h"
|
||||
|
||||
|
||||
void GPIO_configure(GPIO_TypeDef *GPIO ,int pin, char mode){
|
||||
if (mode == 1) { // output push pull 2MHZ
|
||||
GPIO->CRL = (GPIO->CRL & ~(0xF<<pin*4)) | (0x2<<pin*4);
|
||||
}
|
||||
if (mode == 2) { // input pullup
|
||||
GPIO->CRL = (GPIO->CRL & ~(0xF<<pin*4)) | (0x8<<pin*4);
|
||||
GPIO->ODR |= (1<<pin);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void allume_led (GPIO_TypeDef *GPIO , char GPIO_Pin){
|
||||
GPIO->ODR |= (1<<GPIO_Pin);
|
||||
};
|
||||
|
||||
void eteindre_led (GPIO_TypeDef *GPIO , char GPIO_Pin){
|
||||
GPIO->ODR &= ~(1<<GPIO_Pin);
|
||||
};
|
||||
|
||||
void toggle_pin (GPIO_TypeDef *GPIO , char GPIO_Pin){
|
||||
if ((GPIO->ODR & (1<<GPIO_Pin)) == 0)
|
||||
GPIO->ODR |= (1<<GPIO_Pin);
|
||||
else
|
||||
GPIO->ODR &= ~(1<<GPIO_Pin);
|
||||
};
|
||||
|
||||
|
||||
int GPIO_bouton_read (GPIO_TypeDef *GPIO , char GPIO_Pin ){
|
||||
if ((GPIO->IDR & (1<<GPIO_Pin)) == 0) {
|
||||
return 0;
|
||||
}
|
||||
else{
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
BIN
NicolasYarno/MyPWM.c
Normal file
BIN
NicolasYarno/MyPWM.c
Normal file
Binary file not shown.
6
NicolasYarno/MyUart.c
Normal file
6
NicolasYarno/MyUart.c
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#include "stm32f10x.h"
|
||||
|
||||
|
||||
void My_USART_Config(USART_TypeDef* USARTx, uint32_t baudrate) {
|
||||
|
||||
uint32_t f_clk = 0;
|
||||
61
NicolasYarno/Mytimer.c
Normal file
61
NicolasYarno/Mytimer.c
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
#include "stm32f10x.h"
|
||||
|
||||
void MyTimer_Base_Init (TIM_TypeDef * Timer , unsigned short ValARR , unsigned short ValPSC ){
|
||||
Timer->ARR = ValARR;
|
||||
Timer->PSC = ValPSC;
|
||||
};
|
||||
/*
|
||||
TIM2_CH1
|
||||
PWM mode 2 by writing OC1M=’111’ in the TIMx_CCMR1
|
||||
|
||||
he PWM mode can be selected independently on each channel (one PWM per OCx
|
||||
output) by writing ‘110’ (PWM mode 1) or ‘111’ (PWM mode 2) in the OCxM bits in the
|
||||
TIMx_CCMRx register. You must enable the corresponding preload register by setting the
|
||||
OCxPE bit in the TIMx_CCMRx register, and eventually the auto-reload preload register (in
|
||||
upcounting or center-aligned modes) by setting the ARPE bit in the TIMx_CR1 register
|
||||
|
||||
110: PWM mode 1 - In upcounting, channel 1 is active as long as TIMx_CNT<TIMx_CCR1
|
||||
else inactive. In downcounting, channel 1 is inactive (OC1REF=‘0’) as long as
|
||||
TIMx_CNT>TIMx_CCR1 else active (OC1REF=’1’).
|
||||
|
||||
void MyTimer_PWM( TIM_TypeDef * Timer, char Channel){
|
||||
Timer->CCMR1
|
||||
|
||||
|
||||
|
||||
};
|
||||
*/
|
||||
|
||||
|
||||
void (*pFnc) (void);
|
||||
|
||||
void MyTimer_ActiveIT (TIM_TypeDef * Timer , char prio, void (*IT_function)(void)){
|
||||
Timer->DIER |= TIM_DIER_UIE;
|
||||
IRQn_Type IRQn;
|
||||
if (Timer == TIM2) IRQn = TIM2_IRQn;
|
||||
else if (Timer == TIM3) IRQn = TIM3_IRQn;
|
||||
else if (Timer == TIM4) IRQn = TIM4_IRQn;
|
||||
NVIC_EnableIRQ(IRQn);
|
||||
NVIC_SetPriority(IRQn, prio);
|
||||
|
||||
pFnc = IT_function;
|
||||
};
|
||||
|
||||
|
||||
void TIM2_IRQHandler(void){
|
||||
if (pFnc != 0){
|
||||
(*pFnc) (); /* appel indirect de la fonction */
|
||||
}
|
||||
TIM2->SR &= ~TIM_SR_UIF;
|
||||
};
|
||||
|
||||
|
||||
void TIM3_IRQHandler(void){
|
||||
TIM3->SR &= ~TIM_SR_UIF;
|
||||
|
||||
};
|
||||
|
||||
void TIM4_IRQHandler(void){
|
||||
TIM4->SR &= ~TIM_SR_UIF;
|
||||
|
||||
};
|
||||
|
|
@ -1,4 +1,8 @@
|
|||
Bienvenue dans le projet voilier en µcontroleurs 4AE-SE 2025.
|
||||
Velkommen til seilbåtprosjektet i µkontrollere 4AE-SE 2025.
|
||||
|
||||
##Pour créer un projet:
|
||||
|
||||
>>Ajouter les pilotes en cible:
|
||||
|
||||

|
||||
|
|
|
|||
16
TabanJohnse/Pilotes/Headers/Horloge.h
Normal file
16
TabanJohnse/Pilotes/Headers/Horloge.h
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#include <stm32f10x.h>
|
||||
#define PSC_VAL 624
|
||||
#define ARR_VAL 0xE0FF
|
||||
|
||||
//DUTY CYCLE
|
||||
#define DUTYC 70 //Chiffre entre 0 et 100, où 100 est 100% duty cycle
|
||||
#define POWERMODE 1 // 1 vaut powermode 1, 0 vaut powermode 2 (Powermode pour le config de dutycycle)
|
||||
//Powermode 1 reste sur la bonne polarité: cad. si DUTY_CYCLE vaut 60 alors le signal reste HIGH pour 60% du periode, inverse pour pwmd2
|
||||
//Timer
|
||||
void Timer_Init(TIM_TypeDef *Timer, unsigned short Autoreload, unsigned short Prescaler);
|
||||
void MyTimer_ActiveIT(TIM_TypeDef * Timer, char Prio, void(*Interrupt_fonc)(void));
|
||||
void TIM2_IRQHandler(void);
|
||||
|
||||
//PWM
|
||||
void MyTimer_PWM(TIM_TypeDef * Timer , int Channel);
|
||||
int Set_DutyCycle_PWM(TIM_TypeDef *Timer, int Channel, float DutyC);
|
||||
38
TabanJohnse/Pilotes/Headers/MYGPIO.h
Normal file
38
TabanJohnse/Pilotes/Headers/MYGPIO.h
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
//Definitions
|
||||
|
||||
//INTERNE
|
||||
#define LED_PIN_INTERNE (5) // 5 pour le LED de Arduino
|
||||
#define BUTTON_GPIO_INTERNE (GPIOA) //GPIOA pour l'Arduion
|
||||
#define LED_GPIO_INTERNE (GPIOA) //GPIOA pour Arduino
|
||||
#define BUTTON_PIN_INTERNE (13) //13 pour Arduino
|
||||
|
||||
//EXTERNE
|
||||
#define LED_PIN_EXTERNE (8) // 8 pour la porte PB8
|
||||
#define BUTTON_GPIO_EXTERNE (GPIOB) //GPIOB pour externe
|
||||
#define LED_GPIO_EXTERNE (GPIOB) //GPIOB pour Externe
|
||||
#define BUTTON_PIN_EXTERNE (9) //9 pour bouton poussoir
|
||||
|
||||
//STATIQUES
|
||||
#define GPIO_OUTPUT_PPULL_MODE (2) //Mis en GP output 2MHz en mode PP
|
||||
#define GPIO_INPUT_PUPD_MODE (8) //Pour mettre à Pull up/down
|
||||
#define GPIO_INPUT_FLOATING_MODE (4)
|
||||
|
||||
//Pour y entrer dans le: si on est sur l'arduino ou sur le led externe
|
||||
#define INTERNE 1 // 1 c'est vrai, 0 faux
|
||||
|
||||
//FONCTIONS
|
||||
void initGPIO_Interne(void);
|
||||
int boutonAppuye_Interne(void);
|
||||
void allumerDEL_Interne(void);
|
||||
void eteindreDEL_Interne(void);
|
||||
void commuterDEL_Interne(void);
|
||||
void allume_bit_Interne(void);
|
||||
|
||||
void initGPIO_Externe(void);
|
||||
int boutonAppuye_Externe(void);
|
||||
void allumerDEL_Externe(void);
|
||||
void eteindreDEL_Externe(void);
|
||||
void commuterDEL_Externe(void);
|
||||
void allume_bit_Externe(void);
|
||||
|
||||
|
||||
137
TabanJohnse/Pilotes/src/Horloge.c
Normal file
137
TabanJohnse/Pilotes/src/Horloge.c
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
#include <stm32f10x.h>
|
||||
#include <stdio.h>
|
||||
#include <Horloge.h>
|
||||
|
||||
|
||||
//Il faut trouver le signal
|
||||
//On est à Timer 2
|
||||
|
||||
static void (*TIM2_Appel)(void) = 0;
|
||||
|
||||
void Timer_Init(TIM_TypeDef *Timer, unsigned short Autoreload, unsigned short Prescaler){
|
||||
if (Timer == TIM1) {
|
||||
RCC->APB2ENR |= RCC_APB2ENR_TIM1EN; //L'horloge est enabléd
|
||||
} else if (Timer == TIM2) {
|
||||
TIM2->CR1 |= TIM_CR1_CEN; //On enable l'horloge interne
|
||||
RCC->APB1ENR |= RCC_APB1ENR_TIM2EN;
|
||||
} else if (Timer == TIM3) {
|
||||
RCC->APB1ENR |= RCC_APB1ENR_TIM3EN;
|
||||
} else if (Timer == TIM4) {
|
||||
RCC->APB1ENR |= RCC_APB1ENR_TIM4EN;
|
||||
}
|
||||
Timer->ARR |= Autoreload;
|
||||
Timer->PSC |= Prescaler;
|
||||
}
|
||||
|
||||
//La fonction TIM2_IRQHandler s'utilise dans le processeur, on l'a juste redifint, tel qu'à chaque overflow on met un bit 1 dans GPIOA_ODR
|
||||
void TIM2_IRQHandler(void) { //On redefinit le IRQHandler qui est déjà ecrit dans le code source
|
||||
if (TIM2->SR & TIM_SR_UIF) { //On met le bit de overflow à un dès qu'on a overflow
|
||||
TIM2->SR &= ~TIM_SR_UIF; //Remise à zero
|
||||
|
||||
if (TIM2_Appel){TIM2_Appel();}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MyTimer_ActiveIT(TIM_TypeDef * Timer, char Prio, void(*Interrupt_fonc)(void)){ //On veut créer une fonction qui envoie un signal au cas où il y a debordement, avec une prioritaire, 0 plus importante 15 moins importante
|
||||
if (Timer == TIM2){
|
||||
|
||||
TIM2_Appel = Interrupt_fonc;
|
||||
|
||||
NVIC_EnableIRQ(TIM2_IRQn);
|
||||
NVIC_SetPriority(TIM2_IRQn, Prio);
|
||||
TIM2->DIER |= TIM_DIER_UIE; //Le registre DIER(Interrupt Enable Register) est mis au bit Update Interrupt, qui se commute lors d'un overflow
|
||||
TIM2->CR1 |= TIM_CR1_CEN; //Clock Enable
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Fonction qui permet de clignoter le DEL à un pulse volue (Sinusoïdale)
|
||||
//Si le sinus est haut(haute tension) le Duty Cicle est proche de 100%,
|
||||
//si le sinus est bas (vers la tension la plus basse) le Duty Cycle est vers 0%
|
||||
//On s'applique sur un plage de [0V; 3.3V]
|
||||
|
||||
|
||||
void MyTimer_PWM(TIM_TypeDef * Timer , int Channel){
|
||||
int pwrmd;
|
||||
int CCR_VAL = (ARR_VAL + 1) * DUTYC / 100.0f;
|
||||
#if POWERMODE //Powermode 1
|
||||
pwrmd = 0b110;
|
||||
#else
|
||||
pwrmd = 0b111; //Powermode 2
|
||||
#endif
|
||||
if (Channel == 1){
|
||||
Timer->CCR1 = CCR_VAL; //Faut avoir le bon valeur
|
||||
Timer->CCMR1 &= ~(0b111<<4); //On clear les trois bits qui sont de pwm
|
||||
Timer->CCMR1 |= (pwrmd<<4); //On affecte le powermode au bits de lecture pour le µ-controlleur
|
||||
Timer->CCMR1 |= TIM_CCMR1_OC1PE; //Update preload, il n'affecte pas le valeur avant que la prochaine cycle
|
||||
Timer->CCER = TIM_CCER_CC1E; //Enable le pin voulu basculer
|
||||
}
|
||||
else if (Channel == 2){
|
||||
Timer->CCR2 = CCR_VAL;
|
||||
Timer->CCMR1 &= ~(0b111<<12); //Le TIMx_CCMR1 configure deux channels, de bit [6:4] CH1, [14:12] CH2 (OC2M = Output Channel 2 )
|
||||
Timer->CCMR1 |= (pwrmd<<12);
|
||||
Timer->CCMR1 |= TIM_CCMR1_OC2PE;
|
||||
Timer->CCER |= TIM_CCER_CC2E;
|
||||
}
|
||||
else if (Channel == 3){
|
||||
Timer->CCR3 = CCR_VAL;
|
||||
Timer->CCMR1 &= ~(0b111<<4);
|
||||
Timer->CCMR2 |= (pwrmd<<4);
|
||||
Timer->CCMR2 |= TIM_CCMR2_OC3PE;
|
||||
Timer->CCER |= TIM_CCER_CC3E;
|
||||
}
|
||||
else if (Channel == 4){
|
||||
Timer->CCR4 = CCR_VAL;
|
||||
Timer->CCMR1 &= ~(0b111<<12);
|
||||
Timer->CCMR2 |= (pwrmd<<12);
|
||||
Timer->CCMR2 |= TIM_CCMR2_OC4PE;
|
||||
Timer->CCER |= TIM_CCER_CC4E;
|
||||
}
|
||||
|
||||
//En dessous d'ici, on a l'aide du plus gentil chat que je connais
|
||||
// Enable auto-reload preload -- //Ensures that your initial configuration — PWM mode, duty cycle, period — actually takes effect before the timer starts counting.
|
||||
Timer->CR1 |= TIM_CR1_ARPE;
|
||||
// Force update event to load ARR and CCR values immediately
|
||||
Timer->EGR |= TIM_EGR_UG;
|
||||
// Start the timer
|
||||
Timer->CR1 |= TIM_CR1_CEN;
|
||||
|
||||
}
|
||||
|
||||
//Une fonction qui met le bon PWM volue
|
||||
int Set_DutyCycle_PWM(TIM_TypeDef *Timer, int Channel, float DutyC){
|
||||
int CCR_VAL = (ARR_VAL + 1) * DutyC / 100.0f; //ARR_VAL déjà definie
|
||||
switch (Channel){
|
||||
case 1: Timer->CCR1 = CCR_VAL;
|
||||
case 2: Timer->CCR2 = CCR_VAL;
|
||||
case 3: Timer->CCR3 = CCR_VAL;
|
||||
case 4: Timer->CCR4 = CCR_VAL;
|
||||
default: break;
|
||||
}
|
||||
return 0;
|
||||
Timer->EGR |= TIM_EGR_UG;
|
||||
}
|
||||
//Putaing con, ça marche pas
|
||||
|
||||
|
||||
/*
|
||||
Pulse width modulation mode allows you to generate a signal with a frequency determined
|
||||
by the value of the TIMx_ARR register and a duty cycle determined by the value of the
|
||||
TIMx_CCRx register.
|
||||
|
||||
The PWM mode can be selected independently on each channel (one PWM per OCx
|
||||
output) by writing 110 (PWM mode 1) or ‘111 (PWM mode 2) in the OCxM bits in the
|
||||
TIMx_CCMRx register. You must enable the corresponding preload register by setting the
|
||||
OCxPE bit in the TIMx_CCMRx register, and eventually the auto-reload preload register by
|
||||
setting the ARPE bit in the TIMx_CR1 register.
|
||||
*/
|
||||
//Il faut créer une autre fonction qui lui met le bon duty cycle
|
||||
//Timer->CCR1 = Duty_cycle*0.01*3.3; // On divise par cent et multiplue par 3.3V, plage de ADC
|
||||
|
||||
//Pareil pour la frequence, faut une fonction externe qui lui fait ça
|
||||
|
||||
|
||||
//Pendant les vacances terminer l'ADC et l'USART (Activités sur Moodle)
|
||||
//Hell naw, that did not happen cuh
|
||||
|
||||
97
TabanJohnse/Pilotes/src/MYGPIO.c
Normal file
97
TabanJohnse/Pilotes/src/MYGPIO.c
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
#include <stdlib.h>
|
||||
#include <stm32f10x.h>
|
||||
#include <MYGPIO.h>
|
||||
|
||||
|
||||
//FONCTIONS POUR LE DEL INTERNE
|
||||
|
||||
void initGPIO_Interne(void){
|
||||
RCC->APB2ENR |= (0x01 << 2) | (0x01 << 3) | (0x01 << 4) ;
|
||||
|
||||
//Start
|
||||
//CRL pour les 8 premiers portes, CRH pour les 8 dernières portes
|
||||
if (LED_PIN_INTERNE < 8){
|
||||
LED_GPIO_INTERNE->CRL &= ~(0xF << (LED_PIN_INTERNE*4));
|
||||
LED_GPIO_INTERNE->CRL |= GPIO_OUTPUT_PPULL_MODE<<(LED_PIN_INTERNE*4) ; // On met tous les Pins de broche A à ANalog Input sauf broche PA.5 qui correspond au LED GREEN: Output 2MHz et GP output push-pull
|
||||
}
|
||||
else{
|
||||
LED_GPIO_INTERNE->CRH &= ~(0xF <<((LED_PIN_INTERNE-8)*4));
|
||||
LED_GPIO_INTERNE->CRH |= GPIO_OUTPUT_PPULL_MODE<<((LED_PIN_INTERNE-8)*4);
|
||||
}
|
||||
|
||||
if (BUTTON_PIN_INTERNE < 8){
|
||||
BUTTON_GPIO_INTERNE->CRL &= ~(0xF << (BUTTON_PIN_INTERNE*4));
|
||||
BUTTON_GPIO_INTERNE->CRL |= GPIO_INPUT_FLOATING_MODE<<(BUTTON_PIN_INTERNE*4) ; // On met tous les Pins de broche A à ANalog Input sauf broche PA.5 qui correspond au LED GREEN: Output 2MHz et GP output push-pull
|
||||
}
|
||||
else{
|
||||
BUTTON_GPIO_INTERNE->CRH &= ~(0xF <<((BUTTON_PIN_INTERNE-8)*4));
|
||||
BUTTON_GPIO_INTERNE->CRH |= GPIO_INPUT_FLOATING_MODE<<((BUTTON_PIN_INTERNE-8)*4);
|
||||
}
|
||||
}
|
||||
|
||||
int boutonAppuye_Interne(void){
|
||||
return BUTTON_GPIO_INTERNE->IDR &(1<<BUTTON_PIN_INTERNE);
|
||||
}
|
||||
|
||||
void allumerDEL_Interne(void){
|
||||
LED_GPIO_INTERNE->ODR |= (0x01 << LED_PIN_INTERNE) ; //On essaie de mettre en position PA5 de GPIOC_ODR un 1 comme ca allume le LED GREEN
|
||||
}
|
||||
|
||||
void eteindreDEL_Interne(void){
|
||||
LED_GPIO_INTERNE->ODR &= ~(0x01 << LED_PIN_EXTERNE) ; //On essaie de mettre en position PA5 de GPIOC_ODR un 0 comme ca eteint le LED GREEN
|
||||
//ALlumer un LED externe, PB8/D15 OUTPUT, Bouton Poussoir PB9/D14
|
||||
}
|
||||
|
||||
void commuterDEL_Interne(void){
|
||||
LED_GPIO_INTERNE->ODR ^= (0x01 << LED_PIN_INTERNE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//FONCTIONS POUR LE DEL EXTERNE
|
||||
|
||||
void initGPIO_Externe(void){
|
||||
RCC->APB2ENR |= (0x01 << 2) | (0x01 << 3) | (0x01 << 4) ;
|
||||
|
||||
//Start
|
||||
//CRL pour les 8 premiers portes, CRH pour les 8 dernières portes
|
||||
if (LED_PIN_EXTERNE < 8){
|
||||
LED_GPIO_EXTERNE->CRL &= ~(0xF << (LED_PIN_EXTERNE*4));
|
||||
LED_GPIO_EXTERNE->CRL |= GPIO_OUTPUT_PPULL_MODE<<(LED_PIN_EXTERNE*4) ; // On met tous les Pins de broche A à ANalog Input sauf broche PA.5 qui correspond au LED GREEN: Output 2MHz et GP output push-pull
|
||||
}
|
||||
else{
|
||||
LED_GPIO_EXTERNE->CRH &= ~(0xF <<((LED_PIN_EXTERNE-8)*4));
|
||||
LED_GPIO_EXTERNE->CRH |= GPIO_OUTPUT_PPULL_MODE<<((LED_PIN_EXTERNE-8)*4);
|
||||
}
|
||||
|
||||
if (BUTTON_PIN_EXTERNE < 8){
|
||||
BUTTON_GPIO_EXTERNE->CRL &= ~(0xF << (BUTTON_PIN_EXTERNE*4));
|
||||
BUTTON_GPIO_EXTERNE->CRL |= GPIO_INPUT_FLOATING_MODE<<(BUTTON_PIN_EXTERNE*4) ; // On met tous les Pins de broche A à ANalog Input sauf broche PA.5 qui correspond au LED GREEN: Output 2MHz et GP output push-pull
|
||||
}
|
||||
else{
|
||||
BUTTON_GPIO_EXTERNE->CRH &= ~(0xF <<((BUTTON_PIN_EXTERNE-8)*4));
|
||||
BUTTON_GPIO_EXTERNE->CRH |= GPIO_INPUT_FLOATING_MODE<<((BUTTON_PIN_EXTERNE-8)*4);
|
||||
}
|
||||
}
|
||||
|
||||
int boutonAppuye_Externe(void){
|
||||
return BUTTON_GPIO_EXTERNE->IDR &(1<<BUTTON_PIN_EXTERNE);
|
||||
}
|
||||
|
||||
void allumerDEL_Externe(void){
|
||||
LED_GPIO_EXTERNE->ODR |= (0x01 << LED_PIN_EXTERNE) ;
|
||||
} //On essaie de mettre en position PA5 de GPIOC_ODR un 1 comme ca allume le LED GREEN
|
||||
|
||||
|
||||
void eteindreDEL_Externe(void){
|
||||
LED_GPIO_EXTERNE->ODR &= ~(0x01 << LED_PIN_EXTERNE) ; //On essaie de mettre en position PA5 de GPIOC_ODR un 0 comme ca eteint le LED GREEN
|
||||
//ALlumer un LED externe, PB8/D15 OUTPUT, Bouton Poussoir PB9/D14
|
||||
}
|
||||
|
||||
void commuterDEL_Externe(void){
|
||||
LED_GPIO_EXTERNE->ODR ^= (0x01 << LED_PIN_EXTERNE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
3
TabanJohnse/README.md
Normal file
3
TabanJohnse/README.md
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
Comment mettre la bonne sortie en GPIO pour voir le PWM:
|
||||
|
||||
Dans STM32F103RB pages 28-33 regarder sur PIN NAME et Default. Ex.: TIM1_CH1 -> GPIOA_0
|
||||
BIN
TabanJohnse/STM32F103RB.pdf
Normal file
BIN
TabanJohnse/STM32F103RB.pdf
Normal file
Binary file not shown.
BIN
TabanJohnse/STM32RM0008.pdf
Normal file
BIN
TabanJohnse/STM32RM0008.pdf
Normal file
Binary file not shown.
17
TabanJohnse/Services/carte.c
Normal file
17
TabanJohnse/Services/carte.c
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#include "carte.h"
|
||||
|
||||
void init_carte(void){
|
||||
initGPIO();
|
||||
}
|
||||
|
||||
int carte_bouton_appuye(void){
|
||||
return boutonAppuye();
|
||||
}
|
||||
|
||||
void carte_allumer_DEL(void){
|
||||
allumerDEL();
|
||||
}
|
||||
|
||||
void carte_eteindre_DEL(void){
|
||||
eteindreDEL();
|
||||
}
|
||||
6
TabanJohnse/Services/carte.h
Normal file
6
TabanJohnse/Services/carte.h
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#include <MYGPIO.h>
|
||||
|
||||
void init_carte(void);
|
||||
int carte_bouton_appuye(void);
|
||||
void carte_allumer_DEL(void);
|
||||
void carte_eteindre_DEL(void);
|
||||
27
TabanJohnse/principal.c
Normal file
27
TabanJohnse/principal.c
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#include <stm32f10x.h>
|
||||
#include <Horloge.h>
|
||||
#include <MYGPIO.h>
|
||||
|
||||
int main ( void )
|
||||
{
|
||||
RCC->APB2ENR |= (0x01 << 2) | (0x01 << 3) | (0x01 << 4) ;
|
||||
Timer_Init(TIM2, ARR_VAL, PSC_VAL);
|
||||
|
||||
/*
|
||||
//DEL INTERNE
|
||||
#if INTERNE
|
||||
initGPIO_Interne();
|
||||
MyTimer_ActiveIT(TIM2, 2, commuterDEL_Interne);
|
||||
#else
|
||||
//DEL EXTERNE BRANCHE SUR PB8 et GND (D14 & D8 AVEC LA TEXTE BLEUE SUR LA CARTE)
|
||||
initGPIO_Externe();
|
||||
MyTimer_ActiveIT(TIM2, 2, commuterDEL_Externe);
|
||||
#endif
|
||||
*/
|
||||
|
||||
|
||||
//Test du PWM
|
||||
MyTimer_PWM(TIM2, 1);
|
||||
Set_DutyCycle_PWM(TIM2, 1, 30);
|
||||
while (1);
|
||||
}
|
||||
Loading…
Reference in a new issue