STM32F103C8_Plantilla_USB Plantilla para configuración del Puerto USB y la Terminal Serial

Dependencies:   mbed-STM32F103C8T6 USBDevice_STM32F103 mbed-src

Committer:
Antulius
Date:
Thu Sep 05 19:48:05 2019 +0000
Revision:
1:e691f2e04aeb
Parent:
0:16b83f767a7e
STM32F103C8T6_Plantilla_USB

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Antulius 0:16b83f767a7e 1 /* ###########################################################################
Antulius 0:16b83f767a7e 2 ** Archivo : main.c
Antulius 1:e691f2e04aeb 3 ** Proyecto : STM32-F103C8_Plantilla_USB
Antulius 0:16b83f767a7e 4 ** Procesador : STM32F103C8
Antulius 0:16b83f767a7e 5 ** Herramienta : Mbed
Antulius 0:16b83f767a7e 6 ** Version : Driver 01.01
Antulius 0:16b83f767a7e 7 ** Compilador : GNU C Compiler
Antulius 0:16b83f767a7e 8 ** Fecha/Hora : 14-07-2015, 11:48, # CodeGen: 0
Antulius 0:16b83f767a7e 9 ** Descripción :
Antulius 0:16b83f767a7e 10 ** Este proyecto hace...
Antulius 0:16b83f767a7e 11 ** This module contains user's application code.
Antulius 0:16b83f767a7e 12 ** Componentes : GPIO, Timer, etc .
Antulius 0:16b83f767a7e 13 ** Configuraciones : Includes, Stacks y Drivers externos
Antulius 0:16b83f767a7e 14 ** Autores :
Antulius 0:16b83f767a7e 15 ** ATEAM Development Group:
Antulius 0:16b83f767a7e 16 ** - Antulio Morgado Valle
Antulius 0:16b83f767a7e 17 **
Antulius 0:16b83f767a7e 18 ** Versión : Beta
Antulius 0:16b83f767a7e 19 ** Revisión : A
Antulius 0:16b83f767a7e 20 ** Release : 0
Antulius 0:16b83f767a7e 21 ** Bugs & Fixes :
Antulius 0:16b83f767a7e 22 ** Date : 20/10/2019
Antulius 0:16b83f767a7e 23 ** Added support for Led_RGB
Antulius 0:16b83f767a7e 24 ** 22/09/2018
Antulius 0:16b83f767a7e 25 ** Added LCD Menu, Beta version (with bugs)
Antulius 0:16b83f767a7e 26 **
Antulius 0:16b83f767a7e 27 ** ###########################################################################*/
Antulius 0:16b83f767a7e 28 /*
Antulius 0:16b83f767a7e 29 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Antulius 0:16b83f767a7e 30 : Includes
Antulius 0:16b83f767a7e 31 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Antulius 0:16b83f767a7e 32 */
Antulius 1:e691f2e04aeb 33 #include "stm32f103c8t6.h"
Antulius 1:e691f2e04aeb 34 #include "stm32f10x.h"
Antulius 1:e691f2e04aeb 35 #include "mbed_lib.h"
Antulius 0:16b83f767a7e 36 #include "mbed.h"
Antulius 0:16b83f767a7e 37 #include "AnalogIn.h"
Antulius 0:16b83f767a7e 38 #include "Ticker.h"
Antulius 0:16b83f767a7e 39 //#include "Led_RGB.h"
Antulius 0:16b83f767a7e 40 #include "Serial.h"
Antulius 0:16b83f767a7e 41 //#include "stdio.h"
Antulius 0:16b83f767a7e 42
Antulius 0:16b83f767a7e 43 /*
Antulius 0:16b83f767a7e 44 :...............................................................................
Antulius 0:16b83f767a7e 45 : Definiciones
Antulius 0:16b83f767a7e 46 :...............................................................................
Antulius 0:16b83f767a7e 47 */
Antulius 0:16b83f767a7e 48 #define on 0 // Estado para boton presionado
Antulius 0:16b83f767a7e 49 #define off 1 // Estado para boton sin presionar
Antulius 0:16b83f767a7e 50 #define hold 2 // Estado para boton mantenido
Antulius 0:16b83f767a7e 51 #define release 3 // Estado para boton liberado
Antulius 1:e691f2e04aeb 52 #define FALSE 0 // Estado FALSO
Antulius 1:e691f2e04aeb 53 #define TRUE 1 // Estado VERDADERO
Antulius 0:16b83f767a7e 54 #define Ticker_Rate 1000 // Periodo de interrupción (us)
Antulius 1:e691f2e04aeb 55 #define Baud_Rate 115200 // Velocidad de Transmisión (bauds)
Antulius 0:16b83f767a7e 56 /*
Antulius 0:16b83f767a7e 57 +-------------------------------------------------------------------------------
Antulius 0:16b83f767a7e 58 | Configuración de Puertos
Antulius 0:16b83f767a7e 59 +-------------------------------------------------------------------------------
Antulius 0:16b83f767a7e 60 */
Antulius 0:16b83f767a7e 61 Ticker Barrido; // Inicializa la Interrupción por Timer
Antulius 0:16b83f767a7e 62 DigitalOut led_monitor(Green_Led); // Inicializa el LED Monitor
Antulius 0:16b83f767a7e 63 Serial terminal(PA_2, PA_3); // Inicializa la Comunicación Serial a la PC
Antulius 0:16b83f767a7e 64 PwmOut probe(PA_7); // Inicializa el PWM
Antulius 0:16b83f767a7e 65 AnalogIn sensor1 (PB_0); // Inicializa Canal Analógico para sensor 1
Antulius 0:16b83f767a7e 66 /*
Antulius 0:16b83f767a7e 67 +-------------------------------------------------------------------------------
Antulius 0:16b83f767a7e 68 | Variables Globales de Usuario
Antulius 0:16b83f767a7e 69 +-------------------------------------------------------------------------------
Antulius 0:16b83f767a7e 70 */
Antulius 0:16b83f767a7e 71 uint16_t Rate=Ticker_Rate/2; // Velocidad de barrido (500us = 0.5ms)
Antulius 0:16b83f767a7e 72 uint16_t counter=250; // Cuenta inicial de 250us
Antulius 0:16b83f767a7e 73
Antulius 0:16b83f767a7e 74 /*
Antulius 0:16b83f767a7e 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Antulius 0:16b83f767a7e 76 | Definición de Funciones Prototipo y Rutinas de los Vectores de Interrupción
Antulius 0:16b83f767a7e 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Antulius 0:16b83f767a7e 78 */
Antulius 0:16b83f767a7e 79 void Barrido_OnInterrupt(void);
Antulius 0:16b83f767a7e 80 void Blinking_Led(void);
Antulius 0:16b83f767a7e 81 /* END definitions */
Antulius 0:16b83f767a7e 82
Antulius 0:16b83f767a7e 83 /*
Antulius 0:16b83f767a7e 84 #===============================================================================
Antulius 0:16b83f767a7e 85 |
Antulius 0:16b83f767a7e 86 | P R O G R A M A P R I N C I P A L
Antulius 0:16b83f767a7e 87 |
Antulius 0:16b83f767a7e 88 #===============================================================================
Antulius 0:16b83f767a7e 89 */
Antulius 0:16b83f767a7e 90 int main()
Antulius 0:16b83f767a7e 91 { // Inicialización de variables, puertos e interrupciones
Antulius 0:16b83f767a7e 92 confSysClock(); // Inicialización del Sistema, Configure system clock (72MHz HSE clock, 48MHz USB clock)
Antulius 0:16b83f767a7e 93 Barrido.attach_us(&Barrido_OnInterrupt, Ticker_Rate); // Le asigna el periodo de barrido de 1ms (Ticker_Rate =1000)
Antulius 0:16b83f767a7e 94
Antulius 0:16b83f767a7e 95 //terminal.baud(115200); // Se configura la velocidad de transmisión e inicia la comunicación serial.
Antulius 0:16b83f767a7e 96 //terminal.printf(" System is Wake Up!.\n\r");
Antulius 0:16b83f767a7e 97
Antulius 0:16b83f767a7e 98 while (true) // El Lazo del Programa principal está aquí !!!
Antulius 0:16b83f767a7e 99 {
Antulius 0:16b83f767a7e 100 // Blinking_Led(); // Parapadeo del LED por Software
Antulius 0:16b83f767a7e 101 probe = sensor1.read();
Antulius 0:16b83f767a7e 102 terminal.printf("Blink \r\n");
Antulius 0:16b83f767a7e 103 }
Antulius 0:16b83f767a7e 104 }
Antulius 0:16b83f767a7e 105 /* END main */
Antulius 0:16b83f767a7e 106
Antulius 0:16b83f767a7e 107 /*
Antulius 0:16b83f767a7e 108 ................................................................................
Antulius 0:16b83f767a7e 109 : Rutinas de los Vectores de Interrupción
Antulius 0:16b83f767a7e 110 ................................................................................
Antulius 0:16b83f767a7e 111 */
Antulius 0:16b83f767a7e 112 void Barrido_OnInterrupt() // Rutina de Atención al Ticker
Antulius 0:16b83f767a7e 113 { // Aquí va la Rutina de Servicio !
Antulius 0:16b83f767a7e 114 counter--;
Antulius 0:16b83f767a7e 115 if (!counter)
Antulius 0:16b83f767a7e 116 {
Antulius 0:16b83f767a7e 117 terminal.printf("Counter Finish! \r\n");
Antulius 0:16b83f767a7e 118 led_monitor = !led_monitor; // Parapadeo del LED por Interrupción (Toggle the LED)
Antulius 0:16b83f767a7e 119 counter = Rate; // Restablece el contador
Antulius 0:16b83f767a7e 120 }
Antulius 0:16b83f767a7e 121 }
Antulius 0:16b83f767a7e 122 /* END Events */
Antulius 0:16b83f767a7e 123 /*
Antulius 0:16b83f767a7e 124 ________________________________________________________________________________
Antulius 0:16b83f767a7e 125 |
Antulius 0:16b83f767a7e 126 | Funciones Prototipo
Antulius 0:16b83f767a7e 127 |_______________________________________________________________________________
Antulius 0:16b83f767a7e 128 */
Antulius 0:16b83f767a7e 129 // Las Funciones Prototipo van aquí !
Antulius 0:16b83f767a7e 130 void Blinking_Led() // Software Blinking routine for LED
Antulius 0:16b83f767a7e 131 {
Antulius 0:16b83f767a7e 132 // The on-board LED is connected, via a resistor, to +3.3V (not to GND).
Antulius 0:16b83f767a7e 133 // So to turn the LED on or off we have to set it to 0 or 1 respectively
Antulius 0:16b83f767a7e 134 led_monitor = 0; // turn the LED on
Antulius 0:16b83f767a7e 135 wait_ms(200); // 200 millisecond
Antulius 0:16b83f767a7e 136 led_monitor = 1; // turn the LED off
Antulius 0:16b83f767a7e 137 wait_ms(1000); // 1000 millisecond
Antulius 0:16b83f767a7e 138 }
Antulius 1:e691f2e04aeb 139
Antulius 1:e691f2e04aeb 140 void Setup()
Antulius 1:e691f2e04aeb 141 {
Antulius 1:e691f2e04aeb 142 // confSysClock(); // Configure system clock (72MHz HSE clock, 48MHz USB clock)
Antulius 1:e691f2e04aeb 143 // terminal.baud(Baud_Rate); // Se configura la velocidad de transmisión e inicia la comunicación serial.
Antulius 1:e691f2e04aeb 144 terminal.baud(Baud_Rate); // Se configura la velocidad de transmisión e inicia la comunicación serial.
Antulius 1:e691f2e04aeb 145 terminal.printf(" System is Wake Up!.\n\r");
Antulius 1:e691f2e04aeb 146 }
Antulius 0:16b83f767a7e 147 /* END functions */
Antulius 0:16b83f767a7e 148
Antulius 0:16b83f767a7e 149 /* END program */
Antulius 0:16b83f767a7e 150
Antulius 0:16b83f767a7e 151 /* END Mbed */