Help understanding GPIOA->regs->CRL

Post here first, or if you can't find a relevant section!
Post Reply
shaddow501
Posts: 4
Joined: Sat Aug 26, 2017 8:06 pm

Help understanding GPIOA->regs->CRL

Post by shaddow501 » Sat Aug 26, 2017 10:52 pm

Hello

I am running my maple mini board with the 8 bit ili9341 tft.
I have tried two libraries for the ili9341 one is - Adafruit_TFTLCD_8bit_STM32 and the other one is Adafruit_ILI9341_8bit_STM.
Both of them are set to use the GPIOA CRL (low bits) PA0 to PA7.

Ok this was the introduction.

The problem is:

It seems that when setting GPIOA->regs->CRL as inputs all GPIOA (PA0 to PA15) change to inputs , instead only CRL ones that are PA0 to PA7.
it seems that it also affect the CRH and I dont know why.

adding for example - pinMode(PA10,OUTPUT); in the void setup doesnt change anything...

I dont know even where to look for the problem.

From the developer of the Adafruit_ILI9341_8bit_STM the bits are set correctly and it seems that way, but still I cannot use the CRH pins.

Anyone have a clue what is going on there?

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

Re: GPIOA->regs->CRL

Post by RogerClark » Sun Aug 27, 2017 1:06 am

I'm not sure why you would need to use the GPIO control registers

But if you want to work on the direct low level control of the GPIO you should read the reference manual on the F1

http://www.st.com/content/ccc/resource/ ... 171190.pdf

As it has full details of all the peripherals etc

shaddow501
Posts: 4
Joined: Sat Aug 26, 2017 8:06 pm

Re: Help understanding GPIOA->regs->CRL

Post by shaddow501 » Sun Aug 27, 2017 1:17 am

This is in the library of the ili9341 tft...
I cannot change it.

https://github.com/stevstrong/Adafruit_ ... 8bit_STM32
How do I free the other PA8 to PA15?

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

Re: Help understanding GPIOA->regs->CRL

Post by RogerClark » Sun Aug 27, 2017 2:16 am

Of course you can change a library

They are not precompiled binary blobs.

You just need to edit the code and then recompile

shaddow501
Posts: 4
Joined: Sat Aug 26, 2017 8:06 pm

Re: Help understanding GPIOA->regs->CRL

Post by shaddow501 » Sun Aug 27, 2017 6:38 am

It is not a lib issue

Please check this issue, there is a problem with CRL/CRH.

Code: Select all

#if defined(TFT_DATA_LOW_NIBBLE)
  //#warning "Using lower data nibble..."
	// set the pins to input mode
	#define setReadDir() ( dataRegs->CRL = 0x88888888 )	// set the lower 8 bits as input
	//#define setReadDir() ( dataRegs->CRL = 0x44444444 )	// set the lower 8 bits as input floating
	// set the pins to output mode
	#define setWriteDir() ( dataRegs->CRL = 0x33333333 )	// set the lower 8 bits as output
	#define TFT_DATA_SHIFT 0
#elif defined(TFT_DATA_HIGH_NIBBLE)
  #warning "Using high data nibble..."
	// set the pins to input mode
	#define setReadDir() ( dataRegs->CRH = 0x88888888 )	// set the upper 8 bits as input
	// set the pins to output mode
	#define setWriteDir() ( dataRegs->CRH = 0x33333333 )	// set the lower 8 bits as output
	#define TFT_DATA_SHIFT 8
#endif

// set pins to output the 8 bit value
#if 0 // slow write
 #define write8(c) { Serial.print(" write8: "); Serial.print(c,HEX); Serial.write(','); \
					digitalWrite(PB0, (c&BIT0)?HIGH:LOW); \
					digitalWrite(PB1, (c&BIT1)?HIGH:LOW); \
					digitalWrite(PB2, (c&BIT2)?HIGH:LOW); \
					digitalWrite(PB3, (c&BIT3)?HIGH:LOW); \
					digitalWrite(PB4, (c&BIT4)?HIGH:LOW); \
					digitalWrite(PB5, (c&BIT5)?HIGH:LOW); \
					digitalWrite(PB6, (c&BIT6)?HIGH:LOW); \
					digitalWrite(PB7, (c&BIT7)?HIGH:LOW); \
					WR_STROBE; }
#else
 #define write8(c) { uint32_t val = (((c^0x00FF)<<16) | c)<<TFT_DATA_SHIFT; \
					/*Serial.print(" write8: "); Serial.print(val,HEX); Serial.write(',');*/ \
					dataRegs->BSRR = val; WR_STROBE; }
#endif
this is the part of the code that address CRL why does it also changes the CRH?

Code: Select all

#define write8(c) { uint32_t val = (((c^0x00FF)<<16) | c)<<TFT_DATA_SHIFT; \
					/*Serial.print(" write8: "); Serial.print(val,HEX); Serial.write(',');*/ \
					dataRegs->BSRR = val; WR_STROBE; }

dannyf
Posts: 167
Joined: Wed May 11, 2016 4:29 pm

Re: Help understanding GPIOA->regs->CRL

Post by dannyf » Mon Aug 28, 2017 3:08 pm

It becomes an issue if it is done on the wrong data types

For example the register is a 16bit and the code is accessing it via a 32 bit variable. Or rather than changing the specific bits the code writes to all the bits.

You should take a look at either your code or the library used to pin point the issue.
.

shaddow501
Posts: 4
Joined: Sat Aug 26, 2017 8:06 pm

Re: Help understanding GPIOA->regs->CRL

Post by shaddow501 » Mon Aug 28, 2017 6:24 pm

Ok

I have found the problem in the library of the TFT.

#define write8(c) { uint32_t val = (((c^0x00FF)<<16) | c)<<TFT_DATA_SHIFT; \

need to be changed to this:
#define write8(c) { uint32_t val = ((((c^0x00FF)&0x00FF)<<16) | (c&0x00FF))<<TFT_DATA_SHIFT; \

dannyf
Posts: 167
Joined: Wed May 11, 2016 4:29 pm

Re: Help understanding GPIOA->regs->CRL

Post by dannyf » Tue Aug 29, 2017 2:00 pm

Without knowing the context in which the macro is used it is hard to tell if it is buggy.

With that said, two things stand out.

1. The parameter to the macro should be in a bracket. That's probably the single biggest mistake here.

2. The ORing of the parameters lsb to itself makes no sense to me.

Post Reply