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

Dependencies:   mbed-STM32F103C8T6 USBDevice_STM32F103 mbed-src

Committer:
Antulius
Date:
Wed Jun 26 18:48:46 2019 +0000
Revision:
0:16b83f767a7e
Child:
1:e691f2e04aeb
STM32-103C8T6_Plantilla  Plantilla para la Tarjeta "Blue Pill"

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Antulius 0:16b83f767a7e 1 /* ###########################################################################
Antulius 0:16b83f767a7e 2 ** Archivo : main.c
Antulius 0:16b83f767a7e 3 ** Proyecto : STM32-F103C8_Plantilla
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 0:16b83f767a7e 33 #include "mbed.h"
Antulius 0:16b83f767a7e 34 #include "stm32f103c8t6.h"
Antulius 0:16b83f767a7e 35 //#include "stm32f10x.h"
Antulius 0:16b83f767a7e 36 #include "PinNames.h"
Antulius 0:16b83f767a7e 37 #include "SysClockConf.h"
Antulius 0:16b83f767a7e 38 #include "AnalogIn.h"
Antulius 0:16b83f767a7e 39 #include "Ticker.h"
Antulius 0:16b83f767a7e 40 //#include "Led_RGB.h"
Antulius 0:16b83f767a7e 41 #include "Serial.h"
Antulius 0:16b83f767a7e 42 //#include "stdio.h"
Antulius 0:16b83f767a7e 43
Antulius 0:16b83f767a7e 44 /*
Antulius 0:16b83f767a7e 45 :...............................................................................
Antulius 0:16b83f767a7e 46 : Definiciones
Antulius 0:16b83f767a7e 47 :...............................................................................
Antulius 0:16b83f767a7e 48 */
Antulius 0:16b83f767a7e 49 #define on 0 // Estado para boton presionado
Antulius 0:16b83f767a7e 50 #define off 1 // Estado para boton sin presionar
Antulius 0:16b83f767a7e 51 #define hold 2 // Estado para boton mantenido
Antulius 0:16b83f767a7e 52 #define release 3 // Estado para boton liberado
Antulius 0:16b83f767a7e 53 #define Ticker_Rate 1000 // Periodo de interrupción (us)
Antulius 0:16b83f767a7e 54 /*
Antulius 0:16b83f767a7e 55 +-------------------------------------------------------------------------------
Antulius 0:16b83f767a7e 56 | Configuración de Puertos
Antulius 0:16b83f767a7e 57 +-------------------------------------------------------------------------------
Antulius 0:16b83f767a7e 58 */
Antulius 0:16b83f767a7e 59 //confSysClock(); // Configure system clock (72MHz HSE clock, 48MHz USB clock)
Antulius 0:16b83f767a7e 60 Ticker Barrido; // Inicializa la Interrupción por Timer
Antulius 0:16b83f767a7e 61 DigitalOut led_monitor(Green_Led); // Inicializa el LED Monitor
Antulius 0:16b83f767a7e 62 Serial terminal(PA_2, PA_3); // Inicializa la Comunicación Serial a la PC
Antulius 0:16b83f767a7e 63 PwmOut probe(PA_7); // Inicializa el PWM
Antulius 0:16b83f767a7e 64 AnalogIn sensor1 (PB_0); // Inicializa Canal Analógico para sensor 1
Antulius 0:16b83f767a7e 65 /*
Antulius 0:16b83f767a7e 66 +-------------------------------------------------------------------------------
Antulius 0:16b83f767a7e 67 | Variables Globales de Usuario
Antulius 0:16b83f767a7e 68 +-------------------------------------------------------------------------------
Antulius 0:16b83f767a7e 69 */
Antulius 0:16b83f767a7e 70 uint16_t Rate=Ticker_Rate/2; // Velocidad de barrido (500us = 0.5ms)
Antulius 0:16b83f767a7e 71 uint16_t counter=250; // Cuenta inicial de 250us
Antulius 0:16b83f767a7e 72
Antulius 0:16b83f767a7e 73 /*
Antulius 0:16b83f767a7e 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Antulius 0:16b83f767a7e 75 | Definición de Funciones Prototipo y Rutinas de los Vectores de Interrupción
Antulius 0:16b83f767a7e 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Antulius 0:16b83f767a7e 77 */
Antulius 0:16b83f767a7e 78 void Barrido_OnInterrupt(void);
Antulius 0:16b83f767a7e 79 void Blinking_Led(void);
Antulius 0:16b83f767a7e 80 /* END definitions */
Antulius 0:16b83f767a7e 81
Antulius 0:16b83f767a7e 82 /*
Antulius 0:16b83f767a7e 83 #===============================================================================
Antulius 0:16b83f767a7e 84 |
Antulius 0:16b83f767a7e 85 | P R O G R A M A P R I N C I P A L
Antulius 0:16b83f767a7e 86 |
Antulius 0:16b83f767a7e 87 #===============================================================================
Antulius 0:16b83f767a7e 88 */
Antulius 0:16b83f767a7e 89 int main()
Antulius 0:16b83f767a7e 90 { // Inicialización de variables, puertos e interrupciones
Antulius 0:16b83f767a7e 91 confSysClock(); // Inicialización del Sistema, Configure system clock (72MHz HSE clock, 48MHz USB clock)
Antulius 0:16b83f767a7e 92 Barrido.attach_us(&Barrido_OnInterrupt, Ticker_Rate); // Le asigna el periodo de barrido de 1ms (Ticker_Rate =1000)
Antulius 0:16b83f767a7e 93
Antulius 0:16b83f767a7e 94 //terminal.baud(115200); // Se configura la velocidad de transmisión e inicia la comunicación serial.
Antulius 0:16b83f767a7e 95 //terminal.printf(" System is Wake Up!.\n\r");
Antulius 0:16b83f767a7e 96
Antulius 0:16b83f767a7e 97 while (true) // El Lazo del Programa principal está aquí !!!
Antulius 0:16b83f767a7e 98 {
Antulius 0:16b83f767a7e 99 // Blinking_Led(); // Parapadeo del LED por Software
Antulius 0:16b83f767a7e 100 probe = sensor1.read();
Antulius 0:16b83f767a7e 101 terminal.printf("Blink \r\n");
Antulius 0:16b83f767a7e 102 }
Antulius 0:16b83f767a7e 103 }
Antulius 0:16b83f767a7e 104 /* END main */
Antulius 0:16b83f767a7e 105
Antulius 0:16b83f767a7e 106 /*
Antulius 0:16b83f767a7e 107 ................................................................................
Antulius 0:16b83f767a7e 108 : Rutinas de los Vectores de Interrupción
Antulius 0:16b83f767a7e 109 ................................................................................
Antulius 0:16b83f767a7e 110 */
Antulius 0:16b83f767a7e 111 void Barrido_OnInterrupt() // Rutina de Atención al Ticker
Antulius 0:16b83f767a7e 112 { // Aquí va la Rutina de Servicio !
Antulius 0:16b83f767a7e 113 counter--;
Antulius 0:16b83f767a7e 114 if (!counter)
Antulius 0:16b83f767a7e 115 {
Antulius 0:16b83f767a7e 116 terminal.printf("Counter Finish! \r\n");
Antulius 0:16b83f767a7e 117 led_monitor = !led_monitor; // Parapadeo del LED por Interrupción (Toggle the LED)
Antulius 0:16b83f767a7e 118 counter = Rate; // Restablece el contador
Antulius 0:16b83f767a7e 119 }
Antulius 0:16b83f767a7e 120 }
Antulius 0:16b83f767a7e 121 /* END Events */
Antulius 0:16b83f767a7e 122 /*
Antulius 0:16b83f767a7e 123 ________________________________________________________________________________
Antulius 0:16b83f767a7e 124 |
Antulius 0:16b83f767a7e 125 | Funciones Prototipo
Antulius 0:16b83f767a7e 126 |_______________________________________________________________________________
Antulius 0:16b83f767a7e 127 */
Antulius 0:16b83f767a7e 128 // Las Funciones Prototipo van aquí !
Antulius 0:16b83f767a7e 129 void Blinking_Led() // Software Blinking routine for LED
Antulius 0:16b83f767a7e 130 {
Antulius 0:16b83f767a7e 131 // The on-board LED is connected, via a resistor, to +3.3V (not to GND).
Antulius 0:16b83f767a7e 132 // So to turn the LED on or off we have to set it to 0 or 1 respectively
Antulius 0:16b83f767a7e 133 led_monitor = 0; // turn the LED on
Antulius 0:16b83f767a7e 134 wait_ms(200); // 200 millisecond
Antulius 0:16b83f767a7e 135 led_monitor = 1; // turn the LED off
Antulius 0:16b83f767a7e 136 wait_ms(1000); // 1000 millisecond
Antulius 0:16b83f767a7e 137 }
Antulius 0:16b83f767a7e 138 /* END functions */
Antulius 0:16b83f767a7e 139
Antulius 0:16b83f767a7e 140 /* END program */
Antulius 0:16b83f767a7e 141
Antulius 0:16b83f767a7e 142 /* END Mbed */