Jump to content

Recommended Posts

Posted

Hello masters!

After days of strugling, i discovered (throught your forum) that my GTimer is not working! I cant get the mouseXYZ() (of an ADS7843 resistive touch driver, modified by me) working. It is suppoused to enter in this function every X seconds, right? 

Well its not happening.

I even try this example https://wiki.ugfx.io/index.php/GTIMER . I have a Relay working in my hardware. In the callback function, I put it to toggle. Nothing is happening.

Can you show me where is the problem?

gfxconf.h

/******************************************************************************/
/* This file has been generated by the uGFX-Studio                            */
/*                                                                            */
/* http://ugfx.org                                                            */
/******************************************************************************/

#ifndef _GFXCONF_H
#define _GFXCONF_H

#define GFX_USE_OS_RAW32                             TRUE
#define GFX_OS_HEAP_SIZE                         2000



/********************************************************/
/* GDISP stuff                                          */
/********************************************************/
#define GFX_USE_GDISP TRUE

#define GDISP_NEED_CONTROL TRUE
#define GDISP_NEED_VALIDATION TRUE
#define GDISP_NEED_CLIP TRUE
#define GDISP_NEED_ARC FALSE
#define GDISP_NEED_CONVEX_POLYGON FALSE
#define GDISP_NEED_IMAGE FALSE
#define GDISP_NEED_STARTUP_LOGO FALSE
#define GDISP_NEED_CIRCLE TRUE
#define GDISP_NEED_MULTITHREAD TRUE
#define GDISP_DEFAULT_ORIENTATION GDISP_ROTATE_0
#define GDISP_STARTUP_COLOR HTML2COLOR(0xffffff)


/********************************************************/
/* Font stuff                                           */
/********************************************************/
#define GDISP_NEED_TEXT TRUE
#define GDISP_NEED_ANTIALIAS FALSE
#define GDISP_NEED_TEXT_KERNING FALSE
#define GDISP_NEED_UTF8 FALSE
#define GDISP_INCLUDE_USER_FONTS TRUE


/********************************************************/
/* GWIN stuff                                           */
/********************************************************/
#define GFX_USE_GWIN TRUE

#define GWIN_NEED_WINDOWMANAGER TRUE
    #define GWIN_REDRAW_IMMEDIATE TRUE
    #define GWIN_REDRAW_SINGLEOP TRUE

#define GWIN_NEED_WIDGET TRUE
    #define GWIN_NEED_BUTTON TRUE
        #define GWIN_BUTTON_LAZY_RELEASE FALSE
    #define GWIN_FLAT_STYLING FALSE

#define GWIN_NEED_CONTAINERS TRUE
    #define GWIN_NEED_CONTAINER TRUE
    #define GWIN_NEED_FRAME FALSE
    #define GWIN_NEED_TABSET FALSE


/********************************************************/
/* GTIMER stuff                                         */
/********************************************************/
#define GFX_USE_GTIMER TRUE

#define GTIMER_THREAD_PRIORITY NORMAL_PRIORITY
#define GTIMER_THREAD_WORKAREA_SIZE 2048


/********************************************************/
/* GINPUT stuff                                         */
/********************************************************/
#define GFX_USE_GINPUT TRUE

#define GINPUT_NEED_MOUSE TRUE
#define GINPUT_TOUCH_USER_CALIBRATION_LOAD TRUE
#define GINPUT_NEED_KEYBOARD FALSE//TRUE


/********************************************************/
/* GEVENT stuff                                         */
/********************************************************/
#define GFX_USE_GEVENT TRUE

#define GEVENT_ASSERT_NO_RESOURCE FALSE
#define GEVENT_MAXIMUM_SIZE 32
#define GEVENT_MAX_SOURCE_LISTENERS 32


/********************************************************/
/* GEVENT stuff                                         */
/********************************************************/
#define GFX_USE_GQUEUE TRUE

#define GQUEUE_NEED_ASYNC TRUE


/********************************************************/
/* GFILE stuff                                          */
/********************************************************/
#define GFX_USE_GFILE FALSE

#define GFILE_NEED_NATIVEFS FALSE
#define GFILE_NEED_ROMFS FALSE
#define GFILE_MAX_GFILES 1



#endif /* _GFXCONF_H */

gui.c Event Loop


void guiEventLoop(void)
{
	GEvent* pe;
 //	while (1) {
		// Get an event
		pe = geventEventWait(&glistener, 0);
		//printf("pe = %d\r\n", pe);
		
		switch (pe->type) {
			case GEVENT_GWIN_BUTTON:
				if ( ((GEventGWinButton*)pe)->gwin == SISTEMA) {
					// Our button has been pressed
					printf("buttom press");
					//guiShowPage(1);
					//TOUCH_FLAG = 0;
			  } 
				break;
		}
    

	//}
}


OBS: I saw in other posts that peep are modifiing the function geventWait to TIME_INFINITE, etc. I've tried everything.

Posted

It looks like you are running raw32.

Raw32 relies on our own non-preemptive threading library. It is likely this is not working. Please try the demos/modules/gos/threads demo to check if threading is working.

If it is not working the likely culprit is a bug in the c runtime library shipped with your compiler. Try looking at the GFX_CPU setting. By setting that appropriately we can often work around bugs in the c library. In particular specific cpu code is available for ARM Cortex M0..7 processors.

Posted

So, the thread 1 happened one time and one time only. Nothing happened after.

#include <stdio.h>
#include "stm32f1xx_hal.h"


#include "gfx.h"
#include "gui.h"


threadreturn_t heartbeat1(void* param)
{
    (void)param;

    while (TRUE) {
        printf("thread 1\n");
        gfxSleepMilliseconds(500);
    }

    return (threadreturn_t)0;
}

threadreturn_t heartbeat2(void* param)
{
    (void)param;

    while (TRUE) {
        printf("thread 2\n");
        gfxSleepMilliseconds(900);
    }

    return (threadreturn_t)0;
}


int main(void)
{

gfxInit();
    gdispSetBacklight(100);
    gdispSetContrast(100);

    geventListenerInit(&glistener);
    //geventAttachSource(&glistener, ginputGetKeyboard(0), 0);
    gwinAttachListener(&glistener);

    guiCreate();

       gfxThreadCreate(0, 2048, NORMAL_PRIORITY, heartbeat1, 0);
    gfxThreadCreate(0, 2048, NORMAL_PRIORITY, heartbeat2, 0);
      while (1)
  {
        printf("thread main\n");
        gfxSleepMilliseconds(1400);

}

}
/******************************************************************************/
/* This file has been generated by the uGFX-Studio                            */
/*                                                                            */
/* http://ugfx.org                                                            */
/******************************************************************************/

#ifndef _GFXCONF_H
#define _GFXCONF_H

#define GFX_USE_OS_RAW32                             TRUE
#define GFX_OS_HEAP_SIZE                         10240


/********************************************************/
/* GDISP stuff                                          */
/********************************************************/
#define GFX_USE_GDISP TRUE

#define GDISP_NEED_CONTROL TRUE
#define GDISP_NEED_VALIDATION TRUE
#define GDISP_NEED_CLIP TRUE
#define GDISP_NEED_ARC FALSE
#define GDISP_NEED_CONVEX_POLYGON FALSE
#define GDISP_NEED_IMAGE FALSE
#define GDISP_NEED_STARTUP_LOGO FALSE
#define GDISP_NEED_CIRCLE TRUE
#define GDISP_NEED_MULTITHREAD TRUE
#define GDISP_DEFAULT_ORIENTATION GDISP_ROTATE_0
#define GDISP_STARTUP_COLOR HTML2COLOR(0xffffff)


/********************************************************/
/* Font stuff                                           */
/********************************************************/
#define GDISP_NEED_TEXT TRUE
#define GDISP_NEED_ANTIALIAS FALSE
#define GDISP_NEED_TEXT_KERNING FALSE
#define GDISP_NEED_UTF8 FALSE
#define GDISP_INCLUDE_USER_FONTS TRUE


/********************************************************/
/* GWIN stuff                                           */
/********************************************************/
#define GFX_USE_GWIN TRUE

#define GWIN_NEED_WINDOWMANAGER TRUE
    #define GWIN_REDRAW_IMMEDIATE TRUE
    #define GWIN_REDRAW_SINGLEOP TRUE

#define GWIN_NEED_WIDGET TRUE
    #define GWIN_NEED_BUTTON TRUE
        #define GWIN_BUTTON_LAZY_RELEASE FALSE
    #define GWIN_FLAT_STYLING FALSE

#define GWIN_NEED_CONTAINERS TRUE
    #define GWIN_NEED_CONTAINER TRUE
    #define GWIN_NEED_FRAME FALSE
    #define GWIN_NEED_TABSET FALSE


/********************************************************/
/* GTIMER stuff                                         */
/********************************************************/
#define GFX_USE_GTIMER TRUE

#define GTIMER_THREAD_PRIORITY NORMAL_PRIORITY
#define GTIMER_THREAD_WORKAREA_SIZE 2048


/********************************************************/
/* GINPUT stuff                                         */
/********************************************************/
#define GFX_USE_GINPUT TRUE

#define GINPUT_NEED_MOUSE TRUE
#define GINPUT_TOUCH_USER_CALIBRATION_LOAD TRUE
#define GINPUT_NEED_KEYBOARD FALSE//TRUE


/********************************************************/
/* GEVENT stuff                                         */
/********************************************************/
#define GFX_USE_GEVENT TRUE

#define GEVENT_ASSERT_NO_RESOURCE FALSE
#define GEVENT_MAXIMUM_SIZE 32
#define GEVENT_MAX_SOURCE_LISTENERS 32


/********************************************************/
/* GEVENT stuff                                         */
/********************************************************/
#define GFX_USE_GQUEUE TRUE

#define GQUEUE_NEED_ASYNC TRUE


/********************************************************/
/* GFILE stuff                                          */
/********************************************************/
#define GFX_USE_GFILE FALSE

#define GFILE_NEED_NATIVEFS FALSE
#define GFILE_NEED_ROMFS FALSE
#define GFILE_MAX_GFILES 1



#endif /* _GFXCONF_H */

I took of the:

#if defined(WIN32)
	#include <windows.h>

	static DWORD nres;

	// On Win32 don't use the C library fprintf or write as they crash.
	// Maybe we just need to add the multi-thread C library options to the compile.
	// Instead we use the Win32 API directly as that always works.
	#define DEBUGWRITE(str)		WriteFile(GetStdHandle(STD_ERROR_HANDLE), str, strlen(str), &nres, 0)
#else
	#warning "You must alter this demo to define a DEBUGWRITE macro for your platform."
	#warning "Be careful of using C library functions as they sometimes crash if they are not expecting stack changes (if possible use a multi-thread aware C library)"
	#warning "You might flash LED's instead if that is better for your platform."
	#error "--"
#endif

because it was not compiling. What is the error now?

Posted

Replace the printf's in the thread demo with something you can see eg toggle a led.

Most embedded platforms don't have an output device for printf strings to go to. The printf's are only meant to be a debugging notification. If your debugger has a debug output api you could use that to show messages in your debugger.

Posted

The printf worked. I received the message "thread 1" and then nothing. If I lower the HEAP_SIZE i receive "thread main" one time and then nothing too.

But, i didt what you told me: toggle a Led pin. The result was what I expected: the led turn on, and never turn off (just like the printf solution: it showed me ONE time "thread 1").

What should I do now?

 

Posted

Already seen it. Ive posted it what I did. Setting UP the GFX_CPU to ARM M3. Tried to emmulate malloc. Non emmulate malloc. Everything. I really dont know what is the way now

Posted

The next step is to use your debugger to find out where it is crashing.

Raw32 using a GFX_CPU = GFX_CPU_CORTEXM3 (I think that is the right value - check the documentation to be sure) is a known working configuration for both GCC and Keil/ARMCC compilers.

Posted

Sorry folks, I did not paste the correct gfx_conf.h. As you can see now, Ive already set #define GFX_CPU                                  GFX_CPU_CORTEX_M3

I even tried:

#define     GFX_CPU_NO_ALIGNMENT_FAULTS                         TRUE
#define GFX_EMULATE_MALLOC                       TRUE

Without sucess.

I debug and the program stops in thread 1!

/******************************************************************************/
/* This file has been generated by the uGFX-Studio                            */
/*                                                                            */
/* http://ugfx.org                                                            */
/******************************************************************************/

#ifndef _GFXCONF_H
#define _GFXCONF_H


#define GFX_USE_OS_RAW32                             TRUE
#define GFX_OS_HEAP_SIZE                         10240
#define GFX_CPU                                  GFX_CPU_CORTEX_M3
//#define 	GFX_CPU_NO_ALIGNMENT_FAULTS						 TRUE
//#define GFX_EMULATE_MALLOC                       TRUE

/********************************************************/
/* GDISP stuff                                          */
/********************************************************/
#define GFX_USE_GDISP TRUE

#define GDISP_NEED_CONTROL TRUE
#define GDISP_NEED_VALIDATION TRUE
#define GDISP_NEED_CLIP TRUE
#define GDISP_NEED_ARC FALSE
#define GDISP_NEED_CONVEX_POLYGON FALSE
#define GDISP_NEED_IMAGE FALSE
#define GDISP_NEED_STARTUP_LOGO FALSE
#define GDISP_NEED_CIRCLE TRUE
#define GDISP_NEED_MULTITHREAD TRUE
#define GDISP_DEFAULT_ORIENTATION GDISP_ROTATE_0
#define GDISP_STARTUP_COLOR HTML2COLOR(0xffffff)


/********************************************************/
/* Font stuff                                           */
/********************************************************/
#define GDISP_NEED_TEXT TRUE
#define GDISP_NEED_ANTIALIAS FALSE
#define GDISP_NEED_TEXT_KERNING FALSE
#define GDISP_NEED_UTF8 FALSE
#define GDISP_INCLUDE_USER_FONTS TRUE


/********************************************************/
/* GWIN stuff                                           */
/********************************************************/
#define GFX_USE_GWIN TRUE

#define GWIN_NEED_WINDOWMANAGER TRUE
    #define GWIN_REDRAW_IMMEDIATE TRUE
    #define GWIN_REDRAW_SINGLEOP TRUE

#define GWIN_NEED_WIDGET TRUE
    #define GWIN_NEED_BUTTON TRUE
        #define GWIN_BUTTON_LAZY_RELEASE FALSE
    #define GWIN_FLAT_STYLING FALSE

#define GWIN_NEED_CONTAINERS TRUE
    #define GWIN_NEED_CONTAINER TRUE
    #define GWIN_NEED_FRAME FALSE
    #define GWIN_NEED_TABSET FALSE


/********************************************************/
/* GTIMER stuff                                         */
/********************************************************/
#define GFX_USE_GTIMER TRUE

#define GTIMER_THREAD_PRIORITY NORMAL_PRIORITY
#define GTIMER_THREAD_WORKAREA_SIZE 2048


/********************************************************/
/* GINPUT stuff                                         */
/********************************************************/
#define GFX_USE_GINPUT TRUE

#define GINPUT_NEED_MOUSE TRUE
#define GINPUT_TOUCH_USER_CALIBRATION_LOAD TRUE
#define GINPUT_NEED_KEYBOARD FALSE//TRUE


/********************************************************/
/* GEVENT stuff                                         */
/********************************************************/
#define GFX_USE_GEVENT TRUE

#define GEVENT_ASSERT_NO_RESOURCE FALSE
#define GEVENT_MAXIMUM_SIZE 32
#define GEVENT_MAX_SOURCE_LISTENERS 32


/********************************************************/
/* GEVENT stuff                                         */
/********************************************************/
#define GFX_USE_GQUEUE TRUE

#define GQUEUE_NEED_ASYNC TRUE


/********************************************************/
/* GFILE stuff                                          */
/********************************************************/
#define GFX_USE_GFILE FALSE

#define GFILE_NEED_NATIVEFS FALSE
#define GFILE_NEED_ROMFS FALSE
#define GFILE_MAX_GFILES 1



#endif /* _GFXCONF_H */
/* Includes ------------------------------------------------------------------*/
#include <stdio.h>
#include "stm32f1xx_hal.h"
#include "gfx.h"
#include "gui.h"
 
 // ********* FPRINTF FOR KEIL ********************** //
/* Private function prototypes -----------------------------------------------*/
#ifdef __GNUC__
  /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
     set to 'Yes') calls __io_putchar() */
  #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
  #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */

/**
  * @brief  Retargets the C library printf function to the USART.
  * @param  None
  * @retval None
  */
PUTCHAR_PROTOTYPE
{
	/* Place your implementation of fputc here */
	/* e.g. write a character to the USART */
	HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 100);
	
	
	return ch;
}
// ************************************************** //
 
  
//Implementação para uGFX
systemticks_t gfxSystemTicks(void)
{
    return HAL_GetTick();
}
 
systemticks_t gfxMillisecondsToTicks(delaytime_t ms)
{
    return ms;
}
  
  
threadreturn_t heartbeat1(void* param)
{
    (void)param;

    while (TRUE) {
    	printf("thread 1\n");
			HAL_GPIO_TogglePin(Motor_Acion_GPIO_Port, Motor_Acion_Pin);
			gfxSleepMilliseconds(500);
			
    }

    return (threadreturn_t)0;
}

threadreturn_t heartbeat2(void* param)
{
    (void)param;

    while (TRUE) {
    	printf("thread 2\n");
				HAL_GPIO_TogglePin(Motor_Acion_GPIO_Port, Motor_Acion_Pin);
        gfxSleepMilliseconds(900);
    }

    return (threadreturn_t)0;
}

  int main(void)
{
   HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_ADC1_Init();
  MX_ADC2_Init();
  //MX_SPI1_Init();
  MX_SPI2_Init();
  MX_TIM1_Init();
  MX_TIM2_Init();
  MX_TIM3_Init();
  MX_TIM4_Init();
  MX_USART1_UART_Init();
 // SystemClock_Config();
  MX_RTC_Init();
  /* Initialize interrupts */
  MX_NVIC_Init();
  
  	gfxInit();
	gdispSetBacklight(100);
	gdispSetContrast(100);

	geventListenerInit(&glistener);
	//geventAttachSource(&glistener, ginputGetKeyboard(0), 0);
	gwinAttachListener(&glistener);

	guiCreate();
    gfxThreadCreate(0, 2048, NORMAL_PRIORITY, heartbeat1, 0);
    gfxThreadCreate(0, 2048, NORMAL_PRIORITY, heartbeat2, 0);
	
    while (1)
  {
		printf("thread main\n");
       gfxSleepMilliseconds(1400);
//	gfxSleepMilliseconds(500);
	uint16_t icon_touch_temp2 =0;	
  }

OBS: Printf working like a charm 

Posted (edited)

Folks.

Now thread is working because i REMOVED thread 2. Is that correct thing to do?

But still not entering in the function mouseXYZ, for touch implementations.

Edited by ronan_rt
Posted

No. The whole point of the demo is to ensure that multiple threads work.

You will need to debug to find the exact point it crashes. Saying it stops in thread 1 is insufficient information. 

 

Posted

After a several testings, I discovered that the problem is with gfxSleepMilliseconds function. So I add debug points in every single step.

I discovered that "static void _gfxXSwitch(thread *oldt, thread *newt, bool_t doBuildFrame)", in the gos_x_threads.c is breaking. Just in the line:

        // Start the new context
        CXT_RESTORE(newt->cxt, 1);

I believe this is going to something that calls that longjmp stuff, that I saw in your forum that is crashing.

What should I do? Multiple tasks only work if i put HAL_Delay. But this is not the point, I should work with uGFX library.

Posted

The setjmp() and longjmp() implementation is only used when setting GFX_CPU to GFX_CPU_UNKNOWN. In all other cases, specially designed context switching code is used.

Can you please tell us which version of the µGFX library and what compiler you're using? All the processor specific context switching code for all ARM Cortex-M family processors have been completely rewritten a couple of months ago by @inmarket to prevent compatibility issues with the ARMCC compiler.

Posted

Is it possible that I dont have suficient HEAP?? I put two threads into my program (as above). When I REMOVE mouse, I am able to see ONE time each thread (enter in THREAD 1, than enter in THREAD 2, and breaks). When I ACTIVATE mouse, the program just enter in THREAD 1. Is there any connection?

Posted

There is no connection. The heap size of 10000 bytes or so is more than sufficient. If you want to be sure use the original threads demo and config file modified as little as possible eg only add your init sequence and code to make printf work.

When you step into CXT_RESTORE (instruction step if you need to) you will either end up in gos_x_threads.c or gos_x_threads_???.c. If you end up in gos_x_threads.c then it is still using the c library implementation rather than the CPU specific implementation. In your case your c library appears to have bugs that are preventing it from working properly.

Reasons that it might be using the c library instead of the cpu specific code...

1. The macro GFX_CPU is not set properly, or

2. The compiler you are using is not supported (currently only gcc and keil/armcc are supported for cpu specific code)

When you know the answer to the above please let us know and we will see how we can help again.

Posted

@inmarket, so, the     gfxSleepMilliseconds(500); its called in the gos_x_threads.c. Than, into this function, there is a function called gfxYield(); (into the DO WHILE sintax). There is where it crashes. gfxYield(); its called too into the gos_x_threads.c. Inside the gfxYield(), there is a line that calls: _gfxTaskSwitch(me, _gfxCurrentThread);, that calls the:

static void _gfxXSwitch(thread *oldt, thread *newt, bool_t doBuildFrame)  .

Well, as you saw, CXT_RESTORE(newt->cxt, 1); breaks into this function. And all that said is presented into the gos_x_threads.c. There is no other gos_x_threads??.c, only .h (like gos_x_threads347.h). I dont know how I change this. Ive already set GFX_CPU correctly, did you saw the gfx_conf.c that I pasted one day ago?

How can I call the correct gox_x_threads function?

Posted

Folks. Now I guess its working. There is some uploads mistakes (i guess). I downloaded the GIT REPOSITORI instead of the ufgx 2.7 (in the git is called UGFX MASTER). And I guess its working now. Ill keep upgrading info if something went wrong

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...