Hi, i'm doing a code in C for stm32 with LoRa-02, and i came across a weird error.
Hi, i'm doing a code in C for stm32 with LoRa-02, and i came across a weird error.
error:
expected declaration specifiers or '...' before '(' token
A part of a code:
txt:
define PERIPH_BASE (0x40000000UL) /*!< Peripheral base address in the alias region */
/*!< Peripheral memory map */
#define APBPERIPH_BASE PERIPH_BASE
#define AHBPERIPH_BASE (PERIPH_BASE + 0x00020000UL)
#define IOPPERIPH_BASE (PERIPH_BASE + 0x10000000UL)I'm useing a sts library for SX1278. I don't understand whats wrong with the definition. It seems like the declaration sequence is done correctly, maybe something with nested definitions or something, i don't know. Also when i copypaste this fragment of code into new project, error disapears.
Sorry for my bad london, thx for help :v
edit 1: deleted
edit 2:
My code (main.c) is just a few #include and an endless loop.
Part of a code where PERIPH_BASE is used. It's hal rcc header file:
/* Disable Backup domain write protection state change timeout */
#define RCC_DBP_TIMEOUT_VALUE (100U) /* 100 ms */
/* LSE state change timeout */
#define RCC_LSE_TIMEOUT_VALUE LSE_STARTUP_TIMEOUT
#define CLOCKSWITCH_TIMEOUT_VALUE (5000U) /* 5 s */
#define HSE_TIMEOUT_VALUE HSE_STARTUP_TIMEOUT
#define MSI_TIMEOUT_VALUE (2U) /* 2 ms (minimum Tick + 1) */
#define HSI_TIMEOUT_VALUE (2U) /* 2 ms (minimum Tick + 1) */
#define LSI_TIMEOUT_VALUE (2U) /* 2 ms (minimum Tick + 1) */
#define PLL_TIMEOUT_VALUE (2U) /* 2 ms (minimum Tick + 1) */
#if defined(RCC_HSI48_SUPPORT)
#define HSI48_TIMEOUT_VALUE (2U) /* 2 ms (minimum Tick + 1) */
#endif /* RCC_HSI48_SUPPORT */
/**
* @}
*/
/** @defgroup RCC_BitAddress_AliasRegion BitAddress AliasRegion
* @brief RCC registers bit address in the alias region
* @{
*/
#define RCC_OFFSET (RCC_BASE - PERIPH_BASE)
/* --- CR Register ---*/
/* Alias word address of HSION bit */
#define RCC_CR_OFFSET (RCC_OFFSET + 0x00U)
/* --- CFGR Register ---*/
/* Alias word address of I2SSRC bit */
#define RCC_CFGR_OFFSET (RCC_OFFSET + 0x08U)
/* --- CSR Register ---*/
#define RCC_CSR_OFFSET (RCC_OFFSET + 0x74U)
/* CR register byte 3 (Bits[23:16]) base address */
#define RCC_CR_BYTE2_ADDRESS (0x40023802U)
/* CIER register byte 0 (Bits[0:8]) base address */
#define CIER_BYTE0_ADDRESS ((uint32_t)(RCC_BASE + 0x10U + 0x00U))
/**edit 3:
C:/Users/Wojtek/workspace/RA_B-L072Z-LRWAN1/inc/mlm32l0xx_hw_conf.h:120:42: note: in expansion of macro 'USART2'
#define USARTx USART2
^~~~~~
C:/Users/Wojtek/workspace/RA_B-L072Z-LRWAN1/HAL_Driver/Inc/stm32l0xx_ll_rcc.h:1586:62: note: in expansion of macro 'USARTx'
__STATIC_INLINE uint32_t LL_RCC_GetUSARTClockSource(uint32_t USARTx),,In your declaration of function LL_RCC_GetUSARTClockSource, you have attempted to give the parameter a name (USARTx) that is already defined as a macro identifier. The result is that the parameter / macro name is replaced with the macro's expansion text, which ultimately draws on your PERIPH_BASE macro. That's not valid at that point."
This /\ is a comment from the stackoverflow forum, thanks to some random community member for finding this.
the function that probably cause the problem:
stm32l0xx_ll_rcc.c:
uint32_t LL_RCC_GetUSARTClockFreq(uint32_t USARTxSource)
{
uint32_t usart_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
/* Check parameter */
assert_param(IS_LL_RCC_USART_CLKSOURCE(USARTxSource));
#if defined(RCC_CCIPR_USART1SEL)
if (USARTxSource == LL_RCC_USART1_CLKSOURCE)
{
/* USART1CLK clock frequency */
switch (LL_RCC_GetUSARTClockSource(USARTxSource))
{
case LL_RCC_USART1_CLKSOURCE_SYSCLK: /* USART1 Clock is System Clock */
usart_frequency = RCC_GetSystemClockFreq();
break;
case LL_RCC_USART1_CLKSOURCE_HSI: /* USART1 Clock is HSI Osc. */
if (LL_RCC_HSI_IsReady() != 0U)
{
if (LL_RCC_IsActiveFlag_HSIDIV() != 0U)
{
usart_frequency = (HSI_VALUE >> 2U);
}
else
{
usart_frequency = HSI_VALUE;
}
}
break;
case LL_RCC_USART1_CLKSOURCE_LSE: /* USART1 Clock is LSE Osc. */
if (LL_RCC_LSE_IsReady() != 0U)
{
usart_frequency = LSE_VALUE;
}
break;
case LL_RCC_USART1_CLKSOURCE_PCLK2: /* USART1 Clock is PCLK2 */
default:
usart_frequency = RCC_GetPCLK2ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
break;
}
}
#endif /* RCC_CCIPR_USART1SEL */
#if defined(RCC_CCIPR_USART2SEL)
if (USARTxSource == LL_RCC_USART2_CLKSOURCE)
{
/* USART2CLK clock frequency */
switch (LL_RCC_GetUSARTClockSource(USARTxSource))
{
case LL_RCC_USART2_CLKSOURCE_SYSCLK: /* USART2 Clock is System Clock */
usart_frequency = RCC_GetSystemClockFreq();
break;
case LL_RCC_USART2_CLKSOURCE_HSI: /* USART2 Clock is HSI Osc. */
if (LL_RCC_HSI_IsReady() != 0U)
{
if (LL_RCC_IsActiveFlag_HSIDIV() != 0U)
{
usart_frequency = (HSI_VALUE >> 2U);
}
else
{
usart_frequency = HSI_VALUE;
}
}
break;
case LL_RCC_USART2_CLKSOURCE_LSE: /* USART2 Clock is LSE Osc. */
if (LL_RCC_LSE_IsReady() != 0U)
{
usart_frequency = LSE_VALUE;
}
break;
case LL_RCC_USART2_CLKSOURCE_PCLK1: /* USART2 Clock is PCLK1 */
default:
usart_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
break;
}
}
#endif /* RCC_CCIPR_USART2SEL */
return usart_frequency;
}stm32l0xx_ll_rcc.h:
/**
* @brief Get USARTx clock source
* @rmtoll CCIPR USARTxSEL LL_RCC_GetUSARTClockSource
* @param USARTx This parameter can be one of the following values:
* @arg @ref LL_RCC_USART1_CLKSOURCE (*)
* @arg @ref LL_RCC_USART2_CLKSOURCE
* @retval Returned value can be one of the following values:
* @arg @ref LL_RCC_USART1_CLKSOURCE_PCLK2 (*)
* @arg @ref LL_RCC_USART1_CLKSOURCE_SYSCLK (*)
* @arg @ref LL_RCC_USART1_CLKSOURCE_HSI (*)
* @arg @ref LL_RCC_USART1_CLKSOURCE_LSE (*)
* @arg @ref LL_RCC_USART2_CLKSOURCE_PCLK1
* @arg @ref LL_RCC_USART2_CLKSOURCE_SYSCLK
* @arg @ref LL_RCC_USART2_CLKSOURCE_HSI
* @arg @ref LL_RCC_USART2_CLKSOURCE_LSE
*
* (*) value not defined in all devices.
*/
__STATIC_INLINE uint32_t LL_RCC_GetUSARTClockSource(uint32_t USARTx)
{
return (uint32_t)(READ_BIT(RCC->CCIPR, USARTx) | (USARTx << 16U));
}