fix logger (lost first two chars) and setting meterbus uart (8bit data plus parity, so 9bit incl. parity)

This commit is contained in:
Wolfgang Hottgenroth 2020-10-29 23:16:03 +01:00
parent 6ccf85abdb
commit 877dd0fca3
No known key found for this signature in database
GPG Key ID: 656C88C7C1734267
8 changed files with 81 additions and 67 deletions

View File

@ -51,7 +51,7 @@ void MX_UART5_Init(void)
huart5.Instance = UART5; huart5.Instance = UART5;
huart5.Init.BaudRate = 2400; huart5.Init.BaudRate = 2400;
huart5.Init.WordLength = UART_WORDLENGTH_8B; huart5.Init.WordLength = UART_WORDLENGTH_9B;
huart5.Init.StopBits = UART_STOPBITS_1; huart5.Init.StopBits = UART_STOPBITS_1;
huart5.Init.Parity = UART_PARITY_EVEN; huart5.Init.Parity = UART_PARITY_EVEN;
huart5.Init.Mode = UART_MODE_TX_RX; huart5.Init.Mode = UART_MODE_TX_RX;

View File

@ -1,6 +1,6 @@
# Processed by ../tools/insertMyCode.sh # Processed by ../tools/insertMyCode.sh
########################################################################################################################## ##########################################################################################################################
# File automatically-generated by tool: [projectgenerator] version: [3.10.0-B14] date: [Tue Oct 27 22:02:19 CET 2020] # File automatically-generated by tool: [projectgenerator] version: [3.10.0-B14] date: [Thu Oct 29 22:51:14 CET 2020]
########################################################################################################################## ##########################################################################################################################
# ------------------------------------------------ # ------------------------------------------------
@ -36,36 +36,36 @@ BUILD_DIR = build
# source # source
###################################### ######################################
# C sources # C sources
C_SOURCES = \ C_SOURCES = \
User/Src/ringbuffer.c User/Src/logger.c User/Src/mbusComm.c User/Src/led.c User/Src/loopCtrl.c User/Src/main2.c hottislib/PontCoopScheduler.c \ User/Src/led.c User/Src/logger.c User/Src/loopCtrl.c User/Src/main2.c User/Src/mbusComm.c User/Src/ringbuffer.c hottislib/PontCoopScheduler.c \
Core/Src/main.c \ Core/Src/main.c \
Core/Src/gpio.c \ Core/Src/gpio.c \
Core/Src/adc.c \ Core/Src/adc.c \
Core/Src/spi.c \ Core/Src/spi.c \
Core/Src/usart.c \ Core/Src/usart.c \
Core/Src/stm32f1xx_it.c \ Core/Src/stm32f1xx_it.c \
Core/Src/stm32f1xx_hal_msp.c \ Core/Src/stm32f1xx_hal_msp.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c \ Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc.c \ Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc_ex.c \ Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc_ex.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c \ Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c \ Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c \ Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c \ Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c \ Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c \ Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c \ Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c \ Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c \ Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_exti.c \ Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_exti.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_spi.c \ Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_spi.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c \ Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c \ Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c \ Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c \
Core/Src/system_stm32f1xx.c Core/Src/system_stm32f1xx.c
# ASM sources # ASM sources
ASM_SOURCES = \ ASM_SOURCES = \
startup_stm32f103xe.s startup_stm32f103xe.s
@ -109,8 +109,8 @@ MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)
AS_DEFS = AS_DEFS =
# C defines # C defines
C_DEFS = \ C_DEFS = \
-DUSE_HAL_DRIVER \ -DUSE_HAL_DRIVER \
-DSTM32F103xE -DSTM32F103xE
@ -118,14 +118,14 @@ C_DEFS = \
AS_INCLUDES = AS_INCLUDES =
# C includes # C includes
C_INCLUDES = \ C_INCLUDES = \
-Ihottislib \ -Ihottislib \
-IUser/Inc \ -IUser/Inc \
-ICore/Inc \ -ICore/Inc \
-IDrivers/STM32F1xx_HAL_Driver/Inc \ -IDrivers/STM32F1xx_HAL_Driver/Inc \
-IDrivers/STM32F1xx_HAL_Driver/Inc/Legacy \ -IDrivers/STM32F1xx_HAL_Driver/Inc/Legacy \
-IDrivers/CMSIS/Device/ST/STM32F1xx/Include \ -IDrivers/CMSIS/Device/ST/STM32F1xx/Include \
-IDrivers/CMSIS/Include \ -IDrivers/CMSIS/Include \
-IDrivers/CMSIS/Include -IDrivers/CMSIS/Include

View File

@ -1,5 +1,5 @@
########################################################################################################################## ##########################################################################################################################
# File automatically-generated by tool: [projectgenerator] version: [3.10.0-B14] date: [Tue Oct 27 22:02:19 CET 2020] # File automatically-generated by tool: [projectgenerator] version: [3.10.0-B14] date: [Thu Oct 29 22:51:14 CET 2020]
########################################################################################################################## ##########################################################################################################################
# ------------------------------------------------ # ------------------------------------------------

View File

@ -66,11 +66,11 @@ int logMsg(const char *format, ...) {
va_list vl; va_list vl;
va_start(vl, format); va_start(vl, format);
int vcnt = vsnprintf(msgBuffer-2, MSGBUFFER_SIZE, format, vl); int vcnt = vsnprintf(msgBuffer, MSGBUFFER_SIZE-2, format, vl);
va_end(vl); va_end(vl);
if (vcnt < MSGBUFFER_SIZE) { if (vcnt < MSGBUFFER_SIZE) {
strcat(msgBuffer, "\n\r"); strcat(msgBuffer, "\r\n");
if (-1 == (res = ringbufferPut(&logBuffer, (uint8_t*) msgBuffer, strlen(msgBuffer)))) { if (-1 == (res = ringbufferPut(&logBuffer, (uint8_t*) msgBuffer, strlen(msgBuffer)))) {
#ifndef TEST #ifndef TEST

View File

@ -25,6 +25,9 @@ void my_errorHandler() {
void helloMeterbus(void *handle) { void helloMeterbus(void *handle) {
mbusCommRequest(0x5b, 80); mbusCommRequest(0x5b, 80);
// static char msg[] = "Hello";
// HAL_UART_Transmit_IT(&mbusUart, &msg, strlen(msg));
} }
@ -32,7 +35,7 @@ void my_setup_2() {
led(RED, OFF); led(RED, OFF);
led(GREEN, ON); led(GREEN, ON);
schAdd(helloMeterbus, NULL, 0, 10000); schAdd(helloMeterbus, NULL, 0, 2000);
} }
void my_loop() { void my_loop() {

View File

@ -30,11 +30,11 @@ static void handleRequestEngine(void *handle) {
switch (localMbusCommHandle->state) { switch (localMbusCommHandle->state) {
case IDLE: case IDLE:
logMsg("mc state IDLE\n"); logMsg("hre state IDLE");
break; break;
case SEND: case SEND:
logMsg("mc state SEND\n"); logMsg("hre state SEND");
localMbusCommHandle->sendBuf[0] = 0x10; localMbusCommHandle->sendBuf[0] = 0x10;
localMbusCommHandle->sendBuf[1] = localMbusCommHandle->cmd; localMbusCommHandle->sendBuf[1] = localMbusCommHandle->cmd;
localMbusCommHandle->sendBuf[2] = localMbusCommHandle->addr; localMbusCommHandle->sendBuf[2] = localMbusCommHandle->addr;
@ -44,26 +44,28 @@ static void handleRequestEngine(void *handle) {
// no break !! // no break !!
case SEND_CONT: case SEND_CONT:
logMsg("mc state SEND_CONT\n"); logMsg("hre state SEND_CONT");
led(RED, OFF); led(RED, OFF);
if (! loopActive) { if (! loopActive) {
logMsg("hre enabling loop, try %d", localMbusCommHandle->retryCnt);
localMbusCommHandle->retryCnt++; localMbusCommHandle->retryCnt++;
loopEnable(); loopEnable();
schAdd(handleRequestEngine, handle, 10, 0); // give 10ms to settled the loop schAdd(handleRequestEngine, handle, 10, 0); // give 10ms to settled the loop
} else { } else {
// write(fd, sendBuf, 5); // write(fd, sendBuf, 5);
localMbusCommHandle->retryCnt = 0;
HAL_UART_Transmit_IT(&mbusUart, localMbusCommHandle->sendBuf, 5); HAL_UART_Transmit_IT(&mbusUart, localMbusCommHandle->sendBuf, 5);
localMbusCommHandle->state = SENDING; localMbusCommHandle->state = SENDING;
schAdd(handleRequestEngine, handle, 1, 0); // ask me again in 1ms in the next state ... schAdd(handleRequestEngine, handle, 5, 0); // ask me again in 1ms in the next state ...
} }
break; break;
case SENDING: case SENDING:
logMsg("mc state SENDING\n"); logMsg("hre state SENDING");
if (HAL_UART_GetState(&mbusUart) == HAL_UART_STATE_READY) { // ... whether I'm done if (HAL_UART_GetState(&mbusUart) == HAL_UART_STATE_READY) { // ... whether I'm done
localMbusCommHandle->state = IDLE; localMbusCommHandle->state = IDLE;
} else { } else {
schAdd(handleRequestEngine, handle, 1, 0); // not yet done, ask me again in 1ms schAdd(handleRequestEngine, handle, 5, 0); // not yet done, ask me again in 1ms
} }
break; break;

View File

@ -200,9 +200,10 @@ SPI3.VirtualType=VM_MASTER
UART4.IPParameters=VirtualMode UART4.IPParameters=VirtualMode
UART4.VirtualMode=Asynchronous UART4.VirtualMode=Asynchronous
UART5.BaudRate=2400 UART5.BaudRate=2400
UART5.IPParameters=VirtualMode,BaudRate,Parity UART5.IPParameters=VirtualMode,BaudRate,Parity,WordLength
UART5.Parity=PARITY_EVEN UART5.Parity=PARITY_EVEN
UART5.VirtualMode=Asynchronous UART5.VirtualMode=Asynchronous
UART5.WordLength=WORDLENGTH_9B
VP_SYS_VS_Systick.Mode=SysTick VP_SYS_VS_Systick.Mode=SysTick
VP_SYS_VS_Systick.Signal=SYS_VS_Systick VP_SYS_VS_Systick.Signal=SYS_VS_Systick
board=custom board=custom

View File

@ -834,8 +834,9 @@ void testLogger0() {
#ifdef DEBUG #ifdef DEBUG
printf("\nLog a message\n"); printf("\nLog a message\n");
#endif #endif
char goldValue1[] = "Wolfgang\n"; char msg[] = "Wolfgang";
logMsg(goldValue1); char goldValue[] = "Wolfgang\r\n";
logMsg(msg);
#ifdef DEBUG #ifdef DEBUG
printf("\nRead all chars from logging\n"); printf("\nRead all chars from logging\n");
@ -850,7 +851,8 @@ void testLogger0() {
buffer[i] = (uint8_t) c; buffer[i] = (uint8_t) c;
i++; i++;
} }
CU_ASSERT(strcmp(goldValue1, buffer) == 0); // printf(buffer);
CU_ASSERT(strcmp(goldValue, buffer) == 0);
} }
void testLogger1() { void testLogger1() {
@ -859,18 +861,18 @@ void testLogger1() {
#endif #endif
char goldValueFull[128]; char goldValueFull[128];
memset(goldValueFull, 0, 128); memset(goldValueFull, 0, 128);
char goldValue1[] = "Wolfgang\n"; // 9 char goldValue1[] = "Wolfgang"; // 9
strcat(goldValueFull, goldValue1); strcat(goldValueFull, goldValue1);
strcat(goldValueFull, "\r\n");
logMsg(goldValue1); logMsg(goldValue1);
char goldValue2[] = "Andreas\n"; // +8 = 17 char goldValue2[] = "Andreas"; // +8 = 17
strcat(goldValueFull, goldValue2); strcat(goldValueFull, goldValue2);
strcat(goldValueFull, "\r\n");
logMsg(goldValue2); logMsg(goldValue2);
char goldValue3[] = "Frank\n"; // +6 = 23 char goldValue3[] = "Frank"; // +6 = 23
strcat(goldValueFull, goldValue3); strcat(goldValueFull, goldValue3);
strcat(goldValueFull, "\r\n");
logMsg(goldValue3); logMsg(goldValue3);
char goldValue4[] = "Thomas\n"; // +7 = 30
strcat(goldValueFull, goldValue4);
logMsg(goldValue4);
#ifdef DEBUG #ifdef DEBUG
printf("\nRead all chars from logging\n"); printf("\nRead all chars from logging\n");
@ -898,27 +900,33 @@ void testLogger2() {
memset(goldValueFullNotOk, 0, 128); memset(goldValueFullNotOk, 0, 128);
char goldValueFullOk[128]; char goldValueFullOk[128];
memset(goldValueFullOk, 0, 128); memset(goldValueFullOk, 0, 128);
char goldValue1[] = "Wolfgang\n"; // 9 char goldValue1[] = "Wolfgang"; // 9
strcat(goldValueFullNotOk, goldValue1); strcat(goldValueFullNotOk, goldValue1);
strcat(goldValueFullOk, goldValue1); strcat(goldValueFullOk, goldValue1);
strcat(goldValueFullNotOk, "\r\n");
strcat(goldValueFullOk, "\r\n");
int r = logMsg(goldValue1); int r = logMsg(goldValue1);
CU_ASSERT(r == 0); CU_ASSERT(r == 0);
char goldValue2[] = "Andreas\n"; // +8 = 17 char goldValue2[] = "Andreas"; // +8 = 17
strcat(goldValueFullNotOk, goldValue2); strcat(goldValueFullNotOk, goldValue2);
strcat(goldValueFullOk, goldValue2); strcat(goldValueFullOk, goldValue2);
strcat(goldValueFullNotOk, "\r\n");
strcat(goldValueFullOk, "\r\n");
r = logMsg(goldValue2); r = logMsg(goldValue2);
CU_ASSERT(r == 0); CU_ASSERT(r == 0);
char goldValue3[] = "Frank\n"; // +6 = 23 char goldValue3[] = "Frank"; // +6 = 23
strcat(goldValueFullNotOk, goldValue3); strcat(goldValueFullNotOk, goldValue3);
strcat(goldValueFullOk, goldValue3); strcat(goldValueFullOk, goldValue3);
strcat(goldValueFullNotOk, "\r\n");
strcat(goldValueFullOk, "\r\n");
r = logMsg(goldValue3); r = logMsg(goldValue3);
CU_ASSERT(r == 0); CU_ASSERT(r == 0);
char goldValue4[] = "Thomas\n"; // +7 = 30 char goldValue4[] = "Thomas"; // +7 = 30
strcat(goldValueFullNotOk, goldValue4); strcat(goldValueFullNotOk, goldValue4);
strcat(goldValueFullOk, goldValue4); strcat(goldValueFullNotOk, "\r\n");
r = logMsg(goldValue4); r = logMsg(goldValue4);
CU_ASSERT(r == 0); CU_ASSERT(r == -1);
char goldValue5[] = "Barbara\n"; // +8 = 38, too much char goldValue5[] = "Barbara"; // +8 = 38, too much
strcat(goldValueFullNotOk, goldValue5); strcat(goldValueFullNotOk, goldValue5);
r = logMsg(goldValue5); r = logMsg(goldValue5);
CU_ASSERT(r == -1); CU_ASSERT(r == -1);