uart tx running

This commit is contained in:
tkl 2016-08-17 10:06:18 +02:00
parent a8a4cb263d
commit 4a9da1a9fd
14 changed files with 324 additions and 168 deletions

View File

@ -146,7 +146,6 @@
<buildTargets> <buildTargets>
<target name="all" path="software/source/test/firmware/kernel/list" targetID="org.eclipse.cdt.build.MakeTargetBuilder"> <target name="all" path="software/source/test/firmware/kernel/list" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand> <buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>all</buildTarget> <buildTarget>all</buildTarget>
<stopOnError>true</stopOnError> <stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand> <useDefaultCommand>true</useDefaultCommand>
@ -154,7 +153,6 @@
</target> </target>
<target name="clean" path="software/source/test/firmware/kernel/list" targetID="org.eclipse.cdt.build.MakeTargetBuilder"> <target name="clean" path="software/source/test/firmware/kernel/list" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand> <buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>clean</buildTarget> <buildTarget>clean</buildTarget>
<stopOnError>true</stopOnError> <stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand> <useDefaultCommand>true</useDefaultCommand>
@ -162,6 +160,7 @@
</target> </target>
<target name="distclean" path="software/source" targetID="org.eclipse.cdt.build.MakeTargetBuilder"> <target name="distclean" path="software/source" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand> <buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>distclean</buildTarget> <buildTarget>distclean</buildTarget>
<stopOnError>true</stopOnError> <stopOnError>true</stopOnError>
<useDefaultCommand>false</useDefaultCommand> <useDefaultCommand>false</useDefaultCommand>
@ -217,7 +216,6 @@
</target> </target>
<target name="all" path="software/test/firmware/kernel/list" targetID="org.eclipse.cdt.build.MakeTargetBuilder"> <target name="all" path="software/test/firmware/kernel/list" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand> <buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>all</buildTarget> <buildTarget>all</buildTarget>
<stopOnError>true</stopOnError> <stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand> <useDefaultCommand>true</useDefaultCommand>
@ -249,7 +247,6 @@
</target> </target>
<target name="distclean" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder"> <target name="distclean" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand> <buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>distclean</buildTarget> <buildTarget>distclean</buildTarget>
<stopOnError>true</stopOnError> <stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand> <useDefaultCommand>true</useDefaultCommand>
@ -263,6 +260,22 @@
<useDefaultCommand>false</useDefaultCommand> <useDefaultCommand>false</useDefaultCommand>
<runAllBuilders>true</runAllBuilders> <runAllBuilders>true</runAllBuilders>
</target> </target>
<target name="uart debug test" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments>TEST_APP=uart BOARD=stm32f4-discovery DEBUG=y</buildArguments>
<buildTarget>test</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>false</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
<target name="uart debug install" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments> TEST_APP=uart BOARD=stm32f4-discovery DEBUG=y</buildArguments>
<buildTarget>install</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>false</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
<target name="msp430-ccrf example_radio_rx all" path="software/source/test" targetID="org.eclipse.cdt.build.MakeTargetBuilder"> <target name="msp430-ccrf example_radio_rx all" path="software/source/test" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand> <buildCommand>make</buildCommand>
<buildArguments>APP=example_radio_rx BOARD=msp430-ccrf DEBUG=y</buildArguments> <buildArguments>APP=example_radio_rx BOARD=msp430-ccrf DEBUG=y</buildArguments>
@ -289,7 +302,6 @@
</target> </target>
<target name="all" path="software/source/test/firmware/kernel/ringbuffer" targetID="org.eclipse.cdt.build.MakeTargetBuilder"> <target name="all" path="software/source/test/firmware/kernel/ringbuffer" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand> <buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>all</buildTarget> <buildTarget>all</buildTarget>
<stopOnError>true</stopOnError> <stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand> <useDefaultCommand>true</useDefaultCommand>
@ -297,7 +309,6 @@
</target> </target>
<target name="clean" path="software/source/test/firmware/kernel/ringbuffer" targetID="org.eclipse.cdt.build.MakeTargetBuilder"> <target name="clean" path="software/source/test/firmware/kernel/ringbuffer" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand> <buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>clean</buildTarget> <buildTarget>clean</buildTarget>
<stopOnError>true</stopOnError> <stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand> <useDefaultCommand>true</useDefaultCommand>

View File

@ -12,16 +12,7 @@ INCLUDES += \
/opt/arm-2011.09/arm-none-eabi/include \ /opt/arm-2011.09/arm-none-eabi/include \
/opt/arm-2011.09/lib/gcc/arm-none-eabi/4.6.1/include /opt/arm-2011.09/lib/gcc/arm-none-eabi/4.6.1/include
ifeq ($(DEBUG),y) GEN_FLAGS += \
OPTIM = g
GEN_FLAGS += -g3
DBG_EXT = -dbg
else
OPTIM = s
DBG_EXT =
endif
GEN_FLAGS := \
-mcpu=cortex-m4 \ -mcpu=cortex-m4 \
-mthumb \ -mthumb \
-mfloat-abi=hard \ -mfloat-abi=hard \
@ -77,6 +68,15 @@ L_FLAGS := \
-L"config/linker" \ -L"config/linker" \
--specs=nano.specs --specs=nano.specs
ifeq ($(DEBUG),y)
OPTIM = g
GEN_FLAGS += -g3
DBG_EXT = -dbg
else
OPTIM = s
DBG_EXT =
endif
AS_FLAGS := -mapcs-32 -g AS_FLAGS := -mapcs-32 -g
AR_FLAGS := rcs AR_FLAGS := rcs

View File

@ -10,13 +10,14 @@
#include <stdint.h> #include <stdint.h>
#if 0 #if 0
#include "../../../driver/include/stm32f4_pwm.h" #include "../../../driver/include/stm32f4_pwm.h"
#include "../../../driver/include/stm32f4_uart.h"
#include "pwm.h" #include "pwm.h"
#include "uart.h"
#include "ringbuffer.h"
#endif #endif
#include "stm32f4xx.h" #include "stm32f4xx.h"
#include "uart.h"
#include "stm32f4_uart.h"
#include "ringbuffer.h"
#include "timer.h" #include "timer.h"
#include "stm32_sys_tick.h" #include "stm32_sys_tick.h"
#include "sys_tick.h" #include "sys_tick.h"
@ -222,51 +223,55 @@ const struct driver pwm_1 = {
&pwm_ch1, &pwm_ch1,
}; };
#endif #endif
#if 0
// UART 1 // UART 1
static char console_linear_buffer[80]; static const GPIO_InitTypeDef port_cfg_uart1 = {
.Pin = GPIO_PIN_6 | GPIO_PIN_7,
.Mode = GPIO_MODE_AF_PP,
.Pull = GPIO_PULLUP,
.Speed = GPIO_SPEED_FREQ_HIGH,
.Alternate = GPIO_AF7_USART1,
};
static const struct stm32f4_gpio stm32f4_uart1_gpio = {
.port = GPIOB,
.pin = &port_cfg_uart1,
};
static UART_HandleTypeDef stm32f4_discovery_uart1_handle = {
.Instance = USART1,
.Init.BaudRate = 115200,
.Init.WordLength = UART_WORDLENGTH_8B,
.Init.StopBits = UART_STOPBITS_1,
.Init.Parity = UART_PARITY_NONE,
.Init.Mode = UART_MODE_TX_RX,
.Init.HwFlowCtl = UART_HWCONTROL_NONE,
.Init.OverSampling = UART_OVERSAMPLING_16,
.pTxBuffPtr = NULL,
.TxXferSize = 0,
.TxXferCount = 0,
.pRxBuffPtr = NULL,
.RxXferSize = 0,
.RxXferCount = 0,
.hdmatx = NULL,
.hdmarx = NULL,
.Lock = HAL_UNLOCKED,
.gState = HAL_UART_STATE_RESET,
.ErrorCode = 0,
};
static const struct stm32f4_uart stm32f4_uart1 = {
.uart_gpio = &stm32f4_uart1_gpio,
.uart_handle = &stm32f4_discovery_uart1_handle,
};
static char console_linear_buffer[10];
static struct ringbuffer console_buffer = { static struct ringbuffer console_buffer = {
console_linear_buffer, console_linear_buffer,
console_linear_buffer, console_linear_buffer,
console_linear_buffer, console_linear_buffer,
sizeof(console_linear_buffer), 10,
0 0
}; };
static const GPIO_InitTypeDef stm32f4_discovery_uart1_gpio = {
GPIO_Pin_6 | GPIO_Pin_7,
GPIO_Mode_AF,
GPIO_Speed_50MHz,
GPIO_OType_PP,
GPIO_PuPd_UP
};
static const USART_InitTypeDef stm32f4_discovery_uart1_usart_init = {
115200,
USART_WordLength_8b,
USART_StopBits_1,
USART_Parity_No,
USART_Mode_Tx | USART_Mode_Rx,
USART_HardwareFlowControl_None,
};
static const NVIC_InitTypeDef stm32f4_discovery_uart1_nvic_init = {
USART1_IRQn,
0,
0,
ENABLE,
};
static const struct stm32f4_uart stm32f4_uart1 = {
&stm32f4_discovery_uart1_gpio,
GPIOB,
GPIO_PinSource7,
GPIO_PinSource6,
&stm32f4_discovery_uart1_usart_init,
USART1,
USART_IT_RXNE /* | USART_IT_TXE*/,
&stm32f4_discovery_uart1_nvic_init,
};
static const struct uart __uart_1 = { static const struct uart __uart_1 = {
&stm32f4_uart1, &stm32f4_uart1,
@ -282,7 +287,7 @@ const struct driver uart_1 = {
DRIVER_TYPE_UART, DRIVER_TYPE_UART,
&__uart_1, &__uart_1,
}; };
#endif
#if 0 #if 0
// GPIOC0 // GPIOC0
static const GPIO_InitTypeDef port_cfg_C0 = { static const GPIO_InitTypeDef port_cfg_C0 = {

View File

@ -0,0 +1,62 @@
/*
* stm32f4_uart.h
*
* Created on: Jul 24, 2016
* Author: tkl
*/
#ifndef SOURCE_FIRMWARE_ARCH_STM32F4XX_DRIVER_UART_STM32_UART_H_
#define SOURCE_FIRMWARE_ARCH_STM32F4XX_DRIVER_UART_STM32_UART_H_
#include "driver.h"
#include "uart.h"
//! \brief Stm32f4 uart device.
#pragma pack(push)
#pragma pack(1)
struct stm32f4_uart {
const struct stm32f4_gpio *uart_gpio;
UART_HandleTypeDef *uart_handle;
};
#pragma pack(pop)
//! \brief Open an uart device.
//! \param this The uart to open.
//! \retval -1 in error case.
int stm32f4_uart_open(const void *this);
//! \brief Close an uart device.
//! \param this The uart to close.
//! \retval -1 in error case.
int stm32f4_uart_close(const void *this);
//! \brief Read from an uart device.
//! \param this The uart to read from.
//! \param buffer The buffer to read to.
//! \param len The length of the buffer.
//! \retval -1 in error case, otherwise number of read characters.
int stm32f4_uart_read(const void *this, char *buffer, int len);
//! \brief Write to an uart device.
//! \param this The uart to write to.
//! \param buffer The buffer to write.
//! \param len The number of characters to write.
//! \retval -1 in error case, otherwise number of written characters.
int stm32f4_uart_write(const void *this, const char *buffer, int len);
//! \brief Set a callback for interrupt handling of the uart.
//! \param this The uart.
//! \param callback The callback to execute in interrupt case.
//! \param param The argument for the callback.
//! \retval -1 in error case.
int stm32f4_uart_set_cb(const void *this, const void *callback, const void *param);
static const struct uart_fp stm32f4_uart_fp = {
stm32f4_uart_open,
stm32f4_uart_close,
stm32f4_uart_read,
stm32f4_uart_write,
stm32f4_uart_set_cb
};
#endif /* SOURCE_FIRMWARE_ARCH_STM32F4XX_DRIVER_UART_STM32_UART_H_ */

View File

@ -68,6 +68,9 @@ void SysTick_Handler(void)
{ {
enter_isr(); enter_isr();
#if defined(USE_HAL_DRIVER)
HAL_IncTick();
#endif
if(stm32_sys_tick_obj.sys_tick_cb != NULL) { if(stm32_sys_tick_obj.sys_tick_cb != NULL) {
stm32_sys_tick_cb_t cb = stm32_sys_tick_obj.sys_tick_cb; stm32_sys_tick_cb_t cb = stm32_sys_tick_obj.sys_tick_cb;
void *param = stm32_sys_tick_obj.sys_tick_cb_param; void *param = stm32_sys_tick_obj.sys_tick_cb_param;
@ -76,3 +79,8 @@ void SysTick_Handler(void)
exit_isr(); exit_isr();
} }
HAL_StatusTypeDef HAL_InitTick (uint32_t TickPriority)
{
return HAL_OK;
}

View File

@ -83,6 +83,24 @@ int stm32f4_gpio_close(const void *gpio)
return -1; return -1;
struct stm32f4_gpio *this = (struct stm32f4_gpio *)gpio; struct stm32f4_gpio *this = (struct stm32f4_gpio *)gpio;
HAL_GPIO_DeInit(this->port, this->pin->Pin); HAL_GPIO_DeInit(this->port, this->pin->Pin);
if(this->port == GPIOA)
__HAL_RCC_GPIOA_CLK_DISABLE();
else if(this->port == GPIOB)
__HAL_RCC_GPIOB_CLK_DISABLE();
else if(this->port == GPIOC)
__HAL_RCC_GPIOC_CLK_DISABLE();
else if(this->port == GPIOD)
__HAL_RCC_GPIOD_CLK_DISABLE();
else if(this->port == GPIOE)
__HAL_RCC_GPIOE_CLK_DISABLE();
else if(this->port == GPIOF)
__HAL_RCC_GPIOF_CLK_DISABLE();
else if(this->port == GPIOG)
__HAL_RCC_GPIOG_CLK_DISABLE();
else if(this->port == GPIOH)
__HAL_RCC_GPIOH_CLK_DISABLE();
else if(this->port == GPIOI)
__HAL_RCC_GPIOI_CLK_DISABLE();
return 0; return 0;
} }

View File

@ -1,102 +0,0 @@
/*
* stm32f4_uart.c
*
* Created on: Jul 24, 2016
* Author: tkl
*/
#include <stddef.h>
#include <stdint.h>
#include "stm32f4xx.h"
#include "stm32f4xx_isr.h"
#include "stm32f4_uart.h"
struct stm32f4_uart_obj {
const void *callback; //!< Interrupt callback.
const void *parameter; //!< argument for the callback.
};
static volatile struct stm32f4_uart_obj uart1_obj;
int stm32f4_uart_open(const void *this)
{
struct stm32f4_uart *uart = (struct stm32f4_uart *)this;
uint8_t gpio_af = 0;
uint32_t rcc_apb_uart = 0, rcc_apb_gpio = 0;
if(uart->usart_port == USART1) {
gpio_af = GPIO_AF_USART1;
rcc_apb_uart = RCC_APB2Periph_USART1;
}
if(uart->gpio_port == GPIOA) {
rcc_apb_gpio = RCC_AHB1Periph_GPIOA;
}
else if(uart->gpio_port == GPIOB) {
rcc_apb_gpio = RCC_AHB1Periph_GPIOB;
}
RCC_APB2PeriphClockCmd(rcc_apb_uart, ENABLE);
RCC_AHB1PeriphClockCmd(rcc_apb_gpio, ENABLE);
GPIO_Init(uart->gpio_port, (GPIO_InitTypeDef *)uart->gpio_init);
GPIO_PinAFConfig(uart->gpio_port, uart->pin_src_rx, gpio_af);
GPIO_PinAFConfig(uart->gpio_port, uart->pin_src_tx, gpio_af);
USART_Init(uart->usart_port, (USART_InitTypeDef *)uart->usart_init);
USART_ITConfig(uart->usart_port, uart->usart_it_select, ENABLE);
NVIC_Init((NVIC_InitTypeDef *)uart->nvic_init);
USART_Cmd(uart->usart_port, ENABLE);
return (0);
}
int stm32f4_uart_close(const void *this)
{
struct stm32f4_uart *uart = (struct stm32f4_uart *)this;
USART_Cmd(uart->usart_port, DISABLE);
return (0);
}
int stm32f4_uart_read(const void *this, char *buffer, int len)
{
struct stm32f4_uart *uart = (struct stm32f4_uart *)this;
*buffer = uart->usart_port->DR;
return (1);
}
int stm32f4_uart_write(const void *this, const char *buffer, int len)
{
struct stm32f4_uart *uart = (struct stm32f4_uart *)this;
int i;
for(i = 0; i < len; i++) {
// wait until data register is empty
while(!(uart->usart_port->SR & 0x00000040));
USART_SendData(uart->usart_port, buffer[i]);
}
return (i);
}
int stm32f4_uart_set_cb(const void *this, const void *callback, const void *param)
{
struct stm32f4_uart *uart = (struct stm32f4_uart *)this;
if(uart->usart_port == USART1) {
uart1_obj.callback = callback;
uart1_obj.parameter = param;
}
return (0);
}
// this is the interrupt request handler (IRQ) for ALL USART1 interrupts
void USART1_IRQHandler(void)
{
enter_isr();
// check if the USART1 receive interrupt flag was set
if(USART_GetITStatus(USART1, USART_IT_RXNE)) {
if(uart1_obj.callback) {
void (*cb)(const void *) = uart1_obj.callback;
cb(uart1_obj.parameter);
}
}
exit_isr();
}

View File

@ -0,0 +1,94 @@
/*
* stm32f4_uart.c
*
* Created on: Jul 24, 2016
* Author: tkl
*/
#include <stddef.h>
#include <stdint.h>
#include "stm32f4xx.h"
#include "stm32f4xx_isr.h"
#include "stm32f4_uart.h"
#include "gpio.h"
#include "stm32f4_gpio.h"
struct stm32f4_uart_obj {
const void *callback; //!< Interrupt callback.
const void *parameter; //!< argument for the callback.
};
static volatile struct stm32f4_uart_obj uart1_obj;
int stm32f4_uart_open(const void *this)
{
if(NULL == this)
return -1;
struct stm32f4_uart *uart = (struct stm32f4_uart *)this;
/* init gpio */
stm32f4_gpio_open(uart->uart_gpio);
/* uart clock enable */
if(uart->uart_handle->Instance == USART1)
__HAL_RCC_USART1_CLK_ENABLE();
else if(uart->uart_handle->Instance == USART2)
__HAL_RCC_USART2_CLK_ENABLE();
else if(uart->uart_handle->Instance == USART3)
__HAL_RCC_USART3_CLK_ENABLE();
else if(uart->uart_handle->Instance == USART6)
__HAL_RCC_USART6_CLK_ENABLE();
/* init uart */
HAL_UART_Init((UART_HandleTypeDef *)uart->uart_handle);
return (0);
}
int stm32f4_uart_close(const void *this)
{
if(NULL == this)
return -1;
struct stm32f4_uart *uart = (struct stm32f4_uart *)this;
HAL_UART_DeInit((UART_HandleTypeDef *)uart->uart_handle);
if(uart->uart_handle->Instance == USART1)
__HAL_RCC_USART1_CLK_DISABLE();
else if(uart->uart_handle->Instance == USART2)
__HAL_RCC_USART2_CLK_DISABLE();
else if(uart->uart_handle->Instance == USART3)
__HAL_RCC_USART3_CLK_DISABLE();
else if(uart->uart_handle->Instance == USART6)
__HAL_RCC_USART6_CLK_DISABLE();
stm32f4_gpio_close(uart->uart_gpio);
return (0);
}
int stm32f4_uart_read(const void *this, char *buffer, int len)
{
return (1);
}
int stm32f4_uart_write(const void *this, const char *buffer, int len)
{
if(NULL == this)
return -1;
struct stm32f4_uart *uart = (struct stm32f4_uart *)this;
HAL_UART_Transmit((UART_HandleTypeDef *)uart->uart_handle, (uint8_t *)buffer, len, 1000);
return len;
}
int stm32f4_uart_set_cb(const void *this, const void *callback, const void *param)
{
return (0);
}
// this is the interrupt request handler (IRQ) for ALL USART1 interrupts
void USART1_IRQHandler(void)
{
enter_isr();
// check if the USART1 receive interrupt flag was set
exit_isr();
}

View File

@ -41,7 +41,7 @@ int drv_open(const struct driver *driver)
ret = spi_open((const struct spi *)(driver->device_driver)); ret = spi_open((const struct spi *)(driver->device_driver));
break; break;
case DRIVER_TYPE_UART: case DRIVER_TYPE_UART:
// ret = uart_open((const struct uart *)(driver->device_driver)); ret = uart_open((const struct uart *)(driver->device_driver));
break; break;
} }
return ret; return ret;
@ -136,7 +136,7 @@ int drv_write(const struct driver *driver, const char *buffer, int len)
case DRIVER_TYPE_SPI: case DRIVER_TYPE_SPI:
break; break;
case DRIVER_TYPE_UART: case DRIVER_TYPE_UART:
// ret = uart_write((const struct uart *)(driver->device_driver), buffer, len); ret = uart_write((const struct uart *)(driver->device_driver), buffer, len);
break; break;
} }
return ret; return ret;

View File

@ -1,9 +1,15 @@
ifeq ($(TEST_APP), shell)
include source/test/shell/shell.mk
endif
ifeq ($(TEST_APP), pwm)
include source/test/pwm/pwm.mk
endif
ifeq ($(TEST_APP), blinky) ifeq ($(TEST_APP), blinky)
include source/test/blinky/blinky.mk include source/test/blinky/blinky.mk
endif endif
ifeq ($(TEST_APP), pwm)
include source/test/pwm/pwm.mk
endif
ifeq ($(TEST_APP), shell)
include source/test/shell/shell.mk
endif
ifeq ($(TEST_APP), uart)
include source/test/uart/uart.mk
endif

53
source/test/uart/main.c Normal file
View File

@ -0,0 +1,53 @@
//
// This file is part of the GNU ARM Eclipse distribution.
// Copyright (c) 2014 Liviu Ionescu.
//
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include "stack.h"
#include "queue.h"
#include "kernel.h"
#include "board.h"
#include "driver.h"
// Sample pragmas to cope with warnings. Please note the related line at
// the end of this function, used to pop the compiler diagnostics status.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#pragma GCC diagnostic ignored "-Wreturn-type"
#define TH_STACK_SIZE 256
stack_t th_stack[TH_STACK_SIZE];
struct thread_context th_ctx;
static void th_func(void *arg)
{
drv_open(&uart_1);
drv_open(&gpio_d12);
drv_write(&gpio_d12, "0", 1);
while(1) {
sleep_ms(1000);
drv_write(&uart_1, "set_led\r\n", 9);
drv_write(&gpio_d12, "1", 1);
sleep_ms(1000);
drv_write(&uart_1, "unset_led\r\n", 11);
drv_write(&gpio_d12, "0", 1);
}
}
int main(int argc, char* argv[])
{
board_init();
timer_open(&timer_1);
thread_create(&th_ctx, th_stack, TH_STACK_SIZE, th_func, NULL, THREAD_PRIO_LOW);
schedule_start();
return 0;
}
#pragma GCC diagnostic pop

1
source/test/uart/uart.mk Normal file
View File

@ -0,0 +1 @@
SRC_DIR += source/test/uart