cancel
Showing results for 
Search instead for 
Did you mean: 

Hard Fault when calling the HAL_TIM_Encoder_Start_DMA function on the STM32F103C8T6 microcontroller. Can I fix it?

AndrewCh
Associate

 HAL_Init();

 /* USER CODE BEGIN Init */

 /* USER CODE END Init */

 /* Configure the system clock */

 SystemClock_Config();

 /* USER CODE BEGIN SysInit */

 /* USER CODE END SysInit */

 /* Initialize all configured peripherals */

 MX_GPIO_Init();

 MX_DMA_Init();

 MX_CAN_Init();

 MX_USART2_UART_Init();

 MX_TIM3_Init();

 MX_TIM4_Init();

 MX_ADC1_Init();

 MX_USART3_UART_Init();

 MX_TIM2_Init();

 HAL_ADC_Start_DMA(&hadc1,(uint32_t*) &ADC_Data,2);

 HAL_TIM_Base_Start(&htim3);

 HAL_TIM_Encoder_Start_DMA(&htim3, TIM_CHANNEL_ALL, tim3CH1, tim3CH2, 8);

 HAL_TIM_Base_Start(&htim4);

 HAL_TIM_Encoder_Start_DMA(&htim4, TIM_CHANNEL_ALL, tim3CH1, tim3CH2, 8);

/////////////////////////////////////////////////////

in function HAL_TIM_Encoder_Start_DMA(&htim3, TIM_CHANNEL_ALL, tim3CH1, tim3CH2, 8);

stm32f1xx_hal_tim.c

3046 htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;

///////////////////////////////////////////////////

in disassembly

3046      htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;

08003fd4:  ldr   r3, [r7, #12]

08003fd6:  ldr   r3, [r3, #36]  ; 0x24

08003fd8:  ldr   r2, [pc, #176] ; (0x800408c <HAL_TIM_Encoder_Start_DMA+484>)

08003fda:  str   r2, [r3, #44]  ; 0x2c

/////////////////////////////////////////////////

ldr   r3, [r7, #12]

r7 = 0x20004fd0

Failed to execute MI command:

-data-disassemble -s 536891345 -e 536891509 -- 3

Error message from debugger back end:

Cannot access memory at address 0x20005000

4 REPLIES 4

Blue Pill?

Genuine STM32?

JW

Yeap, well your going to have to dig more. Perhaps have a better Hard Fault Handler, and review the code around the fault with much more context.

Check stack and heap.

Check structures, and pointers.

Make sure structures are cleared and setup properly. Especially auto/local ones.

Make sure DMA/IRQ related structures are in scope, and not auto/local variables.

Make sure all IRQ Handlers and Callbacks are present.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..

Yes, this is a blue tablet, but the marking from the ST is written on the chip.

> marking from the ST is written on the chip

This unfortunately is no guarantee. There are many counterfeits around - some are genuine ST chips but relabelled for a higher capacity (e.g. https://github.com/keirf/Greaseweazle/wiki/STM32-Fakes ) ; some are other manufacturer's clones, sometimes also relabelled as ST's (e.g. https://www.richis-lab.de/STM32_04.htm ).

I don't say this *is* the case with your board, and the problem may be elsewhere - see Clive's post above. But if you are starting with STM32, you may be better off buying a - possibly more expensive - board with a guarantee that it will work - maybe a Nucleo board, which comes also with an on-board STLink.

Btw. the STM32F1xx family was the first STM32, is more than 10 years old and - again from the point of view of a novice - using some of its facilities is harder than with some of the newer families.

JW