STM32-F103C8_Plantilla Es la plantilla base para compatibilidad con Mbed para la tarjeta "Blue Pill" basada en el STM32-F103C8T6
Dependencies: mbed
main.cpp@4:e1e547c34929, 2020-06-17 (annotated)
- Committer:
- Antulius
- Date:
- Wed Jun 17 20:25:52 2020 +0000
- Revision:
- 4:e1e547c34929
- Parent:
- 3:1ccbb37e3828
Plantilla mejorada para utilizar la Tarjeta "BluePill" (STM32F103C8T6)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Antulius | 4:e1e547c34929 | 1 | /* ############################################################################# |
Antulius | 0:9f7581d1af6f | 2 | ** Archivo : main.c |
Antulius | 4:e1e547c34929 | 3 | ** Proyecto : STM32F103C8_Plantilla |
Antulius | 4:e1e547c34929 | 4 | ** Procesador : STM32F103C8T6 |
Antulius | 4:e1e547c34929 | 5 | ** Plataforma : Blue Pill |
Antulius | 0:9f7581d1af6f | 6 | ** Herramienta : Mbed |
Antulius | 4:e1e547c34929 | 7 | ** Compilador : Mbed Online C Compiler |
Antulius | 4:e1e547c34929 | 8 | ** Version : Mbed-OS 5.15.0 |
Antulius | 4:e1e547c34929 | 9 | ** Fecha/Hora : 18-12-2019, 11:48, # CodeGen: 0 |
Antulius | 0:9f7581d1af6f | 10 | ** Descripción : |
Antulius | 0:9f7581d1af6f | 11 | ** Este proyecto hace... |
Antulius | 0:9f7581d1af6f | 12 | ** This module contains user's application code. |
Antulius | 0:9f7581d1af6f | 13 | ** Componentes : GPIO, Timer, etc . |
Antulius | 0:9f7581d1af6f | 14 | ** Configuraciones : Includes, Stacks y Drivers externos |
Antulius | 0:9f7581d1af6f | 15 | ** Autores : |
Antulius | 0:9f7581d1af6f | 16 | ** ATEAM Development Group: |
Antulius | 0:9f7581d1af6f | 17 | ** - Antulio Morgado Valle |
Antulius | 0:9f7581d1af6f | 18 | ** |
Antulius | 0:9f7581d1af6f | 19 | ** Versión : Beta |
Antulius | 0:9f7581d1af6f | 20 | ** Revisión : A |
Antulius | 0:9f7581d1af6f | 21 | ** Release : 0 |
Antulius | 0:9f7581d1af6f | 22 | ** Bugs & Fixes : |
Antulius | 0:9f7581d1af6f | 23 | ** Date : 20/10/2019 |
Antulius | 0:9f7581d1af6f | 24 | ** Added support for Led_RGB |
Antulius | 0:9f7581d1af6f | 25 | ** 22/09/2018 |
Antulius | 0:9f7581d1af6f | 26 | ** Added LCD Menu, Beta version (with bugs) |
Antulius | 0:9f7581d1af6f | 27 | ** |
Antulius | 0:9f7581d1af6f | 28 | ** ###########################################################################*/ |
Antulius | 0:9f7581d1af6f | 29 | /* |
Antulius | 0:9f7581d1af6f | 30 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: |
Antulius | 0:9f7581d1af6f | 31 | : Includes |
Antulius | 0:9f7581d1af6f | 32 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: |
Antulius | 0:9f7581d1af6f | 33 | */ |
Antulius | 1:c0ed6c52c441 | 34 | #include "stm32f103c8t6.h" |
Antulius | 0:9f7581d1af6f | 35 | #include "mbed.h" |
Antulius | 0:9f7581d1af6f | 36 | //#include "AnalogIn.h" |
Antulius | 0:9f7581d1af6f | 37 | //#include "Led_RGB.h" |
Antulius | 1:c0ed6c52c441 | 38 | #include "Serial.h" |
Antulius | 0:9f7581d1af6f | 39 | //#include "stdio.h" |
Antulius | 0:9f7581d1af6f | 40 | |
Antulius | 0:9f7581d1af6f | 41 | /* |
Antulius | 0:9f7581d1af6f | 42 | :............................................................................... |
Antulius | 0:9f7581d1af6f | 43 | : Definiciones |
Antulius | 0:9f7581d1af6f | 44 | :............................................................................... |
Antulius | 0:9f7581d1af6f | 45 | */ |
Antulius | 0:9f7581d1af6f | 46 | #define on 0 // Estado para boton presionado |
Antulius | 0:9f7581d1af6f | 47 | #define off 1 // Estado para boton sin presionar |
Antulius | 0:9f7581d1af6f | 48 | #define hold 2 // Estado para boton mantenido |
Antulius | 0:9f7581d1af6f | 49 | #define release 3 // Estado para boton liberado |
Antulius | 1:c0ed6c52c441 | 50 | #define FALSE 0 // Estado FALSO |
Antulius | 1:c0ed6c52c441 | 51 | #define TRUE 1 // Estado VERDADERO |
Antulius | 0:9f7581d1af6f | 52 | #define Ticker_Rate 1000 // Periodo de interrupción (us) |
Antulius | 4:e1e547c34929 | 53 | #define Baud_Rate 115200 // Velocidad de Transmisión (Bauds) |
Antulius | 0:9f7581d1af6f | 54 | /* |
Antulius | 0:9f7581d1af6f | 55 | +------------------------------------------------------------------------------- |
Antulius | 0:9f7581d1af6f | 56 | | Configuración de Puertos |
Antulius | 0:9f7581d1af6f | 57 | +------------------------------------------------------------------------------- |
Antulius | 0:9f7581d1af6f | 58 | */ |
Antulius | 0:9f7581d1af6f | 59 | //confSysClock(); // Configure system clock (72MHz HSE clock, 48MHz USB clock) |
Antulius | 0:9f7581d1af6f | 60 | Ticker TimerInt; // Inicializa la Interrupción por Timer |
Antulius | 4:e1e547c34929 | 61 | DigitalOut led_monitor(LED1); // Inicializa el LED Monitor (Interno) |
Antulius | 4:e1e547c34929 | 62 | DigitalOut led_testigo(PB_1); // Inicializa el LED Testigo (Externo) |
Antulius | 0:9f7581d1af6f | 63 | PwmOut servo(PA_7); // Inicializa el PWM |
Antulius | 0:9f7581d1af6f | 64 | AnalogIn sensor1 (PB_0); // Inicializa Canal Analógico para sensor 1 |
Antulius | 4:e1e547c34929 | 65 | Serial terminal(PA_2, PA_3); // Inicializa la Comunicación Serial a la PC |
Antulius | 0:9f7581d1af6f | 66 | /* |
Antulius | 0:9f7581d1af6f | 67 | +------------------------------------------------------------------------------- |
Antulius | 0:9f7581d1af6f | 68 | | Variables Globales de Usuario |
Antulius | 0:9f7581d1af6f | 69 | +------------------------------------------------------------------------------- |
Antulius | 0:9f7581d1af6f | 70 | */ |
Antulius | 0:9f7581d1af6f | 71 | uint16_t Rate=Ticker_Rate/2; // Velocidad de barrido (500us = 0.5ms) |
Antulius | 0:9f7581d1af6f | 72 | uint16_t counter=250; // Cuenta inicial de 250us |
Antulius | 0:9f7581d1af6f | 73 | /* END variables */ |
Antulius | 0:9f7581d1af6f | 74 | |
Antulius | 0:9f7581d1af6f | 75 | /* |
Antulius | 0:9f7581d1af6f | 76 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
Antulius | 0:9f7581d1af6f | 77 | | Definición de Funciones Prototipo y Rutinas de los Vectores de Interrupción |
Antulius | 0:9f7581d1af6f | 78 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
Antulius | 0:9f7581d1af6f | 79 | */ |
Antulius | 0:9f7581d1af6f | 80 | // Las Definiciones de Funciones Prototipo |
Antulius | 0:9f7581d1af6f | 81 | // y Apuntadores a Vectores de Interrupciones van aquí ! |
Antulius | 0:9f7581d1af6f | 82 | void TimerInt_OnInterrupt(void); |
Antulius | 0:9f7581d1af6f | 83 | void Blinking_Led(void); |
Antulius | 0:9f7581d1af6f | 84 | /* END prototypes */ |
Antulius | 0:9f7581d1af6f | 85 | |
Antulius | 0:9f7581d1af6f | 86 | /* END definitions */ |
Antulius | 0:9f7581d1af6f | 87 | /* |
Antulius | 0:9f7581d1af6f | 88 | #=============================================================================== |
Antulius | 0:9f7581d1af6f | 89 | | |
Antulius | 0:9f7581d1af6f | 90 | | P R O G R A M A P R I N C I P A L |
Antulius | 0:9f7581d1af6f | 91 | | |
Antulius | 0:9f7581d1af6f | 92 | #=============================================================================== |
Antulius | 0:9f7581d1af6f | 93 | */ |
Antulius | 0:9f7581d1af6f | 94 | int main() |
Antulius | 0:9f7581d1af6f | 95 | { // Inicialización de variables, puertos e interrupciones |
Antulius | 0:9f7581d1af6f | 96 | confSysClock(); // Inicialización del Sistema, Configure system clock (72MHz HSE clock, 48MHz USB clock) |
Antulius | 0:9f7581d1af6f | 97 | TimerInt.attach_us(&TimerInt_OnInterrupt, Ticker_Rate); // Le asigna el periodo de interrupción de 1ms (Ticker_Rate=1000) |
Antulius | 0:9f7581d1af6f | 98 | |
Antulius | 4:e1e547c34929 | 99 | terminal.baud(Baud_Rate); // Se configura la velocidad de transmisión e inicia la comunicación serial. |
Antulius | 0:9f7581d1af6f | 100 | terminal.printf(" System is Wake Up!.\n\r"); |
Antulius | 0:9f7581d1af6f | 101 | |
Antulius | 0:9f7581d1af6f | 102 | while (true) // El Lazo del Programa principal está aquí !!! |
Antulius | 0:9f7581d1af6f | 103 | { |
Antulius | 4:e1e547c34929 | 104 | Blinking_Led(); // Parapadeo del LED por Software |
Antulius | 4:e1e547c34929 | 105 | servo = sensor1.read(); // Lee el Potenciometro y mueve el Servo |
Antulius | 0:9f7581d1af6f | 106 | terminal.printf("Blink \r\n"); |
Antulius | 0:9f7581d1af6f | 107 | } |
Antulius | 0:9f7581d1af6f | 108 | } |
Antulius | 0:9f7581d1af6f | 109 | /* END main */ |
Antulius | 0:9f7581d1af6f | 110 | |
Antulius | 0:9f7581d1af6f | 111 | /* |
Antulius | 0:9f7581d1af6f | 112 | ................................................................................ |
Antulius | 0:9f7581d1af6f | 113 | : Rutinas de los Vectores de Interrupción |
Antulius | 0:9f7581d1af6f | 114 | ................................................................................ |
Antulius | 0:9f7581d1af6f | 115 | */ |
Antulius | 0:9f7581d1af6f | 116 | // Las Rutinas de Atención a Interrupciones van aquí ! |
Antulius | 0:9f7581d1af6f | 117 | void TimerInt_OnInterrupt() // Rutina de Atención al Ticker |
Antulius | 0:9f7581d1af6f | 118 | { |
Antulius | 0:9f7581d1af6f | 119 | counter--; // Aquí va la Rutina de Servicio ! |
Antulius | 0:9f7581d1af6f | 120 | if (!counter) |
Antulius | 0:9f7581d1af6f | 121 | { |
Antulius | 0:9f7581d1af6f | 122 | terminal.printf("Counter Finish! \r\n"); |
Antulius | 0:9f7581d1af6f | 123 | led_monitor = !led_monitor; // Parapadeo del LED por Interrupción (LED Toggled) |
Antulius | 4:e1e547c34929 | 124 | counter = Rate; // Restablece el contador, Le asigna el periodo de 0.5ms (Rate=500) |
Antulius | 0:9f7581d1af6f | 125 | } |
Antulius | 0:9f7581d1af6f | 126 | } |
Antulius | 0:9f7581d1af6f | 127 | /* END Events */ |
Antulius | 0:9f7581d1af6f | 128 | /* |
Antulius | 0:9f7581d1af6f | 129 | ________________________________________________________________________________ |
Antulius | 0:9f7581d1af6f | 130 | | |
Antulius | 0:9f7581d1af6f | 131 | | Funciones Prototipo |
Antulius | 0:9f7581d1af6f | 132 | |_______________________________________________________________________________ |
Antulius | 0:9f7581d1af6f | 133 | */ |
Antulius | 0:9f7581d1af6f | 134 | // Las Funciones Prototipo van aquí ! |
Antulius | 0:9f7581d1af6f | 135 | void Blinking_Led() // Software Blinking routine for LED |
Antulius | 0:9f7581d1af6f | 136 | { |
Antulius | 0:9f7581d1af6f | 137 | // The on-board LED is connected, via a resistor, to +3.3V (not to GND). |
Antulius | 0:9f7581d1af6f | 138 | // So to turn the LED on or off we have to set it to 0 or 1 respectively |
Antulius | 0:9f7581d1af6f | 139 | led_testigo = 1; // turn the LED on (using Positive Logic) |
Antulius | 0:9f7581d1af6f | 140 | wait_ms(200); // 200 millisecond |
Antulius | 0:9f7581d1af6f | 141 | led_testigo = 0; // turn the LED off (using Positive Logic) |
Antulius | 0:9f7581d1af6f | 142 | wait_ms(1000); // 1000 millisecond |
Antulius | 0:9f7581d1af6f | 143 | } |
Antulius | 0:9f7581d1af6f | 144 | /* END functions */ |
Antulius | 0:9f7581d1af6f | 145 | |
Antulius | 0:9f7581d1af6f | 146 | /* END program */ |
Antulius | 0:9f7581d1af6f | 147 | |
Antulius | 0:9f7581d1af6f | 148 | /*+----------------------------------------------------------------------------- |
Antulius | 1:c0ed6c52c441 | 149 | *+ La documentación va aquí!: |
Antulius | 1:c0ed6c52c441 | 150 | *+----------------------------------------------------------------------------- |
Antulius | 0:9f7581d1af6f | 151 | *+ Conexión al Led Testigo: |
Antulius | 0:9f7581d1af6f | 152 | *+ |
Antulius | 0:9f7581d1af6f | 153 | *+ Los leds se pueden conectar a cualquier pin que se declare como DigitalOut. |
Antulius | 0:9f7581d1af6f | 154 | *+ El dispositivo puede drenar hasta 20ma por todas sus salidas a un voltaje de |
Antulius | 0:9f7581d1af6f | 155 | *+ 3.3V, pero se recomienda no exceder de 1mA por salida. |
Antulius | 0:9f7581d1af6f | 156 | *+ Esto se logra poniendo una resistencia limitadora de mínimo 330 Ohms. |
Antulius | 0:9f7581d1af6f | 157 | *+ |
Antulius | 0:9f7581d1af6f | 158 | *+ 3.3V o 5V |
Antulius | 0:9f7581d1af6f | 159 | *+ O |
Antulius | 0:9f7581d1af6f | 160 | *+ | |
Antulius | 0:9f7581d1af6f | 161 | *+ | |
Antulius | 0:9f7581d1af6f | 162 | *+ / |
Antulius | 0:9f7581d1af6f | 163 | *+ \ 1K |
Antulius | 0:9f7581d1af6f | 164 | *+ / |
Antulius | 0:9f7581d1af6f | 165 | *+ \ UTILIZANDO LÓGICA NEGATIVA |
Antulius | 0:9f7581d1af6f | 166 | *+ | |
Antulius | 0:9f7581d1af6f | 167 | *+ ___|___ |
Antulius | 0:9f7581d1af6f | 168 | *+ \ / |
Antulius | 0:9f7581d1af6f | 169 | *+ \ / |
Antulius | 0:9f7581d1af6f | 170 | *+ \ / |
Antulius | 0:9f7581d1af6f | 171 | *+ __\/__ |
Antulius | 0:9f7581d1af6f | 172 | *+ | |
Antulius | 0:9f7581d1af6f | 173 | *+ |__________________________ PIN (Digital Out) |
Antulius | 0:9f7581d1af6f | 174 | *+ |
Antulius | 0:9f7581d1af6f | 175 | *+ |
Antulius | 0:9f7581d1af6f | 176 | *+ |
Antulius | 0:9f7581d1af6f | 177 | *+ |
Antulius | 0:9f7581d1af6f | 178 | *+ 1K |
Antulius | 0:9f7581d1af6f | 179 | *+ |
Antulius | 0:9f7581d1af6f | 180 | *+ _________/\ /\ /\ _____ PIN (Digital Out) |
Antulius | 0:9f7581d1af6f | 181 | *+ | \/ \/ \/ |
Antulius | 0:9f7581d1af6f | 182 | *+ | |
Antulius | 0:9f7581d1af6f | 183 | *+ | |
Antulius | 0:9f7581d1af6f | 184 | *+ ___|___ |
Antulius | 0:9f7581d1af6f | 185 | *+ \ / |
Antulius | 0:9f7581d1af6f | 186 | *+ \ / |
Antulius | 0:9f7581d1af6f | 187 | *+ \ / UTILIZANDO LÓGICA POSITIVA |
Antulius | 0:9f7581d1af6f | 188 | *+ __\/__ |
Antulius | 0:9f7581d1af6f | 189 | *+ | |
Antulius | 0:9f7581d1af6f | 190 | *+ | |
Antulius | 0:9f7581d1af6f | 191 | *+ | |
Antulius | 0:9f7581d1af6f | 192 | *+ ___|___ |
Antulius | 0:9f7581d1af6f | 193 | *+ _____ |
Antulius | 0:9f7581d1af6f | 194 | *+ ___ |
Antulius | 0:9f7581d1af6f | 195 | *+ _ |
Antulius | 0:9f7581d1af6f | 196 | *+ |
Antulius | 0:9f7581d1af6f | 197 | *+ GND |
Antulius | 0:9f7581d1af6f | 198 | *+ |
Antulius | 0:9f7581d1af6f | 199 | *+----------------------------------------------------------------------------* |
Antulius | 0:9f7581d1af6f | 200 | *+ |
Antulius | 0:9f7581d1af6f | 201 | *+ Powered by |
Antulius | 0:9f7581d1af6f | 202 | *+ |
Antulius | 0:9f7581d1af6f | 203 | *+ T H E A N T U L I U ' S T E A M R&D Unltd |
Antulius | 0:9f7581d1af6f | 204 | *+ |
Antulius | 0:9f7581d1af6f | 205 | *+ Research, Development, Systems, Equipment, Support & Spare Parts. |
Antulius | 0:9f7581d1af6f | 206 | *+ (C) Copyright 1989-2019, All Rights Reserved |
Antulius | 0:9f7581d1af6f | 207 | *+ |
Antulius | 0:9f7581d1af6f | 208 | *+ Welcome to The Beaners Proyect Community! |
Antulius | 0:9f7581d1af6f | 209 | *+----------------------------------------------------------------------------*/ |
Antulius | 0:9f7581d1af6f | 210 | |
Antulius | 3:1ccbb37e3828 | 211 | /* END documentation */ |
Antulius | 3:1ccbb37e3828 | 212 | |
Antulius | 0:9f7581d1af6f | 213 | /* END Mbed */ |