Enabling interrupt is causes a hard fault - Page 1
Forum section: electronics / general

author: jeet55
author_rank: Contributor
timestamp: April 26, 2021, 11:48:18 am
content: enabling DMA interrupt is causing a hard faultHAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn);

author: m98
author_rank: Frequent Contributor
timestamp: April 26, 2021, 12:14:12 pm
content: So I would suggest to just leave it disabled...More details please.

author: Psi
author_rank: Super Contributor
timestamp: April 26, 2021, 12:56:42 pm
content: Have you defined an interrupt handler for the DMA interrupt?

author: jeet55
author_rank: Contributor
timestamp: April 26, 2021, 01:12:30 pm
content: yes i have and i also called the HAL IRQ handler in it

author: newbrain
author_rank: Super Contributor
timestamp: April 26, 2021, 02:10:34 pm
content: Jeet55,as I said last time I answered you, please help us to help you.We are not psychic - at least, not me.We don't know:1. Which MCU you are using (an STM32, given the HAL - but there are hundreds of them)2. What you are trying to achieve3. How your code looks like4. What you tried and did not work5. Your degree of familiarity the C language (given the previous question, there might be some basic lack there - how are we supposed to know?)Extracting this information piecemeal is tiring for all involved.A good strategy when something is not working, is reducing the code to the very bare minimum that exhibits the problem (we don't need to read hundreds of line of unrelated stuff) and share it, maybe also stating what changes you tried to make it work.As much the HAL are often (and often with reason) maligned for being bloated, inefficient and cumbersome, they generally work.I have used DMA a number of times myself with no major issues.

author: SiliconWizard
author_rank: Super Contributor
timestamp: April 26, 2021, 04:09:03 pm
content: Quote from: m98 on April 26, 2021, 12:14:12 pm"Doc, it hurts when I press right here!- Just don't do it, then."Quote from: m98 on April 26, 2021, 12:14:12 pmYep.

author: Siwastaja
author_rank: Super Contributor
timestamp: April 26, 2021, 06:18:18 pm
content: Most likely, vector table just doesn't contain the address of your intended handler. In other words, you haven't successfully configured the interrupt handler function to be an interrupt handler function for said interrupt. Just a guess, but likely.Tell us how you configured the interrupt handler. Deep down, it's nothing more than placing the address of the function in a correct place near the beginning of the flash memory, but how this is done "automatically" depends on the toolchain.Quote from: jeet55 on April 26, 2021, 01:12:30 pmWhat does this mean? You don't usually call interrupt handlers in interrupt handlers as you are claiming to do. What even is HAL IRQ handler?

author: ejeffrey
author_rank: Super Contributor
timestamp: April 26, 2021, 06:40:03 pm
content: Mostly likely what Siwastaja said: the vector table is incorrect. Make sure the vector table is correct and make sure that you are looking at the right vector table. Make sure you know if the MCU is configured to use the vector table in flash or if it has been copied to SRAM.Another possibility is that the vector table is correct and handler is faulting. Put a breakpoint or toggle a GPIO at the start of the handler so you can see if it is being executed. If you want to single step, make sure your debugger is in "single step assembly" mode --When you say "hard fault" do you mean that you have a debugger attached and see that it enters the hard fault handler? Or do you mean that it "locks up"? Could the interrupt handler be infinite looping instead of a fault?

author: newbrain
author_rank: Super Contributor
timestamp: April 26, 2021, 09:58:07 pm
content: Quote from: Siwastaja on April 26, 2021, 06:18:18 pmThis is quite normal and correct when using the HAL, either manually or relying on MX Cube generated code.As an example:Code:void TIM1_BRK_UP_TRG_COM_IRQHandler(void){/* USER CODE BEGIN TIM1_BRK_UP_TRG_COM_IRQn 0 *//* USER CODE END TIM1_BRK_UP_TRG_COM_IRQn 0 */HAL_TIM_IRQHandler(&htim1);/* USER CODE BEGIN TIM1_BRK_UP_TRG_COM_IRQn 1 *//* USER CODE END TIM1_BRK_UP_TRG_COM_IRQn 1 */}This is generated by MX Cube when one specifies to use interrupts with TIM1.TIM1_BRK_UP_TRG_COM_IRQHandleris the real ISR, declared (and defined as weak) in the startup code, a vector table entry.HAL_TIM_IRQHandleris the generic HAL handler, good for all timers, so it need the handle as parameter (and cannot be an IRS).I swear my message originally ended like this:QuoteThen I removed the bold part before postingQuote from: ejeffrey on April 26, 2021, 06:40:03 pmWhat is the airspeed velocity of an unladen swallow?I still think this game is unfair.

author: SiliconWizard
author_rank: Super Contributor
timestamp: April 27, 2021, 12:01:46 am
content: Yeah, the OP needs to show us enough of their code so we can help though.But yes, with STM32's HAL, the typical use of ISRs is to call a dedicated HAL function within each handled ISR. For the DMA, that typically looks like this (taken from an example project from STM):Code:/*** @brief This function handles DMA interrupt request.* @param None* @retval None*/void DACx_DMA_IRQHandler(void){HAL_DMA_IRQHandler(DacHandle.DMA_Handle1);}Of course you can always implement the ISR another way, but if you stick to the HAL, then this is usually the way to go.Here the HAL_DMA_IRQHandler() will in turn do the housekeeping (clear the interrupt flag, etc) and call callback functions depending on the interrupt cause. So, has the OP properly defined those callback functions? Failing to do so may explain the crash.

author: cv007
author_rank: Frequent Contributor
timestamp: April 27, 2021, 01:31:49 am
content: >Failing to do so may explain the crash.Except that hal code is going to check for null before it uses any callback. Its also probably pretty hard to assign the callback function(s) improperly via a hal function. Navigating your way through the hal dma functions may help to figure out what is going on, but I'm guessing the programming mode here is 'use the hal', not 'understand what the hal is doing' ('what the hal its doing' ?).Not an stm32 dma expert, although I own an 031g, but imagine its not hard to setup dma incorrectly to where improper alignment throws a wrench in the gears and you end up in hard fault.