F1 test project: now with C++ and UART
This commit is contained in:
parent
b8eafd7652
commit
842f3b9b57
|
@ -15,7 +15,7 @@ endif
|
||||||
|
|
||||||
# C++ specific options here (added to USE_OPT).
|
# C++ specific options here (added to USE_OPT).
|
||||||
ifeq ($(USE_CPPOPT),)
|
ifeq ($(USE_CPPOPT),)
|
||||||
USE_CPPOPT = -fno-rtti
|
USE_CPPOPT = -fno-rtti -fno-exceptions -ffast-math -funsafe-math-optimizations -fno-threadsafe-statics -fno-use-cxa-atexit
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Enable this if you want the linker to remove unused code and data.
|
# Enable this if you want the linker to remove unused code and data.
|
||||||
|
@ -94,6 +94,12 @@ CONFDIR := ./cfg
|
||||||
BUILDDIR := ./build
|
BUILDDIR := ./build
|
||||||
DEPDIR := ./.dep
|
DEPDIR := ./.dep
|
||||||
|
|
||||||
|
ifeq ("$(wildcard $(CHIBIOS)/os/license/license.mk)","")
|
||||||
|
# submodules probably aren't checked out, complain to the user about it!
|
||||||
|
# make is not happy about newly checked out module for some reason but next invocation would work
|
||||||
|
$(error Please run 'git submodule update --init --recursive' before trying to build!)
|
||||||
|
endif
|
||||||
|
|
||||||
# Licensing files.
|
# Licensing files.
|
||||||
include $(CHIBIOS)/os/license/license.mk
|
include $(CHIBIOS)/os/license/license.mk
|
||||||
# Startup files.
|
# Startup files.
|
||||||
|
@ -109,18 +115,20 @@ include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk
|
||||||
# Auto-build files in ./source recursively.
|
# Auto-build files in ./source recursively.
|
||||||
include $(CHIBIOS)/tools/mk/autobuild.mk
|
include $(CHIBIOS)/tools/mk/autobuild.mk
|
||||||
# Other files (optional).
|
# Other files (optional).
|
||||||
|
include $(CHIBIOS)/os/hal/lib/streams/streams.mk
|
||||||
|
|
||||||
# Define linker script file here
|
# Define linker script file here
|
||||||
LDSCRIPT= $(STARTUPLD)/STM32F103xB.ld
|
LDSCRIPT= $(STARTUPLD)/STM32F103xB.ld
|
||||||
|
|
||||||
# C sources that can be compiled in ARM or THUMB mode depending on the global
|
# C sources that can be compiled in ARM or THUMB mode depending on the global
|
||||||
# setting.
|
# setting.
|
||||||
CSRC = $(ALLCSRC) \
|
CSRC = $(ALLCSRC)
|
||||||
main.c
|
|
||||||
|
|
||||||
# C++ sources that can be compiled in ARM or THUMB mode depending on the global
|
# C++ sources that can be compiled in ARM or THUMB mode depending on the global
|
||||||
# setting.
|
# setting.
|
||||||
CPPSRC = $(ALLCPPSRC)
|
CPPSRC = $(ALLCPPSRC) \
|
||||||
|
main.cpp \
|
||||||
|
uart.cpp
|
||||||
|
|
||||||
# List ASM source files here.
|
# List ASM source files here.
|
||||||
ASMSRC = $(ALLASMSRC)
|
ASMSRC = $(ALLASMSRC)
|
||||||
|
@ -129,7 +137,7 @@ ASMSRC = $(ALLASMSRC)
|
||||||
ASMXSRC = $(ALLXASMSRC)
|
ASMXSRC = $(ALLXASMSRC)
|
||||||
|
|
||||||
# Inclusion directories.
|
# Inclusion directories.
|
||||||
INCDIR = $(CONFDIR) $(ALLINC) $(TESTINC)
|
INCDIR = $(CONFDIR) $(ALLINC)
|
||||||
|
|
||||||
# Define C warning options here.
|
# Define C warning options here.
|
||||||
CWARN = -Wall -Wextra -Wundef -Wstrict-prototypes
|
CWARN = -Wall -Wextra -Wundef -Wstrict-prototypes
|
||||||
|
|
|
@ -3,5 +3,5 @@ rd /s /q .dep
|
||||||
|
|
||||||
echo Starting compilation
|
echo Starting compilation
|
||||||
rem the important piece
|
rem the important piece
|
||||||
make
|
make -j12
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@
|
||||||
* @brief Enables the CAN subsystem.
|
* @brief Enables the CAN subsystem.
|
||||||
*/
|
*/
|
||||||
#if !defined(HAL_USE_CAN) || defined(__DOXYGEN__)
|
#if !defined(HAL_USE_CAN) || defined(__DOXYGEN__)
|
||||||
#define HAL_USE_CAN FALSE
|
#define HAL_USE_CAN TRUE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -142,7 +142,7 @@
|
||||||
* @brief Enables the SERIAL subsystem.
|
* @brief Enables the SERIAL subsystem.
|
||||||
*/
|
*/
|
||||||
#if !defined(HAL_USE_SERIAL) || defined(__DOXYGEN__)
|
#if !defined(HAL_USE_SERIAL) || defined(__DOXYGEN__)
|
||||||
#define HAL_USE_SERIAL TRUE
|
#define HAL_USE_SERIAL FALSE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -177,7 +177,7 @@
|
||||||
* @brief Enables the UART subsystem.
|
* @brief Enables the UART subsystem.
|
||||||
*/
|
*/
|
||||||
#if !defined(HAL_USE_UART) || defined(__DOXYGEN__)
|
#if !defined(HAL_USE_UART) || defined(__DOXYGEN__)
|
||||||
#define HAL_USE_UART FALSE
|
#define HAL_USE_UART TRUE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
#include "ch.h"
|
#include "ch.h"
|
||||||
#include "hal.h"
|
#include "hal.h"
|
||||||
|
#include "uart.h"
|
||||||
|
|
||||||
#define BL_PORT GPIOC
|
#define BL_PORT GPIOC
|
||||||
#define BL_PIN 13
|
#define BL_PIN 13
|
||||||
|
@ -53,12 +53,6 @@ int main(void) {
|
||||||
halInit();
|
halInit();
|
||||||
chSysInit();
|
chSysInit();
|
||||||
|
|
||||||
/*
|
|
||||||
* Activates the serial driver 2 using the driver default configuration.
|
|
||||||
*/
|
|
||||||
sdStart(&SD2, NULL);
|
|
||||||
|
|
||||||
|
|
||||||
palSetPadMode(BL_PORT, BL_PIN, PAL_MODE_OUTPUT_PUSHPULL);
|
palSetPadMode(BL_PORT, BL_PIN, PAL_MODE_OUTPUT_PUSHPULL);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -66,6 +60,8 @@ int main(void) {
|
||||||
*/
|
*/
|
||||||
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
|
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
|
||||||
|
|
||||||
|
InitUart();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Normal main() thread activity, in this demo it does nothing except
|
* Normal main() thread activity, in this demo it does nothing except
|
||||||
* sleeping in a loop and check the button state.
|
* sleeping in a loop and check the button state.
|
|
@ -81,7 +81,7 @@
|
||||||
/*
|
/*
|
||||||
* CAN driver system settings.
|
* CAN driver system settings.
|
||||||
*/
|
*/
|
||||||
#define STM32_CAN_USE_CAN1 FALSE
|
#define STM32_CAN_USE_CAN1 TRUE
|
||||||
#define STM32_CAN_CAN1_IRQ_PRIORITY 11
|
#define STM32_CAN_CAN1_IRQ_PRIORITY 11
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -154,7 +154,7 @@
|
||||||
* SERIAL driver system settings.
|
* SERIAL driver system settings.
|
||||||
*/
|
*/
|
||||||
#define STM32_SERIAL_USE_USART1 FALSE
|
#define STM32_SERIAL_USE_USART1 FALSE
|
||||||
#define STM32_SERIAL_USE_USART2 TRUE
|
#define STM32_SERIAL_USE_USART2 FALSE
|
||||||
#define STM32_SERIAL_USE_USART3 FALSE
|
#define STM32_SERIAL_USE_USART3 FALSE
|
||||||
#define STM32_SERIAL_USE_UART4 FALSE
|
#define STM32_SERIAL_USE_UART4 FALSE
|
||||||
#define STM32_SERIAL_USE_UART5 FALSE
|
#define STM32_SERIAL_USE_UART5 FALSE
|
||||||
|
@ -187,7 +187,7 @@
|
||||||
/*
|
/*
|
||||||
* UART driver system settings.
|
* UART driver system settings.
|
||||||
*/
|
*/
|
||||||
#define STM32_UART_USE_USART1 FALSE
|
#define STM32_UART_USE_USART1 TRUE
|
||||||
#define STM32_UART_USE_USART2 FALSE
|
#define STM32_UART_USE_USART2 FALSE
|
||||||
#define STM32_UART_USE_USART3 FALSE
|
#define STM32_UART_USE_USART3 FALSE
|
||||||
#define STM32_UART_USART1_IRQ_PRIORITY 12
|
#define STM32_UART_USART1_IRQ_PRIORITY 12
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
#include "ch.h"
|
||||||
|
#include "hal.h"
|
||||||
|
#include "chprintf.h"
|
||||||
|
|
||||||
|
#include "uart.h"
|
||||||
|
|
||||||
|
static const UARTConfig uartCfg =
|
||||||
|
{
|
||||||
|
.txend1_cb = nullptr,
|
||||||
|
.txend2_cb = nullptr,
|
||||||
|
.rxend_cb = nullptr,
|
||||||
|
.rxchar_cb = nullptr,
|
||||||
|
.rxerr_cb = nullptr,
|
||||||
|
.timeout_cb = nullptr,
|
||||||
|
|
||||||
|
#ifdef STM32F0XX
|
||||||
|
.timeout = 0,
|
||||||
|
#endif
|
||||||
|
|
||||||
|
.speed = 115200,
|
||||||
|
.cr1 = 0,
|
||||||
|
.cr2 = 0,
|
||||||
|
.cr3 = 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
static char printBuffer[200];
|
||||||
|
|
||||||
|
static THD_WORKING_AREA(waUartThread, 256);
|
||||||
|
static void UartThread(void*)
|
||||||
|
{
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
|
float lambda = 0;
|
||||||
|
int lambdaIntPart = 1;
|
||||||
|
int lambdaThousandths = 2;
|
||||||
|
|
||||||
|
size_t writeCount = chsnprintf(printBuffer, 200, "%d.%03d\t%d\t%d\r\n", 0, 0, 0, 100);
|
||||||
|
uartStartSend(&UARTD1, writeCount, printBuffer);
|
||||||
|
|
||||||
|
chThdSleepMilliseconds(20);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void InitUart()
|
||||||
|
{
|
||||||
|
// stm32 TX/UART1 - dongle RX often White
|
||||||
|
palSetPadMode(GPIOA, 9, PAL_MODE_STM32_ALTERNATE_PUSHPULL );
|
||||||
|
// stm32 RX/UART1 - dongle TX often Green
|
||||||
|
palSetPadMode(GPIOA,10, PAL_MODE_INPUT_PULLUP );
|
||||||
|
|
||||||
|
uartStart(&UARTD1, &uartCfg);
|
||||||
|
|
||||||
|
chThdCreateStatic(waUartThread, sizeof(waUartThread), NORMALPRIO, UartThread, nullptr);
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
void InitUart();
|
Loading…
Reference in New Issue