mbed-dev-f303

Committer:
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4
Date:
Tue Jun 14 09:21:18 2022 +0000
Revision:
0:bdf663c61a82
lib

Who changed what in which revision?

UserRevisionLine numberNew contents of line
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 1 /* mbed Microcontroller Library
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 2 * Copyright (c) 2006-2013 ARM Limited
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 3 *
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 4 * Licensed under the Apache License, Version 2.0 (the "License");
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 5 * you may not use this file except in compliance with the License.
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 6 * You may obtain a copy of the License at
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 7 *
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 8 * http://www.apache.org/licenses/LICENSE-2.0
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 9 *
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 10 * Unless required by applicable law or agreed to in writing, software
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 11 * distributed under the License is distributed on an "AS IS" BASIS,
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 13 * See the License for the specific language governing permissions and
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 14 * limitations under the License.
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 15 */
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 16 #include <stdio.h>
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 17 #include "hal/gpio_api.h"
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 18 #include "platform/mbed_wait_api.h"
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 19 #include "platform/mbed_toolchain.h"
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 20 #include "platform/mbed_interface.h"
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 21 #include "platform/mbed_critical.h"
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 22 #include "hal/serial_api.h"
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 23
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 24 #if DEVICE_SERIAL
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 25 extern int stdio_uart_inited;
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 26 extern serial_t stdio_uart;
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 27 #endif
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 28
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 29 WEAK void mbed_die(void) {
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 30 #if !defined (NRF51_H) && !defined(TARGET_EFM32)
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 31 core_util_critical_section_enter();
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 32 #endif
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 33 gpio_t led_err; gpio_init_out(&led_err, LED1);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 34
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 35 while (1) {
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 36 for (int i = 0; i < 4; ++i) {
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 37 gpio_write(&led_err, 1);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 38 wait_ms(150);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 39 gpio_write(&led_err, 0);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 40 wait_ms(150);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 41 }
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 42
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 43 for (int i = 0; i < 4; ++i) {
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 44 gpio_write(&led_err, 1);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 45 wait_ms(400);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 46 gpio_write(&led_err, 0);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 47 wait_ms(400);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 48 }
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 49 }
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 50 }
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 51
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 52 void mbed_error_printf(const char* format, ...) {
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 53 va_list arg;
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 54 va_start(arg, format);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 55 mbed_error_vfprintf(format, arg);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 56 va_end(arg);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 57 }
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 58
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 59 void mbed_error_vfprintf(const char * format, va_list arg) {
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 60 #if DEVICE_SERIAL
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 61 #define ERROR_BUF_SIZE (128)
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 62 core_util_critical_section_enter();
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 63 char buffer[ERROR_BUF_SIZE];
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 64 int size = vsnprintf(buffer, ERROR_BUF_SIZE, format, arg);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 65 if (size > 0) {
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 66 if (!stdio_uart_inited) {
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 67 serial_init(&stdio_uart, STDIO_UART_TX, STDIO_UART_RX);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 68 }
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 69 #if MBED_CONF_PLATFORM_STDIO_CONVERT_NEWLINES
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 70 char stdio_out_prev = '\0';
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 71 for (int i = 0; i < size; i++) {
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 72 if (buffer[i] == '\n' && stdio_out_prev != '\r') {
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 73 serial_putc(&stdio_uart, '\r');
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 74 }
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 75 serial_putc(&stdio_uart, buffer[i]);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 76 stdio_out_prev = buffer[i];
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 77 }
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 78 #else
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 79 for (int i = 0; i < size; i++) {
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 80 serial_putc(&stdio_uart, buffer[i]);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 81 }
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 82 #endif
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 83 }
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 84 core_util_critical_section_exit();
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 85 #endif
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 86 }
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 87