|
| 1 | +/* |
| 2 | + * This file is part of the libopencm3 project. |
| 3 | + * |
| 4 | + * Copyright (C) 2009 Uwe Hermann <[email protected]> |
| 5 | + * Copyright (C) 2014 Stefan Agner <[email protected]> |
| 6 | + * |
| 7 | + * This library is free software: you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU Lesser General Public License as published by |
| 9 | + * the Free Software Foundation, either version 3 of the License, or |
| 10 | + * (at your option) any later version. |
| 11 | + * |
| 12 | + * This library is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU Lesser General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU Lesser General Public License |
| 18 | + * along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 19 | + */ |
| 20 | + |
| 21 | +#include <stdio.h> |
| 22 | +#include <errno.h> |
| 23 | +#include <libopencm3/cm3/common.h> |
| 24 | +#include <libopencm3/vf6xx/ccm.h> |
| 25 | +#include <libopencm3/vf6xx/uart.h> |
| 26 | + |
| 27 | +int _write(int file, char *ptr, int len); |
| 28 | + |
| 29 | +int _write(int file, char *ptr, int len) |
| 30 | +{ |
| 31 | + int i; |
| 32 | + |
| 33 | + if (file == 1) { |
| 34 | + for (i = 0; i < len; i++) |
| 35 | + uart_send_blocking(UART2, ptr[i]); |
| 36 | + return i; |
| 37 | + } |
| 38 | + |
| 39 | + errno = EIO; |
| 40 | + return -1; |
| 41 | +} |
| 42 | + |
| 43 | +static void uart_init(void) |
| 44 | +{ |
| 45 | + ccm_clock_gate_enable(CG9_UART2); |
| 46 | + uart_enable(UART2); |
| 47 | + uart_set_baudrate(UART2, 115200); |
| 48 | +} |
| 49 | + |
| 50 | +int main(void) |
| 51 | +{ |
| 52 | + int counter = 0; |
| 53 | + float fcounter = 0.0; |
| 54 | + double dcounter = 0.0; |
| 55 | + |
| 56 | + ccm_calculate_clocks(); |
| 57 | + uart_init(); |
| 58 | + |
| 59 | + /* |
| 60 | + * Write Hello World an integer, float and double all over |
| 61 | + * again while incrementing the numbers. |
| 62 | + */ |
| 63 | + while (1) { |
| 64 | + printf("Hello World! %i %f %f\r\n", counter, fcounter, |
| 65 | + dcounter); |
| 66 | + counter++; |
| 67 | + fcounter += 0.01; |
| 68 | + dcounter += 0.01; |
| 69 | + } |
| 70 | + |
| 71 | + return 0; |
| 72 | +} |
| 73 | + |
0 commit comments