NETMF / netmf-interpreter

.NET Micro Framework Interpreter
http://netmf.github.io/netmf-interpreter/
Other
487 stars 224 forks source link

What is the standard way to update Firmware Package for STM32F4 from ST? #351

Open techcap opened 8 years ago

techcap commented 8 years ago

Current version of stm32f4xx.h is v1.2.1 and the latest one is v2.4.1.

I updated it to latest Firmware Package supplied by ST.

There was two issues for pulling request.

1. How could I include CPU information when compiling?

In new stm32f4xx.h, there's macro like below. I thought if I would put "#define STM32F411xE 1" to platform_selector.h in solution, it would have worked. But it didn't. So temporarily I put it to stm32f4xx_hal_conf.h. But it's wrong way. How can I give the CPU information to stm32f4xx.h in the propery way?

stm32f4xx.h

#if defined(STM32F405xx)
  #include "stm32f405xx.h"
...
#elif defined(STM32F411xE)
  #include "stm32f411xe.h"
...
#else
 #error "Please select first the target STM32F4xx device used in your application (in stm32f4xx.h file)"
#endif

2. Depending on the CPU, the number of IO is different. How can I give that information?

For example, STM32F411xE doesn't have SPI6. So After updating stm32f4xx.h, when I compiled, I got error in STM32F4_SPI_functions.cpp. Because it doesn't have SPI6 definition. So I handled like below. In the case of USB, STM32F411xE doesn't support HS. so I handled similarly. Will it be the right approach? Can you suggest more standardized method?

STM32F4_SPI_functions.cpp

#if defined(STM32F411xE)
static const ptr_SPI_TypeDef g_STM32_Spi_Port[] = {SPI1, SPI2, SPI3, SPI4, SPI5, NULL};
#else
static const ptr_SPI_TypeDef g_STM32_Spi_Port[] = { SPI1, SPI2, SPI3, SPI4, SPI5, SPI6 };
#endif

STM32F4_usb_functions.cpp

    // enable USB clock
    if( STM32F4_USB_IS_HS( Controller ) )
    { // HS on AHB1
#if !defined(STM32F411xE)
        RCC->AHB1ENR |= RCC_AHB1ENR_OTGHSEN;
        // this is needed to enable the FS phy clock when the CPU is sleeping
        RCC->AHB1LPENR &= ~RCC_AHB1LPENR_OTGHSULPILPEN;
#endif
    }
    else
    { // FS on AHB2
        RCC->AHB2ENR |= RCC_AHB2ENR_OTGFSEN;
    }
techcap commented 8 years ago

About first issue, I added #include "platform_selector.h" at stm32f4xx_hal_conf.h, worked properly, and looks good.