Compare commits

...

2 Commits

@ -15,12 +15,12 @@ AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortEnumsOnASingleLine: false
AllowShortBlocksOnASingleLine: Never
AllowShortBlocksOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
@ -30,7 +30,7 @@ AttributeMacros:
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: false
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: Always
AfterEnum: true
@ -38,14 +38,14 @@ BraceWrapping:
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: false
AfterUnion: true
AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyFunction: false
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
@ -95,7 +95,7 @@ IncludeCategories:
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentAccessModifiers: false
IndentCaseLabels: false
IndentCaseLabels: true
IndentCaseBlocks: false
IndentGotoLabels: true
IndentPPDirectives: None

@ -101,3 +101,6 @@ p huart1_rxc
c
p huart1_rxc
q
b 411
r
q

@ -133,12 +133,30 @@ int main(void)
/* USER CODE BEGIN WHILE */
while (1)
{
if (b_timer_struck)
// if (b_timer_struck)
// {
// // PDEBUG("%d\n", sys_time);
// b_timer_struck = false;
// motor_degrees = (motor_degrees + 1) % 360;
// mc_service(motor_degrees, 50);
// }
serial_pkt_t *pkt = NULL;
if ((pkt = p_serial_mgr_service()) != NULL)
{
// PDEBUG("%d\n", sys_time);
b_timer_struck = false;
motor_degrees = (motor_degrees + 1) % 360;
mc_service(motor_degrees, 50);
PDEBUG("Source: %02x\n"
"Destination: %02x\n",
pkt->src_addr, pkt->dest_addr);
PDEBUG("Frame Data: \n");
for (int ind = 0; ind < pkt->len; pkt++)
{
if (ind % 8 == 0)
{
PDEBUG("\n");
}
PDEBUG("%02x ", pkt->frame_data[ind]);
}
PDEBUG("\nChecksum: %02x\n\n");
memset(pkt, 0, sizeof(serial_pkt_t));
}
/* USER CODE END WHILE */
@ -392,7 +410,7 @@ static void MX_GPIO_Init(void)
void UART2_RxCpltCallback(UART_HandleTypeDef *huart)
{
HAL_UART_Transmit(&huart1, &huart2_rxc, 1, 100);
HAL_UART_Transmit(&huart2, &huart2_rxc, 1, 100);
HAL_UART_Receive_IT(&huart2, &huart2_rxc, 1);
}
// void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
@ -437,9 +455,7 @@ void Error_Handler(void)
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
__disable_irq();
while (1)
{
}
while (1) {}
/* USER CODE END Error_Handler_Debug */
}

@ -25,14 +25,14 @@
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/stm32l4xx_hal_uart.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_uart.lst",
"-MFbuild/stm32l4xx_hal_msp.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_msp.lst",
"-o",
"build/stm32l4xx_hal_uart.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_uart.c"
"build/stm32l4xx_hal_msp.o",
"Core/Src/stm32l4xx_hal_msp.c"
],
"directory": "/storage/Shared/Projects/Penguinator/motor_controller",
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_uart.c"
"file": "Core/Src/stm32l4xx_hal_msp.c"
},
{
"arguments": [
@ -60,14 +60,14 @@
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/stm32l4xx_hal_tim_ex.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_tim_ex.lst",
"-MFbuild/stm32l4xx_hal_dma.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_dma.lst",
"-o",
"build/stm32l4xx_hal_tim_ex.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_tim_ex.c"
"build/stm32l4xx_hal_dma.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma.c"
],
"directory": "/storage/Shared/Projects/Penguinator/motor_controller",
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_tim_ex.c"
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma.c"
},
{
"arguments": [
@ -95,14 +95,14 @@
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/stm32l4xx_hal_tim.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_tim.lst",
"-MFbuild/stm32l4xx_hal_gpio.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_gpio.lst",
"-o",
"build/stm32l4xx_hal_tim.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_tim.c"
"build/stm32l4xx_hal_gpio.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_gpio.c"
],
"directory": "/storage/Shared/Projects/Penguinator/motor_controller",
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_tim.c"
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_gpio.c"
},
{
"arguments": [
@ -130,14 +130,14 @@
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/stm32l4xx_hal_flash.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_flash.lst",
"-MFbuild/main.d",
"-Wa,-a,-ad,-alms=build/main.lst",
"-o",
"build/stm32l4xx_hal_flash.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash.c"
"build/main.o",
"Core/Src/main.c"
],
"directory": "/storage/Shared/Projects/Penguinator/motor_controller",
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash.c"
"file": "Core/Src/main.c"
},
{
"arguments": [
@ -165,14 +165,14 @@
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/stm32l4xx_hal_rcc.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_rcc.lst",
"-MFbuild/stm32l4xx_hal_rcc_ex.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_rcc_ex.lst",
"-o",
"build/stm32l4xx_hal_rcc.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rcc.c"
"build/stm32l4xx_hal_rcc_ex.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rcc_ex.c"
],
"directory": "/storage/Shared/Projects/Penguinator/motor_controller",
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rcc.c"
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rcc_ex.c"
},
{
"arguments": [
@ -200,14 +200,14 @@
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/stm32l4xx_hal_i2c.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_i2c.lst",
"-MFbuild/stm32l4xx_hal_flash_ramfunc.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_flash_ramfunc.lst",
"-o",
"build/stm32l4xx_hal_i2c.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_i2c.c"
"build/stm32l4xx_hal_flash_ramfunc.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash_ramfunc.c"
],
"directory": "/storage/Shared/Projects/Penguinator/motor_controller",
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_i2c.c"
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash_ramfunc.c"
},
{
"arguments": [
@ -235,14 +235,14 @@
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/stm32l4xx_hal_cortex.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_cortex.lst",
"-MFbuild/stm32l4xx_hal_tim.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_tim.lst",
"-o",
"build/stm32l4xx_hal_cortex.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_cortex.c"
"build/stm32l4xx_hal_tim.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_tim.c"
],
"directory": "/storage/Shared/Projects/Penguinator/motor_controller",
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_cortex.c"
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_tim.c"
},
{
"arguments": [
@ -270,14 +270,14 @@
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/stm32l4xx_hal_flash_ramfunc.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_flash_ramfunc.lst",
"-MFbuild/p_serial_mgr.d",
"-Wa,-a,-ad,-alms=build/p_serial_mgr.lst",
"-o",
"build/stm32l4xx_hal_flash_ramfunc.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash_ramfunc.c"
"build/p_serial_mgr.o",
"shared/drivers/p_serial_mgr.c"
],
"directory": "/storage/Shared/Projects/Penguinator/motor_controller",
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash_ramfunc.c"
"file": "shared/drivers/p_serial_mgr.c"
},
{
"arguments": [
@ -305,14 +305,14 @@
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/stm32l4xx_hal_msp.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_msp.lst",
"-MFbuild/stm32l4xx_hal.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal.lst",
"-o",
"build/stm32l4xx_hal_msp.o",
"Core/Src/stm32l4xx_hal_msp.c"
"build/stm32l4xx_hal.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal.c"
],
"directory": "/storage/Shared/Projects/Penguinator/motor_controller",
"file": "Core/Src/stm32l4xx_hal_msp.c"
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal.c"
},
{
"arguments": [
@ -340,14 +340,14 @@
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/system_stm32l4xx.d",
"-Wa,-a,-ad,-alms=build/system_stm32l4xx.lst",
"-MFbuild/stm32l4xx_hal_cortex.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_cortex.lst",
"-o",
"build/system_stm32l4xx.o",
"Core/Src/system_stm32l4xx.c"
"build/stm32l4xx_hal_cortex.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_cortex.c"
],
"directory": "/storage/Shared/Projects/Penguinator/motor_controller",
"file": "Core/Src/system_stm32l4xx.c"
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_cortex.c"
},
{
"arguments": [
@ -375,14 +375,14 @@
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/stm32l4xx_hal_dma.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_dma.lst",
"-MFbuild/stm32l4xx_hal_flash.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_flash.lst",
"-o",
"build/stm32l4xx_hal_dma.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma.c"
"build/stm32l4xx_hal_flash.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash.c"
],
"directory": "/storage/Shared/Projects/Penguinator/motor_controller",
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma.c"
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash.c"
},
{
"arguments": [
@ -410,14 +410,14 @@
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/stm32l4xx_hal_gpio.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_gpio.lst",
"-MFbuild/stm32l4xx_it.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_it.lst",
"-o",
"build/stm32l4xx_hal_gpio.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_gpio.c"
"build/stm32l4xx_it.o",
"Core/Src/stm32l4xx_it.c"
],
"directory": "/storage/Shared/Projects/Penguinator/motor_controller",
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_gpio.c"
"file": "Core/Src/stm32l4xx_it.c"
},
{
"arguments": [
@ -445,14 +445,14 @@
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/main.d",
"-Wa,-a,-ad,-alms=build/main.lst",
"-MFbuild/stm32l4xx_hal_i2c.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_i2c.lst",
"-o",
"build/main.o",
"Core/Src/main.c"
"build/stm32l4xx_hal_i2c.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_i2c.c"
],
"directory": "/storage/Shared/Projects/Penguinator/motor_controller",
"file": "Core/Src/main.c"
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_i2c.c"
},
{
"arguments": [
@ -480,14 +480,14 @@
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/stm32l4xx_hal_flash_ex.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_flash_ex.lst",
"-MFbuild/stm32l4xx_hal_pwr_ex.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_pwr_ex.lst",
"-o",
"build/stm32l4xx_hal_flash_ex.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash_ex.c"
"build/stm32l4xx_hal_pwr_ex.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_pwr_ex.c"
],
"directory": "/storage/Shared/Projects/Penguinator/motor_controller",
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash_ex.c"
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_pwr_ex.c"
},
{
"arguments": [
@ -515,14 +515,14 @@
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/stm32l4xx_hal.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal.lst",
"-MFbuild/putil.d",
"-Wa,-a,-ad,-alms=build/putil.lst",
"-o",
"build/stm32l4xx_hal.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal.c"
"build/putil.o",
"shared/util/putil.c"
],
"directory": "/storage/Shared/Projects/Penguinator/motor_controller",
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal.c"
"file": "shared/util/putil.c"
},
{
"arguments": [
@ -550,14 +550,14 @@
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/stm32l4xx_hal_pwr.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_pwr.lst",
"-MFbuild/stm32l4xx_hal_dma_ex.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_dma_ex.lst",
"-o",
"build/stm32l4xx_hal_pwr.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_pwr.c"
"build/stm32l4xx_hal_dma_ex.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma_ex.c"
],
"directory": "/storage/Shared/Projects/Penguinator/motor_controller",
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_pwr.c"
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma_ex.c"
},
{
"arguments": [
@ -585,14 +585,14 @@
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/stm32l4xx_hal_i2c_ex.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_i2c_ex.lst",
"-MFbuild/stm32l4xx_hal_tim_ex.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_tim_ex.lst",
"-o",
"build/stm32l4xx_hal_i2c_ex.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_i2c_ex.c"
"build/stm32l4xx_hal_tim_ex.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_tim_ex.c"
],
"directory": "/storage/Shared/Projects/Penguinator/motor_controller",
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_i2c_ex.c"
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_tim_ex.c"
},
{
"arguments": [
@ -620,14 +620,14 @@
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/p_serial_mgr.d",
"-Wa,-a,-ad,-alms=build/p_serial_mgr.lst",
"-MFbuild/stm32l4xx_hal_pwr.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_pwr.lst",
"-o",
"build/p_serial_mgr.o",
"shared/drivers/p_serial_mgr.c"
"build/stm32l4xx_hal_pwr.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_pwr.c"
],
"directory": "/storage/Shared/Projects/Penguinator/motor_controller",
"file": "shared/drivers/p_serial_mgr.c"
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_pwr.c"
},
{
"arguments": [
@ -655,14 +655,14 @@
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/stm32l4xx_hal_uart_ex.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_uart_ex.lst",
"-MFbuild/motor_controller.d",
"-Wa,-a,-ad,-alms=build/motor_controller.lst",
"-o",
"build/stm32l4xx_hal_uart_ex.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_uart_ex.c"
"build/motor_controller.o",
"shared/devices/motor_controller.c"
],
"directory": "/storage/Shared/Projects/Penguinator/motor_controller",
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_uart_ex.c"
"file": "shared/devices/motor_controller.c"
},
{
"arguments": [
@ -725,14 +725,14 @@
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/putil.d",
"-Wa,-a,-ad,-alms=build/putil.lst",
"-MFbuild/system_stm32l4xx.d",
"-Wa,-a,-ad,-alms=build/system_stm32l4xx.lst",
"-o",
"build/putil.o",
"shared/util/putil.c"
"build/system_stm32l4xx.o",
"Core/Src/system_stm32l4xx.c"
],
"directory": "/storage/Shared/Projects/Penguinator/motor_controller",
"file": "shared/util/putil.c"
"file": "Core/Src/system_stm32l4xx.c"
},
{
"arguments": [
@ -760,14 +760,14 @@
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/motor_controller.d",
"-Wa,-a,-ad,-alms=build/motor_controller.lst",
"-MFbuild/stm32l4xx_hal_flash_ex.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_flash_ex.lst",
"-o",
"build/motor_controller.o",
"shared/devices/motor_controller.c"
"build/stm32l4xx_hal_flash_ex.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash_ex.c"
],
"directory": "/storage/Shared/Projects/Penguinator/motor_controller",
"file": "shared/devices/motor_controller.c"
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash_ex.c"
},
{
"arguments": [
@ -795,21 +795,19 @@
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/stm32l4xx_it.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_it.lst",
"-MFbuild/stm32l4xx_hal_uart_ex.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_uart_ex.lst",
"-o",
"build/stm32l4xx_it.o",
"Core/Src/stm32l4xx_it.c"
"build/stm32l4xx_hal_uart_ex.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_uart_ex.c"
],
"directory": "/storage/Shared/Projects/Penguinator/motor_controller",
"file": "Core/Src/stm32l4xx_it.c"
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_uart_ex.c"
},
{
"arguments": [
"arm-none-eabi-gcc",
"-c",
"-x",
"assembler-with-cpp",
"-mcpu=cortex-m4",
"-mthumb",
"-mfpu=fpv4-sp-d16",
@ -832,18 +830,21 @@
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/startup_stm32l432xx.d",
"-MFbuild/stm32l4xx_hal_uart.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_uart.lst",
"-o",
"build/startup_stm32l432xx.o",
"startup_stm32l432xx.s"
"build/stm32l4xx_hal_uart.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_uart.c"
],
"directory": "/storage/Shared/Projects/Penguinator/motor_controller",
"file": "startup_stm32l432xx.s"
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_uart.c"
},
{
"arguments": [
"arm-none-eabi-gcc",
"-c",
"-x",
"assembler-with-cpp",
"-mcpu=cortex-m4",
"-mthumb",
"-mfpu=fpv4-sp-d16",
@ -866,14 +867,13 @@
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/stm32l4xx_hal_rcc_ex.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_rcc_ex.lst",
"-MFbuild/startup_stm32l432xx.d",
"-o",
"build/stm32l4xx_hal_rcc_ex.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rcc_ex.c"
"build/startup_stm32l432xx.o",
"startup_stm32l432xx.s"
],
"directory": "/storage/Shared/Projects/Penguinator/motor_controller",
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rcc_ex.c"
"file": "startup_stm32l432xx.s"
},
{
"arguments": [
@ -936,14 +936,14 @@
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/stm32l4xx_hal_pwr_ex.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_pwr_ex.lst",
"-MFbuild/stm32l4xx_hal_rcc.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_rcc.lst",
"-o",
"build/stm32l4xx_hal_pwr_ex.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_pwr_ex.c"
"build/stm32l4xx_hal_rcc.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rcc.c"
],
"directory": "/storage/Shared/Projects/Penguinator/motor_controller",
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_pwr_ex.c"
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rcc.c"
},
{
"arguments": [
@ -971,13 +971,13 @@
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/stm32l4xx_hal_dma_ex.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_dma_ex.lst",
"-MFbuild/stm32l4xx_hal_i2c_ex.d",
"-Wa,-a,-ad,-alms=build/stm32l4xx_hal_i2c_ex.lst",
"-o",
"build/stm32l4xx_hal_dma_ex.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma_ex.c"
"build/stm32l4xx_hal_i2c_ex.o",
"Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_i2c_ex.c"
],
"directory": "/storage/Shared/Projects/Penguinator/motor_controller",
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma_ex.c"
"file": "Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_i2c_ex.c"
}
]

@ -66,3 +66,286 @@ A debugging session is active.
Quit anyway? (y or n) [answered Y; input not from terminal]
[Inferior 1 (Remote target) detached]
0x080015ea in HAL_TIM_PWM_MspInit (htim_pwm=0x0) at Core/Src/stm32l4xx_hal_msp.c:95
95 __HAL_RCC_TIM2_CLK_ENABLE();
### Assembly ##########################################################################################################
0x080015de HAL_TIM_PWM_MspInit+6 ldr r1, [pc, #88] ; (0x8001638 <HAL_TIM_Base_MspInit+56>)
0x080015e0 HAL_TIM_PWM_MspInit+8 mov r0, r6
0x080015e2 HAL_TIM_PWM_MspInit+10 bl 0x8004048 <HAL_RS485Ex_Init+136>
0x080015e6 HAL_TIM_PWM_MspInit+14 movs r4, #0
0x080015e8 HAL_TIM_PWM_MspInit+16 ldr r3, [pc, #80] ; (0x800163c <HAL_TIM_Base_MspInit+60>)
0x080015ea HAL_TIM_PWM_MspInit+18 ldrb r3, [r3, #0]
0x080015ec HAL_TIM_PWM_MspInit+20 cmp r3, #0
0x080015ee HAL_TIM_PWM_MspInit+22 beq.n 0x80015e8 <HAL_TIM_PWM_MspInit+16>
0x080015f0 HAL_TIM_PWM_MspInit+24 ldr r3, [pc, #72] ; (0x800163c <HAL_TIM_Base_MspInit+60>)
0x080015f2 HAL_TIM_PWM_MspInit+26 movs r2, #0
### Breakpoints #######################################################################################################
### Expressions #######################################################################################################
### History ###########################################################################################################
### Memory ############################################################################################################
### Registers #########################################################################################################
r0 0x00000000 r5 0x200009c8 r10 0x00000000 pc 0x080015ea primask 0x00
r1 0x00000000 r6 0x20000a60 r11 0x00000000 xPSR 0x61000000 basepri 0x00
r2 0x00000001 r7 0x00000000 r12 0x00001000 fpscr 0x20000010 faultmask 0x00
r3 0x200009c4 r8 0x00000000 sp 0x2000fff0 msp 0x2000fff0 control 0x04
r4 0x00000154 r9 0x00000000 lr 0x08002041 psp 0x00000000
### Source ############################################################################################################
85 * @retval None
86 */
87 void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef* htim_pwm)
88 {
89 if(htim_pwm->Instance==TIM2)
90 {
91 /* USER CODE BEGIN TIM2_MspInit 0 */
92
93 /* USER CODE END TIM2_MspInit 0 */
94 /* Peripheral clock enable */
95 __HAL_RCC_TIM2_CLK_ENABLE();
96 /* USER CODE BEGIN TIM2_MspInit 1 */
97
98 /* USER CODE END TIM2_MspInit 1 */
99 }
100
101 }
102
103 /**
104 * @brief TIM_Base MSP Initialization
### Stack #############################################################################################################
[0] from 0x080015ea in HAL_TIM_PWM_MspInit+18 at Core/Src/stm32l4xx_hal_msp.c:95
[1] from 0x08002040 in HAL_TIM_PWM_Stop+72 at Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_tim.c:1533
[2] from 0x00000000
### Threads ###########################################################################################################
[1] id 0 from 0x080015ea in HAL_TIM_PWM_MspInit+18 at Core/Src/stm32l4xx_hal_msp.c:95
### Variables #########################################################################################################
arg htim_pwm = 0x0: {Instance = 0x20010000,Init = {Prescaler = 134234761,CounterMode = 134223429,Period = …
loc tmpreg = 0
#######################################################################################################################
Loading section .isr_vector, size 0x190 lma 0x8000000
Loading section .text, size 0x9678 lma 0x80001c0
Loading section .rodata, size 0x4d8 lma 0x8009838
Loading section .ARM, size 0x8 lma 0x8009d10
Loading section .init_array, size 0x8 lma 0x8009d18
Loading section .fini_array, size 0x8 lma 0x8009d20
Loading section .data, size 0x9a8 lma 0x8009d28
Start address 0x080042d4, load size 42656
Transfer rate: 29 KB/sec, 4739 bytes/write.
Unable to match requested speed 500 kHz, using 480 kHz
Unable to match requested speed 500 kHz, using 480 kHz
A debugging session is active.
Inferior 1 [Remote target] will be detached.
Quit anyway? (y or n) [answered Y; input not from terminal]
[Inferior 1 (Remote target) detached]
0x0800151c in main () at Core/Src/main.c:144
144 if ((pkt = p_serial_mgr_service()) != NULL)
### Assembly ##################################################################
0x0800150e main+154 movs r1, #0
0x08001510 main+156 mov r0, r4
0x08001512 main+158 bl 0x8004370 <memset>
0x08001516 main+162 bl 0x8004298 <p_serial_mgr_service>
0x0800151a main+166 mov r4, r0
0x0800151c main+168 cmp r0, #0
0x0800151e main+170 beq.n 0x8001516 <main+162>
0x08001520 main+172 ldrb r2, [r0, #1]
0x08001522 main+174 ldrb r1, [r0, #0]
0x08001524 main+176 ldr r0, [pc, #48] ; (0x8001558 <main+228>)
### Breakpoints ###############################################################
### Expressions ###############################################################
### History ###################################################################
### Memory ####################################################################
### Registers #################################################################
r0 0x00000000 r8 0x00000000 xPSR 0x61000000
r1 0x00000000 r9 0x00000000 fpscr 0x00000010
r2 0x00000000 r10 0x00000000 msp 0x2000fff0
r3 0x00000000 r11 0x00000000 psp 0x00000000
r4 0x00000000 r12 0x00001000 primask 0x00
r5 0x200009c8 sp 0x2000fff0 basepri 0x00
r6 0x00000000 lr 0x0800151b faultmask 0x00
r7 0x00000000 pc 0x0800151c control 0x04
### Source ####################################################################
134 while (1)
135 {
136 // if (b_timer_struck)
137 // {
138 // // PDEBUG("%d\n", sys_time);
139 // b_timer_struck = false;
140 // motor_degrees = (motor_degrees + 1) % 360;
141 // mc_service(motor_degrees, 50);
142 // }
143 serial_pkt_t *pkt = NULL;
144 if ((pkt = p_serial_mgr_service()) != NULL)
145 {
146 PDEBUG("Source: %02x\n"
147 "Destination: %02x\n",
148 pkt->src_addr, pkt->dest_addr);
149 PDEBUG("Frame Data: \n");
150 for (int ind = 0; ind < pkt->len; pkt++)
151 {
152 if (ind % 8 == 0)
153 {
### Stack #####################################################################
[0] from 0x0800151c in main+168 at Core/Src/main.c:144
### Threads ###################################################################
[1] id 0 from 0x0800151c in main+168 at Core/Src/main.c:144
### Variables #################################################################
loc pkt = 0x0: {src_addr = 0 '\000',dest_addr = 0 '\000',len = 134234837,frame_data = "a\025\000\bc\0…
###############################################################################
Unable to match requested speed 500 kHz, using 480 kHz
Unable to match requested speed 500 kHz, using 480 kHz
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x080042d4 msp: 0x20010000
Loading section .isr_vector, size 0x190 lma 0x8000000
Loading section .text, size 0x9678 lma 0x80001c0
Loading section .rodata, size 0x4d8 lma 0x8009838
Loading section .ARM, size 0x8 lma 0x8009d10
Loading section .init_array, size 0x8 lma 0x8009d18
Loading section .fini_array, size 0x8 lma 0x8009d20
Loading section .data, size 0x9a8 lma 0x8009d28
Start address 0x080042d4, load size 42656
Transfer rate: 29 KB/sec, 4739 bytes/write.
Breakpoint 1 at 0x8001168: file Core/Src/main.c, line 412.
Note: automatically using hardware breakpoints for read-only addresses.
Starting program: /storage/Shared/Projects/Penguinator/motor_controller/build/motor_controller.elf
### Output/messages ###########################################################
Breakpoint 1, UART2_RxCpltCallback (huart=0x20000b14 <huart2>) at Core/Src/main.c:412
412 {
### Assembly ##################################################################
~
~
~
~
~
!0x08001168 UART2_RxCpltCallback+0 push {r4, lr}
0x0800116a UART2_RxCpltCallback+2 ldr r4, [pc, #24] ; (0x8001184 <UART2_RxCpltCallback+28>)
0x0800116c UART2_RxCpltCallback+4 movs r3, #100 ; 0x64
0x0800116e UART2_RxCpltCallback+6 movs r2, #1
0x08001170 UART2_RxCpltCallback+8 mov r1, r4
### Breakpoints ###############################################################
[1] break at 0x08001168 in Core/Src/main.c:412 for /storage/Shared/Projects/Penguinator/motor_controller/Core/Src/main.c:411 hit 1 time
### Expressions ###############################################################
### History ###################################################################
### Memory ####################################################################
### Registers #################################################################
r0 0x20000b14 r8 0x00000000 xPSR 0x81000036
r1 0x00000000 r9 0x00000000 fpscr 0x00000010
r2 0x40004408 r10 0x00000000 msp 0x2000ff68
r3 0x08001169 r11 0x00000000 psp 0x00000000
r4 0x20000b14 r12 0x00001000 primask 0x00
r5 0x00000001 sp 0x2000ff68 basepri 0x00
r6 0x00000000 lr 0x0800348b faultmask 0x00
r7 0x00000000 pc 0x08001168 control 0x00
### Source ####################################################################
402 GPIO_InitStruct.Pin = m1_dir_Pin | m2_dir_Pin;
403 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
404 GPIO_InitStruct.Pull = GPIO_NOPULL;
405 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
406 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
407 }
408
409 /* USER CODE BEGIN 4 */
410
411 void UART2_RxCpltCallback(UART_HandleTypeDef *huart)
!412 {
413 HAL_UART_Transmit(&huart1, &huart2_rxc, 1, 100);
414 HAL_UART_Receive_IT(&huart2, &huart2_rxc, 1);
415 }
416 // void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
417 // {
418 // else if (huart == &huart2)
419 // {
420 // }
421 // }
### Stack #####################################################################
[0] from 0x08001168 in UART2_RxCpltCallback+0 at Core/Src/main.c:412
[1] from 0x0800348a in UART_RxISR_8BIT+130 at Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_uart.c:4430
[2] from 0x080035dc in HAL_UART_IRQHandler+108 at Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_uart.c:2347
[3] from 0x08001590 in USART2_IRQHandler+8 at Core/Src/stm32l4xx_it.c:225
[4] from 0xffffffe9
[5] from 0x080042a2 in p_serial_mgr_service+10 at shared/drivers/p_serial_mgr.c:143
[6] from 0x0800151a in main+166 at Core/Src/main.c:144
### Threads ###################################################################
[1] id 0 from 0x08001168 in UART2_RxCpltCallback+0 at Core/Src/main.c:412
### Variables #################################################################
arg huart = 0x20000b14 <huart2>: {Instance = 0x40004400,Init = {BaudRate = 115200,WordLength = 0,StopBi…
###############################################################################
Detaching from program: /storage/Shared/Projects/Penguinator/motor_controller/build/motor_controller.elf, Remote target
[Inferior 1 (Remote target) detached]
UART2_RxCpltCallback (huart=0x20000b14 <huart2>) at Core/Src/main.c:412
412 {
### Assembly ##################################################################
~
~
~
~
~
0x08001168 UART2_RxCpltCallback+0 push {r4, lr}
0x0800116a UART2_RxCpltCallback+2 ldr r4, [pc, #24] ; (0x8001184 <UART2_RxCpltCallback+28>)
0x0800116c UART2_RxCpltCallback+4 movs r3, #100 ; 0x64
0x0800116e UART2_RxCpltCallback+6 movs r2, #1
0x08001170 UART2_RxCpltCallback+8 mov r1, r4
### Breakpoints ###############################################################
### Expressions ###############################################################
### History ###################################################################
### Memory ####################################################################
### Registers #################################################################
r0 0x20000b14 r8 0x00000000 xPSR 0x81000036
r1 0x00000000 r9 0x00000000 fpscr 0x00000010
r2 0x40004408 r10 0x00000000 msp 0x2000ff68
r3 0x08001169 r11 0x00000000 psp 0x00000000
r4 0x20000b14 r12 0x00001000 primask 0x00
r5 0x00000001 sp 0x2000ff68 basepri 0x00
r6 0x00000000 lr 0x0800348b faultmask 0x00
r7 0x00000000 pc 0x08001168 control 0x00
### Source ####################################################################
402 GPIO_InitStruct.Pin = m1_dir_Pin | m2_dir_Pin;
403 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
404 GPIO_InitStruct.Pull = GPIO_NOPULL;
405 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
406 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
407 }
408
409 /* USER CODE BEGIN 4 */
410
411 void UART2_RxCpltCallback(UART_HandleTypeDef *huart)
412 {
413 HAL_UART_Transmit(&huart1, &huart2_rxc, 1, 100);
414 HAL_UART_Receive_IT(&huart2, &huart2_rxc, 1);
415 }
416 // void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
417 // {
418 // else if (huart == &huart2)
419 // {
420 // }
421 // }
### Stack #####################################################################
[0] from 0x08001168 in UART2_RxCpltCallback+0 at Core/Src/main.c:412
[1] from 0x0800348a in UART_RxISR_8BIT+130 at Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_uart.c:4430
[2] from 0x080035dc in HAL_UART_IRQHandler+108 at Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_uart.c:2347
[3] from 0x08001590 in USART2_IRQHandler+8 at Core/Src/stm32l4xx_it.c:225
[4] from 0xffffffe9
[5] from 0x080042a2 in p_serial_mgr_service+10 at shared/drivers/p_serial_mgr.c:143
[6] from 0x0800151a in main+166 at Core/Src/main.c:144
### Threads ###################################################################
[1] id 0 from 0x08001168 in UART2_RxCpltCallback+0 at Core/Src/main.c:412
### Variables #################################################################
arg huart = 0x20000b14 <huart2>: {Instance = 0x40004400,Init = {BaudRate = 115200,WordLength = 0,StopBi…
###############################################################################
Loading section .isr_vector, size 0x190 lma 0x8000000
Loading section .text, size 0x9678 lma 0x80001c0
Loading section .rodata, size 0x4d8 lma 0x8009838
Loading section .ARM, size 0x8 lma 0x8009d10
Loading section .init_array, size 0x8 lma 0x8009d18
Loading section .fini_array, size 0x8 lma 0x8009d20
Loading section .data, size 0x9a8 lma 0x8009d28
Start address 0x080042d4, load size 42656
Transfer rate: 29 KB/sec, 4739 bytes/write.
Unable to match requested speed 500 kHz, using 480 kHz
Unable to match requested speed 500 kHz, using 480 kHz
A debugging session is active.
Inferior 1 [Remote target] will be detached.
Quit anyway? (y or n) [answered Y; input not from terminal]
[Inferior 1 (Remote target) detached]

@ -1,15 +1,127 @@
#include "p_serial_mgr.h"
#include "PCircularBuffer.h"
#define MAX_SERIAL_BUFFER_SIZE (256)
static uint8_t buffer[MAX_SERIAL_BUFFER_SIZE];
static p_cb_u8 serial_cb;
#include "putil.h"
#include "stm32l4xx_hal_uart.h"
#define MAX_SERIAL_BUFFER_SIZE (262) // Actually 261, add 1 for padding
// this protocol is very similar to the digi api v2 (inspired from)
// [0]{1} Start delimiter 0x7E
// [1]{1} Source Address
// [2]{1} Destination Address
// [3]{1} Length Byte
// [4-n]{n} frame data
// [n+1]{1} checksum
// Escape bytes are 0x7D, only frame data can be escaped
// Escaped bytes are followed by the byte to be escaped XOR'd with 0x20
// 0x7D and 0x7E need to be escaped (within the frame data)
typedef enum serial_state_t
{
SS_IDLE = 0, // waiting
SS_START = 1, // get start byte, interrupt after 4 more bytes
SS_FRAME = 2, // get byte
SS_ESC = 3, // get byte, dont increment number left
SS_CHECKSUM = 4 // done
} serial_state_t;
static UART_HandleTypeDef *_serial_huart_inst = NULL;
static uint8_t serial_cb_rxc = '\0';
static serial_state_t sstate = SS_IDLE;
static uint8_t rxc = '\0';
static serial_pkt_t pkt_bank[10];
static p_cb_serial_pkt_t serial_pkt_cb;
static volatile uint8_t start_index_tracker = 0;
static volatile uint8_t frame_index_tracker = 0;
#pragma message(Reminder "Move away from cirular buffer to a managed queue")
void UART1_RxCpltCallback(UART_HandleTypeDef *huart)
{
serial_cb.push(&serial_cb, serial_cb_rxc);
switch (sstate)
{
case SS_IDLE: // packet start
{
if (rxc == 0x7E)
{
sstate = SS_START;
}
}
break;
case SS_START:
{
switch (start_index_tracker)
{
case 0: // source addr
{
serial_pkt_cb.buffer[serial_pkt_cb.head].src_addr = rxc;
}
break;
case 1:
{
serial_pkt_cb.buffer[serial_pkt_cb.head].dest_addr = rxc;
}
break;
case 2:
{
serial_pkt_cb.buffer[serial_pkt_cb.head].len = rxc;
frame_index_tracker = 0;
sstate = SS_FRAME;
}
break;
default:
{
// shouldnt get here
for (;;) {}
}
};
}
break;
case SS_FRAME:
{
if (rxc == 0x7E)
{
// error occured. bail
#pragma message(Reminder "add a safe escape routine for this")
}
else if (rxc == 0x7D)
{
sstate = SS_ESC;
}
else
{
serial_pkt_cb.buffer[serial_pkt_cb.head].frame_data[frame_index_tracker++] = rxc;
if (frame_index_tracker + 1 == serial_pkt_cb.buffer[serial_pkt_cb.head].len)
{
sstate = SS_CHECKSUM;
}
}
}
break;
case SS_ESC:
{
serial_pkt_cb.buffer[serial_pkt_cb.head].frame_data[frame_index_tracker++] = rxc ^ 0x20;
if (frame_index_tracker + 1 == serial_pkt_cb.buffer[serial_pkt_cb.head].len)
{
sstate = SS_CHECKSUM;
}
}
break;
case SS_CHECKSUM:
{
serial_pkt_cb.buffer[serial_pkt_cb.head].checksum = rxc;
serial_pkt_cb.buffer[serial_pkt_cb.head].b_ready = true;
serial_pkt_cb.head = (serial_pkt_cb.head + 1) % serial_pkt_cb.max_len;
}
break;
default:
{
PDEBUG("Shouldn't have hit this!\n");
}
};
HAL_UART_Receive_IT(_serial_huart_inst, &rxc, 1);
// serial_cb.push(&serial_cb, serial_cb_rxc);
// HAL_GPIO_WritePin(USART1_DE_GPIO_Port, USART1_DE_Pin, 1);
// huart2_rxc = huart1_rxc;
@ -22,15 +134,23 @@ void p_serial_mgr_init(UART_HandleTypeDef *huart)
_serial_huart_inst = huart;
_serial_huart_inst->RxCpltCallback = UART1_RxCpltCallback;
memset(buffer, 0, MAX_SERIAL_BUFFER_SIZE);
p_cb_u8_init(&serial_cb, buffer, MAX_SERIAL_BUFFER_SIZE);
p_cb_serial_pkt_init(&serial_pkt_cb, pkt_bank, 10);
}
void p_serial_mgr_service(void)
serial_pkt_t *p_serial_mgr_service(void)
{
// this will be less garbage when i switch to a queue
for (int ind = 0; ind < serial_pkt_cb.max_len; ind++)
{
if (serial_pkt_cb.buffer[ind].b_ready)
{
return &serial_pkt_cb.buffer;
}
}
return NULL;
}
void p_serial_mgr_start()
{
HAL_UART_Receive_IT(_serial_huart_inst, &serial_cb_rxc, 1);
HAL_UART_Receive_IT(_serial_huart_inst, &rxc, 1);
}

@ -2,8 +2,20 @@
#define _P_SERIAL_MGR_H_
#include "stm32l4xx_hal.h"
#include <stdbool.h>
typedef struct serial_pkt_t
{
uint8_t src_addr;
uint8_t dest_addr;
int len;
uint8_t frame_data[256];
uint8_t checksum;
bool b_ready;
} serial_pkt_t;
void p_serial_mgr_init(UART_HandleTypeDef *huart);
void p_serial_mgr_service(void);
serial_pkt_t *p_serial_mgr_service(void);
#endif

@ -1,3 +1,4 @@
#include "putil.h"
#include <PCircularBuffer.h>
// Error handler used for debugging only
@ -7,73 +8,20 @@ static void handle_status(const char *func, PB_CB_STATUS status_code)
{
if (status_code != PB_CB_GOOD)
{
printf("%s failed: error code: %d\r\n", func, status_code);
PDEBUG("%s failed: error code: %d\r\n", func, status_code);
}
}
#endif
// Circular Buffer Prototypes -- uint8_t
#if PB_CB_U8
static PB_CB_STATUS p_cb_u8_push(p_cb_u8 *cbuffer, uint8_t value);
static PB_CB_STATUS p_cb_u8_empty(p_cb_u8 *cbuffer);
#endif
// Circular Buffer Prototypes -- uint16_t
#if PB_CB_U16
static PB_CB_STATUS p_cb_u16_push(p_cb_double *cbuffer, uint16_t value);
static PB_CB_STATUS p_cb_u16_empty(p_cb_double *cbuffer);
#endif
// Circular Buffer Prototypes -- uint32_t
#if PB_CB_U32
static PB_CB_STATUS p_cb_u32_push(p_cb_double *cbuffer, uint32_t value);
static PB_CB_STATUS p_cb_u32_empty(p_cb_double *cbuffer);
#endif
// Circular Buffer Prototypes -- uint64_t
#if PB_CB_U64
static PB_CB_STATUS p_cb_u64_push(p_cb_double *cbuffer, uint64_t value);
static PB_CB_STATUS p_cb_u64_empty(p_cb_double *cbuffer);
#endif
// Circular Buffer Prototypes -- int8_t
#if PB_CB_I8
static PB_CB_STATUS p_cb_i8_push(p_cb_double *cbuffer, int8_t value);
static PB_CB_STATUS p_cb_i8_empty(p_cb_double *cbuffer);
#endif
// Circular Buffer Prototypes -- int16_t
#if PB_CB_I16
static PB_CB_STATUS p_cb_i16_push(p_cb_double *cbuffer, int16_t value);
static PB_CB_STATUS p_cb_i16_empty(p_cb_double *cbuffer);
#endif
// Circular Buffer Prototypes -- int32_t
#if PB_CB_I32
static PB_CB_STATUS p_cb_i32_push(p_cb_double *cbuffer, int32_t value);
static PB_CB_STATUS p_cb_i32_empty(p_cb_double *cbuffer);
#endif
// Circular Buffer Prototypes -- int64_t
#if PB_CB_I64
static PB_CB_STATUS p_cb_i64_push(p_cb_double *cbuffer, int64_t value);
static PB_CB_STATUS p_cb_i64_empty(p_cb_double *cbuffer);
#endif
// Circular Buffer Prototypes -- Float
#if PB_CB_FLOAT
static PB_CB_STATUS p_cb_float_push(p_cb_double *cbuffer, float value);
static PB_CB_STATUS p_cb_float_empty(p_cb_double *cbuffer);
#endif
// Circular Buffer Prototypes -- Double
#if PB_CB_DOUBLE
static PB_CB_STATUS p_cb_double_push(p_cb_double *cbuffer, double value);
static PB_CB_STATUS p_cb_double_empty(p_cb_double *cbuffer);
#endif
// serial_pkt
static PB_CB_STATUS p_cb_serial_pkt_push(p_cb_serial_pkt_t *cbuffer, serial_pkt_t value);
static PB_CB_STATUS p_cb_serial_pkt_empty(p_cb_serial_pkt_t *cbuffer);
// Circular Buffer Definitions -- uint8_t
#if PB_CB_U8
PB_CB_STATUS p_cb_u8_init(p_cb_u8 *circ_buffer, uint8_t *buff, uint32_t max_length)
{
PB_CB_STATUS ret = PB_CB_GOOD;
@ -123,6 +71,7 @@ PB_CB_STATUS p_cb_u8_push(p_cb_u8 *cbuffer, uint8_t value)
return ret;
}
PB_CB_STATUS p_cb_u8_empty(p_cb_u8 *cbuffer)
{
PB_CB_STATUS ret = PB_CB_GOOD;
@ -153,214 +102,9 @@ PB_CB_STATUS p_cb_u8_empty(p_cb_u8 *cbuffer)
return ret;
}
#endif
// Circular Buffer Definitions -- uint16_t
#if PB_CB_U16
PB_CB_STATUS p_cb_u16_init(p_cb_u16 *circ_buffer, uint16_t *buff, uint32_t max_length)
{
PB_CB_STATUS ret = PB_CB_GOOD;
do
{
// Make sure the buffer isn't bad (null)
if (!buff)
{
ret = PB_CB_NULL_BUFFER;
break;
}
// Make sure the max buffer is a useable size
if (max_length > PB_CB_MAX_BUFFER_SIZE || max_length <= 0)
{
ret = PB_CB_BAD_BUFFER_SIZE;
break;
}
} while (0);
// Debugging
#ifdef PB_CB_DEBUG
handle_status(__func__, ret);
#endif
return ret;
}
PB_CB_STATUS p_cb_u16_push(p_cb_double *cbuffer, uint16_t value)
{
PB_CB_STATUS ret = PB_CB_GOOD;
// Debugging
#ifdef PB_CB_DEBUG
handle_status(__func__, ret);
#endif
return ret;
}
PB_CB_STATUS p_cb_u16_empty(p_cb_double *cbuffer)
{
PB_CB_STATUS ret = PB_CB_GOOD;
// Debugging
#ifdef PB_CB_DEBUG
handle_status(__func__, ret);
#endif
return ret;
}
#endif
// Circular Buffer Definitions -- uint32_t
#if PB_CB_U32
PB_CB_STATUS p_cb_u32_init(p_cb_u32 *circ_buffer, uint32_t *buff, uint32_t max_length)
{
PB_CB_STATUS ret = PB_CB_GOOD;
do
{
// Make sure the buffer isn't bad (null)
if (!buff)
{
ret = PB_CB_NULL_BUFFER;
break;
}
// Make sure the max buffer is a useable size
if (max_length > PB_CB_MAX_BUFFER_SIZE || max_length <= 0)
{
ret = PB_CB_BAD_BUFFER_SIZE;
break;
}
} while (0);
// Debugging
#ifdef PB_CB_DEBUG
handle_status(__func__, ret);
#endif
return ret;
}
PB_CB_STATUS p_cb_u32_push(p_cb_double *cbuffer, uint32_t value)
{
PB_CB_STATUS ret = PB_CB_GOOD;
// Debugging
#ifdef PB_CB_DEBUG
handle_status(__func__, ret);
#endif
return ret;
}
PB_CB_STATUS p_cb_u32_empty(p_cb_double *cbuffer)
{
PB_CB_STATUS ret = PB_CB_GOOD;
// Debugging
#ifdef PB_CB_DEBUG
handle_status(__func__, ret);
#endif
return ret;
}
#endif
// Circular Buffer Definitions -- uint64_t
#if PB_CB_U64
PB_CB_STATUS p_cb_u64_init(p_cb_u64 *circ_buffer, uint64_t *buff, uint32_t max_length)
{
PB_CB_STATUS ret = PB_CB_GOOD;
do
{
// Make sure the buffer isn't bad (null)
if (!buff)
{
ret = PB_CB_NULL_BUFFER;
break;
}
// Make sure the max buffer is a useable size
if (max_length > PB_CB_MAX_BUFFER_SIZE || max_length <= 0)
{
ret = PB_CB_BAD_BUFFER_SIZE;
break;
}
} while (0);
// Debugging
#ifdef PB_CB_DEBUG
handle_status(__func__, ret);
#endif
return ret;
}
PB_CB_STATUS p_cb_u64_push(p_cb_double *cbuffer, uint64_t value)
{
PB_CB_STATUS ret = PB_CB_GOOD;
// Debugging
#ifdef PB_CB_DEBUG
handle_status(__func__, ret);
#endif
return ret;
}
PB_CB_STATUS p_cb_u64_empty(p_cb_double *cbuffer)
{
PB_CB_STATUS ret = PB_CB_GOOD;
// Debugging
#ifdef PB_CB_DEBUG
handle_status(__func__, ret);
#endif
return ret;
}
#endif
#if PB_CB_FLOAT
PB_CB_STATUS p_cb_float_init(p_cb_float *circ_buffer, float *buff, uint32_t max_length)
{
PB_CB_STATUS ret = PB_CB_GOOD;
do
{
// Make sure the buffer isn't bad (null)
if (!buff)
{
ret = PB_CB_NULL_BUFFER;
break;
}
// Make sure the max buffer is a useable size
if (max_length > PB_CB_MAX_BUFFER_SIZE || max_length <= 0)
{
ret = PB_CB_BAD_BUFFER_SIZE;
break;
}
} while (0);
// Debugging
#ifdef PB_CB_DEBUG
handle_status(__func__, ret);
#endif
return ret;
}
PB_CB_STATUS p_cb_float_push(p_cb_double *cbuffer, float value)
{
PB_CB_STATUS ret = PB_CB_GOOD;
// Debugging
#ifdef PB_CB_DEBUG
handle_status(__func__, ret);
#endif
return ret;
}
PB_CB_STATUS p_cb_float_empty(p_cb_double *cbuffer)
{
PB_CB_STATUS ret = PB_CB_GOOD;
// Debugging
#ifdef PB_CB_DEBUG
handle_status(__func__, ret);
#endif
return ret;
}
#endif
// Circular Buffer Definitions -- double
#if PB_CB_DOUBLE
PB_CB_STATUS p_cb_double_init(p_cb_double *circ_buffer, double *buff, uint32_t max_length)
// Circular Buffer Definitions -- uint8_t
PB_CB_STATUS p_cb_serial_pkt_init(p_cb_serial_pkt_t *inst, serial_pkt_t *buff, uint32_t max_length)
{
PB_CB_STATUS ret = PB_CB_GOOD;
do
@ -378,12 +122,6 @@ PB_CB_STATUS p_cb_double_init(p_cb_double *circ_buffer, double *buff, uint32_t m
ret = PB_CB_BAD_BUFFER_SIZE;
break;
}
circ_buffer->buffer = buff;
circ_buffer->max_len = (uint16_t)max_length;
circ_buffer->head = 0;
circ_buffer->push = p_cb_double_push;
circ_buffer->empty = p_cb_double_empty;
circ_buffer->empty(circ_buffer);
} while (0);
// Debugging
@ -394,7 +132,7 @@ PB_CB_STATUS p_cb_double_init(p_cb_double *circ_buffer, double *buff, uint32_t m
return ret;
}
PB_CB_STATUS p_cb_double_push(p_cb_double *cbuffer, double value)
PB_CB_STATUS p_cb_serial_pkt_push(p_cb_serial_pkt_t *cbuffer, serial_pkt_t value)
{
PB_CB_STATUS ret = PB_CB_GOOD;
@ -415,7 +153,8 @@ PB_CB_STATUS p_cb_double_push(p_cb_double *cbuffer, double value)
return ret;
}
PB_CB_STATUS p_cb_double_empty(p_cb_double *cbuffer)
PB_CB_STATUS p_cb_serial_pkt_empty(p_cb_serial_pkt_t *cbuffer)
{
PB_CB_STATUS ret = PB_CB_GOOD;
@ -432,7 +171,7 @@ PB_CB_STATUS p_cb_double_empty(p_cb_double *cbuffer)
ret = PB_CB_NULL_BUFFER;
break;
}
memset(cbuffer->buffer, 0, sizeof(double) * cbuffer->max_len);
memset(cbuffer->buffer, 0, sizeof(serial_pkt_t) * cbuffer->max_len);
cbuffer->head = 0;
cbuffer->b_empty = true;
cbuffer->b_filled = false;
@ -445,4 +184,3 @@ PB_CB_STATUS p_cb_double_empty(p_cb_double *cbuffer)
return ret;
}
#endif

@ -31,43 +31,18 @@
#ifndef _PCIRCULARBUFFER_H_
#define _PCIRCULARBUFFER_H_
#include "p_serial_mgr.h"
#include <stdbool.h>
#include <stdint.h>
// comment this out for release builds
//#define PB_CB_DEBUG
// Making these PB_EN/DIS rather than just ENABLE/DISABLE because
// some enable/disable definition might already exist that is
// inversely active (enabled = 0, disable = 1)
// this way our en/dis definitions are explicit
#ifndef PB_ENABLE
#define PB_ENABLE (1)
#endif
#ifndef PB_DISABLE
#define PB_DISABLE (0)
#ifdef _DEBUG
#define PC_CB_DEBUG
#endif
// Max size is 65535 (2^16 - 1) so variables can be safely set 16 bits (unsigned)
// If you want to change this, you'll need to change the sizes of all heads and max lengths
#define PB_CB_MAX_BUFFER_SIZE (65535)
// Config
// Disable or Enable types needed here
// We can save code size this way
// While there are better ways to do this, this is the most accessible for anyone imo
#define PB_CB_FLOAT PB_DISABLE
#define PB_CB_DOUBLE PB_DISABLE
#define PB_CB_U8 PB_ENABLE
#define PB_CB_U16 PB_DISABLE
#define PB_CB_U32 PB_DISABLE
#define PB_CB_U64 PB_DISABLE
#define PB_CB_I8 PB_DISABLE
#define PB_CB_I16 PB_DISABLE
#define PB_CB_I32 PB_DISABLE
#define PB_CB_I64 PB_DISABLE
typedef enum PB_CB_STATUS
{
PB_CB_GOOD = 0,
@ -77,7 +52,6 @@ typedef enum PB_CB_STATUS
PB_CB_NULL_CBUFFER = 4
} PB_CB_STATUS;
#if PB_CB_U8
typedef struct p_cb_u8
{
uint8_t *buffer;
@ -95,106 +69,20 @@ typedef struct p_cb_u8
} p_cb_u8;
PB_CB_STATUS p_cb_u8_init(p_cb_u8 *circ_buffer, uint8_t *buff, uint32_t max_length);
#endif
#if PB_CB_U16
typedef struct p_cb_u16
{
uint16_t *buffer;
uint16_t head;
uint16_t max_len;
// Signifies the buffer being filled at least once.
// Useful for initializing sensor data
bool b_filled;
// Signifies the buffer being empty
// Useful for knowing if data is being received
bool b_empty;
PB_CB_STATUS (*push)(struct p_cb_u16 *cbuffer, uint16_t value);
PB_CB_STATUS (*empty)(struct p_cb_u16 *cbuffer);
} p_cb_u16;
PB_CB_STATUS p_cb_u16_init(p_cb_u16 *circ_buffer, uint16_t *buff, uint32_t max_length);
#endif
#if PB_CB_U32
typedef struct p_cb_u32
typedef struct p_cb_serial_pkt_t
{
uint32_t *buffer;
serial_pkt_t *buffer;
uint16_t head;
uint16_t max_len;
// Signifies the buffer being filled at least once.
// Useful for initializing sensor data
bool b_filled;
// Signifies the buffer being empty
// Useful for knowing if data is being received
bool b_empty;
PB_CB_STATUS (*push)(struct p_cb_u32 *cbuffer, uint32_t value);
PB_CB_STATUS (*empty)(struct p_cb_u32 *cbuffer);
} p_cb_u32;
PB_CB_STATUS p_cb_u32_init(p_cb_u32 *circ_buffer, uint32_t *buff, uint32_t max_length);
#endif
#if PB_CB_U64
typedef struct p_cb_u64
{
uint64_t *buffer;
uint16_t head;
uint16_t max_len;
// Signifies the buffer being filled at least once.
// Useful for initializing sensor data
bool b_filled;
// Signifies the buffer being empty
// Useful for knowing if data is being received
bool b_empty;
PB_CB_STATUS (*push)(struct p_cb_u64 *cbuffer, uint64_t value);
PB_CB_STATUS (*empty)(struct p_cb_u64 *cbuffer);
} p_cb_u64;
PB_CB_STATUS p_cb_u64_init(p_cb_u64 *circ_buffer, uint64_t *buff, uint32_t max_length);
#endif
#if PB_CB_FLOAT
typedef struct p_cb_float
{
float *buffer;
uint16_t head;
uint16_t max_len;
// Signifies the buffer being filled at least once.
// Useful for initializing sensor data
bool b_filled;
// Signifies the buffer being empty
// Useful for knowing if data is being received
bool b_empty;
PB_CB_STATUS (*push)(struct p_cb_float *cbuffer, float value);
PB_CB_STATUS (*empty)(struct p_cb_float *cbuffer);
} p_cb_float;
PB_CB_STATUS p_cb_float_init(p_cb_float *circ_buffer, float *buff, uint32_t max_length);
#endif
#if PB_CB_DOUBLE
typedef struct p_cb_double
{
double *buffer;
uint16_t head;
uint16_t max_len;
// Signifies the buffer being filled at least once.
// Useful for initializing sensor data
bool b_filled;
// Signifies the buffer being empty
// Useful for knowing if data is being received
bool b_empty;
PB_CB_STATUS (*push)(struct p_cb_double *cbuffer, double value);
PB_CB_STATUS (*empty)(struct p_cb_double *cbuffer);
} p_cb_double;
PB_CB_STATUS p_cb_double_init(p_cb_double *circ_buffer, double *buff, uint32_t max_length);
#endif
PB_CB_STATUS (*push)(struct p_cb_u8 *cbuffer, uint8_t value);
PB_CB_STATUS (*empty)(struct p_cb_u8 *cbuffer);
} p_cb_serial_pkt_t;
PB_CB_STATUS p_cb_serial_pkt_init(p_cb_serial_pkt_t *inst, serial_pkt_t *buff, uint32_t max_length);
#endif

@ -6,6 +6,11 @@
int p_printf(const char *fmt, ...);
void p_uart_init(UART_HandleTypeDef *huart);
#define Stringize(L) #L
#define MakeString(M, L) M(L)
#define $Line MakeString(Stringize, __LINE__)
#define Reminder __FILE__ "(" $Line ") : Reminder: "
#ifdef _DEBUG
#define PDEBUG(f_, ...) p_printf((f_), ##__VA_ARGS__)
#else

Loading…
Cancel
Save