Jump to content

uGFX + FreeRtos + STM32L1 + stucked vTaskStartScheduler()


tombalabomba

Recommended Posts

Hi folks,

I face problems to get ugfx and freertos running. Essentially, I followed the demo CPU20 has made for a STM32F7 bord.

The code of my main.c is at the bottom of this post. I'm sorry for the unprofessional appearance. Unfortunatly, wehter code insertion nor file upload works with the tested browsers (chrome, firefox, edge).

 

I first checked if the FreeRtos works before I imported the ugfx lib. Since everthing seemed to be OK I tired ugfx in  RAW_32 mode by setting 

#define GFX_USE_OS_RAW32                             GFXON

#define GFX_USE_GDISP                                GFXON

#define GDISP_NEED_TEXT                              GFXON

#define GDISP_INCLUDE_FONT_DEJAVUSANS16          GFXON

 

in gfxconf.h. Conclusio: Everything is ok.

 

Then I changed in gfxconf.h:

#define GFX_USE_OS_RAW32                             GFXOFF

#define GFX_USE_OS_FREERTOS                          GFXON

#define GFX_OS_HEAP_SIZE                         4096

#define GFX_OS_NO_INIT                           GFXON

 

Now the problem is that the system gets stuck as soon vTaskStartScheduler() is called. I tried to debug it but it never reaches one of the tasks.

 

 

Any help is kindly apprechiated!

 

 

/**
 ******************************************************************************
 * @file    main.c
 * @author  Ac6
 * @version V1.0
 * @date    01-December-2013
 * @brief   Default main function.
 ******************************************************************************
 */

#include <board_ILI9225.h>
#include "stm32l1xx_hal.h"
#include "FreeRTOS.h"
#include "task.h"

#include "gfx.h"

void SystemClock_Config(void);
static void GPIO_Init(void);
static void I2C_Init(void);
static void SPI_Init(void);
void Error_Handler(void);


TaskHandle_t uGFXInitTask;

I2C_HandleTypeDef hi2c1;
SPI_HandleTypeDef hspi2;


//-----------------------------------------------------------------------------
void uGFXUpdate(void* pvParameters)
{
    (void)pvParameters;

    font_t font = gdispOpenFont("DejaVuSans16");

    while (1) {
        gdispFillString(10, 10, "uGFX FreeRTOS", font, White, Black);
        HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);
        vTaskDelay(500/portTICK_PERIOD_MS);
    }
}


//-----------------------------------------------------------------------------
void uGFXInit(void* pvParameters)
{
    (void)pvParameters;

    while (1) {
        gfxInit();
        xTaskCreate(uGFXUpdate,"uGFXUpdate", 200, NULL, 0, NULL);
        vTaskDelete(uGFXInitTask);
    }
}


//-----------------------------------------------------------------------------
int main(void)
{

    HAL_Init();
    SystemClock_Config();
    GPIO_Init();
    SPI_Init();
    I2C_Init();


#if GFX_USE_OS_FREERTOS == GFXON

    xTaskCreate(uGFXInit, "uGFXInit", 200, NULL, 0, &uGFXInitTask);
    vTaskStartScheduler();

#elif GFX_USE_OS_RAW32 == GFXON

    font_t font = gdispOpenFont("DejaVuSans16");
    gfxInit();

    while(1){
        gdispFillString(10, 10, "GFX_RAW_32", font, White, Black);
        HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);
        gfxSleepMilliseconds(200);
    }


#endif

    for (;;);

}

//-----------------------------------------------------------------------------
void SystemClock_Config(void)
{
    RCC_OscInitTypeDef RCC_OscInitStruct = {0};
    RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

    /**Configure the main internal regulator output voltage
     */
    __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
    /**Initializes the CPU, AHB and APB busses clocks
     */
    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
    RCC_OscInitStruct.HSIState = RCC_HSI_ON;
    RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
    RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
    RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
    RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6;
    RCC_OscInitStruct.PLL.PLLDIV = RCC_PLL_DIV3;
    if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
    {
        Error_Handler();
    }
    /**Initializes the CPU, AHB and APB busses clocks
     */
    RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
            |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
    RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
    RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
    RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
    RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

    if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
    {
        Error_Handler();
    }
}

//-----------------------------------------------------------------------------
static void I2C_Init(void)
{

    /* USER CODE BEGIN I2C1_Init 0 */

    /* USER CODE END I2C1_Init 0 */

    /* USER CODE BEGIN I2C1_Init 1 */

    /* USER CODE END I2C1_Init 1 */
    hi2c1.Instance = I2C1;
    hi2c1.Init.ClockSpeed = 100000;
    hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
    hi2c1.Init.OwnAddress1 = 0;
    hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
    hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
    hi2c1.Init.OwnAddress2 = 0;
    hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
    hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
    if (HAL_I2C_Init(&hi2c1) != HAL_OK)
    {
        Error_Handler();
    }
    /* USER CODE BEGIN I2C1_Init 2 */

    /* USER CODE END I2C1_Init 2 */

}


//-----------------------------------------------------------------------------
static void SPI_Init(void)
{

    /* SPI2 parameter configuration*/
    hspi2.Instance = SPI2;
    hspi2.Init.Mode = SPI_MODE_MASTER;
    hspi2.Init.Direction = SPI_DIRECTION_2LINES;
    hspi2.Init.DataSize = SPI_DATASIZE_8BIT;
    hspi2.Init.CLKPolarity = SPI_POLARITY_HIGH;
    hspi2.Init.CLKPhase = SPI_PHASE_2EDGE;
    hspi2.Init.NSS = SPI_NSS_SOFT;
    hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
    hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
    hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
    hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
    hspi2.Init.CRCPolynomial = 10;
    if (HAL_SPI_Init(&hspi2) != HAL_OK)
    {
        Error_Handler();
    }

}

//-----------------------------------------------------------------------------
static void GPIO_Init(void)
{
    GPIO_InitTypeDef GPIO_InitStruct = {0};

    /* GPIO Ports Clock Enable */
    __HAL_RCC_GPIOC_CLK_ENABLE();
    __HAL_RCC_GPIOH_CLK_ENABLE();
    __HAL_RCC_GPIOA_CLK_ENABLE();
    __HAL_RCC_GPIOB_CLK_ENABLE();

    /*Configure GPIO pin Output Level */
    HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET);

    /*Configure GPIO pin Output Level */
    HAL_GPIO_WritePin(GPIOB, LCD_RS_Pin|LCD_RST_Pin|LCD_CS_Pin, GPIO_PIN_RESET);

    /*Configure GPIO pin : B1_Pin */
    GPIO_InitStruct.Pin = B1_Pin;
    GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct);

    /*Configure GPIO pin : LD2_Pin */
    GPIO_InitStruct.Pin = LD2_Pin;
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    HAL_GPIO_Init(LD2_GPIO_Port, &GPIO_InitStruct);

    /*Configure GPIO pins : LCD_RS_Pin LCD_CS_Pin */
    GPIO_InitStruct.Pin = LCD_RS_Pin|LCD_CS_Pin;
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

    /*Configure GPIO pin : LCD_RST_Pin */
    GPIO_InitStruct.Pin = LCD_RST_Pin;
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    HAL_GPIO_Init(LCD_RST_GPIO_Port, &GPIO_InitStruct);

}

//-----------------------------------------------------------------------------
void Error_Handler(void)
{
    /* USER CODE BEGIN Error_Handler_Debug */
    /* User can add his own implementation to report the HAL error return state */

    /* USER CODE END Error_Handler_Debug */
}

 

 

 

 

Edited by tombalabomba
Link to comment
Share on other sites

Hi,

I guess I can close this issue. I wrongly suspected the uGFX lib to be part of the problem. The root cause was that I modified the code of by RAW_32 implementation for using FreeRtos. Since I used CubeMx for HAL generation, I just had to remove HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_0) in the HAL_MspInit() routine of the corresponding MCU support package file.

By the way. I''m not able to use link, code and file upload tools of this homepage anymore. Apparently, something has changed since it perfectly worked a couple of months ago.

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