Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E-paper library using STM32CubeIDE not working #7

Open
aminesmith opened this issue Jul 12, 2024 · 1 comment
Open

E-paper library using STM32CubeIDE not working #7

aminesmith opened this issue Jul 12, 2024 · 1 comment

Comments

@aminesmith
Copy link

Hello, I am currently working on a project using a 2.13-inch E-paper display with my STM32F756ZG Nucleo board. I am not using Keil MDK but STM32CubeIDE as an IDE. However, when I program the board, nothing happens on the display and all I get is a screen with white noise and black/white dots. Here are the steps I took:

  • Created the project using STM32CubeIDE and configured the peripherals/pins exactly as defined in the "epd2in13-demo" PDF file found in the "2.13inch_e-paper" file.

  • Generated the code and copied the FONTS and BSP C/H files to the project.

  • Changed the #include "stm32f7xx_hal.h" in the epdif.h file.

  • Copied the int main function from the example and compiled the code with no errors. Programmed the board, but the screen doesn't show anything at all.

here's the main.c code :

`/* USER CODE BEGIN Header /
/
*



  • @attention
  • Copyright (c) 2024 STMicroelectronics.
  • All rights reserved.
  • This software is licensed under terms that can be found in the LICENSE file
  • in the root directory of this software component.
  • If no LICENSE file comes with this software, it is provided AS-IS.

/
/
USER CODE END Header /
/
Includes ------------------------------------------------------------------*/
#include "main.h"

/* Private includes ----------------------------------------------------------/
/
USER CODE BEGIN Includes /
#include "epd2in13.h"
#include "epdif.h"
#include "epdpaint.h"
#include "imagedata.h"
#include <stdlib.h>
#include <stdio.h>
/
USER CODE END Includes */

/* Private typedef -----------------------------------------------------------/
/
USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------/
/
USER CODE BEGIN PD */

/* USER CODE END PD */

/* Private macro -------------------------------------------------------------/
/
USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/

SPI_HandleTypeDef hspi1;

UART_HandleTypeDef huart3;

/* USER CODE BEGIN PV /
#define COLORED 0
#define UNCOLORED 1
/
USER CODE END PV */

/* Private function prototypes -----------------------------------------------/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART3_UART_Init(void);
static void MX_SPI1_Init(void);
/
USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------/
/
USER CODE BEGIN 0 */

int _write(int file, char ptr, int len)
{
HAL_UART_Transmit(&huart3, (uint8_t
)ptr, len, HAL_MAX_DELAY);
return len;
}

/* USER CODE END 0 */

/**

  • @brief The application entry point.
  • @RetVal int
    /
    int main(void)
    {
    /
    USER CODE BEGIN 1 /
    /
    you have to edit the startup_stm32fxxx.s file and set a big enough heap size /
    unsigned char
    frame_buffer = (unsigned char*)malloc(EPD_WIDTH * EPD_HEIGHT / 8);
    char time_string[] = {'0', '0', ':', '0', '0', '\0'};
    unsigned long time_start_ms;
    unsigned long time_now_s;
    /* USER CODE END 1 */

/* MCU Configuration--------------------------------------------------------*/

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();

/* USER CODE BEGIN Init */

/* USER CODE END Init */

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

/* USER CODE BEGIN SysInit */

/* USER CODE END SysInit */

/* Initialize all configured peripherals /
MX_GPIO_Init();
MX_USART3_UART_Init();
MX_SPI1_Init();
/
USER CODE BEGIN 2 */
EPD epd;
if (EPD_Init(&epd, lut_full_update) != 0) {
printf("e-Paper init failed\n");
return -1;
}

Paint paint;
Paint_Init(&paint, frame_buffer, epd.width, epd.height);
Paint_Clear(&paint, UNCOLORED);

/* For simplicity, the arguments are explicit numerical coordinates /
/
Write strings to the buffer */
Paint_DrawFilledRectangle(&paint, 0, 10, 128, 30, COLORED);
Paint_DrawStringAt(&paint, 30, 14, "Hello world!", &Font12, UNCOLORED);
Paint_DrawStringAt(&paint, 30, 34, "e-Paper Demo", &Font12, COLORED);

/* Draw something to the frame buffer */
Paint_DrawRectangle(&paint, 10, 60, 50, 100, COLORED);
Paint_DrawLine(&paint, 10, 60, 50, 100, COLORED);
Paint_DrawLine(&paint, 50, 60, 10, 100, COLORED);
Paint_DrawCircle(&paint, 88, 80, 30, COLORED);
Paint_DrawFilledRectangle(&paint, 10, 120, 50, 180, COLORED);
Paint_DrawFilledCircle(&paint, 88, 150, 30, COLORED);

/* Display the frame_buffer */
EPD_SetFrameMemory(&epd, frame_buffer, 0, 0, Paint_GetWidth(&paint), Paint_GetHeight(&paint));
EPD_DisplayFrame(&epd);
EPD_DelayMs(&epd, 2000);

/**

  • there are 2 memory areas embedded in the e-paper display
  • and once the display is refreshed, the memory area will be auto-toggled,
  • i.e. the next action of SetFrameMemory will set the other memory area
  • therefore you have to set the frame memory and refresh the display twice.
    */
    EPD_ClearFrameMemory(&epd, 0xFF);
    EPD_DisplayFrame(&epd);
    EPD_ClearFrameMemory(&epd, 0xFF);
    EPD_DisplayFrame(&epd);

/* EPD_or partial update */
if (EPD_Init(&epd, lut_partial_update) != 0) {
printf("e-Paper init failed\n");
return -1;
}

/**

  • there are 2 memory areas embedded in the e-paper display
  • and once the display is refreshed, the memory area will be auto-toggled,
  • i.e. the next action of SetFrameMemory will set the other memory area
  • therefore you have to set the frame memory and refresh the display twice.
    */
    EPD_SetFrameMemory(&epd, IMAGE_DATA, 0, 0, epd.width, epd.height);
    EPD_DisplayFrame(&epd);
    EPD_SetFrameMemory(&epd, IMAGE_DATA, 0, 0, epd.width, epd.height);
    EPD_DisplayFrame(&epd);

time_start_ms = HAL_GetTick();
/* USER CODE END 2 */

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

/* USER CODE BEGIN 3 */
time_now_s = (HAL_GetTick() - time_start_ms) / 1000;
time_string[0] = time_now_s / 60 / 10 + '0';
time_string[1] = time_now_s / 60 % 10 + '0';
time_string[3] = time_now_s % 60 / 10 + '0';
time_string[4] = time_now_s % 60 % 10 + '0';

Paint_SetWidth(&paint, 32);
Paint_SetHeight(&paint, 96);
Paint_SetRotate(&paint, ROTATE_90);

Paint_Clear(&paint, UNCOLORED);
Paint_DrawStringAt(&paint, 0, 4, time_string, &Font24, COLORED);
EPD_SetFrameMemory(&epd, frame_buffer, 80, 72, Paint_GetWidth(&paint), Paint_GetHeight(&paint));
EPD_DisplayFrame(&epd);

EPD_DelayMs(&epd, 500);

}
/* USER CODE END 3 */
}

/**

  • @brief System Clock Configuration
  • @RetVal None
    */
    void SystemClock_Config(void)
    {
    RCC_OscInitTypeDef RCC_OscInitStruct = {0};
    RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

/** Configure the main internal regulator output voltage
*/
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);

/** Initializes the RCC Oscillators according to the specified parameters

  • in the RCC_OscInitTypeDef structure.
    */
    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
    RCC_OscInitStruct.HSEState = RCC_HSE_ON;
    RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
    RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
    RCC_OscInitStruct.PLL.PLLM = 4;
    RCC_OscInitStruct.PLL.PLLN = 72;
    RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
    RCC_OscInitStruct.PLL.PLLQ = 3;
    if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
    {
    Error_Handler();
    }

/** Initializes the CPU, AHB and APB buses 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_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

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

/**

  • @brief SPI1 Initialization Function
  • @param None
  • @RetVal None
    */
    static void MX_SPI1_Init(void)
    {

/* USER CODE BEGIN SPI1_Init 0 */

/* USER CODE END SPI1_Init 0 */

/* USER CODE BEGIN SPI1_Init 1 */

/* USER CODE END SPI1_Init 1 /
/
SPI1 parameter configuration*/
hspi1.Instance = SPI1;
hspi1.Init.Mode = SPI_MODE_MASTER;
hspi1.Init.Direction = SPI_DIRECTION_1LINE;
hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi1.Init.NSS = SPI_NSS_SOFT;
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi1.Init.CRCPolynomial = 7;
hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
if (HAL_SPI_Init(&hspi1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN SPI1_Init 2 */

/* USER CODE END SPI1_Init 2 */

}

/**

  • @brief USART3 Initialization Function
  • @param None
  • @RetVal None
    */
    static void MX_USART3_UART_Init(void)
    {

/* USER CODE BEGIN USART3_Init 0 */

/* USER CODE END USART3_Init 0 */

/* USER CODE BEGIN USART3_Init 1 */

/* USER CODE END USART3_Init 1 /
huart3.Instance = USART3;
huart3.Init.BaudRate = 115200;
huart3.Init.WordLength = UART_WORDLENGTH_8B;
huart3.Init.StopBits = UART_STOPBITS_1;
huart3.Init.Parity = UART_PARITY_NONE;
huart3.Init.Mode = UART_MODE_TX_RX;
huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart3.Init.OverSampling = UART_OVERSAMPLING_16;
huart3.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart3.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&huart3) != HAL_OK)
{
Error_Handler();
}
/
USER CODE BEGIN USART3_Init 2 */

/* USER CODE END USART3_Init 2 */

}

/**

  • @brief GPIO Initialization Function
  • @param None
  • @RetVal None
    /
    static void MX_GPIO_Init(void)
    {
    GPIO_InitTypeDef GPIO_InitStruct = {0};
    /
    USER CODE BEGIN MX_GPIO_Init_1 /
    /
    USER CODE END MX_GPIO_Init_1 */

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

/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOB, LD1_Pin|LD3_Pin|SPI_CS_Pin|LD2_Pin, GPIO_PIN_RESET);

/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(RST_GPIO_Port, RST_Pin, GPIO_PIN_RESET);

/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(DC_GPIO_Port, DC_Pin, GPIO_PIN_RESET);

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

/*Configure GPIO pins : LD1_Pin LD3_Pin SPI_CS_Pin LD2_Pin */
GPIO_InitStruct.Pin = LD1_Pin|LD3_Pin|SPI_CS_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(GPIOB, &GPIO_InitStruct);

/*Configure GPIO pin : BUSY_Pin */
GPIO_InitStruct.Pin = BUSY_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(BUSY_GPIO_Port, &GPIO_InitStruct);

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

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

/* USER CODE BEGIN MX_GPIO_Init_2 /
/
USER CODE END MX_GPIO_Init_2 */
}

/* USER CODE BEGIN 4 */

/* USER CODE END 4 */

/**

  • @brief This function is executed in case of error occurrence.
  • @RetVal None
    /
    void Error_Handler(void)
    {
    /
    USER CODE BEGIN Error_Handler_Debug /
    /
    User can add his own implementation to report the HAL error return state /
    __disable_irq();
    while (1)
    {
    }
    /
    USER CODE END Error_Handler_Debug */
    }

#ifdef USE_FULL_ASSERT
/**

  • @brief Reports the name of the source file and the source line number
  •     where the assert_param error has occurred.
    
  • @param file: pointer to the source file name
  • @param line: assert_param error line source number
  • @RetVal None
    */
    void assert_failed(uint8_t file, uint32_t line)
    {
    /
    USER CODE BEGIN 6 /
    /
    User can add his own implementation to report the file name and line number,
    ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) /
    /
    USER CODE END 6 /
    }
    #endif /
    USE_FULL_ASSERT */
    `

Can anyone please help me identify what might be going wrong?

@SafuraColette
Copy link

Did you get this to work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants