Modification of Mbed-dev library for LQFP48 package microcontrollers: STM32F103C8 (STM32F103C8T6) and STM32F103CB (STM32F103CBT6) (Bluepill boards, Maple mini etc. )

Fork of mbed-STM32F103C8_org by Nothing Special

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers mbed_board.c Source File

mbed_board.c

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2006-2013 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #include <stdio.h>
00017 #include "hal/gpio_api.h"
00018 #include "platform/mbed_wait_api.h"
00019 #include "platform/mbed_toolchain.h"
00020 #include "platform/mbed_interface.h"
00021 #include "platform/mbed_critical.h"
00022 #include "hal/serial_api.h"
00023 
00024 #if DEVICE_SERIAL
00025 extern int stdio_uart_inited;
00026 extern serial_t stdio_uart;
00027 #endif
00028 
00029 WEAK void mbed_die(void) {
00030 #if !defined (NRF51_H) && !defined(TARGET_EFM32)
00031     core_util_critical_section_enter();
00032 #endif
00033 #if   (DEVICE_ERROR_RED == 1)
00034     gpio_t led_red; gpio_init_out(&led_red, LED_RED);
00035 #elif (DEVICE_ERROR_PATTERN == 1)
00036     gpio_t led_1; gpio_init_out(&led_1, LED1);
00037     gpio_t led_2; gpio_init_out(&led_2, LED2);
00038     gpio_t led_3; gpio_init_out(&led_3, LED3);
00039     gpio_t led_4; gpio_init_out(&led_4, LED4);
00040 #endif
00041 
00042     while (1) {
00043 #if   (DEVICE_ERROR_RED == 1)
00044         gpio_write(&led_red, 1);
00045 
00046 #elif (DEVICE_ERROR_PATTERN == 1)
00047         gpio_write(&led_1, 1);
00048         gpio_write(&led_2, 0);
00049         gpio_write(&led_3, 0);
00050         gpio_write(&led_4, 1);
00051 #endif
00052 
00053         wait_ms(150);
00054 
00055 #if   (DEVICE_ERROR_RED == 1)
00056         gpio_write(&led_red, 0);
00057 
00058 #elif (DEVICE_ERROR_PATTERN == 1)
00059         gpio_write(&led_1, 0);
00060         gpio_write(&led_2, 1);
00061         gpio_write(&led_3, 1);
00062         gpio_write(&led_4, 0);
00063 #endif
00064 
00065         wait_ms(150);
00066     }
00067 }
00068 
00069 void mbed_error_printf(const char* format, ...) {
00070     va_list arg;
00071     va_start(arg, format);
00072     mbed_error_vfprintf(format, arg);
00073     va_end(arg);
00074 }
00075 
00076 void mbed_error_vfprintf(const char * format, va_list arg) {
00077 #if DEVICE_SERIAL
00078 
00079 #if MBED_CONF_PLATFORM_STDIO_CONVERT_NEWLINES
00080     char stdio_out_prev;
00081 #endif
00082 
00083     core_util_critical_section_enter();
00084     char buffer[128];
00085     int size = vsprintf(buffer, format, arg);
00086     if (size > 0) {
00087         if (!stdio_uart_inited) {
00088             serial_init(&stdio_uart, STDIO_UART_TX, STDIO_UART_RX);
00089         }
00090 #if MBED_CONF_PLATFORM_STDIO_CONVERT_NEWLINES
00091         for (unsigned int i = 0; i < size; i++) {
00092             if (buffer[i] == '\n' && stdio_out_prev != '\r') {
00093                  serial_putc(&stdio_uart, '\r');
00094             }
00095             serial_putc(&stdio_uart, buffer[i]);
00096             stdio_out_prev = buffer[i];
00097         }
00098 #else
00099         for (unsigned int i = 0; i < size; i++) {
00100             serial_putc(&stdio_uart, buffer[i]);
00101         }
00102 #endif
00103     }
00104     core_util_critical_section_exit();
00105 #endif
00106 }