-
Notifications
You must be signed in to change notification settings - Fork 171
Expand file tree
/
Copy pathhello.c
More file actions
39 lines (32 loc) · 822 Bytes
/
hello.c
File metadata and controls
39 lines (32 loc) · 822 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdint.h>
#include "reg.h"
/* USART TXE Flag
* This flag is cleared when data is written to USARTx_DR and
* set when that data is transferred to the TDR
*/
#define USART_FLAG_TXE ((uint16_t) 0x0080)
void print_str(const char *str)
{
while (*str) {
while (!(*(USART2_SR) & USART_FLAG_TXE));
*(USART2_DR) = (*str & 0xFF);
str++;
}
}
void main(void)
{
*(RCC_APB2ENR) |= (uint32_t) (0x00000001 | 0x00000004);
*(RCC_APB1ENR) |= (uint32_t) (0x00020000);
/* USART2 Configuration, Rx->PA3, Tx->PA2 */
*(GPIOA_CRL) = 0x00004B00;
*(GPIOA_CRH) = 0x44444444;
*(GPIOA_ODR) = 0x00000000;
*(GPIOA_BSRR) = 0x00000000;
*(GPIOA_BRR) = 0x00000000;
*(USART2_CR1) = 0x0000000C;
*(USART2_CR2) = 0x00000000;
*(USART2_CR3) = 0x00000000;
*(USART2_CR1) |= 0x2000;
print_str("Hello World!\n");
while (1);
}