PlatformIO Community

How in include disco_f429zi headers?


#1

I need to use LCD/touch libraries for disco_f429zi. As far as i understand, there are 2 possibilities:

  1. Use built-in libraries, with hardcode absolute lib path in platform.ini
  2. Use https://platformio.org/lib/show/2208/BSP_DISCO_F429ZI

Since hardcoded paths are not acceptable for my project, i tried to use BSP_DISCO_F429ZI. But ldf still fails to include files:

// Both fail to find header
#include "Utilities/Fonts/fonts.h"
#include "fonts.h"

I also could not find any sample projects for disco_f429zi with LCD sample.

Could you guide me to proper direction? That’s not my first pio project, but first attempt to use extended built-in libs.


#2

Compiles for me. You also need https://platformio.org/lib/show/2432/LCD_DISCO_F429ZI

platformio.ini

[env:disco_f429z]
platform = ststm32
board = disco_f429zi
framework = mbed
lib_deps = 
	BSP_DISCO_F429ZI
	LCD_DISCO_F429ZI

main.cpp from the DISCO-F429ZI_LCD_demo_main.cpp

#include "mbed.h"
#include "LCD_DISCO_F429ZI.h"

LCD_DISCO_F429ZI lcd;

DigitalOut led1(LED1);

int main()
{
    led1 = 1;

    BSP_LCD_SetFont(&Font20);
    lcd.DisplayStringAt(0, LINE(1), (uint8_t *)"MBED EXAMPLE", CENTER_MODE);
    wait(1);

    while(1)
    {
      lcd.Clear(LCD_COLOR_BLUE);
      lcd.SetBackColor(LCD_COLOR_BLUE);
      lcd.SetTextColor(LCD_COLOR_WHITE);
      wait(0.3);
      lcd.DisplayStringAt(0, LINE(4), (uint8_t *)"DISCOVERY", CENTER_MODE);
      lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"STM32F429ZI", CENTER_MODE);
      wait(1);

      lcd.Clear(LCD_COLOR_GREEN);

      lcd.SetTextColor(LCD_COLOR_BLUE);
      lcd.FillRect(10, 20, 50, 50);
      wait(0.1);
      lcd.SetTextColor(LCD_COLOR_BROWN);
      lcd.FillCircle(80, 80, 50);
      wait(0.1);
      lcd.SetTextColor(LCD_COLOR_YELLOW);
      lcd.FillEllipse(150, 150, 50, 100);
      wait(0.1);
      lcd.SetTextColor(LCD_COLOR_RED);
      lcd.FillCircle(200, 200, 40);
      wait(1);

      lcd.SetBackColor(LCD_COLOR_ORANGE);
      lcd.SetTextColor(LCD_COLOR_CYAN);
      BSP_LCD_SetFont(&Font24);
      lcd.DisplayStringAt(0, LINE(7), (uint8_t *)"HAVE FUN !!!", CENTER_MODE);
      wait(1);

      led1 = !led1;
      wait(0.5);
    }
}


#3

Works for me: #include <fonts.h>. The library.json of the BSP_DISCO_F429ZI library correctly does

    "build": {
        "flags": [
            "-IDrivers",
            "-IDrivers/BSP",
            "-IDrivers/BSP/STM32F429I-Discovery",
            "-IDrivers/BSP/Components",
            "-IDrivers/BSP/Components/ili9341",
            "-IDrivers/BSP/Components/stmpe811",
            "-IDrivers/BSP/Components/l3gd20",
            "-IDrivers/BSP/Components/Common",
            "-IUtilities",
            "-IUtilities/Fonts"
        ]
    },

so since font.h is in Utilities/Fonts/fonts.h it sufficies to so say include <fonts.h> or include <Fonts/fonts.h>


#4

Also with the touch screen you’ll need https://platformio.org/lib/show/2803/TS_DISCO_F429ZI :slight_smile:


#5

@maxgerhardt thanks for example! I found the root of problem. All those packages are restricted to mbed framework in manifest, but i use stm32cube. So, libraries were silently excluded from build.

Is it possible to fix issue for stm32cube? Created a test repo https://github.com/puzrin/pio_disco_test

See this line https://github.com/puzrin/pio_disco_test/blob/master/src/main.c#L11 As far as i understand, it exists in stm32cube framework too, but include fails.


#6

Hmm even if you add -I $PIOHOME_DIR/packages/framework-stm32cube/f4/Drivers/BSP/STM32F429I-Discovery the #include <stm32f429i_discovery.h> is found but it doesn’t compile the objects file in that library. The STM32Cube builder script doesn’t seem to process the Drivers/BSP/<board_variant> files? (@ivankravets) Only everything in Drivers\BSP\Components.

Note that there is a lib_compat_mode = off possibility (https://docs.platformio.org/en/latest/projectconf/section_env_library.html#lib-compat-mode) but sadly the BSP_DISCO_F429ZI has an mbed-os specific include so it won’t work in this case.

The easiest way to get it working is to copy .platformio\packages\framework-stm32cube\f4\Drivers\BSP\STM32F429I-Discovery into lib/STM32F429I-Discovery and rewrite the include paths in the code

See pull-request https://github.com/puzrin/pio_disco_test/pull/1

Note that to get a working firmware you must initialize the HAL and setup handlers as in https://github.com/platformio/platform-ststm32/blob/master/examples/stm32cube-hal-blink/src/main.c


#7

Also if you look at the LCD libraries, every function just forwards the execution into the BSP_XXX functitons so the examples should actually be really easy to port to STM32Cube by calling the wrapped functions directly instead of the C++ object functions. https://os.mbed.com/teams/ST/code/LCD_DISCO_F429ZI/file/dc55a068bc1a/LCD_DISCO_F429ZI.cpp/


#8

@valeros should it be fixed on our side?


#9

Thanks for detailed explanations. I’m familiar with hacks via lib/ and use it often, when have no time to investigate details. But scope if this thread was to understand how to do things “right and beautiful” :slight_smile:.

I’m not sure if this should be posted to tracker or it’s my mistake because something is done wrong.

Note that to get a working firmware you must initialize the HAL and setup handlers as in

Sure. Sample repo is just a minimal cut to demonstrate problem. It skips a lot of thing from real project.


#10

Okay this has a second part. There is code that attempts to do that

However the path that it constructs here in my case is C:\Users\Maxi\.platformio\packages\framework-stm32cube\f4\Drivers\BSP\DISCO_F429ZI and not C:\Users\Maxi\.platformio\packages\framework-stm32cube\f4\Drivers\BSP\STM32F429I-Discovery. In general variant may not correspond to the folder names inside that directory.


#11

There is nothing to fix as it’s already implemented. Probably just need to add a new entry with this board to the variant_remap.json file.


#12

You’re right. The platformio\packages\framework-stm32cube\platformio\variants_remap.json is missing the entry

"disco_f429zi": "STM32F429I-Discovery",

in this case.


#13

Yes. Clean way:

Add "disco_f429zi": "STM32F429I-Discovery" as an entry the JSON file variants_remap.json

Write the platformio.ini as

[env:stm32f429_disco]
platform = ststm32
board = disco_f429zi
framework = stm32cube
lib_deps =
        BSP-ili9341

main.c

#include "stm32f429i_discovery.h"
#include <stm32f429i_discovery_lcd.h>


int main(void)
{
        BSP_GetVersion();
        BSP_LCD_Init();
}

or more sophisticated

#include <stm32f4xx_hal.h>
#include <stm32f429i_discovery.h>
#include <stm32f429i_discovery_lcd.h>

#define LCD_FRAME_BUFFER_LAYER0                  (LCD_FRAME_BUFFER+0x130000)
#define LCD_FRAME_BUFFER_LAYER1                  LCD_FRAME_BUFFER
#define CONVERTED_FRAME_BUFFER                   (LCD_FRAME_BUFFER+0x260000)

int main(void)
{
	HAL_Init();

	BSP_LCD_Init();
	BSP_LCD_LayerDefaultInit(1, LCD_FRAME_BUFFER_LAYER1);
	BSP_LCD_SelectLayer(1);
	BSP_LCD_Clear(LCD_COLOR_WHITE);
	BSP_LCD_SetColorKeying(1, LCD_COLOR_WHITE);
	BSP_LCD_SetLayerVisible(1, DISABLE);
	BSP_LCD_LayerDefaultInit(0, LCD_FRAME_BUFFER_LAYER0);
	BSP_LCD_SelectLayer(0);
	BSP_LCD_SetFont(&Font16);
	BSP_LCD_DisplayOn();

	//clear LCD
	BSP_LCD_Clear(LCD_COLOR_WHITE);

	//set font (and size)
	BSP_LCD_SetFont(&Font20);

	//display string
	BSP_LCD_DisplayStringAt(0, LINE(1), (uint8_t *)"MBED EXAMPLE", CENTER_MODE);

	//endless loop
	while(1);
}


void SysTick_Handler(void)
{
  HAL_IncTick();
}

void NMI_Handler(void)
{
}

void HardFault_Handler(void)
{
  while (1) {}
}


void MemManage_Handler(void)
{
  while (1) {}
}

void BusFault_Handler(void)
{
  while (1) {}
}

void UsageFault_Handler(void)
{
  while (1) {}
}

void SVC_Handler(void)
{
}


void DebugMon_Handler(void)
{
}

void PendSV_Handler(void)
{
}

and delete all previous lib/ folders, no duplication needed. I guess @valeros will fix this is upstream soon.


#14

@maxgerhardt could you explain how BSP-ili9341 dependency works in your sample? It not exists in registry. Is it really needed?


#15

Yes, otherwise the ILI9341 driver (framework-stm32cube\f4\Drivers\BSP\Components\ili9341) won’t be compiled and you will get an undefinded reference to .. error when calling BSP_LCD_XXX functions. The needed name is comprised of BSP- plus the folder name inside Components/, see the Python code at


#16

Hm… do i understand right, this code dynamically register ghost BSP-* libs as “available for use”?

Seems this feature is not documented anywhere in stm32cube platform docs. Probably worth to add - even with correct variant_remap.json i could not resolve this without your help.


#17

Seems alternative is to add

#include <ili9341.h>

somewhere. Also works, but without warning “library not found”.