uc-sdk
Main Page
Related Pages
Modules
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Groups
Pages
BoardConsole.c
Go to the documentation of this file.
1
#include "
BoardConsole.h
"
2
#include <
stdio.h
>
3
#include <
malloc.h
>
4
#include <stdarg.h>
5
6
#include <
stm32f10x_gpio.h
>
7
#include <
stm32f10x_rcc.h
>
8
#include <
stm32f10x_usart.h
>
9
10
void
BoardConsoleInit
() {
11
RCC_APB2PeriphClockCmd
(
RCC_APB2Periph_USART1
|
RCC_APB2Periph_GPIOA
|
RCC_APB2Periph_AFIO
,
ENABLE
);
12
13
GPIO_InitTypeDef
gpiodef;
14
gpiodef.
GPIO_Pin
=
GPIO_Pin_9
;
15
gpiodef.
GPIO_Mode
=
GPIO_Mode_AF_PP
;
16
gpiodef.
GPIO_Speed
=
GPIO_Speed_50MHz
;
17
GPIO_Init
(
GPIOA
, &gpiodef);
18
gpiodef.
GPIO_Pin
=
GPIO_Pin_10
;
19
gpiodef.
GPIO_Mode
=
GPIO_Mode_IN_FLOATING
;
20
GPIO_Init
(
GPIOA
, &gpiodef);
21
22
USART_InitTypeDef
usartdef;
23
24
usartdef.
USART_BaudRate
= 115200;
25
usartdef.
USART_HardwareFlowControl
=
USART_HardwareFlowControl_None
;
26
usartdef.
USART_Mode
=
USART_Mode_Rx
|
USART_Mode_Tx
;
27
usartdef.
USART_WordLength
=
USART_WordLength_8b
;
28
usartdef.
USART_StopBits
=
USART_StopBits_1
;
29
usartdef.
USART_Parity
=
USART_Parity_No
;
30
31
USART_Init
(
USART1
, &usartdef);
32
33
USART_ClockInitTypeDef
clockdef;
34
USART_ClockStructInit
(&clockdef);
35
USART_ClockInit
(
USART1
, &clockdef);
36
37
USART_Cmd
(
USART1
,
ENABLE
);
38
}
39
40
void
BoardConsolePuts
(
const
char
* str) {
41
while
(*str)
42
BoardConsolePutc
(*(str++));
43
BoardConsolePutc
(
'\n'
);
44
}
45
46
void
BoardConsolePutc
(
int
c) {
47
if
(c ==
'\r'
)
return
;
48
if
(c ==
'\n'
) c =
'\r'
;
49
while
(
USART_GetFlagStatus
(
USART1
,
USART_FLAG_TXE
) ==
RESET
);
50
USART_SendData
(
USART1
, c);
51
if
(c ==
'\r'
) {
52
c =
'\n'
;
53
USART_SendData
(
USART1
, c);
54
}
55
}
56
57
58
void
BoardConsolePrintf
(
const
char
* fmt, ...) {
59
va_list ap;
60
va_start(ap, fmt);
61
BoardConsoleVPrintf
(fmt, ap);
62
va_end(ap);
63
}
64
65
static
void
xprintfCallback(
const
char
* str,
int
strsize,
void
* opaque0) {
66
while
(strsize--)
67
BoardConsolePutc
(*str++);
68
}
69
70
void
BoardConsoleVPrintf
(
const
char
* fmt, va_list ap) {
71
vxprintf
(xprintfCallback,
NULL
, fmt, ap);
72
}
arch
arm
stm32f10x
inemo
BoardConsole.c
Generated on Fri Nov 15 2013 05:00:16 for uc-sdk by
1.8.4