diff --git a/assets/raspberry_config.jpg b/assets/raspberry_config.jpg new file mode 100644 index 0000000..5e97a93 Binary files /dev/null and b/assets/raspberry_config.jpg differ diff --git a/assets/raspberry_uart.jpg b/assets/raspberry_uart.jpg new file mode 100644 index 0000000..06c5277 Binary files /dev/null and b/assets/raspberry_uart.jpg differ diff --git a/assets/resultcmd0.png b/assets/resultcmd0.png new file mode 100644 index 0000000..a6a111a Binary files /dev/null and b/assets/resultcmd0.png differ diff --git a/driver/adc.c b/driver/adc.c index 366b286..0ddd5df 100644 --- a/driver/adc.c +++ b/driver/adc.c @@ -41,4 +41,4 @@ void ADC1_2_IRQHandler(void) (*pFncADC) (); /* appel indirect de la fonction */ MyADC_Base_Start(ADC1); ADC1->SR &= ~ADC_SR_EOC; //Prochaine lecture pouvant �tre effectu�e. -} \ No newline at end of file +} diff --git a/driver/timer.c b/driver/timer.c index 0d15cd4..1c18d17 100644 --- a/driver/timer.c +++ b/driver/timer.c @@ -190,4 +190,4 @@ void MyTimer_DutyCycle(TIM_TypeDef * Timer, char Channel, unsigned int DutyCycle Timer->CCR4 = RC; break; } -} \ No newline at end of file +} diff --git a/driver/uart.c b/driver/uart.c index 84df976..ff29c1a 100644 --- a/driver/uart.c +++ b/driver/uart.c @@ -2,83 +2,156 @@ #include "gpio.h" //faire GPIO +void (* pFncUART) (uint8_t data); /* d�claration d�un pointeur de fonction */ -char data1 = 0x00; -char data2 = 0x00; -char data3 = 0x00; +void MyUART_Init_Periph (void (* ptrFonction)(uint8_t)) +{ + pFncUART = ptrFonction; /* affectation du pointeur */ +} + +int MyUART_setClockBit(MyUART_Struct_Typedef * UARTStructPtr) +{ + if (UARTStructPtr->UART == USART1) + { + RCC->APB2ENR |= RCC_APB2ENR_USART1EN; + USART1->BRR = 72000000/(UARTStructPtr->BaudRate); //Calculating the baudrate depending on the clock frequency + return 0; + } + else if (UARTStructPtr->UART == USART2) + { + RCC->APB1ENR |= RCC_APB1ENR_USART2EN; + USART2->BRR = 36000000/(UARTStructPtr->BaudRate); + return 0; + } + else if (UARTStructPtr->UART == USART3) + { + RCC->APB1ENR |= RCC_APB1ENR_USART3EN; + USART3->BRR = 36000000/(UARTStructPtr->BaudRate); + return 0; + } + else { + return 1; + } +} + +uint8_t MyUART_GetInterruptNum(USART_TypeDef * UART) +{ + if(UART == USART1) + { + return USART1_IRQn; + } + else if(UART == USART2) + { + return USART2_IRQn; + } + else if(UART == USART3) + { + return USART3_IRQn; + } + else{ + return 0; + } +} + +void MyUART_ActiveIT(USART_TypeDef * UART, uint8_t Prio) +{ + uint32_t IRQNumber = MyUART_GetInterruptNum(UART); + UART->CR1 |= (USART_CR1_RXNEIE); //Interruption active pour la reception UNIQUEMENT + NVIC->IP[IRQNumber] |= (Prio << 0x4); //Prio de l'interruption (p.197 manuel reference RM0008 pour ADC1_IRQn) + NVIC->ISER[1] |= (0x1<<(IRQNumber-32)); //Active l'interruption au niveau NVIC (p.119 manuel programming pour ISER[1]) +} void MyUART_Init(MyUART_Struct_Typedef * UARTStructPtr){ - if (UARTStructPtr->UART == USART1) - RCC->APB2ENR |= RCC_APB2ENR_USART1EN; - if (UARTStructPtr->UART == USART2) - RCC->APB2ENR |= RCC_APB1ENR_USART2EN; - if (UARTStructPtr->UART == USART3) - RCC->APB2ENR |= RCC_APB1ENR_USART3EN; + MyUART_setClockBit(UARTStructPtr); //Clock enable and setting the baud. + UARTStructPtr->UART->CR1 = 0x00; // Clear ALL + UARTStructPtr->UART->CR1 |= USART_CR1_UE; + UARTStructPtr->UART->CR1 |= ((UARTStructPtr->length)<<12); //Setting the Length of the data transmitted - UARTStructPtr->UART->BRR = 72000000/(UARTStructPtr->BaudRate); - UARTStructPtr->UART->CR1 |= ((UARTStructPtr->Wlengh)<<12); - UARTStructPtr->UART->CR1 |= (0x1<<10); - - if(UARTStructPtr->Wparity == parity_none) - UARTStructPtr->UART->CR1 &= ~(0x1<<10); - if(UARTStructPtr->Wparity == parity_odd) - UARTStructPtr->UART->CR1 |= (0x1<<9); - if(UARTStructPtr->Wparity == parity_even) - UARTStructPtr->UART->CR1 &= ~(0x1<<9); - - if(UARTStructPtr->Wstop == stop1b) - UARTStructPtr->UART->CR2 &= ~(0x3<<12); - if(UARTStructPtr->Wstop == stop2b){ - UARTStructPtr->UART->CR2 &= ~(0x3<<12); - UARTStructPtr->UART->CR2 |= (0x1<<13); + UARTStructPtr->UART->CR1 &= ~(0x3<<9); //reset CR1 9-10 bits, Parity Selection + if(UARTStructPtr->parity != parityNone) //if parity is enabled + { + UARTStructPtr->UART->CR1 |= (UARTStructPtr->parity<<9); //depending on the parity changing the 9th bit, and set 10th bit to 1 } - UARTStructPtr->UART->CR1 |= (USART_CR1_TE | USART_CR1_RE | USART_CR1_UE | USART_CR1_RXNEIE); - - NVIC_EnableIRQ(USART1_IRQn); + + UARTStructPtr->UART->CR2 &= ~(0x3<<12); //reset CR2 13-12 bits, Stop bits + if(UARTStructPtr->stop != stopBit1) //if stop bits > 1 + { + UARTStructPtr->UART->CR2 |= (UARTStructPtr->stop<<12); //depending on the stop changing the 12th and 13th bit. + } + //TxD Enable, RxD Enable, USART Global Enable + UARTStructPtr->UART->CR1 |= (USART_CR1_TE | USART_CR1_RE); + MyUART_ActiveIT(UARTStructPtr->UART,1); +} + +void MyUART_InitGPIO(MyUART_Struct_Typedef * UARTStructPtr) +{ + MyGPIO_Struct_TypeDef rxd,txd; + if(UARTStructPtr->UART == USART1) + { + rxd = (MyGPIO_Struct_TypeDef){GPIOA,10,In_Floating}; + txd = (MyGPIO_Struct_TypeDef){GPIOA,9,AltOut_Ppull}; + } + else if(UARTStructPtr->UART == USART2) { + rxd = (MyGPIO_Struct_TypeDef){GPIOA,3,In_Floating}; + txd = (MyGPIO_Struct_TypeDef){GPIOA,2,AltOut_Ppull}; + } + else if(UARTStructPtr->UART == USART3) { + rxd = (MyGPIO_Struct_TypeDef){GPIOB,11,In_PullUp}; + txd = (MyGPIO_Struct_TypeDef){GPIOB,10,AltOut_Ppull}; + } + else { + return; + } + MyGPIO_Init(&rxd); + MyGPIO_Init(&txd); +} + +void MyUART_Send(MyUART_Struct_Typedef *UART, uint8_t data) +{ + UART->UART->DR = data; + //du DR au Registre de Transmission, on attend que le shift register ai récupéré le DR + while (!(UART->UART->SR & USART_SR_TXE)); +} + +uint8_t MyUART_Receive(MyUART_Struct_Typedef *UART) +{ + while (!(UART->UART->SR & USART_SR_RXNE)); // Si RXNE est mis à 1, alors on vient de recevoir une donnée ! + uint8_t data = UART->UART->DR; // Read the data. + UART->UART->SR &= ~USART_SR_RXNE; //flag to 0 + return data; } void USART1_IRQHandler(void) { - // Check if receive data register not empty - if(USART1->SR & USART_SR_RXNE) - { - data1 = USART1->DR; // read received data - // do something with received data - } + if((USART1->SR & USART_SR_RXNE) == USART_SR_RXNE) //verify the flag + { + if (pFncUART != 0) + (*pFncUART) (USART1->DR); /* appel indirect de la fonction */ + USART1->SR &= ~USART_SR_RXNE; //flag to 0 + } } void USART2_IRQHandler(void) { - // Check if receive data register not empty - if(USART2->SR & USART_SR_RXNE) - { - data2 = USART2->DR; // read received data - // do something with received data - } + if((USART2->SR & USART_SR_RXNE) == USART_SR_RXNE) //verify the flag + { + if (pFncUART != 0) + (*pFncUART) (USART2->DR); /* appel indirect de la fonction */ + USART2->SR &= ~USART_SR_RXNE; //flag to 0 + } } void USART3_IRQHandler(void) { // Check if receive data register not empty - if(USART3->SR & USART_SR_RXNE) + if((USART3->SR & USART_SR_RXNE) == USART_SR_RXNE) //verify the flag { - data3 = USART3->DR; // read received data - // do something with received data + if (pFncUART != 0) + (*pFncUART) (USART3->DR); /* appel indirect de la fonction */ + USART2->SR &= ~USART_SR_RXNE; //flag to 0 } } -char MyUART_Read(MyUART_Struct_Typedef * UARTStructPtr) -{ - if(UARTStructPtr->UART == USART1) - return data1; - else if(UARTStructPtr->UART == USART2) - return data2; - else if(UARTStructPtr->UART == USART3) - return data3; - else - return 0xFF; -} - /* exemple utilisation fonction : UART1.UART = USART1; // choix UART (USART1, USART2, USART3) diff --git a/driver/uart.h b/driver/uart.h index 70aa2d7..262a4c5 100644 --- a/driver/uart.h +++ b/driver/uart.h @@ -2,26 +2,35 @@ #define UART_H #include "stm32f10x.h" +typedef enum { + lengthBit8, + lengthBit9 +} MyUART_Enum_Length; + +typedef enum { + parityNone, + parityEven = 0b10, + parityOdd = 0b11 +} MyUART_Enum_Parity; + +typedef enum { + stopBit1, + stopBit0d5, + stopBit2, + stopBit1d5 +} MyUART_Enum_StopBits; + typedef struct { USART_TypeDef * UART; - unsigned int BaudRate; - unsigned char Wlengh; - unsigned char Wparity; - unsigned char Wstop; - + uint32_t BaudRate; + MyUART_Enum_Length length; + MyUART_Enum_Parity parity; + MyUART_Enum_StopBits stop; }MyUART_Struct_Typedef; -#define parity_none 0x0 -#define parity_even 0x1 -#define parity_odd 0x2 -#define Wlengh8 0x0 -#define Wlengh9 0X1 -#define stop1b 0x0 -#define stop2b 0x2 - void MyUART_Init(MyUART_Struct_Typedef * UARTStructPtr); -void USART1_IRQHandler(void); -void USART2_IRQHandler(void); -void USART3_IRQHandler(void); -char MyUART_Read(MyUART_Struct_Typedef * UARTStructPtr); -#endif \ No newline at end of file +void MyUART_InitGPIO(MyUART_Struct_Typedef * UARTStructPtr); +void MyUART_Send(MyUART_Struct_Typedef *UART, uint8_t data); +uint8_t MyUART_Receive(MyUART_Struct_Typedef *UART); +void MyUART_Init_Periph (void (* ptrFonction)(uint8_t)); +#endif diff --git a/implementation/remote.c b/implementation/remote.c new file mode 100644 index 0000000..f5394ac --- /dev/null +++ b/implementation/remote.c @@ -0,0 +1,33 @@ +#include "remote.h" +#include "gpio.h" + +MyUART_Struct_Typedef uartCool = {USART1,9600,lengthBit8,parityNone,stopBit1}; + +void remote(uint8_t data) +{ + MyUART_Send(&uartCool,data); + int8_t signedData = (int8_t)data; + if(signedData > 0) + { + MyGPIO_Set(GPIOA,5); + } + else { + MyGPIO_Reset(GPIOA,5); + } +} + +void initRemote(void) +{ + MyUART_InitGPIO(&uartCool); + MyUART_Init(&uartCool); + MyUART_Init_Periph(remote); +} + +void testRemote(void) +{ + MyUART_Send(&uartCool,'s'); + MyUART_Send(&uartCool,'a'); + MyUART_Send(&uartCool,'l'); + MyUART_Send(&uartCool,'u'); + MyUART_Send(&uartCool,'t'); +} diff --git a/implementation/remote.h b/implementation/remote.h new file mode 100644 index 0000000..581bfd4 --- /dev/null +++ b/implementation/remote.h @@ -0,0 +1,11 @@ +#ifndef REMOTE_H +#define REMOTE_H +#include "uart.h" + +//XBEE 9600 baud, zero parite, 1 bit de stop, + +void remote(uint8_t data); +void initRemote(void); +void testRemote(void); + +#endif diff --git a/implementation/remote.md b/implementation/remote.md new file mode 100644 index 0000000..bc7299a --- /dev/null +++ b/implementation/remote.md @@ -0,0 +1,51 @@ +# Initialisation de l'UART avec un Raspberry Pi +### Yohan Boujon +--- +Pour tester l'intégration de l'UART j'ai décidé de me focaliser uniquement sur l'UART 1 du STM32. Afin de simplifier la programmation côté microcontrôleur, et aussi d'apprendre plus sur mon Raspberry Pi ce choix était plus complaisant. + +## Configuration du Raspberry Pi + +La première chose est de vérifier si les pins pour la communication UART sont dans le bon mode. Pour se faire il suffit de lancer la commande : +```bash +sudo raspi-gpio get 14-15 +``` +Normalement le résultat devrait être le suivant : +![sudo raspi-gpio get 14-15](../assets/resultcmd0.png) +Si func n'est pas TXD/RXD alors entrez ces commandes : +```bash +sudo raspi-gpio set 15 a5 +sudo raspi-gpio set 14 a5 +``` +Pour rappel, le terme après 15/14 détermine l'alternative function, plus d'informations peuvent être trouvées ici [Détail sur les différentes ALT](https://blog.boochow.com/wp-content/uploads/rpi-gpio-table.png). Pour vérifier si vous voulez UART1 ou UART 0, avec la commande ```ls -l /dev``` il est possible de voir le lien symbolique réalisé entre votre serialX et la pin réelle de votre pi. Choisissez celle que vous voulez, mais si vous avez besoin du bluetooth, **ttyS0** est la liaison serie recommandée. *(Dans notre cas elle est reliée à l'UART1)* + +Pour finalement activer du côté hardware l'UART, il faut entrer la commande suivante : +```bash +sudo raspi-config +``` +Après cela une fenêtre bleue avec divers paramètres sont disponible. Ce qui nous intéresse c'est donc d'activer le port UART, soit : +**3 Interface Option** > **I6 Serial Port** > **No** > **Yes** +Il faut ensuite vérifier que le fichier de configuration accepte bien l'UART, soit : +```bash +sudo nano /boot/config.txt +``` +et entrez les paramètres suivants en fin de ligne : +``` +enable_uart=1 +dtoverlay=disable-bt +dtoverlay=uart1,txd1_pin=14,rxd1_pin=15 +``` +Le premier active l'UART, le second désactive le bluetooth *(peut poser des problèmes sur l'UART 1 ou 0, dépendant des cas)* et enfin le dernier active le txd/rxd 0/1 pour une certaine pin. +Faites **CTRL+X** , **'y'** et rebootez votre Raspberry : +```bash +sudo reboot +``` + +Ensuite il ne reste plus qu'à tester ! à l'aide du programme [**minicom**](https://doc.ubuntu-fr.org/minicom) il est possible de tester simplement l'UART en rebouclant les GPIO comme ici : +![Raspberry Pi](../assets/raspberry_config.jpg) + +Maintenant testons avec la commande +```bash +minicom -b 9600 -o -D /dev/ttyS0 +``` + +![Raspberry Pi UART](../assets/raspberry_uart.jpg) \ No newline at end of file diff --git a/keilproject/RTE/Device/STM32F103RB/startup_stm32f10x_md.s b/keilproject/RTE/Device/STM32F103RB/startup_stm32f10x_md.s index 1ab7096..0ac2873 100644 --- a/keilproject/RTE/Device/STM32F103RB/startup_stm32f10x_md.s +++ b/keilproject/RTE/Device/STM32F103RB/startup_stm32f10x_md.s @@ -132,7 +132,7 @@ Reset_Handler PROC EXPORT Reset_Handler [WEAK] IMPORT __main IMPORT SystemInit - LDR R0, =SystemInit +a LDR R0, =SystemInit BLX R0 LDR R0, =__main BX R0 diff --git a/keilproject/Source/Principale.c b/keilproject/Source/Principale.c index a0cfee4..1806698 100644 --- a/keilproject/Source/Principale.c +++ b/keilproject/Source/Principale.c @@ -1,4 +1,5 @@ #include "stm32f10x.h" +<<<<<<< HEAD #include "servo.h" #include "motoreducteur.h" #include "rtc.h" @@ -17,3 +18,21 @@ int main (void) while(1){}; } +======= +#include "MyI2C.h" +#include "MySPI.h" +#include "remote.h" +#include "gpio.h" + +int main (void) +{ + MyGPIO_Struct_TypeDef led = {GPIOA,5,Out_PullUp}; //led + MyGPIO_Init(&led); //test des leds pour ignorer les contraintes liées aux différents ports + + initRemote(); + testRemote(); + + while(1){ + }; + } +>>>>>>> origin/yohan diff --git a/keilproject/voilier.uvoptx b/keilproject/voilier.uvoptx index 7292b15..483ef5b 100644 --- a/keilproject/voilier.uvoptx +++ b/keilproject/voilier.uvoptx @@ -125,7 +125,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=1468,53,1889,480,1)(121=1469,437,1890,864,1)(122=875,109,1296,536,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=1285,87,1879,838,1)(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=1460,461,1836,1018,1)(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=1009,499,1430,926,1)(121=1469,437,1890,864,0)(122=875,109,1296,536,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=105,137,504,482,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=879,71,1473,822,0)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=1014,43,1462,457,1)(161=568,150,1016,564,1)(162=1351,117,1799,531,1)(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 @@ -142,9 +142,15 @@ 0 0 +<<<<<<< HEAD 13 1
0
+======= + 29 + 1 +
134219444
+>>>>>>> origin/yohan 0 0 0 @@ -153,27 +159,36 @@ 0 .\Source\Principale.c +<<<<<<< HEAD +======= + \\cool_Simule\Source/Principale.c\29 +>>>>>>> origin/yohan
1 0 +<<<<<<< HEAD 12 +======= + 28 +>>>>>>> origin/yohan 1 -
0
+
134219442
0 0 0 0 0 - 0 + 1 .\Source\Principale.c - + \\cool_Simule\Source/Principale.c\28
2 0 +<<<<<<< HEAD 15 1
134218740
@@ -222,18 +237,20 @@ 5 0 +======= +>>>>>>> origin/yohan 8 1 -
0
+
134219308
0 0 0 0 0 - 0 + 1 .\Source\Principale.c - + \\cool_Simule\Source/Principale.c\8
@@ -290,16 +307,6 @@ - - - System Viewer\GPIOA - 35905 - - - System Viewer\GPIOB - 35904 - - 1 1 @@ -446,22 +453,35 @@ 0 0 +<<<<<<< HEAD 24 1
134219864
+======= + 10 + 1 +
134219708
+>>>>>>> origin/yohan 0 0 0 0 0 1 +<<<<<<< HEAD C:\Users\alixc\Desktop\Scolarité\INSA\Cours\Microcontroleur\voilier-team-1\implementation\rtc.c \\cool_reel\../implementation/rtc.c\24 +======= + ..\implementation\remote.c + + \\cool_reel\../implementation/remote.c\10 +>>>>>>> origin/yohan
1 0 +<<<<<<< HEAD 25 1
134219874
@@ -495,6 +515,9 @@ 3 0 23 +======= + 9 +>>>>>>> origin/yohan 1
0
0 @@ -503,7 +526,11 @@ 0 0 0 +<<<<<<< HEAD ..\implementation\rtc.c +======= + ..\implementation\remote.c +>>>>>>> origin/yohan
@@ -562,6 +589,12 @@ + + + System Viewer\USART1 + 35905 + + 1 0 @@ -590,6 +623,18 @@ 0 0 + + 1 + 2 + 1 + 0 + 0 + 0 + ..\implementation\remote.c + remote.c + 0 + 0 + @@ -600,7 +645,7 @@ 0 2 - 2 + 3 4 0 0 @@ -612,9 +657,27 @@ 2 +<<<<<<< HEAD 3 1 0 +======= + 4 + 1 + 1 + 0 + 0 + ..\driver\adc.c + adc.c + 0 + 0 + + + 2 + 5 + 1 + 1 +>>>>>>> origin/yohan 0 0 ..\driver\gpio.c @@ -624,7 +687,11 @@ 2 +<<<<<<< HEAD 4 +======= + 6 +>>>>>>> origin/yohan 1 0 0 @@ -636,7 +703,11 @@ 2 +<<<<<<< HEAD 5 +======= + 7 +>>>>>>> origin/yohan 1 0 0 @@ -646,6 +717,7 @@ 0 0 +<<<<<<< HEAD 2 6 @@ -702,6 +774,8 @@ 0 0 +======= +>>>>>>> origin/yohan