partially fixed issue where motor controller was seeing a chirp on the RX line, causing some start bytes to be seen as a combination of the start byte and the src addr byte. Only partially fixed because the buffer stream is still skipped occasionally. Its just not due to that issue. The issue was fixed by driving the max485 chips with 5v at vcc instead of 3.3

stable
Penguin 3 years ago
parent 1ee7e71711
commit 25d46974e3

@ -1,96 +1,3 @@
b p_serial_mgr.c:113
r
q
q
b p_serial_mgr.c:119
r
q
b p_serial_mgr.c:87
r
p serial_pkt_cb.buffer[serial_pkt_cb.head]
q
b p_serial_mgr.c:87
r
b p_serial_mgr.c:122
r
q
q
b p_serial_mgr.c:100 if frame_index_tracker > 5
r
b p_serial_mgr.c:100 if frame_index_tracker > 0
r
q
b p_serial_mgr.c:79
r
b p_serial_mgr.c:100 if frame_index_tracker > 5
r
r
b p_serial_mgr.c:110 if frame_index_tracker > 5
r
del
b p_serial_mgr.c:79
r
del
b p_serial_mgr.c:86
r
p rxc
p serial_pkt_cb.buffer[serial_pkt_cb.head]
p serial_pkt_cb.buffer[serial_pkt_cb.head].frame_data
p/x serial_pkt_cb.buffer[serial_pkt_cb.head].frame_data
q
b p_serial_mgr.c:86
r
p rxc
p serial_pkt_cb.buffer[serial_pkt_cb.head]
p/x serial_pkt_cb.buffer[serial_pkt_cb.head].frame_data
q
b p_serial_mgr.c:86
r
p/x serial_pkt_cb.buffer[serial_pkt_cb.head].frame_data
p/x serial_pkt_cb.buffer
p\ serial_pkt_cb.buffer
p\ serial_pkt_cb.buffer
p\serial_pkt_cb.buffer
pserial_pkt_cb.buffer
p serial_pkt_cb.buffer
p serial_pkt_cb.buffer[0]
p/x serial_pkt_cb.buffer[0]
q
b p_serial_mgr.c:44
r
p serial_pkt_cb.head
p serial_pkt_cb.buffer[serial_pkt_cb.head]
p/x serial_pkt_cb.buffer[serial_pkt_cb.head]
p sizeof(serial_pkt_t)
q
b p_serial_mgr.c:44
r
p sizeof(serial_pkt_t)
c
c
r
make
r
c
r
p sizeof(serial_pkt_t)
p/x serial_pkt_cb.buffer[serial_pkt_cb.head]
make
r
p/x serial_pkt_cb.buffer[serial_pkt_cb.head]
c
r
c
del
q
q
b p_serial_mgr.c:43 if rxc == 0x7D
r
make -j20
load
r
make -j20
load
r
del
b p_serial_mgr.c:44
@ -254,3 +161,96 @@ n
p ret
make clean
q
b main.c:138
r
s
n
s
s
b p_serial_mgr.c:45
del 0
del
b p_serial_mgr.c:45
r
s
s
s
p sstate
make
load
r
s
s
s
p sstate
b p_serial_mgr.c:45 if (sstate == SS_START)
del 3
r
b p_serial_mgr.c:30
r
c
p rxc
make
load
r
q
b p_serial_mgr.c:47 if sstate == SS_START
r
b p_serial_mgr.c:30
r
p rxb[0]
c
p rxb[0]
p huart
p *huart
make
load
r
del
b p_serial_mgr.c:30
r
p rxb
p/x *rxb@10
p/x *rxb@10
c
q
b p_serial_mgr.c:35
r
q
b p_serial_mgr.c:35
r
s
q
b p_serial_mgr.c:35
r
p/x *q
q
b p_serial_mgr.c:35
r
p/x *sbuffer[active_buffer]@24
r
b p_serial_mgr.c:35
r
q
b p_serial_mgr.c:35
r
p/x *sbuffer[active_buffer]@24
c
q
b p_serial_mgr.c:35
r
qq
q
b p_serial_mgr.c:35
r
p sstate
c
b p_serial_mgr.c:35
c
make
load
r
p sbuffer[active_buffer][0]
c
p sbuffer[active_buffer][0]
q

@ -55,6 +55,7 @@ void SVC_Handler(void);
void DebugMon_Handler(void);
void PendSV_Handler(void);
void SysTick_Handler(void);
void DMA1_Channel5_IRQHandler(void);
void USART1_IRQHandler(void);
void USART2_IRQHandler(void);
void TIM6_DAC_IRQHandler(void);

@ -50,6 +50,7 @@ TIM_HandleTypeDef htim6;
UART_HandleTypeDef huart1;
UART_HandleTypeDef huart2;
DMA_HandleTypeDef hdma_usart1_rx;
/* USER CODE BEGIN PV */
volatile uint8_t huart2_rxc;
@ -64,8 +65,9 @@ void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_TIM2_Init(void);
static void MX_USART2_UART_Init(void);
static void MX_TIM6_Init(void);
static void MX_DMA_Init(void);
static void MX_USART1_UART_Init(void);
static void MX_TIM6_Init(void);
/* USER CODE BEGIN PFP */
static void UART2_RxCpltCallback(UART_HandleTypeDef *huart);
@ -106,8 +108,9 @@ int main(void)
MX_GPIO_Init();
MX_TIM2_Init();
MX_USART2_UART_Init();
MX_TIM6_Init();
MX_DMA_Init();
MX_USART1_UART_Init();
MX_TIM6_Init();
/* USER CODE BEGIN 2 */
huart2.RxCpltCallback = UART2_RxCpltCallback;
@ -116,15 +119,15 @@ int main(void)
// HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_2);
// HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_4);
setPWM(&htim2, TIM_CHANNEL_2, 50);
setPWM(&htim2, TIM_CHANNEL_4, 25);
// setPWM(&htim2, TIM_CHANNEL_2, 50);
// setPWM(&htim2, TIM_CHANNEL_4, 25);
HAL_GPIO_WritePin(m1_dir_GPIO_Port, m1_dir_Pin, 1);
HAL_GPIO_WritePin(m2_dir_GPIO_Port, m2_dir_Pin, 1);
mc_init(&htim2);
// mc_init(&htim2);
HAL_UART_Receive_IT(&huart2, &huart2_rxc, 1);
HAL_TIM_Base_Start_IT(&htim6);
// HAL_TIM_Base_Start_IT(&htim6);
p_serial_mgr_start();
@ -133,22 +136,9 @@ int main(void)
/* Infinite loop */
/* USER CODE BEGIN WHILE */
uint8_t rxb[256] = {0};
while (1)
{
if (p_serial_mgr_service())
{
volatile HAL_StatusTypeDef ret;
ret = HAL_UART_Receive(&huart1, rxb, 256, 5);
for (int ind = 0; ind < 20; ind++)
{
p_uart_async_write_byte(rxb[ind]);
}
PDEBUG("\n\n\n\n");
memset(rxb, 0, 256);
p_serial_mgr_start();
}
p_serial_mgr_service();
// if (b_timer_struck)
// {
// // PDEBUG("%d\n", sys_time);
@ -398,6 +388,21 @@ static void MX_USART2_UART_Init(void)
/* USER CODE END USART2_Init 2 */
}
/**
* Enable DMA controller clock
*/
static void MX_DMA_Init(void)
{
/* DMA controller clock enable */
__HAL_RCC_DMA1_CLK_ENABLE();
/* DMA interrupt init */
/* DMA1_Channel5_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DMA1_Channel5_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(DMA1_Channel5_IRQn);
}
/**
* @brief GPIO Initialization Function
* @param None

@ -23,6 +23,7 @@
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
extern DMA_HandleTypeDef hdma_usart1_rx;
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN TD */
@ -240,6 +241,24 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart)
GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* USART1 DMA Init */
/* USART1_RX Init */
hdma_usart1_rx.Instance = DMA1_Channel5;
hdma_usart1_rx.Init.Request = DMA_REQUEST_2;
hdma_usart1_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
hdma_usart1_rx.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_usart1_rx.Init.MemInc = DMA_MINC_ENABLE;
hdma_usart1_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
hdma_usart1_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
hdma_usart1_rx.Init.Mode = DMA_NORMAL;
hdma_usart1_rx.Init.Priority = DMA_PRIORITY_LOW;
if (HAL_DMA_Init(&hdma_usart1_rx) != HAL_OK)
{
Error_Handler();
}
__HAL_LINKDMA(huart,hdmarx,hdma_usart1_rx);
/* USART1 interrupt Init */
HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(USART1_IRQn);
@ -317,6 +336,9 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
*/
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10|USART1_DE_Pin);
/* USART1 DMA DeInit */
HAL_DMA_DeInit(huart->hdmarx);
/* USART1 interrupt DeInit */
HAL_NVIC_DisableIRQ(USART1_IRQn);
/* USER CODE BEGIN USART1_MspDeInit 1 */

@ -56,6 +56,7 @@
/* External variables --------------------------------------------------------*/
extern TIM_HandleTypeDef htim6;
extern DMA_HandleTypeDef hdma_usart1_rx;
extern UART_HandleTypeDef huart1;
extern UART_HandleTypeDef huart2;
/* USER CODE BEGIN EV */
@ -200,6 +201,20 @@ void SysTick_Handler(void)
/* please refer to the startup file (startup_stm32l4xx.s). */
/******************************************************************************/
/**
* @brief This function handles DMA1 channel5 global interrupt.
*/
void DMA1_Channel5_IRQHandler(void)
{
/* USER CODE BEGIN DMA1_Channel5_IRQn 0 */
/* USER CODE END DMA1_Channel5_IRQn 0 */
HAL_DMA_IRQHandler(&hdma_usart1_rx);
/* USER CODE BEGIN DMA1_Channel5_IRQn 1 */
/* USER CODE END DMA1_Channel5_IRQn 1 */
}
/**
* @brief This function handles USART1 global interrupt.
*/

@ -1,5 +1,5 @@
##########################################################################################################################
# File automatically-generated by tool: [projectgenerator] version: [3.16.0] date: [Fri Apr 08 17:14:47 CDT 2022]
# File automatically-generated by tool: [projectgenerator] version: [3.16.0] date: [Mon May 02 17:19:20 CDT 2022]
##########################################################################################################################
# ------------------------------------------------
@ -126,7 +126,8 @@ C_INCLUDES = \
-Ishared \
-Ishared/devices \
-Ishared/drivers \
-Ishared/util
-Ishared/util \
-IPenguinBuffer
# compile gcc flags

@ -18,6 +18,7 @@
"-Ishared/devices",
"-Ishared/drivers",
"-Ishared/util",
"-IPenguinBuffer",
"-Og",
"-Wall",
"-fdata-sections",
@ -25,13 +26,13 @@
"-g3",
"-gdwarf-2",
"-D_DEBUG",
"-MFbuild/main.d",
"-Wa,-a,-ad,-alms=build/main.lst",
"-MFbuild/p_serial_mgr.d",
"-Wa,-a,-ad,-alms=build/p_serial_mgr.lst",
"-o",
"build/main.o",
"Core/Src/main.c"
"build/p_serial_mgr.o",
"shared/drivers/p_serial_mgr.c"
],
"directory": "/storage/Shared/Projects/Penguinator/motor_controller",
"file": "Core/Src/main.c"
"file": "shared/drivers/p_serial_mgr.c"
}
]

5025
gdb.txt

File diff suppressed because it is too large Load Diff

@ -129,7 +129,7 @@ ProjectManager.FreePins=false
ProjectManager.HalAssertFull=false
ProjectManager.HeapSize=0x200
ProjectManager.KeepUserCode=true
ProjectManager.LastFirmware=true
ProjectManager.LastFirmware=false
ProjectManager.LibraryCopy=1
ProjectManager.MainLocation=Core/Src
ProjectManager.NoMain=false
@ -142,7 +142,7 @@ ProjectManager.StackSize=0x400
ProjectManager.TargetToolchain=Makefile
ProjectManager.ToolChainLocation=
ProjectManager.UnderRoot=false
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,4-MX_TIM2_Init-TIM2-false-HAL-true,5-MX_USART2_UART_Init-USART2-false-HAL-true,6-MX_DMA_Init-DMA-false-HAL-true,7-MX_USART1_UART_Init-USART1-false-HAL-true
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_TIM2_Init-TIM2-false-HAL-true,4-MX_USART2_UART_Init-USART2-false-HAL-true,5-MX_DMA_Init-DMA-false-HAL-true,6-MX_USART1_UART_Init-USART1-false-HAL-true,7-MX_TIM6_Init-TIM6-false-HAL-true
RCC.48CLKFreq_Value=24000000
RCC.AHBFreq_Value=32000000
RCC.APB1Freq_Value=32000000

@ -2,8 +2,12 @@
#include "putil.h"
#include "stm32l4xx_hal_uart.h"
#define MAX_SERIAL_BUFFER_SIZE (262) // Actually 261, add 1 for padding
#define NUM_BUFFERS (10)
uint8_t sbuffer[NUM_BUFFERS][MAX_MESSAGE_LEN];
uint8_t active_buffer = 0;
uint8_t rxb[MAX_MESSAGE_LEN];
// this protocol is very similar to the digi api v2 (inspired from)
// [0]{1} Start delimiter 0x7E
// [1]{1} Source Address
@ -28,10 +32,14 @@ static serial_state_t sstate = SS_IDLE;
void UART1_RxCpltCallback(UART_HandleTypeDef *huart)
{
if (rxc == 0x7E && sstate == SS_IDLE)
if (sstate == SS_IDLE && sbuffer[active_buffer][0] == 0x7E)
{
sstate = SS_START;
}
else
{
HAL_UART_Receive_IT(_serial_huart_inst, sbuffer[active_buffer], 1);
}
}
void p_serial_mgr_init(UART_HandleTypeDef *huart)
@ -43,14 +51,20 @@ void p_serial_mgr_service(void)
{
if (sstate == SS_START)
{
return;
HAL_UART_Receive(_serial_huart_inst, &sbuffer[active_buffer][1], MAX_MESSAGE_LEN, 10);
for (int ind = 0; ind < 24; ind++)
{
PDEBUG("[%d]: 0x%02x\n", ind, sbuffer[active_buffer][ind]);
}
PDEBUG("\n\n");
sstate = SS_IDLE;
active_buffer = (active_buffer + 1) % NUM_BUFFERS;
HAL_UART_Receive_IT(_serial_huart_inst, sbuffer[active_buffer], 1);
}
else if (sstate = SS_IDLE) {}
return b_go;
}
void p_serial_mgr_start()
{
b_go = false;
HAL_UART_Receive_IT(_serial_huart_inst, &rxc, 1);
sstate = SS_IDLE;
HAL_UART_Receive_IT(_serial_huart_inst, sbuffer[active_buffer], 1);
}

@ -1,9 +1,9 @@
#ifndef _P_SERIAL_MGR_H_
#define _P_SERIAL_MGR_H_
#include "p_cbuffer.h"
#include "stm32l4xx_hal.h"
#include <stdbool.h>
// start byte
// src_addr {1} +
// dest_addr {1} +
@ -30,7 +30,7 @@ typedef struct serial_pkt_t
void p_serial_mgr_init(UART_HandleTypeDef *huart);
bool p_serial_mgr_service(void);
void p_serial_mgr_service(void);
void p_serial_mgr_start();

Loading…
Cancel
Save