Basic Example / test application for the on-board MICRON QSPI-Flash. Ported from DISCO_L476VG_QSPI. Added printing on serial output and LCD screen.
Dependencies: BSP_DISCO_F746NG LCD_DISCO_F746NG QSPI_DISCO_F746NG TS_DISCO_F746NG mbed
Diff: main.cpp
- Revision:
- 4:95cde28a5cf1
- Parent:
- 3:13b323fb08e8
- Child:
- 5:9b9fbd929243
diff -r 13b323fb08e8 -r 95cde28a5cf1 main.cpp --- a/main.cpp Wed Oct 21 18:08:19 2015 +0000 +++ b/main.cpp Sun Nov 15 14:31:04 2015 +0000 @@ -1,15 +1,11 @@ -#include "mbed.h" -#include "TS_DISCO_F746NG.h" -#include "LCD_DISCO_F746NG.h" - #include "main.h" LCD_DISCO_F746NG lcd; TS_DISCO_F746NG ts; DigitalOut myled(LED1); +QSPI_DISCO_F746NG qspi; -//MenuGUIButton button01; -//MenuGUIButton button02; +Serial pc(USBTX, USBRX); // DEBUG // TODO : add Ticker function @@ -46,71 +42,129 @@ lcd.SetTextColor(LCD_COLOR_WHITE); led_off(); - /* For test / demo - ------------------ - 2 menus + 1 main menu. The main menu has two buttons, each calling one of the two sub-menus: + // Check initialization + QSPI_Info pQSPI_Info; + uint8_t WriteBuffer[BUFFER_SIZE] = "Hello World !!!"; + uint8_t ReadBuffer[BUFFER_SIZE]; + pc.printf("\n\nQSPI demo started\n\r"); + uint8_t init_return = qspi.Init(); + + pc.printf("Return: %d\n\r", init_return); - |------| |------| |------| - | b1 | | b3 | | b6 | - |------| |------| |------| - ->menu01 + //if (qspi.Init() != QSPI_OK) + if (init_return != QSPI_OK) + { + //error("QSPI Initialization FAILED\n"); + pc.printf("QSPI Initialization FAILED\n\r"); + lcd.Clear(LCD_COLOR_RED); + lcd.SetBackColor(LCD_COLOR_RED); + lcd.SetTextColor(LCD_COLOR_WHITE); + lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"QSPI Initialization FAILED", CENTER_MODE); + } + else + { + pc.printf("QSPI Initialization PASSED\n\r"); + lcd.Clear(LCD_COLOR_GREEN); + lcd.SetBackColor(LCD_COLOR_GREEN); + lcd.SetTextColor(LCD_COLOR_WHITE); + lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"QSPI Initialization PASSED", CENTER_MODE); + } - |------| |------| |------| - | b2 | | b4 | | b7 | - |------| |------| |------| - ->menu02 -> Led ON - - |------| |------| - | b5 | | b8 | - |------| |------| - -> Led OFF - menu_main menu01 menu02 + wait(2); - */ + // Check memory informations + qspi.GetInfo(&pQSPI_Info); + if ((pQSPI_Info.FlashSize != N25Q128A_FLASH_SIZE) || + (pQSPI_Info.EraseSectorSize != N25Q128A_SUBSECTOR_SIZE) || + (pQSPI_Info.ProgPageSize != N25Q128A_PAGE_SIZE) || + (pQSPI_Info.EraseSectorsNumber != N25Q128A_SUBSECTOR_SIZE) || + (pQSPI_Info.ProgPagesNumber != N25Q128A_SECTOR_SIZE)) + { + //error("QSPI informations FAILED\n"); + pc.printf("QSPI informations FAILED\n\r"); + lcd.Clear(LCD_COLOR_RED); + lcd.SetBackColor(LCD_COLOR_RED); + lcd.SetTextColor(LCD_COLOR_WHITE); + lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"QSPI informations FAILED", CENTER_MODE); + } + else + { + //printf("QSPI informations PASSED\n"); + pc.printf("QSPI informations PASSED\n\r"); + lcd.Clear(LCD_COLOR_GREEN); + lcd.SetBackColor(LCD_COLOR_GREEN); + lcd.SetTextColor(LCD_COLOR_WHITE); + lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"QSPI informations PASSED", CENTER_MODE); + } - MenuGUIButton button01 (10, 80, 80, 50, "b1", &lcd); - MenuGUIButton button02 (10, 140, 80, 50, "b2", &lcd); - MenuGUIButton button03 (100, 80, 80, 50, "b3", &lcd); - MenuGUIButton button04 (100, 140, 80, 50, "b4", &lcd); + wait (2); - MenuGUIButton button05 (190, 80, 80, 50, "b5", &lcd); - button05.callback = true; - //button05.callback_function = led_off; - button05.callback_function = led_toggle; - MenuGUIButton button06 (190, 140, 80, 50, "b6", &lcd); - MenuGUIButton button07 (190, 80, 80, 50, "b7", &lcd); - button07.callback = true; - //button07.callback_function = led_on; - button07.callback_function = led_toggle; - MenuGUIButton button08 (190, 140, 80, 50, "b8", &lcd); + // Erase memory + if (qspi.Erase_Block(WRITE_READ_ADDR) != QSPI_OK) + { + //error("QSPI erase FAILED\n"); + pc.printf("QSPI erase FAILED\n\r"); + lcd.Clear(LCD_COLOR_RED); + lcd.SetBackColor(LCD_COLOR_RED); + lcd.SetTextColor(LCD_COLOR_WHITE); + lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"QSPI erase FAILED", CENTER_MODE); + } + else + { + //printf("QSPI erase PASSED\n"); + pc.printf("QSPI erase PASSED\n\r"); + lcd.Clear(LCD_COLOR_GREEN); + lcd.SetBackColor(LCD_COLOR_GREEN); + lcd.SetTextColor(LCD_COLOR_WHITE); + lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"QSPI erase PASSED", CENTER_MODE); + } - // Main menu - MenuGUIMenu menu_main (2, 10, 80); - menu_main.add_button(&button01, 0, 1); - menu_main.add_button(&button02, 1, 1); + wait (2); - // Menu01 - MenuGUIMenu menu01 (3, 100, 80); - menu01.add_button(&button03, 0, 1); - menu01.add_button(&button04, 1, 1); - menu01.add_button(&button05, 2, 1); + // Write memory + if (qspi.Write(WriteBuffer, WRITE_READ_ADDR, 15) != QSPI_OK) + { + //error("QSPI write FAILED\n"); + pc.printf("QSPI write FAILED\n\r"); + lcd.Clear(LCD_COLOR_RED); + lcd.SetBackColor(LCD_COLOR_RED); + lcd.SetTextColor(LCD_COLOR_WHITE); + lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"QSPI write FAILED", CENTER_MODE); + } + else + { + //printf("QSPI write PASSED\n"); + pc.printf("QSPI write PASSED\n\r"); + lcd.Clear(LCD_COLOR_GREEN); + lcd.SetBackColor(LCD_COLOR_GREEN); + lcd.SetTextColor(LCD_COLOR_WHITE); + lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"QSPI write PASSED", CENTER_MODE); + } + + wait (2); - // Menu02 - MenuGUIMenu menu02 (3, 190, 80); - menu02.add_button(&button06, 0, 1); - menu02.add_button(&button07, 1, 1); - menu02.add_button(&button08, 2, 1); + // Read memory + if (qspi.Read(ReadBuffer, WRITE_READ_ADDR, 11) != QSPI_OK) + { + //error("QSPI read FAILED\n"); + pc.printf("QSPI read FAILED\n\r"); + lcd.Clear(LCD_COLOR_RED); + lcd.SetBackColor(LCD_COLOR_RED); + lcd.SetTextColor(LCD_COLOR_WHITE); + lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"QSPI read FAILED", CENTER_MODE); + } + else + { + //printf("QSPI read PASSED - [%s]\n", ReadBuffer); + pc.printf("QSPI read PASSED\n\r"); + lcd.Clear(LCD_COLOR_GREEN); + lcd.SetBackColor(LCD_COLOR_GREEN); + lcd.SetTextColor(LCD_COLOR_WHITE); + lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"QSPI read PASSED", CENTER_MODE); + } - // Main MenuGUI object - MenuGUI menugui01 (3); - menugui01.add_menu (&menu_main, 0); - menugui01.add_menu (&menu01, 1); - menugui01.add_menu (&menu02, 2); - - // Set transitions - menugui01.set_transition(1, 0, 0); - menugui01.set_transition(2, 0, 1); - + wait (2); + while(1) { @@ -152,22 +206,12 @@ } } -/* ------------------------------------------------------------------------ */ - + // Touch detection of one button if (TS_State.touchDetected > 0) { - - menugui01.update(TS_State.touchX[0], TS_State.touchY[0]); - } else { - - menugui01.update(); - } - - menugui01.display(); - } }