AnsweredAssumed Answered

HAL_SYSTICK_Callback is not called in STM32F746 Discovery

Question asked by mich.lei on Oct 18, 2017
Latest reply on Oct 18, 2017 by Vangelis Fortounas

I have a simple program to test interrupts in STM32F746 Discovery. I have tried callbacks before but now I can't get it to work. The following is my test code

 
/* Includes ------------------------------------------------------------------*/

#include <main.h>

/* USER CODE BEGIN Includes */

#include "stm32746g_discovery_lcd.h"
#include "stm32746g_discovery_ts.h"

/* Definition for ADCx clock resources */
#define ADCx_CLK_ENABLE()                 __HAL_RCC_ADC3_CLK_ENABLE()

#define ADCx_FORCE_RESET()                __HAL_RCC_ADC_FORCE_RESET()
#define ADCx_RELEASE_RESET()              __HAL_RCC_ADC_RELEASE_RESET()

/* Definition for ADCx Channel Pin */
#define ADCx_CHANNEL_PIN                  GPIO_PIN_8
#define ADCx_CHANNEL_GPIO_PORT            GPIOF

/* Definition for ADCx's Channel */
#define ADCx_CHANNEL                      ADC_CHANNEL_6
#define SAMPLINGTIME                    ADC_SAMPLETIME_3CYCLES
#define ADCx_POLL_TIMEOUT               10
volatile uint16_t own4,own2=0;

void HAL_SYSTICK_Callback(void)
{
  own2++;
     if (own2>1000)
     {
          own2=0;
          own4++;
     }
}


/** @addtogroup STM32F7xx_HAL_Examples
  * @{
  */


/** @addtogroup Templates
  * @{
  */


/* Private typedef -----------------------------------------------------------*/

/* Private define ------------------------------------------------------------*/
#define LCD_FRAME_BUFFER          SDRAM_DEVICE_ADDR
#define RGB565_BYTE_PER_PIXEL     2
#define ARBG8888_BYTE_PER_PIXEL   4
#define ADCx_CHANNEL_GPIO_CLK_ENABLE()  __HAL_RCC_GPIOF_CLK_ENABLE()
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/

TS_StateTypeDef TS_State;
DMA2D_HandleTypeDef hdma2d;

I2C_HandleTypeDef hi2c3;

LTDC_HandleTypeDef hltdc;

UART_HandleTypeDef huart1;

DMA_HandleTypeDef hdma_memtomem_dma2_stream0;
SDRAM_HandleTypeDef hsdram1;
ADC_HandleTypeDef hadc1;

UART_HandleTypeDef huart2;

char klaa[40];
int ***;
/* Private function prototypes -----------------------------------------------*/
static void SystemClock_Config(void);
static void Error_Handler(void);
static void MPU_Config(void);
static void CPU_CACHE_Enable(void);

/* Private functions ---------------------------------------------------------*/
static void MX_ADC1_Init(void);
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */

int main(void)
{
  /* Configure the MPU attributes as Write Through */
  MPU_Config();

  /* Enable the CPU Cache */
  CPU_CACHE_Enable();

  /* STM32F7xx HAL library initialization:
       - Configure the Flash ART accelerator on ITCM interface
       - Configure the Systick to generate an interrupt each 1 msec
       - Set NVIC Group Priority to 4
       - Low Level Initialization
     */

  HAL_Init();

     
  /* Configure the System clock to have a frequency of 216 MHz */
SystemClock_Config();

MX_ADC1_Init();

// Set up the LCD
BSP_LCD_Init();
BSP_LCD_LayerDefaultInit(LTDC_ACTIVE_LAYER, LCD_FRAME_BUFFER);
BSP_LCD_SetLayerVisible(LTDC_ACTIVE_LAYER, ENABLE);
BSP_LCD_SelectLayer(LTDC_ACTIVE_LAYER);
BSP_LCD_Clear(LCD_COLOR_BLACK);
BSP_LCD_SetBackColor(LCD_COLOR_BLACK);
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
BSP_LCD_DisplayOn();

while (1)
  {

     if (own4>0)
          {
          own4=0;
          own2++;
    BSP_LCD_DisplayStringAtLine(2, (uint8_t *) "interruptddddd") ;
          HAL_Delay(5000);
          }
          
            /*##-3- Start the conversion process #######################################*/
  if (HAL_ADC_Start(&hadc1) != HAL_OK)
  {
    /* Start Conversation Error */
    Error_Handler();
  }

  /*##-4- Wait for the end of conversion #####################################*/
  /*  Before starting a new conversion, you need to check the current state of
       the peripheral; if it’s busy you need to wait for the end of current
       conversion before starting a new one.
       For simplicity reasons, this example is just waiting till the end of the
       conversion, but application may perform other tasks while conversion
       operation is ongoing. */

  HAL_ADC_PollForConversion(&hadc1, 10);

  /* Check if the continous conversion of regular channel is finished */ 
  if(HAL_IS_BIT_SET(HAL_ADC_GetState(&hadc1), HAL_ADC_STATE_REG_EOC))
{
    /*##-5- Get the converted value of regular channel  ########################*/
    *** = HAL_ADC_GetValue(&hadc1);
  }

  sprintf (klaa,"result %u", ***);
  BSP_LCD_DisplayStringAtLine(6, (uint8_t *) "           ") ;                              
  BSP_LCD_DisplayStringAtLine(6, (uint8_t *) klaa) ;    
     HAL_Delay(500);
  }

}

               /* ADC1 init function */
               static void MX_ADC1_Init(void)
               {
      GPIO_InitTypeDef          GPIO_InitStruct;
      ADC_ChannelConfTypeDef    ADC_Config;
   
    /* ADC an GPIO Periph clock enable */
    ADCx_CLK_ENABLE();
    ADCx_CHANNEL_GPIO_CLK_ENABLE();

    /* ADC Channel GPIO pin configuration */
    GPIO_InitStruct.Pin = ADCx_CHANNEL_PIN;
    GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    HAL_GPIO_Init(ADCx_CHANNEL_GPIO_PORT, &GPIO_InitStruct);
                    
                    
                    ADC_ChannelConfTypeDef sConfig;

                         /**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
                         */

                    hadc1.Instance = ADC3;
                    //hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2;
                    hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
                    hadc1.Init.Resolution = ADC_RESOLUTION_12B;
                    hadc1.Init.ScanConvMode = DISABLE;
                    hadc1.Init.ContinuousConvMode = DISABLE;
                    hadc1.Init.DiscontinuousConvMode = DISABLE;
                    hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
                    hadc1.Init.ExternalTrigConv      = ADC_EXTERNALTRIGCONV_T1_CC1;
                    //hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
                    hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
                    hadc1.Init.NbrOfConversion = 1;
                    hadc1.Init.DMAContinuousRequests = DISABLE;
                    hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
                    if (HAL_ADC_Init(&hadc1) != HAL_OK)
                    {
                         Error_Handler();
                    }

                         /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
                         */

                    //sConfig.Channel = ADC_CHANNEL_1;
                    sConfig.Channel = ADC_CHANNEL_6;
                    sConfig.Rank = 1;
                    //sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
                    sConfig.SamplingTime = ADC_SAMPLETIME_15CYCLES;
                    if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
                    {
                         Error_Handler();
                    }

               }

/**
  * @brief  System Clock Configuration
  *         The system Clock is configured as follow :
  *            System Clock source            = PLL (HSE)
  *            SYSCLK(Hz)                     = 216000000
  *            HCLK(Hz)                       = 216000000
  *            AHB Prescaler                  = 1
  *            APB1 Prescaler                 = 4
  *            APB2 Prescaler                 = 2
  *            HSE Frequency(Hz)              = 25000000
  *            PLL_M                          = 25
  *            PLL_N                          = 432
  *            PLL_P                          = 2
  *            PLL_Q                          = 9
  *            VDD(V)                         = 3.3
  *            Main regulator output voltage  = Scale1 mode
  *            Flash Latency(WS)              = 7
  * @param  None
  * @retval None
  */

static void SystemClock_Config(void)
{
  RCC_ClkInitTypeDef RCC_ClkInitStruct;
  RCC_OscInitTypeDef RCC_OscInitStruct;

  /* Enable HSE Oscillator and activate PLL with HSE as source */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  RCC_OscInitStruct.HSIState = RCC_HSI_OFF;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLM = 25;
  RCC_OscInitStruct.PLL.PLLN = 432; 
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  RCC_OscInitStruct.PLL.PLLQ = 9;
  if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }

  /* activate the OverDrive to reach the 216 Mhz Frequency */
  if(HAL_PWREx_EnableOverDrive() != HAL_OK)
  {
    Error_Handler();
  }
 
  /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
     clocks dividers */

  RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; 
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; 
  if(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_7) != HAL_OK)
  {
    Error_Handler();
  }
}

/**
  * @brief  This function is executed in case of error occurrence.
  * @param  None
  * @retval None
  */

static void Error_Handler(void)
{
  /* User may add here some code to deal with this error */
  while(1)
  {
          //     BSP_LCD_DisplayStringAtLine(6, (uint8_t *) buffer) ;
  }
}

/**
  * @brief  Configure the MPU attributes as Write Through for SRAM1/2.
  * @note   The Base Address is 0x20010000 since this memory interface is the AXI.
  *         The Region Size is 256KB, it is related to SRAM1 and SRAM2  memory size.
  * @param  None
  * @retval None
  */

static void MPU_Config(void)
{
  MPU_Region_InitTypeDef MPU_InitStruct;
 
  /* Disable the MPU */
  HAL_MPU_Disable();

  /* Configure the MPU attributes as WT for SRAM */
  MPU_InitStruct.Enable = MPU_REGION_ENABLE;
  MPU_InitStruct.BaseAddress = 0x20010000;
  MPU_InitStruct.Size = MPU_REGION_SIZE_256KB;
  MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
  MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
  MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE;
  MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
  MPU_InitStruct.Number = MPU_REGION_NUMBER0;
  MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
  MPU_InitStruct.SubRegionDisable = 0x00;
  MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;

  HAL_MPU_ConfigRegion(&MPU_InitStruct);

  /* Enable the MPU */
  HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
}

/**
  * @brief  CPU L1-Cache enable.
  * @param  None
  * @retval None
  */

static void CPU_CACHE_Enable(void)
{
  /* Enable I-Cache */
  SCB_EnableICache();

  /* Enable D-Cache */
  SCB_EnableDCache();
}

#ifdef  USE_FULL_ASSERT

/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */

void assert_failed(uint8_t* file, uint32_t line)
{
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */


  /* Infinite loop */
  while (1)
  {
  }
}
#endif

/**
  * @}
  */


/**
  * @}
  */


/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

Outcomes