Skip to content

Commit

Permalink
Unity test over USART1 print
Browse files Browse the repository at this point in the history
  • Loading branch information
dzid26 committed Aug 20, 2023
1 parent 1c31038 commit 3559c8c
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 4 deletions.
23 changes: 22 additions & 1 deletion firmware/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,25 @@ test_ignore = system/*
platform = [email protected]
build_flags =
test_ignore = system/*
debug_test = test_utils
debug_test = test_utils



######## Wokwi system test #########
[env:ServoCAN_wokwi]
board = genericSTM32F103C8
build_type = debug
upload_protocol =
build_flags = ${env.build_flags}
-D USE_FULL_ASSERT #ST
-D IGNORE_CAN_CHECKSUM
-D SYSCLK_FREQ_72MHz

debug_build_flags=
-Og -g3 -ggdb3 ;O0 is too slow
; -Wl,--undefined,_printf_float ;enables printing floats

test_build_src = yes
test_testing_command =
wokwi-cli
test/system/test_adc
88 changes: 88 additions & 0 deletions firmware/test/system/test_adc/diagram.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"version": 1,
"author": "Uri Shaked",
"editor": "wokwi",
"parts": [
{ "type": "board-stm32-bluepill", "id": "stm32", "top": 0, "left": 0, "attrs": {} },
{
"type": "wokwi-led",
"id": "led1",
"top": 57.71,
"left": 145.42,
"rotate": 90,
"attrs": { "color": "red", "flip": "1" }
},
{
"type": "wokwi-pushbutton",
"id": "btn1",
"top": 233.26,
"left": 126.17,
"attrs": { "color": "black", "key": "1" }
},
{
"type": "wokwi-led",
"id": "led2",
"top": 161.67,
"left": 142.6,
"rotate": 90,
"attrs": { "color": "blue" }
},
{
"type": "wokwi-resistor",
"id": "r1",
"top": 260.31,
"left": 34.51,
"attrs": { "value": "10000" }
},
{
"type": "wokwi-resistor",
"id": "r2",
"top": 209.65,
"left": 75.9,
"rotate": 90,
"attrs": { "value": "1000" }
},
{
"type": "wokwi-pushbutton",
"id": "btn2",
"top": 308.54,
"left": 124.34,
"attrs": { "color": "black", "key": "2" }
},
{
"type": "wokwi-resistor",
"id": "r3",
"top": 204.56,
"left": 188.31,
"rotate": 90,
"attrs": { "value": "1000" }
},
{
"type": "wokwi-resistor",
"id": "r4",
"top": 334.78,
"left": 49.83,
"attrs": { "value": "10000" }
},
{ "type": "wokwi-vcc", "id": "vcc1", "top": 6.39, "left": 201.14, "attrs": {} }
],
"connections": [
[ "stm32:A10", "$serialMonitor:TX", "green", [] ],
[ "stm32:A9", "$serialMonitor:RX", "green", [] ],
[ "led1:C", "stm32:GND.1", "black", [ "v-0.85", "h-32.28", "v130.12", "h-75.68", "v-33.22" ] ],
[ "led1:A", "stm32:B0", "green", [ "v0" ] ],
[ "led2:C", "stm32:C13", "green", [ "h0" ] ],
[ "stm32:GND.1", "led2:A", "black", [ "h27.05", "v32.92", "h105.32" ] ],
[ "stm32:3V3.1", "r1:1", "red", [ "h-0.91", "v84.44" ] ],
[ "r1:2", "btn1:2.l", "red", [ "v0" ] ],
[ "r2:1", "stm32:C14", "green", [ "v0" ] ],
[ "r2:2", "btn1:1.l", "green", [ "h0" ] ],
[ "r3:1", "stm32:C15", "green", [ "v-16.21", "h-144.9" ] ],
[ "btn2:1.r", "r3:2", "green", [ "v-0.12", "h25.78" ] ],
[ "r4:2", "btn2:2.l", "green", [ "v0" ] ],
[ "stm32:3V3.1", "r4:1", "red", [ "h-0.91", "v147.07" ] ],
[ "vcc1:VCC", "stm32:A7", "red", [ "v67.5", "h-108.67", "v-14.17" ] ],
[ "vcc1:VCC", "stm32:B1", "red", [ "v0" ] ]
],
"dependencies": {}
}
4 changes: 4 additions & 0 deletions firmware/test/system/test_adc/wokwi.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[wokwi]
version = 1
firmware = '../../../.pio/build/ServoCAN_wokwi/firmware.bin'
elf = '../../../.pio/build/ServoCAN_wokwi/firmware.elf'
46 changes: 43 additions & 3 deletions firmware/test/unity_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,66 @@

#include <stdio.h>
#include "unity_config.h"

#ifdef USE_STDPERIPH_DRIVER
#include "stm32f10x.h"
#endif
extern void initialise_monitor_handles(void);


void unityOutputStart(void)
{
#ifdef DEBUG
initialise_monitor_handles(); //semihosting
#elif USE_STDPERIPH_DRIVER
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;

/* Enable GPIOB, AFIO and USART1 clocks */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO | RCC_APB2Periph_USART1, ENABLE);

/* Remap USART1 from PA9/PA10 to PB6/PB7 */
// GPIO_PinRemapConfig(GPIO_Remap_USART1, ENABLE);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOA, &GPIO_InitStructure);

USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Tx;

USART_Init(USART1, &USART_InitStructure);
USART_Cmd(USART1, ENABLE);
#endif
}

void unityOutputChar(char c)
{
#ifdef DEBUG
(void) putchar(c);
#elif USE_STDPERIPH_DRIVER
while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
USART_SendData(USART1, (uint16_t)c);
#endif
}

void unityOutputFlush(void)
{
#ifdef DEBUG
(void) fflush(stdout);
#elif USE_STDPERIPH_DRIVER
USART_DeInit(USART1);
#endif
}

void unityOutputComplete(void)
{
void unityOutputComplete(void){
//unused
}

0 comments on commit 3559c8c

Please sign in to comment.