STM32 PWM only works correctly when I leave in two unused variables: StartUpCounter and HSEStatus
Is PLL_SOURCE_HSI #defined in your code? 

In system_stm32f30x.c, it looks like HSEStatus, and StartUpCounter should never be defined IFF your code is using the HSI oscillator.

Their definition is in the code:

#if defined (PLL_SOURCE_HSI)
...
#else
#if defined (PLL_SOURCE_HSE)
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;


So, it appears that something is undefine-ing PLL_SOURCE_HSI, and hence allowing StartUpCounter and HSEStatus to be defined.

I can't see anything in the source file src/system_stm32f30x.c to cause that.

So either:


the src/system_stm32f30x.c file at github is not the one being used in your build, or
your build is somehow causing PLL_SOURCE_HSI to become undefined
and PLL_SOURCE_HSE to be defined (which seems unlikely to get both), or
the include file stm32f30x.h contains a syntax error which is
causing some of this.


1 and 3 seem more likely.

Those two variables are local to SetSysClock. So their names can be safely changed.

Commenting out their definition should cause the compile of that source file to fail. 

If the build is producing a program, then src/system_stm32f30x.c is not part of the program, or an old object is being used, or their is an inconsistency in the question.

If the HSI oscillator is being used in one case, and not in another, it is plausible that the PWM period is inconsistent.