microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.54k stars 1.56k forks source link

Code regions become Inactive when the defines exist that should activate them #3524

Closed noppej closed 5 years ago

noppej commented 5 years ago

Type: LanguageService

Describe the bug

To Reproduce

  1. Go to ' Command Palette, and >Reload Window'
  2. Click on 'any .c file' in the STMCubeF4 library and look for code regions controlled by defines.
  3. I should note that the same problem is not reproduce-able in my own code. I'm not sure if the difference comes in from the larger code in the library files.
  4. Also worth noticing, is that if I configure the same project in Eclipse (using SW4STM workbench), the code regions work as expected.

Screenshots

Inactive Code Problem

sean-mcmanus commented 5 years ago

This appears to be a bug with the new UI editor that doesn't save the results. After adding the defines, can you click in a different UI field, such as the "Include Path" one?

noppej commented 5 years ago

Hi Sean, Thank you for your quick response, but I don't think that was it. The variable is saved in my c_cpp_properties file. I'm attaching another screenshot, showing same behaviour for USE_FULL_LL_DRIVER define, as well as copies of the two files in the screenshot. Any help will be welcomed :)

Inactive Code example 2

{
    "env": {
        "____________________USER_FIELDS_CAN_BE_MODIFIED____________________": "",
        "user_cSources": [
            "/Users/Jack/SSTP/Motor/Src/xformatc.c",
            "/Users/Jack/SSTP/Motor/Src/sstpCommon.c",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/BSP/STM32F4xx-Nucleo/stm32f4xx_nucleo.c"
        ],
        "user_asmSources": [],
        "user_ldSources": [],
        "user_cIncludes": [
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/BSP/STM32F4xx-Nucleo"
        ],
        "user_asmIncludes": [],
        "user_ldIncludes": [],
        "user_cDefines": [
            "AVOID_EMPTY_DEFINE_FIELD_C",
            "__weak=\"__attribute__((weak))\"",
            "__packed=\"__attribute__((__packed__))\""
        ],
        "user_asmDefines": [
            "AVOID_EMPTY_DEFINE_FIELD_ASM"
        ],
        "user_cFlags": [
            "-fmessage-length=0 -Wall -Werror-implicit-function-declaration -Werror=int-to-pointer-cast -Werror=pointer-to-int-cast"
        ],
        "user_asmFlags": [],
        "user_ldFlags": [
            "-specs=nosys.specs"
        ],
        "____________________DO_NOT_MODIFY_FIELDS_BELOW____________________": "",
        "cubemx_sourceFiles": [
            "Src/main.c",
            "Src/gpio.c",
            "Src/adc.c",
            "Src/dma.c",
            "Src/freertos.c",
            "Src/i2c.c",
            "Src/iwdg.c",
            "Src/spi.c",
            "Src/tim.c",
            "Src/stm32f4xx_it.c",
            "Src/stm32f4xx_hal_msp.c",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc.c",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc_ex.c",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_gpio.c",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_dma.c",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_i2c.c",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_iwdg.c",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_spi.c",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_exti.c",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_rcc.c",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_utils.c",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_exti.c",
            "Src/system_stm32f4xx.c",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Middlewares/Third_Party/FreeRTOS/Source/croutine.c",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Middlewares/Third_Party/FreeRTOS/Source/event_groups.c",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Middlewares/Third_Party/FreeRTOS/Source/list.c",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Middlewares/Third_Party/FreeRTOS/Source/queue.c",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Middlewares/Third_Party/FreeRTOS/Source/stream_buffer.c",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Middlewares/Third_Party/FreeRTOS/Source/tasks.c",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Middlewares/Third_Party/FreeRTOS/Source/timers.c",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c",
            "startup_stm32f446xx.s"
        ],
        "cubemx_includes": [
            "Inc",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/STM32F4xx_HAL_Driver/Inc",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/STM32F4xx_HAL_Driver/Inc/Legacy",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Middlewares/Third_Party/FreeRTOS/Source/include",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/CMSIS/Device/ST/STM32F4xx/Include",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/CMSIS/Include",
            "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/CMSIS/Include"
        ],
        "cubemx_defines": [
            "USE_FULL_LL_DRIVER",
            "USE_HAL_DRIVER",
            "STM32F446xx"
        ],
        "gccExePath": "/Users/Jack/Library/xPacks/@gnu-mcu-eclipse/arm-none-eabi-gcc/8.2.1-1.4.1/.content/bin/arm-none-eabi-gcc",
        "gccIncludePath": "/Users/Jack/Library/xPacks/@gnu-mcu-eclipse/arm-none-eabi-gcc/8.2.1-1.4.1/.content/lib/gcc/arm-none-eabi/8.2.1/include"
    },
    "configurations": [
        {
            "name": "Motor",
            "intelliSenseMode": "msvc-x64",
            "includePath": [
                "${workspaceFolder}",
                "${cubemx_includes}",
                "${gccIncludePath}",
                "${user_cIncludes}",
                "${user_asmIncludes}",
                "${user_ldIncludes}"
            ],
            "browse": {
                "path": [
                    "${workspaceFolder}",
                    "${cubemx_includes}",
                    "${gccIncludePath}",
                    "${user_cIncludes}",
                    "${user_asmIncludes}",
                    "${user_ldIncludes}"
                ],
                "limitSymbolsToIncludedHeaders": true
            },
            "defines": [
                "${cubemx_defines}",
                "${user_cDefines}",
                "${user_asmDefines}"
            ],
            "forcedInclude": [],
            "compilerPath": "${gccExePath}",
            "cStandard": "c11",
            "cppStandard": "c++17"
        }
    ],
    "version": 4
}
/**
  ******************************************************************************
  * @file    stm32f4xx_ll_i2c.c
  * @author  MCD Application Team
  * @brief   I2C LL module driver.
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by ST under BSD 3-Clause license,
  * the "License"; You may not use this file except in compliance with the
  * License. You may obtain a copy of the License at:
  *                        opensource.org/licenses/BSD-3-Clause
  *
  ******************************************************************************
  */
#if defined(USE_FULL_LL_DRIVER)

/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx_ll_i2c.h"
#include "stm32f4xx_ll_bus.h"
#include "stm32f4xx_ll_rcc.h"
#ifdef  USE_FULL_ASSERT
#include "stm32_assert.h"
#else
#define assert_param(expr) ((void)0U)
#endif

/** @addtogroup STM32F4xx_LL_Driver
  * @{
  */

#if defined (I2C1) || defined (I2C2) || defined (I2C3)

/** @defgroup I2C_LL I2C
  * @{
  */

/* Private types -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private constants ---------------------------------------------------------*/
/* Private macros ------------------------------------------------------------*/
/** @addtogroup I2C_LL_Private_Macros
  * @{
  */

#define IS_LL_I2C_PERIPHERAL_MODE(__VALUE__)    (((__VALUE__) == LL_I2C_MODE_I2C)          || \
                                                 ((__VALUE__) == LL_I2C_MODE_SMBUS_HOST)   || \
                                                 ((__VALUE__) == LL_I2C_MODE_SMBUS_DEVICE) || \
                                                 ((__VALUE__) == LL_I2C_MODE_SMBUS_DEVICE_ARP))

#define IS_LL_I2C_CLOCK_SPEED(__VALUE__)           (((__VALUE__) > 0U) && ((__VALUE__) <= LL_I2C_MAX_SPEED_FAST))

#define IS_LL_I2C_DUTY_CYCLE(__VALUE__)            (((__VALUE__) == LL_I2C_DUTYCYCLE_2) || \
                                                 ((__VALUE__) == LL_I2C_DUTYCYCLE_16_9))

#if  defined(I2C_FLTR_ANOFF)&&defined(I2C_FLTR_DNF)
#define IS_LL_I2C_ANALOG_FILTER(__VALUE__)      (((__VALUE__) == LL_I2C_ANALOGFILTER_ENABLE) || \
                                                 ((__VALUE__) == LL_I2C_ANALOGFILTER_DISABLE))

#define IS_LL_I2C_DIGITAL_FILTER(__VALUE__)     ((__VALUE__) <= 0x0000000FU)

#endif
#define IS_LL_I2C_OWN_ADDRESS1(__VALUE__)       ((__VALUE__) <= 0x000003FFU)

#define IS_LL_I2C_TYPE_ACKNOWLEDGE(__VALUE__)   (((__VALUE__) == LL_I2C_ACK) || \
                                                 ((__VALUE__) == LL_I2C_NACK))

#define IS_LL_I2C_OWN_ADDRSIZE(__VALUE__)       (((__VALUE__) == LL_I2C_OWNADDRESS1_7BIT) || \
                                                 ((__VALUE__) == LL_I2C_OWNADDRESS1_10BIT))
/**
  * @}
  */

/* Private function prototypes -----------------------------------------------*/

/* Exported functions --------------------------------------------------------*/
/** @addtogroup I2C_LL_Exported_Functions
  * @{
  */

/** @addtogroup I2C_LL_EF_Init
  * @{
  */

/**
  * @brief  De-initialize the I2C registers to their default reset values.
  * @param  I2Cx I2C Instance.
  * @retval An ErrorStatus enumeration value:
  *          - SUCCESS  I2C registers are de-initialized
  *          - ERROR  I2C registers are not de-initialized
  */
uint32_t LL_I2C_DeInit(I2C_TypeDef *I2Cx)
{
  ErrorStatus status = SUCCESS;

  /* Check the I2C Instance I2Cx */
  assert_param(IS_I2C_ALL_INSTANCE(I2Cx));

  if (I2Cx == I2C1)
  {
    /* Force reset of I2C clock */
    LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_I2C1);

    /* Release reset of I2C clock */
    LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_I2C1);
  }
  else if (I2Cx == I2C2)
  {
    /* Force reset of I2C clock */
    LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_I2C2);

    /* Release reset of I2C clock */
    LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_I2C2);

  }
#if defined(I2C3)
  else if (I2Cx == I2C3)
  {
    /* Force reset of I2C clock */
    LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_I2C3);

    /* Release reset of I2C clock */
    LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_I2C3);
  }
#endif
  else
  {
    status = ERROR;
  }

  return status;
}

/**
  * @brief  Initialize the I2C registers according to the specified parameters in I2C_InitStruct.
  * @param  I2Cx I2C Instance.
  * @param  I2C_InitStruct pointer to a @ref LL_I2C_InitTypeDef structure.
  * @retval An ErrorStatus enumeration value:
  *          - SUCCESS  I2C registers are initialized
  *          - ERROR  Not applicable
  */
uint32_t LL_I2C_Init(I2C_TypeDef *I2Cx, LL_I2C_InitTypeDef *I2C_InitStruct)
{
  LL_RCC_ClocksTypeDef rcc_clocks;

  /* Check the I2C Instance I2Cx */
  assert_param(IS_I2C_ALL_INSTANCE(I2Cx));

  /* Check the I2C parameters from I2C_InitStruct */
  assert_param(IS_LL_I2C_PERIPHERAL_MODE(I2C_InitStruct->PeripheralMode));
  assert_param(IS_LL_I2C_CLOCK_SPEED(I2C_InitStruct->ClockSpeed));
  assert_param(IS_LL_I2C_DUTY_CYCLE(I2C_InitStruct->DutyCycle));
#if  defined(I2C_FLTR_ANOFF)&&defined(I2C_FLTR_DNF)
  assert_param(IS_LL_I2C_ANALOG_FILTER(I2C_InitStruct->AnalogFilter));
  assert_param(IS_LL_I2C_DIGITAL_FILTER(I2C_InitStruct->DigitalFilter));
#endif
  assert_param(IS_LL_I2C_OWN_ADDRESS1(I2C_InitStruct->OwnAddress1));
  assert_param(IS_LL_I2C_TYPE_ACKNOWLEDGE(I2C_InitStruct->TypeAcknowledge));
  assert_param(IS_LL_I2C_OWN_ADDRSIZE(I2C_InitStruct->OwnAddrSize));

  /* Disable the selected I2Cx Peripheral */
  LL_I2C_Disable(I2Cx);

  /* Retrieve Clock frequencies */
  LL_RCC_GetSystemClocksFreq(&rcc_clocks);

#if  defined(I2C_FLTR_ANOFF)&&defined(I2C_FLTR_DNF)
  /*---------------------------- I2Cx FLTR Configuration -----------------------
   * Configure the analog and digital noise filters with parameters :
   * - AnalogFilter: I2C_FLTR_ANFOFF bit
   * - DigitalFilter: I2C_FLTR_DNF[3:0] bits
   */
  LL_I2C_ConfigFilters(I2Cx, I2C_InitStruct->AnalogFilter, I2C_InitStruct->DigitalFilter);

#endif
  /*---------------------------- I2Cx SCL Clock Speed Configuration ------------
   * Configure the SCL speed :
   * - ClockSpeed: I2C_CR2_FREQ[5:0], I2C_TRISE_TRISE[5:0], I2C_CCR_FS,
   *           and I2C_CCR_CCR[11:0] bits
   * - DutyCycle: I2C_CCR_DUTY[7:0] bits
   */
  LL_I2C_ConfigSpeed(I2Cx, rcc_clocks.PCLK1_Frequency, I2C_InitStruct->ClockSpeed, I2C_InitStruct->DutyCycle);

  /*---------------------------- I2Cx OAR1 Configuration -----------------------
   * Disable, Configure and Enable I2Cx device own address 1 with parameters :
   * - OwnAddress1:  I2C_OAR1_ADD[9:8], I2C_OAR1_ADD[7:1] and I2C_OAR1_ADD0 bits
   * - OwnAddrSize:  I2C_OAR1_ADDMODE bit
   */
  LL_I2C_SetOwnAddress1(I2Cx, I2C_InitStruct->OwnAddress1, I2C_InitStruct->OwnAddrSize);

  /*---------------------------- I2Cx MODE Configuration -----------------------
  * Configure I2Cx peripheral mode with parameter :
   * - PeripheralMode: I2C_CR1_SMBUS, I2C_CR1_SMBTYPE and I2C_CR1_ENARP bits
   */
  LL_I2C_SetMode(I2Cx, I2C_InitStruct->PeripheralMode);

  /* Enable the selected I2Cx Peripheral */
  LL_I2C_Enable(I2Cx);

  /*---------------------------- I2Cx CR2 Configuration ------------------------
   * Configure the ACKnowledge or Non ACKnowledge condition
   * after the address receive match code or next received byte with parameter :
   * - TypeAcknowledge: I2C_CR2_NACK bit
   */
  LL_I2C_AcknowledgeNextData(I2Cx, I2C_InitStruct->TypeAcknowledge);

  return SUCCESS;
}

/**
  * @brief  Set each @ref LL_I2C_InitTypeDef field to default value.
  * @param  I2C_InitStruct Pointer to a @ref LL_I2C_InitTypeDef structure.
  * @retval None
  */
void LL_I2C_StructInit(LL_I2C_InitTypeDef *I2C_InitStruct)
{
  /* Set I2C_InitStruct fields to default values */
  I2C_InitStruct->PeripheralMode  = LL_I2C_MODE_I2C;
  I2C_InitStruct->ClockSpeed      = 5000U;
  I2C_InitStruct->DutyCycle       = LL_I2C_DUTYCYCLE_2;
#if  defined(I2C_FLTR_ANOFF)&&defined(I2C_FLTR_DNF)
  I2C_InitStruct->AnalogFilter    = LL_I2C_ANALOGFILTER_ENABLE;
  I2C_InitStruct->DigitalFilter   = 0U;
#endif
  I2C_InitStruct->OwnAddress1     = 0U;
  I2C_InitStruct->TypeAcknowledge = LL_I2C_NACK;
  I2C_InitStruct->OwnAddrSize     = LL_I2C_OWNADDRESS1_7BIT;
}

/**
  * @}
  */

/**
  * @}
  */

/**
  * @}
  */

#endif /* I2C1 || I2C2 || I2C3 */

/**
  * @}
  */

#endif /* USE_FULL_LL_DRIVER */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
sean-mcmanus commented 5 years ago

I'm not reproing the bug using those settings and source file. Can you run the C/C++: Log Diagnostics command?

I'm seeing Defines: USE_FULL_LL_DRIVER

noppej commented 5 years ago

Hi @sean-mcmanus,

Here is the output of my diagnostics. I don't see any Defines, and the line that has "/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Projects/STM32F411E-Discovery/Examples/RCC/RCC_ClockConfig/Inc" really doesn't belong in my project. I'm not sure where it came from because it is not part of my c_cpp_properties config.

Thoughts?

-------- Diagnostics - 4/26/2019, 10:34:28 AM
Version: 0.23.0-insiders
Translation Unit Mappings:
[/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c]:
    /Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c
Translation Unit Configurations:
[/Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c]:
    Compiler Path: /usr/bin/clang
    Includes:
        /usr/local/include
        /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.1/include
        /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
        /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
        /Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/STM32F4xx_HAL_Driver/Inc
        /Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Projects/STM32F411E-Discovery/Examples/RCC/RCC_ClockConfig/Inc
        /Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/STM32F4xx_HAL_Driver/Inc/Legacy
        /Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/CMSIS/Device/ST/STM32F4xx/Include
        /Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/CMSIS/Core/Include
    Frameworks:
        /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks
    Standard Version: c11
    IntelliSense Mode: clang-x64
    Other Flags:
        --clang
        --clang_version=100001
noppej commented 5 years ago

@sean-mcmanus ... I think this might be a knowledge-gap on my side. Let me explain ...

The translation unit in the above output (stm32f4xx_hal_i2c.c) is installed as part of the STM32CubeF4 libraries. It lives in a directory adjacent to my own project, but as you will see from my c_cpp_properties it is referenced by my project, and compiles/runs successfully. So it seems the problem is caused by the directory structure. When I look at that file, inside my project, it doesn't pickup the c_cpp_properties config. Conversely, the diagnostics on main.c in my own project, reflects a config consistent with what I would expect. ) Please scroll to the bottom of this post for my question.

-------- Diagnostics - 4/26/2019, 10:52:53 AM
Version: 0.23.0-insiders
Translation Unit Mappings:
[/Users/Jack/SSTP/Motor/Src/sstpCommon.c]:
    /Users/Jack/SSTP/Motor/Src/sstpCommon.c
[/Users/Jack/SSTP/Motor/Src/iwdg.c]:
    /Users/Jack/SSTP/Motor/Src/iwdg.c
[/Users/Jack/SSTP/Motor/Src/main.c]:
    /Users/Jack/SSTP/Motor/Src/main.c
Translation Unit Configurations:
[/Users/Jack/SSTP/Motor/Src/sstpCommon.c]:
    Compiler Path: /Users/Jack/Library/xPacks/@gnu-mcu-eclipse/arm-none-eabi-gcc/8.2.1-1.4.1/.content/bin/arm-none-eabi-gcc
    Includes:
        /Users/Jack/SSTP/Motor
        /Users/Jack/SSTP/Motor/Inc
        /Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/STM32F4xx_HAL_Driver/Inc
        /Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/STM32F4xx_HAL_Driver/Inc/Legacy
        /Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Middlewares/Third_Party/FreeRTOS/Source/include
        /Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2
        /Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F
        /Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/CMSIS/Device/ST/STM32F4xx/Include
        /Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/CMSIS/Include
        /Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/BSP/STM32F4xx-Nucleo
        /Users/Jack/Library/xPacks/@gnu-mcu-eclipse/arm-none-eabi-gcc/8.2.1-1.4.1/.content/lib/gcc/arm-none-eabi/8.2.1/include
        /Users/Jack/Library/xPacks/@gnu-mcu-eclipse/arm-none-eabi-gcc/8.2.1-1.4.1/.content/lib/gcc/arm-none-eabi/8.2.1/include-fixed
        /Users/Jack/Library/xPacks/@gnu-mcu-eclipse/arm-none-eabi-gcc/8.2.1-1.4.1/.content/arm-none-eabi/include
    Defines:
        USE_FULL_LL_DRIVER
        USE_HAL_DRIVER
        STM32F446xx
        AVOID_EMPTY_DEFINE_FIELD_C
        __weak="__attribute__((weak))"
        __packed="__attribute__((__packed__))"
        AVOID_EMPTY_DEFINE_FIELD_ASM
    Standard Version: c11
    IntelliSense Mode: gcc-x64
    Other Flags:
        --gcc
        --gnu_version=80201
[/Users/Jack/SSTP/Motor/Src/iwdg.c]:
    Compiler Path: /Users/Jack/Library/xPacks/@gnu-mcu-eclipse/arm-none-eabi-gcc/8.2.1-1.4.1/.content/bin/arm-none-eabi-gcc
    Includes:
        /Users/Jack/SSTP/Motor
        /Users/Jack/SSTP/Motor/Inc
        /Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/STM32F4xx_HAL_Driver/Inc
        /Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/STM32F4xx_HAL_Driver/Inc/Legacy
        /Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Middlewares/Third_Party/FreeRTOS/Source/include
        /Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2
        /Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F
        /Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/CMSIS/Device/ST/STM32F4xx/Include
        /Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/CMSIS/Include
        /Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/BSP/STM32F4xx-Nucleo
        /Users/Jack/Library/xPacks/@gnu-mcu-eclipse/arm-none-eabi-gcc/8.2.1-1.4.1/.content/lib/gcc/arm-none-eabi/8.2.1/include
        /Users/Jack/Library/xPacks/@gnu-mcu-eclipse/arm-none-eabi-gcc/8.2.1-1.4.1/.content/lib/gcc/arm-none-eabi/8.2.1/include-fixed
        /Users/Jack/Library/xPacks/@gnu-mcu-eclipse/arm-none-eabi-gcc/8.2.1-1.4.1/.content/arm-none-eabi/include
    Defines:
        USE_FULL_LL_DRIVER
        USE_HAL_DRIVER
        STM32F446xx
        AVOID_EMPTY_DEFINE_FIELD_C
        __weak="__attribute__((weak))"
        __packed="__attribute__((__packed__))"
        AVOID_EMPTY_DEFINE_FIELD_ASM
    Standard Version: c11
    IntelliSense Mode: gcc-x64
    Other Flags:
        --gcc
        --gnu_version=80201
[/Users/Jack/SSTP/Motor/Src/main.c]:
    Compiler Path: /Users/Jack/Library/xPacks/@gnu-mcu-eclipse/arm-none-eabi-gcc/8.2.1-1.4.1/.content/bin/arm-none-eabi-gcc
    Includes:
        /Users/Jack/SSTP/Motor
        /Users/Jack/SSTP/Motor/Inc
        /Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/STM32F4xx_HAL_Driver/Inc
        /Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/STM32F4xx_HAL_Driver/Inc/Legacy
        /Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Middlewares/Third_Party/FreeRTOS/Source/include
        /Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2
        /Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F
        /Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/CMSIS/Device/ST/STM32F4xx/Include
        /Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/CMSIS/Include
        /Users/Jack/SSTP/STM32Cube/STM32Cube_FW_F4_V1.24.1/Drivers/BSP/STM32F4xx-Nucleo
        /Users/Jack/Library/xPacks/@gnu-mcu-eclipse/arm-none-eabi-gcc/8.2.1-1.4.1/.content/lib/gcc/arm-none-eabi/8.2.1/include
        /Users/Jack/Library/xPacks/@gnu-mcu-eclipse/arm-none-eabi-gcc/8.2.1-1.4.1/.content/lib/gcc/arm-none-eabi/8.2.1/include-fixed
        /Users/Jack/Library/xPacks/@gnu-mcu-eclipse/arm-none-eabi-gcc/8.2.1-1.4.1/.content/arm-none-eabi/include
    Defines:
        USE_FULL_LL_DRIVER
        USE_HAL_DRIVER
        STM32F446xx
        AVOID_EMPTY_DEFINE_FIELD_C
        __weak="__attribute__((weak))"
        __packed="__attribute__((__packed__))"
        AVOID_EMPTY_DEFINE_FIELD_ASM
    Standard Version: c11
    IntelliSense Mode: gcc-x64
    Other Flags:
        --gcc
        --gnu_version=80201

So my question is this ... how should I reference the library files (installed adjacent to my project, because many projects use it)? Is there some way it can inherit my c_cpp_properties or some way for me to reference it correctly in my config?

sean-mcmanus commented 5 years ago

You can reference shared defines by setting C_Cpp.default.defines and using "${default}}. Is that what you want? Or did you want c_cpp_properties.json to be processed in subfolders? Another option to try is using multiple root folders. compile_commands.json also enables per-file includes/defines.

noppej commented 5 years ago

Thanks. The problem with all three suggested approaches, is that the folder with the STM32Cube libraries are shared by multiple projects, and those projects have unique 'defines' ... Now that I understand the root of the problem, I'm not sure if there is a logical solution, other than copying the library files to a sub-folder for each project. I will experiment with symbolic links (hoping to trick the extension into thinking that the library files are part of my project) and update this post if I find a viable solution.

Update: I used symbolic links to include the libraries under my workspaceFolder, and update c_cpp_properties and Makefile appropriately. My defines now work exactly as I want them to :) PS. I should note, that when I navigate to a library include file by doing a "Go to Definition", VSCode opens the correct file and shows the physical file path (not the symbolic link file path). This is slightly confusing, but the behaviour during editing, compiling and debugging is exactly what I need.