cancel
Showing results for 
Search instead for 
Did you mean: 

Errors While Compiling STM32F10x Standard Peripheral Library in Keil

romi
Associate

Hello,

I’m encountering multiple errors and warnings when trying to compile a project using the STM32F10x Standard Peripheral Library in Keil uVision. The specific errors are related to assert_param being undeclared and numerous UTF-8 warnings in comments.

Environment:

STM32F10x Standard Peripheral Library
Keil uVision (Using ARM Compiler v6.21)
Key Errors:

call to undeclared function 'assert_param'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
invalid UTF-8 in comment [-Winvalid-utf8] in stm32f10x.h
It seems like the compiler isn't recognizing the assert_param macro, which is leading to multiple errors. I’ve ensured that the stm32f10x_conf.h file includes the necessary header files, but the issue persists.

Has anyone experienced similar issues or can provide guidance on resolving these errors?

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions

Thank you for your kind response. I found the solution by defining USE_STDPERIPH_DRIVER in the project header file. I made the following changes in the stm32f10x_rcc.h header file, and now everything is working fine:

#ifndef __STM32F10X_CONF_H
#define __STM32F10X_CONF_H

#define USE_STDPERIPH_DRIVER

#include "stm32f10x.h" // Main STM32F10x header
#include "stm32f10x_gpio.h" // GPIO header
#include "stm32f10x_rcc.h" // RCC header
// Include other necessary headers...

// Define assert_param macro if not already defined
#ifdef USE_STDPERIPH_DRIVER
#define assert_param(expr) ((void)0) // Implement according to your needs
#else
#define assert_param(expr) ((void)0)
#endif

#endif /* __STM32F10X_CONF_H */

View solution in original post

6 REPLIES 6
TDK
Guru

> invalid UTF-8 in comment [-Winvalid-utf8] in stm32f10x.h

You sure you have valid files? The library shouldn't have non UTF-8 characters.

stm32f10x-stdperiph-lib/Project/STM32F10x_StdPeriph_Template/stm32f10x_conf.h at afa743577f2784e95be2d5003380fdb84a702519 · wajatimur/stm32f10x-stdperiph-lib (github.com)

Perhaps post your file here?

If you feel a post has answered your question, please click "Accept as Solution".

Thank you for your response. I double-checked the files, and they seem to be valid. The issue might not be with the library itself but potentially with the encoding settings on my end. I’ve followed the instructions as you suggested, but the problem persists.

Here’s what I’ve tried so far:

  • Verified that the files are not corrupted and match the repository.
  • Made sure my editor is set to use UTF-8 encoding.
  • Recompiled the project after ensuring everything is in UTF-8.

However, I still get the invalid UTF-8 in comment [-Winvalid-utf8] error in stm32f10x.h

The SPL data back to uVision 4

Where are you pulling these files? Some third-party repo, or the .zip files for the libraries off ST's site? What version?

What line and comment is it objected too?

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

I am using Keil uVision 5 to run some code. When I translate the current file, I get zero errors but 5 warnings. However, when I build the target files, I encounter many errors. I have attached the code and the error messages below. I have been trying to solve this problem for more than five days but still can't figure it out. Can someone help me identify the issue and how to fix it?

 

***************************************************************************************************************************

#include "stm32f10x.h"
#include "stm32f10x_rcc.h"
#include "stm32f10x_gpio.h"
#include "stm32f10x_tim.h"

// Function Prototypes
void PWM_Init(uint16_t period, uint16_t prescaler);
void Set_PWM_DutyCycle(uint16_t dutyCycle);

int main(void) {
// Initialize PWM with a period of 1000 and a prescaler of 72
PWM_Init(1000, 72);

while (1) {
// Set the PWM duty cycle to 50% (mid-speed)
Set_PWM_DutyCycle(500);

// Add your control logic here (e.g., changing the duty cycle based on speed commands)
}
}

void PWM_Init(uint16_t period, uint16_t prescaler) {
// Enable clock for GPIOA and TIM2
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);

// Configure PA0 (TIM2_CH1) as alternate function push-pull
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);

// Timer configuration
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_TimeBaseStructure.TIM_Period = period - 1;
TIM_TimeBaseStructure.TIM_Prescaler = prescaler - 1;
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);

// PWM mode configuration
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 0; // Start with 0% duty cycle
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC1Init(TIM2, &TIM_OCInitStructure);

// Start TIM2
TIM_Cmd(TIM2, ENABLE);
}

void Set_PWM_DutyCycle(uint16_t dutyCycle) {
TIM_SetCompare1(TIM2, dutyCycle);
}

 

*******************************************************************************************************************************

Are you defining USE_STDPERIPH_DRIVER during the build process? Or you can make sure it's defined from within stm32f10x.h. Need that to pull in assert_param.

Looks like your apostrophe marks are not UTF-8.

If you feel a post has answered your question, please click "Accept as Solution".

Thank you for your kind response. I found the solution by defining USE_STDPERIPH_DRIVER in the project header file. I made the following changes in the stm32f10x_rcc.h header file, and now everything is working fine:

#ifndef __STM32F10X_CONF_H
#define __STM32F10X_CONF_H

#define USE_STDPERIPH_DRIVER

#include "stm32f10x.h" // Main STM32F10x header
#include "stm32f10x_gpio.h" // GPIO header
#include "stm32f10x_rcc.h" // RCC header
// Include other necessary headers...

// Define assert_param macro if not already defined
#ifdef USE_STDPERIPH_DRIVER
#define assert_param(expr) ((void)0) // Implement according to your needs
#else
#define assert_param(expr) ((void)0)
#endif

#endif /* __STM32F10X_CONF_H */