uart
This commit is contained in:
parent
ed3f82222d
commit
7086e5f9e9
2 changed files with 10 additions and 17 deletions
10
main.c
10
main.c
|
@ -16,7 +16,6 @@ static void gpio_setup(void) {
|
||||||
/* Setup GPIO6 and 7 (in GPIO port A) for LED use. */
|
/* Setup GPIO6 and 7 (in GPIO port A) for LED use. */
|
||||||
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO12);
|
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO12);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void clock_setup(void) {
|
static void clock_setup(void) {
|
||||||
rcc_clock_setup_pll(&rcc_hse_configs[RCC_CLOCK_HSE8_72MHZ]);
|
rcc_clock_setup_pll(&rcc_hse_configs[RCC_CLOCK_HSE8_72MHZ]);
|
||||||
|
|
||||||
|
@ -37,14 +36,7 @@ int main(void) {
|
||||||
sys_tick_setup();
|
sys_tick_setup();
|
||||||
usart_setup();
|
usart_setup();
|
||||||
|
|
||||||
usart_send_blocking(USART1, 'H');
|
printf("Printf is working!\n");
|
||||||
usart_send_blocking(USART1, 'e');
|
|
||||||
usart_send_blocking(USART1, 'l');
|
|
||||||
usart_send_blocking(USART1, 'l');
|
|
||||||
usart_send_blocking(USART1, 'o');
|
|
||||||
usart_send_blocking(USART1, '\n');
|
|
||||||
|
|
||||||
printf("Well hello");
|
|
||||||
|
|
||||||
gpio_clear(GPIOC, GPIO13);
|
gpio_clear(GPIOC, GPIO13);
|
||||||
gpio_set(GPIOC, GPIO13);
|
gpio_set(GPIOC, GPIO13);
|
||||||
|
|
17
uart.c
17
uart.c
|
@ -5,6 +5,7 @@
|
||||||
#include <libopencm3/stm32/rcc.h>
|
#include <libopencm3/stm32/rcc.h>
|
||||||
#include <libopencm3/stm32/usart.h>
|
#include <libopencm3/stm32/usart.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
int _write(int file, char *ptr, int len);
|
int _write(int file, char *ptr, int len);
|
||||||
|
|
||||||
|
@ -12,7 +13,6 @@ void usart_setup(void) {
|
||||||
/* Setup GPIO pin GPIO_USART1_RE_TX on GPIO port B for transmit. */
|
/* Setup GPIO pin GPIO_USART1_RE_TX on GPIO port B for transmit. */
|
||||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_TX);
|
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_TX);
|
||||||
|
|
||||||
/* Setup UART parameters. */
|
|
||||||
usart_set_baudrate(USART1, 115200);
|
usart_set_baudrate(USART1, 115200);
|
||||||
usart_set_databits(USART1, 8);
|
usart_set_databits(USART1, 8);
|
||||||
usart_set_stopbits(USART1, USART_STOPBITS_1);
|
usart_set_stopbits(USART1, USART_STOPBITS_1);
|
||||||
|
@ -20,18 +20,19 @@ void usart_setup(void) {
|
||||||
usart_set_flow_control(USART1, USART_FLOWCONTROL_NONE);
|
usart_set_flow_control(USART1, USART_FLOWCONTROL_NONE);
|
||||||
usart_set_mode(USART1, USART_MODE_TX);
|
usart_set_mode(USART1, USART_MODE_TX);
|
||||||
|
|
||||||
/* Finally enable the USART. */
|
|
||||||
usart_enable(USART1);
|
usart_enable(USART1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int _write(int file, char *ptr, int len) {
|
int _write(int file, char *ptr, int len) {
|
||||||
int i;
|
if (file == STDOUT_FILENO || file == STDERR_FILENO) {
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
if (file == 1) {
|
if (ptr[i] == '\n') {
|
||||||
for (i = 0; i < len; i++) usart_send_blocking(USART1, ptr[i]);
|
usart_send_blocking(USART1, '\r');
|
||||||
return i;
|
}
|
||||||
|
usart_send_blocking(USART1, ptr[i]);
|
||||||
|
}
|
||||||
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
errno = EIO;
|
errno = EIO;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue