Function is not called if not declared as inline/static
Hi I am starting to do some basics with register operations and came across with this situation.
The board I am using is a STM32L031k6 nucleo.
Code is the following
#include "stm32l031xx.h"
// Green led is at PB3
static void delay_ms(uint32_t delay);
int main(void)
{
// Enable clock for GPIOB
RCC->IOPENR |= RCC_IOPENR_GPIOBEN;
// Set Gpio B3 as output, default mode is analog mode
GPIOB->MODER = (GPIOB->MODER & ~(GPIO_MODER_MODE3)) | (GPIO_MODER_MODE3_0);
while (1)
{
GPIOB->BSRR |= 0x8;
delay_ms(20);
GPIOB->BRR |= 0x8;
delay_ms(20);
}
}
void delay_ms(uint32_t delay)
{
for (; delay > 0; delay--)
{
for (uint16_t i = 0; i < 2000; i++)
{
/* code */
}
}
}if function is not declared as static, it never works.
If declared as static, it works most of the times that I do clean-build-transfer ( I don' t understand when it doesn' t)
if declared as __INLINE code takes like extra 60 B of space and works.
As IDE I am using VSCode with stm32-for-vscode extension, which sets the makefile based on a CubeMx proy.
Is the compiler doing some optimization and removing the function ? Is the MCU hanging for some reason ?