mmoskal / uf2-stm32f

UF2 bootloader for STM32F4
Other
110 stars 62 forks source link

add fsmc driver for prarllel-8b screen ili9341/st7789 #18

Closed wbbw55 closed 3 years ago

wbbw55 commented 4 years ago

optimized some code style and add new screen st7789.

CF for ili9341 exsample:

DISPLAY_WIDTH = 320 DISPLAY_HEIGHT = 240 DISPLAY_TYPE = 9341 DISPLAY_CFG0 = 0x10000c8 DISPLAY_CFG1 = 0x1bff DISPLAY_CFG2 = 0x1000004

CF for st7789 exsample:

DISPLAY_WIDTH = 320 DISPLAY_HEIGHT = 240 DISPLAY_TYPE = 7789 DISPLAY_CFG0 = 0x1000080 DISPLAY_CFG1 = 0x10ff DISPLAY_CFG2 = 0x1000004

btw the PXT/Codal's screen driver is not include the st7789, i will try to add it and pr later.:)

mmoskal commented 4 years ago

This is great! I hope to merge it as soon as I have some hardware to test this...

yuanyanhui commented 4 years ago

I tested it. The bootloader image displays correctly on the LCD screen, however the arcade drive does not show up.

mmoskal commented 4 years ago

Are you sure you have the right oscillator speed in board.h ?

yuanyanhui commented 4 years ago

yes, it's correct. The speed is 24MHz. Actually, the first time I made a mistake with the wrong oscillator speed, as a result, there was nothing on the screen. I changed setting to the right number, and it worked.

mmoskal commented 4 years ago

do you get the USB drive without this patch? does USB work on your board using any other software?

I know that the USB bootloader drive generally works on the F412.

yuanyanhui commented 4 years ago

It seems the usb on my newly made board is faulty. I compiled the bootloader using both versions of screen.c and they both worked on another dev board. I will have a look at my board.

yuanyanhui commented 4 years ago

The usb on my arcade board is fine. I tested it with a standalone program. There is one difference between the dev board and my arcade board. The design of my arcade board follows the reference design without a pullup resistor on the D+ line. The dev board has a pullup resistor controlled by a switch. If the switch is not on, the bootloader will not show up. Attached below is its schematic.

image PD2 has to be pulled low for USB to be recognized. I also verified this by a standalone program.

I thought STM32F4 has an internall pullup resistor for D+ line, so this 1.5K resistor is not really needed? My other F411 arcade board also has no D+ pullup, it works fine with the bootloader.

mmoskal commented 4 years ago

the manual says something about enabling that pull up based on Vbus. There is probably some bit in USB registers that we need to flip, but I'm not sure which...

yuanyanhui commented 4 years ago

image image How to set it in board.h?

yuanyanhui commented 4 years ago

if defined(BOARD_USB_VBUS_SENSE_DISABLED)

OTG_FS_GCCFG |= OTG_GCCFG_NOVBUSSENS;
OTG_FS_DCTL &= ~OTG_DCTL_SDIS;

endif

Clearing the SDIS bit did not work.

yuanyanhui commented 3 years ago

F412's GCCFG register is very different to F411's, e.g. F412's bit 21 is VBDEN, F411's bit 21 is NOVBUSSENS. To disable Vbus sensing on F412, this bit should be cleared instead. Bits 18-20 look totally different. Tried a few options, but no luck.

yuanyanhui commented 3 years ago

Found a clue from ST's code. The following lines worked. OTG_FS_GCCFG &= ~OTG_GCCFG_VBDEN; OTG_FS_DCTL |= ~OTG_DCTL_SDIS; OTG_FS_GOTGCTL |= OTG_GOTGCTL_BVALOEN; OTG_FS_GOTGCTL |= OTG_GOTGCTL_BVALOVAL;

mmoskal commented 3 years ago

Thanks @wbbw55 ! This is now merged. I also did some changes afterwards to simplify.

@yuanyanhui - I have done some changes to USB code - you can try defining BL_F412 in your board.h and seeing if that works for you. You may need the USB_FORCE_DISCONNECT if there's an external pullup.

yuanyanhui commented 3 years ago

Unfortunately, adding BL_F412 did not work. The bootloader image did not look quite right and the arcade drive did not show up. Previously, I got the bootloader working properly, but the screen went black after receiving a uf2 game file.

Here is my board.h.

ifndef BOARD_H

define BOARD_H

define BL_F412

define OSC_FREQ 24

define USBDEVICESTRING "Arcade F412"

define USBMFGSTRING "Contoso Ltd."

define BOARD_FLASH_SECTORS 8

define BOARD_FLASH_SIZE (512 * 1024)

ifdef DEFINE_CONFIGDATA

attribute((section(".config"))) attribute((used)) // const uint32_t configData[] = { / CF2 START / 513675505, 539130489, // magic 36, 100, // used entries, total entries 1, 0x1F, // PIN_ACCELEROMETER_INT = PB15 2, 0x08, // PIN_ACCELEROMETER_SCL = PA08 3, 0x14, // PIN_ACCELEROMETER_SDA = PB04 4, 0x20, // PIN_BTN_A = PC00 5, 0x21, // PIN_BTN_B = PC01 13, 0x2D, // PIN_LED = PC13 21, 0x0A, // PIN_RX = PA10 26, 0x10, // PIN_SPEAKER_AMP = PB0 28, 0x09, // PIN_TX = PA09 33, 0x25, // PIN_DISPLAY_MISO = PC05 34, 0x22, // PIN_DISPLAY_MOSI = PC02 35, 0x24, // PIN_DISPLAY_CS = PC04 36, 0x23, // PIN_DISPLAY_DC = PC03 37, 0x140, // DISPLAY_WIDTH = 320 38, 0xf0, // DISPLAY_HEIGHT = 240 39, 0xc0, // DISPLAY_CFG0 = 0x8 40, 0x603, // DISPLAY_CFG1 = 0x18ff 41, 0x16, // DISPLAY_CFG2 = 0x1000004 43, 0x0F, // PIN_DISPLAY_RST = PA15 44, 0x06, // PIN_DISPLAY_BL = PA06 47, 0x1A, // PIN_BTN_LEFT = PB10 48, 0x1C, // PIN_BTN_RIGHT = PB12 49, 0x18, // PIN_BTN_UP = PB08 50, 0x19, // PIN_BTN_DOWN = PB09 51, 0x00, // PIN_BTN_MENU = 0x110000 59, 0x80, // SPEAKER_VOLUME = 128 70, 0x68, // ACCELEROMETER_TYPE = MPU6050 78, 0x247d, // _78 = 9341 204, 0x80000, // FLASH_BYTES = 0x80000 205, 0x20000, // RAM_BYTES = 0x18000 208, 0x6e3a4053, // BOOTLOADER_BOARD_ID = 0x1f884ff3 209, 0x57755a57, // UF2_FAMILY = STM32F401 210, 0x10, // PINS_PORT_SIZE = PA_16 211, 0x0, // BOOTLOADER_PROTECTION = 0 212, 0x78, // POWER_DEEPSLEEP_TIMEOUT = 120 214, 0x60, // CPU_MHZ = 96 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, / CF2 END / };

endif

endif / BOARD_H /