F1 test project: now with C++ and UART

This commit is contained in:
rusefi 2022-01-22 23:30:03 -05:00
parent b8eafd7652
commit 842f3b9b57
7 changed files with 80 additions and 19 deletions

View File

@ -15,7 +15,7 @@ endif
# C++ specific options here (added to USE_OPT).
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
# Enable this if you want the linker to remove unused code and data.
@ -94,6 +94,12 @@ CONFDIR := ./cfg
BUILDDIR := ./build
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.
include $(CHIBIOS)/os/license/license.mk
# Startup files.
@ -109,18 +115,20 @@ include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk
# Auto-build files in ./source recursively.
include $(CHIBIOS)/tools/mk/autobuild.mk
# Other files (optional).
include $(CHIBIOS)/os/hal/lib/streams/streams.mk
# Define linker script file here
LDSCRIPT= $(STARTUPLD)/STM32F103xB.ld
# C sources that can be compiled in ARM or THUMB mode depending on the global
# setting.
CSRC = $(ALLCSRC) \
main.c
CSRC = $(ALLCSRC)
# C++ sources that can be compiled in ARM or THUMB mode depending on the global
# setting.
CPPSRC = $(ALLCPPSRC)
CPPSRC = $(ALLCPPSRC) \
main.cpp \
uart.cpp
# List ASM source files here.
ASMSRC = $(ALLASMSRC)
@ -129,7 +137,7 @@ ASMSRC = $(ALLASMSRC)
ASMXSRC = $(ALLXASMSRC)
# Inclusion directories.
INCDIR = $(CONFDIR) $(ALLINC) $(TESTINC)
INCDIR = $(CONFDIR) $(ALLINC)
# Define C warning options here.
CWARN = -Wall -Wextra -Wundef -Wstrict-prototypes

View File

@ -3,5 +3,5 @@ rd /s /q .dep
echo Starting compilation
rem the important piece
make
make -j12

View File

@ -51,7 +51,7 @@
* @brief Enables the CAN subsystem.
*/
#if !defined(HAL_USE_CAN) || defined(__DOXYGEN__)
#define HAL_USE_CAN FALSE
#define HAL_USE_CAN TRUE
#endif
/**
@ -142,7 +142,7 @@
* @brief Enables the SERIAL subsystem.
*/
#if !defined(HAL_USE_SERIAL) || defined(__DOXYGEN__)
#define HAL_USE_SERIAL TRUE
#define HAL_USE_SERIAL FALSE
#endif
/**
@ -177,7 +177,7 @@
* @brief Enables the UART subsystem.
*/
#if !defined(HAL_USE_UART) || defined(__DOXYGEN__)
#define HAL_USE_UART FALSE
#define HAL_USE_UART TRUE
#endif
/**

View File

@ -16,7 +16,7 @@
#include "ch.h"
#include "hal.h"
#include "uart.h"
#define BL_PORT GPIOC
#define BL_PIN 13
@ -53,12 +53,6 @@ int main(void) {
halInit();
chSysInit();
/*
* Activates the serial driver 2 using the driver default configuration.
*/
sdStart(&SD2, NULL);
palSetPadMode(BL_PORT, BL_PIN, PAL_MODE_OUTPUT_PUSHPULL);
/*
@ -66,6 +60,8 @@ int main(void) {
*/
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
InitUart();
/*
* Normal main() thread activity, in this demo it does nothing except
* sleeping in a loop and check the button state.

View File

@ -81,7 +81,7 @@
/*
* CAN driver system settings.
*/
#define STM32_CAN_USE_CAN1 FALSE
#define STM32_CAN_USE_CAN1 TRUE
#define STM32_CAN_CAN1_IRQ_PRIORITY 11
/*
@ -154,7 +154,7 @@
* SERIAL driver system settings.
*/
#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_UART4 FALSE
#define STM32_SERIAL_USE_UART5 FALSE
@ -187,7 +187,7 @@
/*
* 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_USART3 FALSE
#define STM32_UART_USART1_IRQ_PRIORITY 12

View File

@ -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);
}

View File

@ -0,0 +1,3 @@
#pragma once
void InitUart();