Jump to content

µGFX and mbedos


vahid4134

Recommended Posts

Hello vahid4134 and welcome to the community!

You can use uGFX on top of any platform. However, uGFX doesn't come with a MbedOS port (yet). This means that you have to write a port yourself to make it work.

Writing a port is not as hard as it sounds as everything you have to implement is in one place (the GOS module) and there are more than enough existing ports that can serve as examples. Furthermore, the interface is well documented.

We also port uGFX to other platforms for customers as part of a commercial support contract.

Kind regards,

~ Tectu

Link to comment
Share on other sites

Minar doesn't seem to be a pre-emptive scheduler and that can lead to serious performance issues in case of uGFX.

However, uGFX comes with an optional built-in scheduler which you can use. The scheduler is optimizable: It either uses setjmp()/longjmp() or you can supply your own context switching (assembly) code. We already implemented the optimized custom schedulers for all Cortex-M microcontrollers.

Note: In case of MbedOS doesn't provide a memory manager either we have an optional built-in one as well. We provide a port called RAW32 which uses both the built-in scheduler and the build-in memory manager. If you want to use the memory manager of MbedOS (in case of it has one) then you can just copy the RAW32 port and throw out the memory manager part.

In either case I would recommend you to create a new port called MbedOS. This way you can share the port and other users might be quite thankful for that :)

~ Tectu

Link to comment
Share on other sites

mbedOs provice allocator manager. is this memory manager?

Yes, that is exactly it.

All you need to do know when implementing an uGFX port is wrapping the uGFX functions such as gfxAlloc() and gfxFree() around those ualloc calls. That is usually just a matter of either a macro or a simple one-line function.

Eg. here you can see how it is done for FreeRTOS and ChibiOS/RT. It really just is a matter of forwarding the calls:


#define gfxAlloc(sz) chHeapAlloc(0, sz)
#define gfxFree(ptr) chHeapFree(ptr)

~ Tectu

Link to comment
Share on other sites

I have this error when compile


[11/66] Building CXX object ym/mbed-ugfx/source/CMakeFiles/mbed-ugfx.dir/drivers/gdisp/ILI9341/gdisp_lld_ILI9341.c.o
FAILED: /usr/bin/arm-none-eabi-g++ -DYOTTA_COMPONENT_VERSION=\"0.0.1\" -fno-exceptions -fno-unwind-tables -ffunction-sections -fdata-sections -Wall -Wextra -fno-rtti -fno-threadsafe-statics -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -D__thumb2__ -Os -g -DNDEBUG -I/home/vahid/blinky2 -I/home/vahid/blinky2/yotta_modules/mbed-drivers -I/home/vahid/blinky2/yotta_modules/mbed-unigraphic -I/home/vahid/blinky2/yotta_modules/mbed-ugfx -I/home/vahid/blinky2/yotta_modules/mbed-hal -I/home/vahid/blinky2/yotta_modules/cmsis-core -I/home/vahid/blinky2/yotta_modules/ualloc -I/home/vahid/blinky2/yotta_modules/minar -I/home/vahid/blinky2/yotta_modules/core-util -I/home/vahid/blinky2/yotta_modules/compiler-polyfill -I/home/vahid/blinky2/yotta_modules/mbed-hal-st -I/home/vahid/blinky2/yotta_modules/mbed-hal-st-stm32f4 -I/home/vahid/blinky2/yotta_modules/uvisor-lib -I/home/vahid/blinky2/yotta_modules/mbed-hal-st-stm32cubef4 -I/home/vahid/blinky2/yotta_modules/mbed-hal-st-stm32f429zi -I/home/vahid/blinky2/yotta_modules/cmsis-core-st -I/home/vahid/blinky2/yotta_modules/cmsis-core-stm32f4 -I/home/vahid/blinky2/yotta_modules/cmsis-core-stm32f429xi -I/home/vahid/blinky2/yotta_modules/dlmalloc -I/home/vahid/blinky2/yotta_modules/minar-platform -I/home/vahid/blinky2/yotta_modules/minar-platform-mbed -I/home/vahid/blinky2/yotta_modules/mbed-ugfx/mbed-ugfx/src -I/home/vahid/blinky2/yotta_modules/mbed-ugfx/mbed-ugfx/src/gdisp/mcufont -I/home/vahid/blinky2/yotta_modules/mbed-ugfx/mbed-ugfx/drivers/gdisp/ILI93xx -I/home/vahid/blinky2/yotta_modules/mbed-ugfx/mbed-ugfx/drivers/gdisp/ILI9341 -I/home/vahid/blinky2/yotta_modules/mbed-ugfx/mbed-ugfx/src/gdriver -I/home/vahid/blinky2/yotta_modules/mbed-ugfx/mbed-ugfx/src/gdisp -I/home/vahid/blinky2/yotta_modules/mbed-ugfx/mbed-ugfx/src/gwin -I/home/vahid/blinky2/yotta_modules/mbed-ugfx/mbed-ugfx -I/home/vahid/blinky2/yotta_modules/mbed-drivers/mbed -I/home/vahid/blinky2/yotta_modules/mbed-hal/mbed-hal -I/home/vahid/blinky2/yotta_modules/cmsis-core/cmsis-core -I/home/vahid/blinky2/yotta_modules/mbed-hal-st-stm32f4/mbed-hal-st-stm32f4 -I/home/vahid/blinky2/yotta_modules/mbed-hal-st-stm32cubef4/mbed-hal-st-stm32cubef4 -I/home/vahid/blinky2/yotta_modules/mbed-hal-st-stm32f429zi/mbed-hal-st-stm32f429zi -I/home/vahid/blinky2/yotta_modules/cmsis-core-stm32f4/cmsis-core-stm32f4 -I/home/vahid/blinky2/yotta_modules/cmsis-core-stm32f429xi/cmsis-core-stm32f429xi -DTOOLCHAIN_GCC -DTOOLCHAIN_GCC_ARM -DMBED_OPERATORS -DTARGET_STM32F429I_DISCO -DTARGET_STM32F429ZI -DTARGET_STM32F4 -DTOOLCHAIN_GCC -DTOOLCHAIN_GCC_ARM -include "/home/vahid/blinky2/build/stm32f429i-disco-gcc/yotta_config.h" -MMD -MT ym/mbed-ugfx/source/CMakeFiles/mbed-ugfx.dir/drivers/gdisp/ILI9341/gdisp_lld_ILI9341.c.o -MF ym/mbed-ugfx/source/CMakeFiles/mbed-ugfx.dir/drivers/gdisp/ILI9341/gdisp_lld_ILI9341.c.o.d -o ym/mbed-ugfx/source/CMakeFiles/mbed-ugfx.dir/drivers/gdisp/ILI9341/gdisp_lld_ILI9341.c.o -c /home/vahid/blinky2/yotta_modules/mbed-ugfx/source/drivers/gdisp/ILI9341/gdisp_lld_ILI9341.c
In file included from /home/vahid/blinky2/yotta_modules/mbed-ugfx/mbed-ugfx/src/gdisp/gdisp_driver.h:22:0,
from /home/vahid/blinky2/yotta_modules/mbed-ugfx/source/drivers/gdisp/ILI9341/gdisp_lld_ILI9341.c:23:
/home/vahid/blinky2/yotta_modules/mbed-ugfx/mbed-ugfx/src/gdriver/gdriver.h:90:33: error: duplicate 'const'
typedef const struct GDriverVMT const GDriverVMTList[1];
^
In file included from /home/vahid/blinky2/yotta_modules/mbed-ugfx/source/drivers/gdisp/ILI9341/gdisp_lld_ILI9341.c:23:0:
/home/vahid/blinky2/yotta_modules/mbed-ugfx/mbed-ugfx/src/gdisp/gdisp_driver.h:731:17: error: duplicate 'const'
const GDISPVMT const GDISP_DRIVER_VMT[1] = {{
^
[11/66] Building CXX object ym/mbed-ugfx/source/CMakeFiles/mbed-ugfx.dir/src/gwin/gwin_wm.c.o
ninja: build stopped: subcommand failed.
error: command ['ninja'] failed

Link to comment
Share on other sites

My g++ version


gcc version 4.9.3 20150529 (release) [ARM/embedded-4_9-branch revision 224288] (GNU Tools for ARM Embedded Processors)

Ok I change some code in ugfx to work correctly with g++ :D

but now I have again problem

this is my config file


#define GFX_USE_OS_RAW32 TRUE
/* GFX sub-systems to turn on */
#define GFX_USE_GDISP TRUE
#define GFX_USE_GWIN TRUE
#define GFX_USE_GINPUT TRUE
#define GFX_USE_GEVENT TRUE
#define GFX_USE_GTIMER TRUE
#define GFX_USE_GQUEUE TRUE

/* Features for the GDISP sub-system. */
#define GDISP_NEED_VALIDATION TRUE
#define GDISP_NEED_CLIP TRUE
#define GDISP_NEED_CIRCLE TRUE
#define GDISP_NEED_TEXT TRUE
#define GDISP_NEED_CONTROL TRUE
#define GDISP_NEED_MULTITHREAD TRUE
#define GQUEUE_NEED_ASYNC TRUE

/* GDISP fonts to include */
#define GDISP_INCLUDE_FONT_UI2 TRUE

/* Features for the GWIN subsystem. */
#define GWIN_NEED_WINDOWMANAGER FALSE
#define GWIN_NEED_WIDGET FALSE
#define GWIN_NEED_BUTTON FALSE

/* Features for the GINPUT subsystem. */
#define GINPUT_NEED_MOUSE FALSE


FAILED: : && /usr/bin/arm-none-eabi-g++ -fno-exceptions -fno-unwind-tables -Wl,--gc-sections -Wl,--sort-common -Wl,--sort-section=alignment -Wl,-wrap,main -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -T"/home/vahid/blinky2/yotta_targets/stm32f429i-disco-gcc/CMake/../ld/STM32F429ZI.ld" -Wl,-Map,source/blinky2.map -Wl,--start-group source/CMakeFiles/blinky2.dir/home/vahid/blinky2/source/blinky.cpp.o ym/mbed-drivers/source/mbed-drivers.a ym/mbed-unigraphic/source/mbed-unigraphic.a ym/mbed-ugfx/source/mbed-ugfx.a ym/mbed-drivers/source/mbed-drivers.a ym/mbed-hal/yotta_dummy_lib_mbed_hal/mbed-hal.a ym/cmsis-core/yotta_dummy_lib_cmsis_core/cmsis-core.a ym/minar/source/minar.a ym/core-util/source/core-util.a ym/mbed-hal-st/yotta_dummy_lib_mbed_hal_st/mbed-hal-st.a ym/cmsis-core-st/yotta_dummy_lib_cmsis_core_st/cmsis-core-st.a ym/minar-platform/yotta_dummy_lib_minar_platform/minar-platform.a ym/mbed-hal-st-stm32f4/source/mbed-hal-st-stm32f4.a ym/cmsis-core-stm32f4/source/cmsis-core-stm32f4.a ym/minar-platform-mbed/source/minar-platform-mbed.a ym/mbed-hal-st-stm32cubef4/source/mbed-hal-st-stm32cubef4.a ym/mbed-hal-st-stm32f429zi/source/mbed-hal-st-stm32f429zi.a ym/cmsis-core-stm32f429xi/source/cmsis-core-stm32f429xi.a ym/mbed-drivers/source/mbed-drivers.a ym/mbed-hal/yotta_dummy_lib_mbed_hal/mbed-hal.a ym/cmsis-core/yotta_dummy_lib_cmsis_core/cmsis-core.a ym/minar/source/minar.a ym/core-util/source/core-util.a ym/mbed-hal-st/yotta_dummy_lib_mbed_hal_st/mbed-hal-st.a ym/cmsis-core-st/yotta_dummy_lib_cmsis_core_st/cmsis-core-st.a ym/minar-platform/yotta_dummy_lib_minar_platform/minar-platform.a ym/mbed-hal-st-stm32f4/source/mbed-hal-st-stm32f4.a ym/cmsis-core-stm32f4/source/cmsis-core-stm32f4.a ym/minar-platform-mbed/source/minar-platform-mbed.a ym/mbed-hal-st-stm32cubef4/source/mbed-hal-st-stm32cubef4.a ym/mbed-hal-st-stm32f429zi/source/mbed-hal-st-stm32f429zi.a ym/cmsis-core-stm32f429xi/source/cmsis-core-stm32f429xi.a ym/compiler-polyfill/yotta_dummy_lib_compiler_polyfill/compiler-polyfill.a ym/ualloc/source/ualloc.a ym/dlmalloc/source/dlmalloc.a -Wl,-wrap,_malloc_r -Wl,-wrap,_calloc_r -Wl,-wrap,_realloc_r -Wl,-wrap,_free_r -Wl,-wrap,_sbrk_r ym/uvisor-lib/source/uvisor-lib.a -lstdc++ -lsupc++ -lm -lc -lgcc -lstdc++ -lsupc++ -lm -lc -lgcc -Wl,--end-group --specs=nano.specs -o source/blinky2 && cd /home/vahid/blinky2/build/stm32f429i-disco-gcc/source && /usr/bin/arm-none-eabi-objcopy -O binary blinky2 blinky2.bin && cd /home/vahid/blinky2/build/stm32f429i-disco-gcc/source && /usr/bin/arm-none-eabi-objcopy -O binary blinky2 blinky2.bin
ym/mbed-ugfx/source/mbed-ugfx.a(gdisp.c.o): In function `_gdispInit()':
/home/vahid/blinky2/yotta_modules/mbed-ugfx/source/src/gdisp/gdisp.c:607: undefined reference to `GDISPVMT_OnlyOne'

I use ili9341.

Link to comment
Share on other sites

4.9 is quite a recent release. This must be something else in that case.

To your compilation issue: This can either be related to your changes or due to the fact that you didn't properly include a display driver. Please make sure that you properly include/select/define the ILI9341 driver (how you do this depends on many factors such as your build system, whether it is a custom board or an already existing one and so on).

~ Tectu

Link to comment
Share on other sites

You need to compile the ugfx source code with gcc not g++.

Your own files however can be compiled with either g++ or gcc as you see appropriate. The ugfx header files are designed to be used by either compiler whereas the ugfx source MUST be compiled with gcc as it is C source NOT C++ source. Whilst C++ is mostly a superset of C and some C programs can be compiled using the C++ compiler, there are also many language incompatibilities.

Normally a C++ compiler will detect the language based on the file extension. GNU however takes a different approach - it supplies two different compilers (gcc and g++). You must use the correct one in each case. Make will normally take care of those issues for you based on the file extension.

If you are trying to port your C++ operating system into the ugfx GOS layer then there are one of two approaches you need to take...

  • Using the C binding API for your operating system in the GOS layer - most operating systems will provide one
  • Create stub routines in gos_your_os.h for each GOS routine needed. Create a gos_your_os.cpp file that implements each of those routines as extern "C" functions. That source file can include your operating system c++ header files and will be compiled by the g++ compiler without affecting the compilation of any other part of ugfx.
    As an example:
    gos_xyz.h

    extern "C" {
    void *gfxAlloc(uint32_t sz);
    void gfxFree(void *ptr);
    ...
    }


    gos_xyz.cpp


    #include

    #include "ugfx.h" // Optional - but does pull in ugfx typedefs and function prototypes

    extern "C" void *gfxAlloc(uint32_t sz) {
    // Not real code - but using c++ only symantics as an example
    return new byte[sz];
    }

    extern "C" void gfxFree(void *ptr) {
    // Not real code - but using c++ only symantics as an example
    delete ptr;
    }

    ...

Link to comment
Share on other sites

Thank you.

I finaly compile with out error and runtime error. but on my dispay not show anything.

I create new ili9341 to work with mbed spi


void init_board(GDisplay *g){

_spi.format(8,0);
_spi.frequency(100000);

_CS=1;
_DC=1;
_reset=1;


}



void post_init_board(GDisplay *g) {

(void) g;


}


void setpin_reset(GDisplay *g, bool_t state) {
if (state == TRUE) {
_reset=0;

} else {
_reset=1;
}
(void) g;

// (void) state;
}

void setpin_dc(GDisplay *g, bool_t state) {
if (state == TRUE) {
_DC.write(1);

} else {
_DC.write(0);
}
(void) g;
// (void) state;
}

void set_backlight(GDisplay *g, uint8_t percent) {
(void) g;
(void) percent;
}

void acquire_bus(GDisplay *g) {
_CS = 0;
}

void release_bus(GDisplay *g) {
_CS = 1;
}

void write_index(GDisplay *g, uint16_t index) {

_DC.write(0); // 0=cmd
_spi.write((int)index); // write 8bit
_DC.write(1); // 1=data next
}

void write_data(GDisplay *g, uint16_t data) {
_spi.write((int)index); // write 8bit
}

void setreadmode(GDisplay *g) {
(void) g;
}

void setwritemode(GDisplay *g) {
(void) g;
}

int16_t read_data(GDisplay *g) {
return _spi.write(0);
}

and in my app


coord_t width, height;
coord_t i, j;
gfxInit();

width = gdispGetWidth();
height = gdispGetHeight();

// Code Here
gdispDrawBox(10, 10, width/2, height/2, Yellow);

Link to comment
Share on other sites

I don't know the underlying system that you are using but your board file seems to be mostly fine. The thing you really want to change is setting the DC pin in write_data() as well in case of anything happens between write_index() and write_data().

Usually it is also a good idea to start with a lower bus frequency to rule out any wiring related issues.

I would recommend you to grab a logic analyzer to see whether the data is sent via SPI properly.

~ Tectu

Link to comment
Share on other sites

I think i under stand the question.

You are not sure what to do when the c++ mutex type needs to be used in the gos_xyz.h file.

The solution is:

gfx_xyz.h



typedef gfxMutex void;

#define Mutex gfxMutex

The gfx mutex function definitions

In your c++ file:


#include "gfx.h"

#undef Mutex

#include

extern "C" gfxInit (gfxMutex *p) {
p = new Mutex;
}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...