UART fini et testé mais sans DMA

This commit is contained in:
Olivier Chevilley 2023-04-04 12:58:52 +02:00
parent adcecf465c
commit a6bd0409e6
8 changed files with 110 additions and 137 deletions

View file

@ -1,12 +1,6 @@
#ifndef MYGPIO_H
#define MYGPIO_H
#include "stm32f10x.h"
typedef struct
{
GPIO_TypeDef * GPIO ;
char GPIO_Pin ; // numero de 0 a 15
char GPIO_Conf ; // voir ci dessous
} MyGPIO_Struct_TypeDef ;
#define In_Floating 0x4 // a completer
#define In_PullDown 0x8
@ -17,6 +11,15 @@ typedef struct
#define AltOut_Ppull 0xA // deux derniers bits pour regler la vitesse max (due a la valeur de res) (01:10MHz 10:2MHz 11:50MHz)
#define AltOut_OD 0xD // deux derniers bits pour regler la vitesse max (due a la valeur de res) (01:10MHz 10:2MHz 11:50MHz)
typedef struct
{
GPIO_TypeDef * GPIO ;
char GPIO_Pin ; // numero de 0 a 15
char GPIO_Conf ; // voir ci dessous
} MyGPIO_Struct_TypeDef ;
void MyGPIO_Init ( MyGPIO_Struct_TypeDef * GPIOStructPtr ) ;
int MyGPIO_Read ( GPIO_TypeDef * GPIO , char GPIO_Pin ) ; // renvoie 0 ou autre chose different de 0
void MyGPIO_Set ( GPIO_TypeDef * GPIO , char GPIO_Pin ) ;

View file

@ -3,8 +3,8 @@
#include "stm32f10x.h"
void MyUART_init(void);
void UART_send(char data); //à revoir
void MyUART_ActiveIT(char Prio, void (*IT_function)(void), char mode); //mode permet d'activer soit l'interruption sur RX (mode='r') soit TX (mode='t')
char UART_receive();
void UART_send(char data);
void MyUART_ActiveIT(char Prio, void (*IT_function)(void));
char UART_receive(void);
#endif

View file

@ -88,7 +88,7 @@ void TIM4_IRQHandler (void)
TIM4->SR &= ~(1<<0) ;
}
void TIM1_UP_IRQHandler (void) // à vérifier
void TIM1_UP_IRQHandler (void)
{
if(tim_ptr1_func!=0)
{

View file

@ -1,4 +1,5 @@
#include "UART.h"
#include "GPIO.h"
void (*uart_rx_ptr_func)(void);
void (*uart_tx_ptr_func)(void);
@ -6,32 +7,43 @@ char buffer[1000]={0};
void MyUART_init(void) // que pour du 9600 bauds
{
MyGPIO_Struct_TypeDef RX_pin;
MyGPIO_Struct_TypeDef TX_pin;
RX_pin.GPIO = GPIOA;
RX_pin.GPIO_Conf = In_Floating;
RX_pin.GPIO_Pin = 10;
TX_pin.GPIO = GPIOA;
TX_pin.GPIO_Conf = AltOut_Ppull;
TX_pin.GPIO_Pin = 9;
MyGPIO_Init (&RX_pin);
MyGPIO_Init (&TX_pin);
RCC->APB2ENR |= RCC_APB2ENR_USART1EN; // validation horloge USART1
USART1->CR1 |= USART_CR1_UE; // Activation de l'USART
USART1->CR1 &= ~USART_CR1_M; // Choix d'une taille de 8 bits de données
USART1->CR2 &= USART_CR2_STOP; // Choix d'un seul bit de stop
USART1->BRR |= 468 << 4; // Fixe le baud rate à 9600bps //valeurs trouvé p804
USART1->BRR |= 75; // Fixe le baud rate à 9600bps
USART1->CR1 |= USART_CR1_TE; // Envoi de la première trame d'attente
USART1->CR1 |= USART_CR1_RE;
USART1->CR1 |= USART_CR1_TE;
}
void UART_send(char data)
{
USART1->DR |= data; // Ecriture de la donnée dans le registre DR
while(!(USART1->SR & USART_SR_TXE))
{
}
USART1->DR = data; // Ecriture de la donnée dans le registre DR
}
void MyUART_ActiveIT(char Prio, void (*IT_function)(void), char mode)
{
if (mode=='r')
void MyUART_ActiveIT(char Prio, void (*IT_function)(void))
{
//activer l'interrupt sur reception
USART1->CR1 |= USART_CR1_RXNEIE;
uart_rx_ptr_func=IT_function;
}
else if (mode=='t')
{
USART1->CR1 |= USART_CR1_TXEIE;
uart_tx_ptr_func=IT_function;
}
NVIC->ISER[1] |= 0x01<<(USART1_IRQn%32);
NVIC->IP[USART1_IRQn] |= Prio << 4;
}
@ -46,18 +58,9 @@ void USART1_IRQHandler()
(*uart_rx_ptr_func)();
}
}
else if (USART1->SR & USART_SR_TXE) // à revoir car si rien dedans il va tout le temps y retourner vu qu'il est vide
{
USART1->SR &= ~USART_SR_TXE;
if(uart_tx_ptr_func!=0)
{
(*uart_tx_ptr_func)();
}
}
}
char UART_receive()
{
return USART1->DR;
return USART1->DR; // on recupere dans DR
}

View file

@ -2,79 +2,34 @@
#include <stdio.h>
#include <string.h>
#include "GPIO.h"
#include "TIMER.h"
#include "ADC.h"
#include "UART.h"
int val_adc=0;
int cpt_buff_tx=0;
int cpt_buff_rx=0;
MyGPIO_Struct_TypeDef PA5; //PA5 LED
MyGPIO_Struct_TypeDef PC13; //PC13 Bouton
MyTimer_Struct_TypeDef timer2;
MyADC_Struct_TypeDef myADC;
char buffer_tx[100]={0};
char buffer_rx[100]={0};
void GPIO_led_IT (void);
void ADC_IT(void);
void UART_RX_IT(void);
void UART_TX_IT(void);
char MyChar;
int main ( void )
{
myADC.ADC=ADC1;
myADC.channel=2;
MyADC_init(&myADC);
MyADC_ActiveIT(myADC.ADC,4,&ADC_IT);
MyADC_start_conversion(myADC.ADC);
MyUART_init();
MyUART_ActiveIT(1, &UART_RX_IT, 'r'); //mode permet d'activer soit l'interruption sur RX (mode=0) soit TX (mode=1)
MyUART_ActiveIT(3, &UART_TX_IT, 't'); //mode permet d'activer soit l'interruption sur RX (mode=0) soit TX (mode=1)
sprintf(buffer_tx,"Test");
while(1)
{
}
}
void GPIO_led_IT (void)
{
MyGPIO_Toggle(PA5.GPIO,5);
}
void ADC_IT (void)
{
val_adc=MyADC_result(myADC.ADC);
}
void UART_TX_IT (void)
{
if(buffer_tx[cpt_buff_tx]!=0)
{
UART_send(buffer_tx[cpt_buff_tx]);
cpt_buff_tx++;
}
else
{
cpt_buff_tx=0;
memset(buffer_tx, 0, sizeof buffer_tx);
}
}
//MyGPIO_Struct_TypeDef PA5; //PA5 LED
//MyGPIO_Struct_TypeDef PC13; //PC13 Bouton
void UART_RX_IT (void)
{
if((cpt_buff_rx!=-1)&&(cpt_buff_rx<100))
MyChar=UART_receive();
}
int main ( void )
{
buffer_rx[cpt_buff_rx]=UART_receive();
}
else
MyGPIO_Struct_TypeDef myGPIO;
myGPIO.GPIO = GPIOA;
myGPIO.GPIO_Conf = Out_Ppull;
myGPIO.GPIO_Pin = 5;
MyGPIO_Init (&myGPIO);
MyUART_init();
MyUART_ActiveIT(1, &UART_RX_IT); //mode permet d'activer soit l'interruption sur TX
while(1)
{
cpt_buff_rx=0;
memset(buffer_rx, 0, sizeof buffer_rx);
}
}

View file

@ -125,7 +125,7 @@
<SetRegEntry>
<Number>0</Number>
<Key>DLGDARM</Key>
<Name>(1010=984,109,1360,666,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=733,260,1154,687,0)(121=-1,-1,-1,-1,0)(122=939,341,1360,768,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=335,17,929,768,0)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=695,235,1143,649,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=298,17,901,768,0)(151=-1,-1,-1,-1,0)</Name>
<Name>(1010=984,109,1360,666,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=1084,185,1505,612,0)(121=-1,-1,-1,-1,0)(122=939,341,1360,768,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=335,17,929,768,0)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=1177,417,1625,831,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=298,17,901,768,0)(151=-1,-1,-1,-1,0)</Name>
</SetRegEntry>
<SetRegEntry>
<Number>0</Number>
@ -142,9 +142,9 @@
<Bp>
<Number>0</Number>
<Type>0</Type>
<LineNumber>31</LineNumber>
<LineNumber>15</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>134219858</Address>
<Address>134219150</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
@ -153,7 +153,7 @@
<BreakIfRCount>1</BreakIfRCount>
<Filename>.\Sources\Principal.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\TP1\Sources/Principal.c\31</Expression>
<Expression>\\TP1\Sources/Principal.c\15</Expression>
</Bp>
</Breakpoint>
<WatchWindow1>
@ -167,6 +167,26 @@
<WinNumber>1</WinNumber>
<ItemText>ADC</ItemText>
</Ww>
<Ww>
<count>2</count>
<WinNumber>1</WinNumber>
<ItemText>MyChar</ItemText>
</Ww>
<Ww>
<count>3</count>
<WinNumber>1</WinNumber>
<ItemText>RX_pin</ItemText>
</Ww>
<Ww>
<count>4</count>
<WinNumber>1</WinNumber>
<ItemText>RX_pin</ItemText>
</Ww>
<Ww>
<count>5</count>
<WinNumber>1</WinNumber>
<ItemText>MyChar</ItemText>
</Ww>
</WatchWindow1>
<Tracepoint>
<THDelay>0</THDelay>
@ -217,12 +237,6 @@
<SecondString>FF000000000000000000000000000000E0FFEF400100000000000000000000000000000028504F5254412026203078303030303030323029203E3E2035000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000001000000000000000000F03F170000000000000000000000000000000000000090020008</SecondString>
</Wi>
</LogicAnalyzers>
<SystemViewers>
<Entry>
<Name>System Viewer\USART1</Name>
<WinId>35905</WinId>
</Entry>
</SystemViewers>
<DebugDescription>
<Enable>1</Enable>
<EnableFlashSeq>1</EnableFlashSeq>
@ -337,7 +351,7 @@
<SetRegEntry>
<Number>0</Number>
<Key>DLGTARM</Key>
<Name>(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=318,388,739,793,0)(121=1101,403,1522,808,0)(122=1281,393,1702,798,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=-1,-1,-1,-1,0)(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)(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)</Name>
<Name>(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=318,388,739,793,0)(121=1101,403,1522,808,0)(122=1281,393,1702,798,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=-1,-1,-1,-1,0)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=1106,213,1554,627,1)(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)(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)</Name>
</SetRegEntry>
<SetRegEntry>
<Number>0</Number>
@ -369,7 +383,7 @@
<periodic>1</periodic>
<aLwin>1</aLwin>
<aCover>0</aCover>
<aSer1>0</aSer1>
<aSer1>1</aSer1>
<aSer2>0</aSer2>
<aPa>0</aPa>
<viewmode>1</viewmode>
@ -381,7 +395,7 @@
<AscS3>0</AscS3>
<aSer3>0</aSer3>
<eProf>0</eProf>
<aLa>1</aLa>
<aLa>0</aLa>
<aPa1>0</aPa1>
<AscS4>0</AscS4>
<aSer4>0</aSer4>
@ -459,7 +473,7 @@
<GroupNumber>1</GroupNumber>
<FileNumber>4</FileNumber>
<FileType>1</FileType>
<tvExp>1</tvExp>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\Drivers\Src\ADC.c</PathWithFileName>
@ -471,7 +485,7 @@
<GroupNumber>1</GroupNumber>
<FileNumber>5</FileNumber>
<FileType>1</FileType>
<tvExp>1</tvExp>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\Drivers\Src\UART.c</PathWithFileName>

View file

@ -10,13 +10,13 @@
<TargetName>Simulé</TargetName>
<ToolsetNumber>0x4</ToolsetNumber>
<ToolsetName>ARM-ADS</ToolsetName>
<pCCUsed>6190000::V6.19::ARMCLANG</pCCUsed>
<uAC6>1</uAC6>
<pCCUsed>5060960::V5.06 update 7 (build 960)::.\ARMCC</pCCUsed>
<uAC6>0</uAC6>
<TargetOption>
<TargetCommonOption>
<Device>STM32F103RB</Device>
<Vendor>STMicroelectronics</Vendor>
<PackID>Keil.STM32F1xx_DFP.2.4.0</PackID>
<PackID>Keil.STM32F1xx_DFP.2.3.0</PackID>
<PackURL>http://www.keil.com/pack/</PackURL>
<Cpu>IRAM(0x20000000,0x00005000) IROM(0x08000000,0x00020000) CPUTYPE("Cortex-M3") CLOCK(12000000) ELITTLE</Cpu>
<FlashUtilSpec></FlashUtilSpec>
@ -186,7 +186,6 @@
<RvdsVP>0</RvdsVP>
<RvdsMve>0</RvdsMve>
<RvdsCdeCp>0</RvdsCdeCp>
<nBranchProt>0</nBranchProt>
<hadIRAM2>0</hadIRAM2>
<hadIROM2>0</hadIROM2>
<StupSel>8</StupSel>
@ -314,7 +313,7 @@
</ArmAdsMisc>
<Cads>
<interw>1</interw>
<Optim>2</Optim>
<Optim>1</Optim>
<oTime>0</oTime>
<SplitLS>0</SplitLS>
<OneElfS>1</OneElfS>
@ -323,7 +322,7 @@
<PlainCh>0</PlainCh>
<Ropi>0</Ropi>
<Rwpi>0</Rwpi>
<wLevel>3</wLevel>
<wLevel>2</wLevel>
<uThumb>0</uThumb>
<uSurpInc>0</uSurpInc>
<uC99>0</uC99>
@ -599,7 +598,6 @@
<RvdsVP>0</RvdsVP>
<RvdsMve>0</RvdsMve>
<RvdsCdeCp>0</RvdsCdeCp>
<nBranchProt>0</nBranchProt>
<hadIRAM2>0</hadIRAM2>
<hadIROM2>0</hadIROM2>
<StupSel>8</StupSel>
@ -837,15 +835,15 @@
<RTE>
<apis/>
<components>
<component Cclass="CMSIS" Cgroup="CORE" Cvendor="ARM" Cversion="5.6.0" condition="ARMv6_7_8-M Device">
<package name="CMSIS" schemaVersion="1.7.7" url="http://www.keil.com/pack/" vendor="ARM" version="5.9.0"/>
<component Cclass="CMSIS" Cgroup="CORE" Cvendor="ARM" Cversion="5.4.0" condition="ARMv6_7_8-M Device">
<package name="CMSIS" schemaVersion="1.3" url="http://www.keil.com/pack/" vendor="ARM" version="5.7.0"/>
<targetInfos>
<targetInfo name="Réel"/>
<targetInfo name="Simulé"/>
</targetInfos>
</component>
<component Cclass="Device" Cgroup="Startup" Cvendor="Keil" Cversion="1.0.0" condition="STM32F1xx CMSIS">
<package name="STM32F1xx_DFP" schemaVersion="1.7.2" url="http://www.keil.com/pack/" vendor="Keil" version="2.4.0"/>
<package name="STM32F1xx_DFP" schemaVersion="1.4.0" url="http://www.keil.com/pack/" vendor="Keil" version="2.3.0"/>
<targetInfos>
<targetInfo name="Réel"/>
<targetInfo name="Simulé"/>
@ -856,7 +854,7 @@
<file attr="config" category="header" name="RTE_Driver\Config\RTE_Device.h" version="1.1.2">
<instance index="0">RTE\Device\STM32F103RB\RTE_Device.h</instance>
<component Cclass="Device" Cgroup="Startup" Cvendor="Keil" Cversion="1.0.0" condition="STM32F1xx CMSIS"/>
<package name="STM32F1xx_DFP" schemaVersion="1.7.2" url="http://www.keil.com/pack/" vendor="Keil" version="2.4.0"/>
<package name="STM32F1xx_DFP" schemaVersion="1.4.0" url="http://www.keil.com/pack/" vendor="Keil" version="2.3.0"/>
<targetInfos>
<targetInfo name="Réel"/>
<targetInfo name="Simulé"/>
@ -865,7 +863,7 @@
<file attr="config" category="source" condition="STM32F1xx MD ARMCC" name="Device\Source\ARM\startup_stm32f10x_md.s" version="1.0.0">
<instance index="0">RTE\Device\STM32F103RB\startup_stm32f10x_md.s</instance>
<component Cclass="Device" Cgroup="Startup" Cvendor="Keil" Cversion="1.0.0" condition="STM32F1xx CMSIS"/>
<package name="STM32F1xx_DFP" schemaVersion="1.7.2" url="http://www.keil.com/pack/" vendor="Keil" version="2.4.0"/>
<package name="STM32F1xx_DFP" schemaVersion="1.4.0" url="http://www.keil.com/pack/" vendor="Keil" version="2.3.0"/>
<targetInfos>
<targetInfo name="Réel"/>
<targetInfo name="Simulé"/>
@ -874,7 +872,7 @@
<file attr="config" category="source" name="Device\Source\system_stm32f10x.c" version="1.0.0">
<instance index="0">RTE\Device\STM32F103RB\system_stm32f10x.c</instance>
<component Cclass="Device" Cgroup="Startup" Cvendor="Keil" Cversion="1.0.0" condition="STM32F1xx CMSIS"/>
<package name="STM32F1xx_DFP" schemaVersion="1.7.2" url="http://www.keil.com/pack/" vendor="Keil" version="2.4.0"/>
<package name="STM32F1xx_DFP" schemaVersion="1.4.0" url="http://www.keil.com/pack/" vendor="Keil" version="2.3.0"/>
<targetInfos>
<targetInfo name="Réel"/>
<targetInfo name="Simulé"/>