2020-09-14 09:47 PM
Hi to All,
I like to inform you that i am using the STM32F103RC controller and the problem is that when i do the DAC init between any of the peripheral init in STM32CubeIDE inside the main function, than i am getting the hard fault handler as shown below :
int main(void)
{
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_RTC_Init();
MX_DAC_Init();
MX_I2C1_Init();
MX_SPI2_Init();
MX_USART1_UART_Init();
MX_USART2_UART_Init();
while(1)
{
// application level logic
}
}
But when i define the DAC init at the last after initialising all other peripherals than i do not get the hard fault handler as shown below:
int main(void)
{
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_RTC_Init();
MX_I2C1_Init();
MX_SPI2_Init();
MX_USART1_UART_Init();
MX_USART2_UART_Init();
MX_DAC_Init();
while(1)
{
// application level logic
}
}
DAC init is generated by the STM32CubeMX as shown below
/* DAC init function */
void MX_DAC_Init(void)
{
DAC_ChannelConfTypeDef sConfig = {0};
/** DAC Initialization
*/
hdac.Instance = DAC;
if (HAL_DAC_Init(&hdac) != HAL_OK)
{
Error_Handler();
}
/** DAC channel OUT1 config
*/
sConfig.DAC_Trigger = DAC_TRIGGER_NONE;
sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
if (HAL_DAC_ConfigChannel(&hdac, &sConfig, DAC_CHANNEL_1) != HAL_OK)
{
Error_Handler();
}
if (HAL_DAC_Start(&hdac, DAC_CHANNEL_1) != HAL_OK)
{
/* Start Error */
Error_Handler();
}
}
So can you please let me know the reason behind this why i am getting the hard fault handler when i do the DAC init in between other peripheral init and not getting hard fault handler when i do the DAC init at the last of all other peripheral init.
Thanks and regards,
Ronak Jain