SPI doesn't seem to be working on GD32

Boards based on the GigaDevices GD32F103 microcontroller
Post Reply
User avatar
RogerClark
Posts: 6893
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

SPI doesn't seem to be working on GD32

Post by RogerClark » Tue Sep 08, 2015 11:28 am

Just a note about SPI on the GD32.

I have tried the Adafruit_ILI9341_STM graphics test, but I can't get it to work on the GD32

I'm not sure if there is some difference in the fundamental operation of the SPI hardware or if its something else

As a lot of the libs require __STM32F1__ to be defined, I initially changed the libs, but in case I missed something I also added -D__STM32F1__ into the compile recipes in platform.txt so that the libs would use the same #ifdef path as for the STM32 but this has not fixed the problem

I also tried changing the ILI9341 lib to use SPI_DIV_4 instead of DIV2 in case its too fast but that didnt fix it


Looking at what is read back from the display in the graphics test, I don't get stable data. It seems to depend on what divider I select, but I went down as far as DIV_8 and it still didnt work.

I'll need to compare the readback data with what I get from the STM32

This is what I get at DIV_2 @72Mhz
Display Power Mode: 0xFF
MADCTL Mode: 0xDE
Pixel Format: 0x6C
Image Format: 0x7
Self Diagnostic: 0xDE
I tried pulling CS low all the time, in case it was a timing issue. But that didnt help

So I think its something a bit more fundamental :-(

And its time to get the logic analyser out (well, another day...)

User avatar
RogerClark
Posts: 6893
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: SPI doesn't seem to be working on GD32

Post by RogerClark » Wed Sep 09, 2015 11:23 am

Just a quick update, and as far as I can tell SPI does work on the GD32, but its not working with my ILI9341 display.

I did a loopback test and it reads back its on data OK and I looked at the signals on my scope and they seemed OK.

@120Mhz, DIV 2 my scope was displaying that the clock was 60Mhz, but at that speed the waveforms were not showing up very well on my scope.

I will need to double check on the logic analyser side of the scope to see if it also looks OK.

This doesnt solve the mystery of why the LCD display is not working, when I know for sure it works with a STM32F103C because I swapped boards and loaded the same sketch on an STM32 and it worked fine.

Its not a speed thing, as I selected 72Mhz for the GD32.

Ummm. More analysis required.

I bet I'm doing something stupid, like getting the SPI pins swapped over

madias
Posts: 813
Joined: Mon Apr 27, 2015 11:26 am
Location: Vienna, Austria

Re: SPI doesn't seem to be working on GD32

Post by madias » Wed Sep 09, 2015 11:26 am

Have you tried to connect the display on a additional power supply (don't forget the common ground ;) )?
On some of my MCU dev boards (not STM32) I had strange problems with adding the TFT to the same onboard voltage regulator (MCU wont start every time).

madias
Posts: 813
Joined: Mon Apr 27, 2015 11:26 am
Location: Vienna, Austria

Re: SPI doesn't seem to be working on GD32

Post by madias » Wed Sep 09, 2015 11:35 am

Another thing (stupid, I know :) ):
Have you double checked the DC and RST line? - Are they defined in the sketch?
(I many example codes the RST is not defined, this caused also problems to me)

User avatar
RogerClark
Posts: 6893
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: SPI doesn't seem to be working on GD32

Post by RogerClark » Thu Sep 10, 2015 9:12 pm

Just a quick update.

SPI looks OK when I connect my logic analyser and even seems to be functioning on DIV_2 @ 120MHz, i.e 60MHz clock.

I also tested just looping MOSI back into MISO and it reads back OK using SPI.transfer

But I have not had time to do more testing about why the ILI9341 doesn't work.

alex
Posts: 19
Joined: Tue Jul 28, 2015 2:12 am

Re: SPI doesn't seem to be working on GD32

Post by alex » Sun Aug 28, 2016 3:40 am

RogerClark wrote:Just a quick update.

SPI looks OK when I connect my logic analyser and even seems to be functioning on DIV_2 @ 120MHz, i.e 60MHz clock.

I also tested just looping MOSI back into MISO and it reads back OK using SPI.transfer

But I have not had time to do more testing about why the ILI9341 doesn't work.
There are many difference between stm32 and gd32.

from http://wenku.baidu.com/view/853a8342737 ... f8f7e.html

10. SPI
1) 输入与输出配置要求(STM32 不需要如此要求)
input and output configuration ( no need for stm32 )

解决方法
solution

GD32 在使用 SPI 时,IO 的配置必须严格遵守主从模式下的输入与输出配置,而STM32 无此要求,相关代码如下:
When use spi of GD32, the configuration of IO must follow master/slave mode, no need for stm32, code as follow;

主机模式下 IO 配置(主机以 SPI 为例):
Master mode: (use SPI)
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5|GPIO_Pin_7;
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_Init(GPIOA,&GPIO_InitStructure);

从机模式下 IO 配置(从机以 SPI2 为例):
Slave mode: (use SPI2)
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13|GPIO_Pin_15;
GPIO_Init(GPIOB,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14;
GPIO_Init(GPIOB,&GPIO_InitStructure);

2) 在 GD32 的 SPI 的时钟信号,空闲状态需要配置成高电平,以保证数据的稳定性,具体代码如下:红色字体代码
When the clock signal of gd32's spi is idle, it need to be high to keep data stable.
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(SPI1, &SPI_InitStructure);


3) 当作为从机时,在 GD32 中,时钟信号必须为 8 的整数倍。
When used as slave mode, the clock signal must be a multiple of 8.
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(SPI1, &SPI_InitStructure);

4) 在 GD32 中,不能使用 SPI_I2S_FLAG_BSY 该位来判断 SPI 总线数据是否接收或发送完成。
With GD32, you can't use SPI_I2S_FLAG_BSY to check if SPI data send/recv complete.

I don't know how to patch libopencm3 with these informations, if anyone can share the patch of libopencm3 for gd32, it's very nice.
Last edited by alex on Sun Aug 28, 2016 7:47 am, edited 1 time in total.

User avatar
RogerClark
Posts: 6893
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: SPI doesn't seem to be working on GD32

Post by RogerClark » Sun Aug 28, 2016 4:02 am

I can't seem to access that doc, can you check the link, or perhaps somehow you have to login to access it

Re: Other changes to the SPI structs

I suspect the GD32 has extra features which require some bit patterns in the SPI control register to be initialised slightly differently

The same thing applies to USB, but luckily it defaulted to a configuration that works, but SPI appears not to.

Re: LibOpenCM3

The main STM32F103 repo is based on libmaple not openlibcm3. I know some forum members have developed a prototype core based on libopencm3, but you'd need to contact them about this it.

try PM'ing @vassilis

alex
Posts: 19
Joined: Tue Jul 28, 2015 2:12 am

Re: SPI doesn't seem to be working on GD32

Post by alex » Sun Aug 28, 2016 8:01 am

Download the attachements, and rename GD32.z??.zip to GD32.z??
Attachments
GD32.z02.zip
(240 KiB) Downloaded 37 times
GD32.z01.zip
(240 KiB) Downloaded 27 times
GD32.zip
(60.03 KiB) Downloaded 40 times

alex
Posts: 19
Joined: Tue Jul 28, 2015 2:12 am

Re: SPI doesn't seem to be working on GD32

Post by alex » Sun Aug 28, 2016 8:02 am

more attachement
Attachments
GD32.z03.zip
(240 KiB) Downloaded 34 times

User avatar
RogerClark
Posts: 6893
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: SPI doesn't seem to be working on GD32

Post by RogerClark » Sun Aug 28, 2016 8:39 am

Thanks

I'll take a look.

Post Reply