Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
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 { 00031 #if !defined (NRF51_H) && !defined(TARGET_EFM32) 00032 core_util_critical_section_enter(); 00033 #endif 00034 gpio_t led_err; 00035 gpio_init_out(&led_err, LED1); 00036 00037 while (1) { 00038 for (int i = 0; i < 4; ++i) { 00039 gpio_write(&led_err, 1); 00040 wait_ms(150); 00041 gpio_write(&led_err, 0); 00042 wait_ms(150); 00043 } 00044 00045 for (int i = 0; i < 4; ++i) { 00046 gpio_write(&led_err, 1); 00047 wait_ms(400); 00048 gpio_write(&led_err, 0); 00049 wait_ms(400); 00050 } 00051 } 00052 } 00053 00054 void mbed_error_printf(const char *format, ...) 00055 { 00056 va_list arg; 00057 va_start(arg, format); 00058 mbed_error_vfprintf(format, arg); 00059 va_end(arg); 00060 } 00061 00062 void mbed_error_vfprintf(const char *format, va_list arg) 00063 { 00064 #if DEVICE_SERIAL 00065 #define ERROR_BUF_SIZE (128) 00066 core_util_critical_section_enter(); 00067 char buffer[ERROR_BUF_SIZE]; 00068 int size = vsnprintf(buffer, ERROR_BUF_SIZE, format, arg); 00069 if (size > 0) { 00070 if (!stdio_uart_inited) { 00071 serial_init(&stdio_uart, STDIO_UART_TX, STDIO_UART_RX); 00072 } 00073 #if MBED_CONF_PLATFORM_STDIO_CONVERT_NEWLINES 00074 char stdio_out_prev = '\0'; 00075 for (int i = 0; i < size; i++) { 00076 if (buffer[i] == '\n' && stdio_out_prev != '\r') { 00077 serial_putc(&stdio_uart, '\r'); 00078 } 00079 serial_putc(&stdio_uart, buffer[i]); 00080 stdio_out_prev = buffer[i]; 00081 } 00082 #else 00083 for (int i = 0; i < size; i++) { 00084 serial_putc(&stdio_uart, buffer[i]); 00085 } 00086 #endif 00087 } 00088 core_util_critical_section_exit(); 00089 #endif 00090 }
Generated on Tue Aug 9 2022 00:37:14 by
