Skip to content

Commit

Permalink
fix can: enable interrupts on rx
Browse files Browse the repository at this point in the history
  • Loading branch information
PonomarevDA committed Jun 30, 2024
1 parent dc90159 commit 741f054
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 5 deletions.
7 changes: 7 additions & 0 deletions Core/Inc/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,15 @@ void Error_Handler(void);
#define ADC_VIN_GPIO_Port GPIOA
#define ADC_5V_Pin GPIO_PIN_1
#define ADC_5V_GPIO_Port GPIOA
#define ADC_CURRENT_Pin GPIO_PIN_6
#define ADC_CURRENT_GPIO_Port GPIOA
#define ADC_VERSION_Pin GPIO_PIN_7
#define ADC_VERSION_GPIO_Port GPIOA
#define CAN2_TERMINATOR_Pin GPIO_PIN_15
#define CAN2_TERMINATOR_GPIO_Port GPIOB
#define CAN1_TERMINATOR_Pin GPIO_PIN_15
#define CAN1_TERMINATOR_GPIO_Port GPIOA

/* USER CODE BEGIN Private defines */

/* USER CODE END Private defines */
Expand Down
1 change: 1 addition & 0 deletions Core/Inc/stm32g0xx_it.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void PendSV_Handler(void);
void SysTick_Handler(void);
void DMA1_Channel1_IRQHandler(void);
void TIM1_BRK_UP_TRG_COM_IRQHandler(void);
void TIM16_FDCAN_IT0_IRQHandler(void);
/* USER CODE BEGIN EFP */

/* USER CODE END EFP */
Expand Down
6 changes: 4 additions & 2 deletions Core/Src/adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,10 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle)
/**ADC1 GPIO Configuration
PA0 ------> ADC1_IN0
PA1 ------> ADC1_IN1
PA6 ------> ADC1_IN6
PA7 ------> ADC1_IN7
*/
GPIO_InitStruct.Pin = ADC_VIN_Pin|ADC_5V_Pin|ADC_VERSION_Pin;
GPIO_InitStruct.Pin = ADC_VIN_Pin|ADC_5V_Pin|ADC_CURRENT_Pin|ADC_VERSION_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
Expand Down Expand Up @@ -181,9 +182,10 @@ void HAL_ADC_MspDeInit(ADC_HandleTypeDef* adcHandle)
/**ADC1 GPIO Configuration
PA0 ------> ADC1_IN0
PA1 ------> ADC1_IN1
PA6 ------> ADC1_IN6
PA7 ------> ADC1_IN7
*/
HAL_GPIO_DeInit(GPIOA, ADC_VIN_Pin|ADC_5V_Pin|ADC_VERSION_Pin);
HAL_GPIO_DeInit(GPIOA, ADC_VIN_Pin|ADC_5V_Pin|ADC_CURRENT_Pin|ADC_VERSION_Pin);

/* ADC1 DMA DeInit */
HAL_DMA_DeInit(adcHandle->DMA_Handle);
Expand Down
5 changes: 5 additions & 0 deletions Core/Src/fdcan.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef* fdcanHandle)
GPIO_InitStruct.Alternate = GPIO_AF3_FDCAN1;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

/* FDCAN1 interrupt Init */
HAL_NVIC_SetPriority(TIM16_FDCAN_IT0_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(TIM16_FDCAN_IT0_IRQn);
/* USER CODE BEGIN FDCAN1_MspInit 1 */

/* USER CODE END FDCAN1_MspInit 1 */
Expand All @@ -124,6 +127,8 @@ void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef* fdcanHandle)
*/
HAL_GPIO_DeInit(GPIOD, GPIO_PIN_0|GPIO_PIN_1);

/* FDCAN1 interrupt Deinit */
HAL_NVIC_DisableIRQ(TIM16_FDCAN_IT0_IRQn);
/* USER CODE BEGIN FDCAN1_MspDeInit 1 */

/* USER CODE END FDCAN1_MspDeInit 1 */
Expand Down
21 changes: 21 additions & 0 deletions Core/Src/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,39 @@ void MX_GPIO_Init(void)
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOF_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();

/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOC, INTERNAL_LED_RED_Pin|INTERNAL_LED_GREEN_Pin|INTERNAL_LED_BLUE_Pin, GPIO_PIN_RESET);

/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(CAN2_TERMINATOR_GPIO_Port, CAN2_TERMINATOR_Pin, GPIO_PIN_RESET);

/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(CAN1_TERMINATOR_GPIO_Port, CAN1_TERMINATOR_Pin, GPIO_PIN_RESET);

/*Configure GPIO pins : PCPin PCPin PCPin */
GPIO_InitStruct.Pin = INTERNAL_LED_RED_Pin|INTERNAL_LED_GREEN_Pin|INTERNAL_LED_BLUE_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

/*Configure GPIO pin : PtPin */
GPIO_InitStruct.Pin = CAN2_TERMINATOR_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(CAN2_TERMINATOR_GPIO_Port, &GPIO_InitStruct);

/*Configure GPIO pin : PtPin */
GPIO_InitStruct.Pin = CAN1_TERMINATOR_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(CAN1_TERMINATOR_GPIO_Port, &GPIO_InitStruct);

}

/* USER CODE BEGIN 2 */
Expand Down
1 change: 1 addition & 0 deletions Core/Src/stm32g0xx_hal_msp.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

/* Includes ------------------------------------------------------------------*/
#include "main.h"

/* USER CODE BEGIN Includes */

/* USER CODE END Includes */
Expand Down
1 change: 1 addition & 0 deletions Core/Src/stm32g0xx_hal_timebase_tim.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
htim1.Instance = TIM1;

/* Initialize TIMx peripheral as follow:
+ Period = [(TIM1CLK/1000) - 1]. to have a (1/1000) s time base.
+ Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock.
+ ClockDivision = 0
Expand Down
15 changes: 15 additions & 0 deletions Core/Src/stm32g0xx_it.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@

/* External variables --------------------------------------------------------*/
extern DMA_HandleTypeDef hdma_adc1;
extern FDCAN_HandleTypeDef hfdcan1;
extern TIM_HandleTypeDef htim1;

/* USER CODE BEGIN EV */
Expand Down Expand Up @@ -170,6 +171,20 @@ void TIM1_BRK_UP_TRG_COM_IRQHandler(void)
/* USER CODE END TIM1_BRK_UP_TRG_COM_IRQn 1 */
}

/**
* @brief This function handles TIM16, FDCAN1_IT0 and FDCAN2_IT0 Interrupt.
*/
void TIM16_FDCAN_IT0_IRQHandler(void)
{
/* USER CODE BEGIN TIM16_FDCAN_IT0_IRQn 0 */

/* USER CODE END TIM16_FDCAN_IT0_IRQn 0 */
HAL_FDCAN_IRQHandler(&hfdcan1);
/* USER CODE BEGIN TIM16_FDCAN_IT0_IRQn 1 */

/* USER CODE END TIM16_FDCAN_IT0_IRQn 1 */
}

/* USER CODE BEGIN 1 */

/* USER CODE END 1 */
9 changes: 6 additions & 3 deletions project_v3.ioc
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,16 @@ Mcu.PinsNb=18
Mcu.ThirdPartyNb=0
Mcu.UserConstants=
Mcu.UserName=STM32G0B1CEUx
MxCube.Version=6.6.0
MxDb.Version=DB.6.0.60
MxCube.Version=6.10.0
MxDb.Version=DB.6.0.100
NVIC.DMA1_Channel1_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true
NVIC.ForceEnableDMAVector=true
NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
NVIC.SVC_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:true
NVIC.SysTick_IRQn=true\:3\:0\:false\:false\:true\:false\:true\:false
NVIC.TIM16_FDCAN_IT0_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
NVIC.TIM1_BRK_UP_TRG_COM_IRQn=true\:3\:0\:false\:false\:true\:false\:true\:true
NVIC.TimeBase=TIM1_BRK_UP_TRG_COM_IRQn
NVIC.TimeBaseIP=TIM1
Expand Down Expand Up @@ -173,7 +174,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
Expand All @@ -186,6 +187,8 @@ ProjectManager.RegisterCallBack=
ProjectManager.StackSize=0x400
ProjectManager.TargetToolchain=STM32CubeIDE
ProjectManager.ToolChainLocation=
ProjectManager.UAScriptAfterPath=
ProjectManager.UAScriptBeforePath=
ProjectManager.UnderRoot=true
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_DMA_Init-DMA-false-HAL-true,4-MX_FDCAN1_Init-FDCAN1-false-HAL-true,5-MX_ADC1_Init-ADC1-false-HAL-true
RCC.ADCFreq_Value=64000000
Expand Down

0 comments on commit 741f054

Please sign in to comment.