This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Trouble with auto-generated code in Keil

Hi there!

I just recently decided to move to ARM based MCUs from 8-bit AVRs.

I bought myself a NUCLEO-F303K8 board to start exploring. I started with STM32CubeIDE and hated it.

So... I decided to get Keil-MDK and so far, I like it.

I installed all the device specific drivers for the whole F3 family of MCUs and in project creation, I chose the STM32F303K8T6 that is on the evaluation board.

I only included CMSIS->Core package and Device->Startup package as shown in the picture below.

I then encountered a strange problem when building the solution. It said that a header file was missing that apparently is part of HAL (I did not include any HAL libraries).

D:/Programi/Keil_v5/Packs/Keil/STM32F3xx_DFP/2.2.0/Drivers/CMSIS/Device/ST/STM32F3xx/Include\stm32f3xx.h(213): error: 'stm32f3xx_hal.h' file not found

I found out that an auto-generated header file includes the option to use the HAL driver, however, I never selected any HAL library. By commenting it out.

/*
 * Auto generated Run-Time-Environment Configuration File
 *      *** Do not modify ! ***
 *
 * Project: 'test' 
 * Target:  'Target 1' 
 */

#ifndef PRE_INCLUDE_GLOBAL_H
#define PRE_INCLUDE_GLOBAL_H

/* Keil.Standalone::Device:Startup:1.11.2 */
#define USE_HAL_DRIVER
          #define USE_FULL_LL_DRIVER


#endif /* PRE_INCLUDE_GLOBAL_H */

By commenting out "#define USE_HAL_DRIVER" I got a simple blinking example to work.

However, the header file says that it should not be modified.

I must have missed the option to not use the HAL driver somewhere, but I cannot figure out where.

What am I doing wrong?

The rest of the code:

#include "stm32f3xx.h"


int main(void) {
	
	RCC->AHBENR |= (1 << 18); // Enable clock for I/O port B
	
	GPIOB->MODER |= (1 << 6); // Pin PB3 set as general purpose output
	GPIOB->MODER &= (unsigned int)(~(1 << 7));
	
	// Push-pull output by default
	
	GPIOB->OSPEEDR |= (1 << 6) | (1 << 7); // High speed output

	while(1) {
	
		GPIOB->BSRR = (1 << 3); // Set PB3
		for(uint32_t i = 0; i < 500000; i++);
		GPIOB->BSRR = (1 << 19); // Reset PB3
		for(uint32_t i = 0; i < 500000; i++);
	
	}

}