BRT Community

Please login or register.

Login with username, password and session length
Advanced search  

News:

Welcome to the Bridgetek Community!

Please read our Welcome Note

Technical Support enquires
please contact the team
@ Bridgetek Support

Please refer to our website for detailed information on all our products - Bridgetek - Bridging Technology

Author Topic: STM32CubeIDE EVE4 Library Integration  (Read 4870 times)

kumaichi

  • Newbie
  • *
  • Posts: 11
    • View Profile
STM32CubeIDE EVE4 Library Integration
« on: January 23, 2024, 08:15:38 PM »

Hello All,

New here, I've been writing Windows based software for longer than I'd like to admit and I'm having the hardest time trying to integrate any of the EVE libraries out on GitHub into an STM32CubeIDE project.  I've tried Riverdi (that's the display I'm trying to get working), Rudolph Riedel's and MatrixOrbital's libraries without much luck.  The steps I've tried:

1. Create a new project in Stm32CubeIDE using the STM32Wb55RG Nucleo board (I'm creating a custom board based off the MCU so bought the Nucleo for prototyping).
2. Dragged the cooresponding .c & .h files from the perspective library into the STM32CubeIDE file tree, .c to Src folder and .h to Inc folder.  Trying to keep it simple instead of creating specific folders like in the libraries for now to try and get something to compile.
3. Copied the contents of the host_layer/Stm32/platform.h and platform.c and copied into my main.h and main.c files.

Then I spend a few hours trying to get it to build.  Fail miserably and moved onto the next library trying the same steps (I am the definition of insanity, lol).  Can anyone provide some guidance to getting one of the libraries to build in an STM32CubeIDE project?

I am very new to hardware and STM32CubeIDE, which is why I think I'm having so much difficulty.

Kindest regards
Logged

BRT Community

  • Administrator
  • Hero Member
  • *****
  • Posts: 721
    • View Profile
Re: STM32CubeIDE EVE4 Library Integration
« Reply #1 on: January 24, 2024, 11:28:41 AM »

Hello,

[edit to add the image]

Welcome to the BRT Community,

We have a couple of examples on our Github which you could look at,

This example supports many different MCUs and we have recently added an STM32 CUBE IDE project, here is the link for the overall repository and a link to the project file.
https://github.com/Bridgetek/EVE-MCU-BRT_AN_025/tree/main
https://github.com/Bridgetek/EVE-MCU-BRT_AN_025/tree/main/examples/simple/STM32CUBE
If you download and unzip the full BRT_AN_025 code from the first link above, you can then open the project by browsing to the folder in the second link above within your download. This has the project file. We used the STM32F0 Discovery board and so some edits may be needed, I'll post an image of the hardware connection but we can also email you a document covering the code (please contact support.emea@brtchip.com)

A second project is our ESD porting guide which uses CUBE IDE, you can find a full document and code at this link on Github
https://github.com/Bridgetek/BRT_AN_073-ESD-exported-Project-Porting-Guide
This is for exporting the EVE Screen Designer project to C code for our FT900 MCUs and then porting to other platforms.

Rudolph also has a comprehensive library and examples for EVE which covers many different MCUs including STM32 and is worth checking out too,

Best Regards, BRT Community







 

« Last Edit: January 24, 2024, 08:30:26 PM by BRT Community »
Logged

kumaichi

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: STM32CubeIDE EVE4 Library Integration
« Reply #2 on: January 24, 2024, 05:51:56 PM »

Thank you for your reply, I must have missed the "simple" during my searching.  I opened the project in CUBE IDE and although it successfully builds, when I try to write the firmware to an STM32F03 board I had laying around, it bricks the MCU and can only get it back by resetting it. 

Thanks again, I will continue to try and figure out what is happening.

I couldn't get Rudolph's library to build in my CUBE IDE project.

Kindest regards.
Logged

Rudolph

  • Sr. Member
  • ****
  • Posts: 378
    • View Profile
Re: STM32CubeIDE EVE4 Library Integration
« Reply #3 on: January 24, 2024, 06:06:56 PM »

I am not really working with STM32, but my Workspace in STM32CubeIDE is not empty. :-)
Setting up a project for the STM32Wb55RG revealed that my passwort on www.st.com had expired...
Oh, I also still did not implement DMA suppport.


Anyways, I started a new project with the NUCLEO-WB55RG and configured SPI1:
PA5 = SPI1_SCK
PA6 = SPI1_MISO
PA7 = SPI1_MOSI

And two GPIO-Outputs, PA3 and PA4.
I set the driver for SPI and GPIO to "LL".

I have no idea though to what the clocks are configured.
The SPI needs to be (at least initially) set to 11MHz or less.


The code is generated and the project builds.
Now I opened the project in the file explorer and went into /Core/Src/.
I created a folder "EmbeddedVideoEngine" and copied over the files from my library.
The folder EVE_target only needs to have the file EVE_target_STM32.h .

In the "examples" folder are several copies of "tfc.c", "tft.h", "tft_data.c" and "tft_data.h", for the most part these are all the same but the ones
in the "...PlatformIo" folders do not have the "EmbeddedVideoEngine" in the include for "EVE.h".
So I used the files from examples\EVE_Test_SAMC21_EVE2-50G\ and copied them to /Core/Src/.

Refreshing the project in STM32CubeIDE and the files show up.

Building the project fails however, the first error here is:
../Core/Src/EmbeddedVideoEngine/EVE_commands.c:3037:36: error: unknown type name 'int16_t'
And the reason is, my library does not know what a STM32WB is, yet.

Checking the properties/"C/C++ Build"/Settings/MCU GCC Compiler/Preprocessor, there is the symbol "STM32WB55xx" defined.
So the first thing to do is to add this symbol to EVE_target.h so that EVE_target_STM32.h gets included.

And now EVE_target_STM32.h needs to be expanded to load the correct includes:
Code: [Select]
#if defined (STM32WB55xx) /* set with "build_flags = -D STM32WB55xx" in platformio.ini */
#include "stm32wbxx.h"
#include "stm32wbxx_hal.h"
#include "stm32wbxx_ll_spi.h"
#endif

Building the project again, it still fails, but now the error is:
#error "Please add a define for the desired display to your build-environment, e.g. -DEVE_EVE3_50G"

So there is no display selected.
Back to the properties I added a new symbol: "EVE_EVE3_50G".

-> 18:57:17 Build Finished. 0 errors, 0 warnings. (took 1s.755ms)

In EVE_target_STM32.h also is the configuration for the CS and PD pins as well the SPI to use:
Code: [Select]
#if !defined (EVE_CS)
#define EVE_CS_PORT GPIOA
#define EVE_CS GPIO_PIN_4
#endif

#if !defined (EVE_PDN)
#define EVE_PDN_PORT GPIOA
#define EVE_PDN GPIO_PIN_3
#endif

#if !defined (EVE_SPI)
#define EVE_SPI SPI1
#endif

Nice coincidence, I already setup PA3 and PA4 as outputs and selected SPI1. :-)


And I just uploaded the modified EVE_target.h and EVE_target_STM32.h to Github.


But the project won't display anything so far.
So now main.c needs to be modified:

Code: [Select]
/* USER CODE BEGIN Includes */
#include "tft.h"

/* USER CODE END Includes */

Code: [Select]
int main(void)
{
...
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_SPI1_Init();

  /* USER CODE BEGIN 2 */
  TFT_init();

  TFT_display();

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

This should at least display one frame.
Usually I would put this in the endless loop, together with the TFT_touch() function from the example.
But the default main.c from STM32CubeIDE does not have even a primitive scheduler and while there is a SysTick_Handler(),
I am not sure to what tick it is configured.
Normally I would go for 5ms ticks, execute TFT_display() every 20ms and execute TFT_touch() every 5ms when TFT_display()
is not executed.
But well, my job was done when it compiled. :-)
« Last Edit: January 26, 2024, 06:11:31 PM by Rudolph »
Logged

kumaichi

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: STM32CubeIDE EVE4 Library Integration
« Reply #4 on: January 24, 2024, 08:36:06 PM »

Wow!  Thank you so much Rudolph!  I'm a newbie to CUBE IDE and trying to figure all of this out.  Guess I shouldn't have started with a display, LOL.

I have it building without errors or warnings using your very detailed steps, very cool!!!

This is light years ahead of where I've been for the last week.  Thanks again for your time and effort helping a newbie and putting this library together.

Currently stuck inside:

EVE_target_STM32.h->spi_transmit(...)->while (!LL_SPI_IsActiveFlag_RXNE(EVE_SPI)) {}

It never comes out of the while loop and the return always = 0, ugh. 

Kindest regards
« Last Edit: January 25, 2024, 01:26:26 AM by kumaichi »
Logged

Rudolph

  • Sr. Member
  • ****
  • Posts: 378
    • View Profile
Re: STM32CubeIDE EVE4 Library Integration
« Reply #5 on: January 25, 2024, 06:46:07 PM »

That might be the clock configuration.
But I can't explain that so easily.
I opened the clocktree and just closed it again. :-)
Logged

kumaichi

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: STM32CubeIDE EVE4 Library Integration
« Reply #6 on: January 25, 2024, 08:13:45 PM »

I got it! :)  But not sure the best way to solve it permanently.  I added, LL_SPI_Enable(EVE_SPI); to spi_trasmit(...):

static inline void spi_transmit(uint8_t data)
{
   LL_SPI_Enable(EVE_SPI);
   LL_SPI_TransmitData8(EVE_SPI, data);
   while (!LL_SPI_IsActiveFlag_TXE(EVE_SPI)) {}
   while (!LL_SPI_IsActiveFlag_RXNE(EVE_SPI)) {}
   LL_SPI_ReceiveData8(EVE_SPI); /* dummy read-access to clear SPI_SR_RXNE */
}

I'm confident that's not where it should go.  Any thoughts?

Kindest regards
« Last Edit: January 25, 2024, 08:16:14 PM by kumaichi »
Logged

BRT Community

  • Administrator
  • Hero Member
  • *****
  • Posts: 721
    • View Profile
Re: STM32CubeIDE EVE4 Library Integration
« Reply #7 on: January 26, 2024, 11:37:04 AM »

Hi,

Could you confirm what that call which you added does in the STM32 library, does it assert CS or enable the SPI Master itself?

Best Regards, BRT Community
Logged

kumaichi

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: STM32CubeIDE EVE4 Library Integration
« Reply #8 on: January 26, 2024, 02:29:32 PM »

Hello,

I just came across it while I was searching for why the RXNE was always return 0, there are two methods the LL SPI uses to initialize itself, LL_SPI_Init() and LL_SPI_Enable().  I searched the STM32 documentation and couldn't find exactly what it does but this is the source:

/**
  * @brief  Enable SPI peripheral
  * @rmtoll CR1          SPE           LL_SPI_Enable
  * @param  SPIx SPI Instance
  * @retval None
  */
__STATIC_INLINE void LL_SPI_Enable(SPI_TypeDef *SPIx)
{
  SET_BIT(SPIx->CR1, SPI_CR1_SPE);
}

There's also a way to ensure the LL_SPI is initialized:

/**
  * @brief  Check if SPI peripheral is enabled
  * @rmtoll CR1          SPE           LL_SPI_IsEnabled
  * @param  SPIx SPI Instance
  * @retval State of bit (1 or 0).
  */
__STATIC_INLINE uint32_t LL_SPI_IsEnabled(SPI_TypeDef *SPIx)
{
  return ((READ_BIT(SPIx->CR1, SPI_CR1_SPE) == (SPI_CR1_SPE)) ? 1UL : 0UL);
}

I changed Rudolph's spi_transmit method to look like this:

static inline void spi_transmit(uint8_t data)
{
   if(!LL_SPI_IsEnabled(EVE_SPI))
   {
      LL_SPI_Enable(EVE_SPI);
   }

   LL_SPI_TransmitData8(EVE_SPI, data);
   while (!LL_SPI_IsActiveFlag_TXE(EVE_SPI)) {}
   while (!LL_SPI_IsActiveFlag_RXNE(EVE_SPI)) {}
   LL_SPI_ReceiveData8(EVE_SPI); /* dummy read-access to clear SPI_SR_RXNE */
}

I still have an icky feeling putting that code in the spi_transmit(), just doesn't feel right and I doubt Rudolph has anyone complaining about it.  Could be just something in my CUBE IDE configuration I missed too.

I don't know if it needs to call, LL_SPI_DISABLE() at some point or not.  The above source came from my, stm32wbxx_ll_spi.h.

If there is anything I can look at for you let me know.

Kindest regards
Logged

BRT Community

  • Administrator
  • Hero Member
  • *****
  • Posts: 721
    • View Profile
Re: STM32CubeIDE EVE4 Library Integration
« Reply #9 on: January 26, 2024, 04:10:52 PM »

Hi,

Do you have a logic analyser etc. to see what differs on the SPI lines with and without the code,

I have used MCUs before where the SPI seemed to need re-enabled between transitions but not sure if this device is one of them (our BRT_AN_025 code did not use this https://github.com/Bridgetek/EVE-MCU-BRT_AN_025/tree/main/ports/eve_arch_stm32cube)

One thing may be to do with the chip select if the MCU thinks it is controlling CS automatically, or if a certain frame size is set in the SPI master (not 100% sure if your one does this Rudolph but most EVE libraries send byte by byte so that they can send the address and then the data as per EVE protocol). Some MCU by default have a buffer set so that it expects more than one byte. I think Rudolph's code would set this up anyway as needed but might be a setting in the MCU SPI Master that differs in that MCU.

Best Regards, BRT Community

Logged

Rudolph

  • Sr. Member
  • ****
  • Posts: 378
    • View Profile
Re: STM32CubeIDE EVE4 Library Integration
« Reply #10 on: January 26, 2024, 06:10:49 PM »

LL_SPI_Enable() should be at the end of MX_SPI1_Init() in main.c.

I just checked what STM32CubeIDE is generating for me and I also do not have this line,
whatever the idea behind fully configuring a unit and then not activating it in the end is.

Well, STM32CubeIDE, I still have the Code that it generated for the STM32G0B1CET6, took me a bit to find out that the
generated MX_SPI1_Init() neither activated the clock or configured the SPI pins.
And the one working version I have in the other folder has __HAL_SPI_ENABLE(&hspi1); at the end, the generated one does not.

If only you had pick one of the few STM32 controllers I have a Nucleo board with here... :-)
« Last Edit: January 26, 2024, 06:15:00 PM by Rudolph »
Logged

kumaichi

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: STM32CubeIDE EVE4 Library Integration
« Reply #11 on: January 26, 2024, 08:23:44 PM »

I connected my Diligent Analog Discovery 3 to the SPI lines and the screenshots are attached.  I'm new to hardware so I'm not sure if what I captured was correct.  However, the big difference is WITH the LL_SPI_Enable(), there is a bunch of traffic captured, the screenshot is only the first "set" of data, there is a bunch more but I can't really see anything when zoomed out enough to see the whole process but there is A LOT of communication happening.  The capture WITHOUT the LL_SPI_Enable(), has the CS line going high and then low but nothing after that, it's just flat, there is nothing happening in the capture after the CS.

Let me know if there is something I can do differently in WaveForms to give you better information.

Kindest regards
« Last Edit: January 26, 2024, 09:42:12 PM by kumaichi »
Logged

kumaichi

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: STM32CubeIDE EVE4 Library Integration
« Reply #12 on: January 29, 2024, 05:28:26 PM »

LL_SPI_Enable() should be at the end of MX_SPI1_Init() in main.c.

What's worse for me, it didn't include the stm32wbxx_ll_spi.h file, so I had to add that to my main.h file as well, ugh.  This has solved the issue though and is a much better solution that what I was doing.

I just checked what STM32CubeIDE is generating for me and I also do not have this line,
whatever the idea behind fully configuring a unit and then not activating it in the end is.

Yeah, I'm beginning to question my choice here.

Well, STM32CubeIDE, I still have the Code that it generated for the STM32G0B1CET6, took me a bit to find out that the
generated MX_SPI1_Init() neither activated the clock or configured the SPI pins.
And the one working version I have in the other folder has __HAL_SPI_ENABLE(&hspi1); at the end, the generated one does not.

I apologize for this consuming so much of your time, I really do appreciate your assistance with this, it was driving me crazy.

If only you had pick one of the few STM32 controllers I have a Nucleo board with here... :-)

Ha, I was getting to a place that I would have sent you one :).

Thanks again for all of your assistance.

Kindest regards
Logged