TF CD32 Riser Revision 2 Design Complete

TF CD32 Riser

Moderators: terriblefire, Terriblefire Moderator

terriblefire
Admin sponsor
Admin sponsor
Posts: 5686
Joined: 28 Aug 2017 22:56
Location: Glasgow, UK

Re: TF CD32 Riser Revision 2 Design Complete

Post by terriblefire »

A simple implementation of WriteData() that does exactly the same thing you do but faster is..

Code: Select all


void WriteData(uint8_t data)
{
                 uint32_t pupdr = GPIOB->PUPDR;
		
		GPIOB->PUPDR = pupdr & 0xFFFF0000; // no pull on bits 0 to 7;
		GPIOB->OTYPER |= 0xFF; // set to open drain - can this be done once?
		GPIOB->MODER = (GPIOB->MODER & 0xFFFF0000) | 0x5555; // set to output
	
		GPIOB->ODR = (GPIOB->ODR & 0xFF00) | data; 
		
		// Maybe flash ack here?
		
		GPIOB->OTYPER &= ~(0xFF); // reset to non-open drain (why?)
		GPIOB->MODER = (GPIOB->MODER & 0xFFFF0000); // set to input
		GPIOB->PUPDR = pupdr; // restore

		// do this inline to avoid function call overhead
		GPIOC->BSRR = GPIO_PIN_11 << 16; // set 
		GPIOC->BSRR = GPIO_PIN_11; // reset				
}

I would setup all other settings ahead of time. I havent checked if all the masks will work but it should be close.

Also you shouldnt need to change the state of the pull ups between read and write. so that could maybe go away too.

I would honestly avoid using the HAL as its dog slow and its not really all that hard to write the routines you want.
———
"It is not necessarily a supply voltage at no load, but the amount of current it can provide when touched that
indicates how much hurting you shall receive."
User avatar
arkadiusz.makarenko
Moderator Team
Moderator Team
Posts: 1371
Joined: 19 Jun 2019 07:36
Location: Edinburgh

Re: TF CD32 Riser Revision 2 Design Complete

Post by arkadiusz.makarenko »

@terriblefire

I changed as you suggested
Only places of setting up push/pull and open drain, as it should be pushpull for placing data on the bus, and releasing it later to open drain.
(need to check if this is even required for changes between input/output)

Code: Select all

	GPIOB->OTYPER &= ~(0xFF);  
	GPIOB->OTYPER |= 0xFF; // set to open drain - can this be done once?
plus

Code: Select all

uint8_t ReadData() {
	uint8_t data = 0;
	data = GPIOB->IDR;
	return data;
}
and

Code: Select all

	GPIOC->BSRR = GPIO_PIN_11 << 16; // set
	GPIOC->BSRR = GPIO_PIN_11; // reset
	
I did try to place ack after comment
// Maybe flash ack here?
but Amiga was not booting.

It is already is snappier and I think Amiga boots faster.

I will have a look at enable/disable override when only required.
Do not trust people. They are capable of greatness.
~ Stanislaw Lem
User avatar
arkadiusz.makarenko
Moderator Team
Moderator Team
Posts: 1371
Joined: 19 Jun 2019 07:36
Location: Edinburgh

Re: TF CD32 Riser Revision 2 Design Complete

Post by arkadiusz.makarenko »

I fixed port clash in case when keyboard+mouse combo + gamepad is used... dirty fix but it works.
Do not trust people. They are capable of greatness.
~ Stanislaw Lem
terriblefire
Admin sponsor
Admin sponsor
Posts: 5686
Joined: 28 Aug 2017 22:56
Location: Glasgow, UK

Re: TF CD32 Riser Revision 2 Design Complete

Post by terriblefire »

Excellent. I can look at other optimisations for you. Did you optimize the address read?

Also set readdata and writedata as inline

e.g.

Code: Select all

inline uint8_t ReadData() {
	uint8_t data = 0;
	data = GPIOB->IDR;
	GPIOC->BSRR = GPIO_PIN_11 << 16; // set
	GPIOC->BSRR = GPIO_PIN_11; // reset
	return data;
}
Then you can remove the code in the interrupt handler...

Code: Select all

HAL_GPIO_WritePin(INTSIG7_GPIO_Port, INTSIG7_Pin, GPIO_PIN_SET);
	HAL_GPIO_WritePin(INTSIG7_GPIO_Port, INTSIG7_Pin, GPIO_PIN_RESET);
	
Every function call will eat several ARM cycles pushing and popping state from the stack.

Finally.. .when the new board arrives you can set A3 out on SPI_MISO and then you can get the whole address bus (A0-A5) (albeit with the bits out of order) from port C.
Screenshot 2020-10-28 at 20.17.40.png
EDIT: Ah A4 is on port A. Bummer.. still 2 reads isnt bad.
You do not have the required permissions to view the files attached to this post.
———
"It is not necessarily a supply voltage at no load, but the amount of current it can provide when touched that
indicates how much hurting you shall receive."
User avatar
arkadiusz.makarenko
Moderator Team
Moderator Team
Posts: 1371
Joined: 19 Jun 2019 07:36
Location: Edinburgh

Re: TF CD32 Riser Revision 2 Design Complete

Post by arkadiusz.makarenko »

Yes, I replaced Read function to just using GPIOB->IDR directly, and replaced HAL calls to intsig7 to

Code: Select all

	GPIOC->BSRR = GPIO_PIN_11 << 16; // set //HAL_GPIO_WritePin(INTSIG7_GPIO_Port, INTSIG7_Pin, GPIO_PIN_SET);
	GPIOC->BSRR = GPIO_PIN_11; // reset //HAL_GPIO_WritePin(INTSIG7_GPIO_Port, INTSIG7_Pin, GPIO_PIN_RESET);
Plus implemented crude enable/disable.
If any HID device is attached (except keyboard only) override is applied on ports.
I could do it more gradually, but would still need to take joystick buttons 2,3 on mouse override. Buttons are rarely used, but still cannot easily be done as I wanted initially. I would say good enough for now.

EDIT
I still have address reads to do.
Do not trust people. They are capable of greatness.
~ Stanislaw Lem
terriblefire
Admin sponsor
Admin sponsor
Posts: 5686
Joined: 28 Aug 2017 22:56
Location: Glasgow, UK

Re: TF CD32 Riser Revision 2 Design Complete

Post by terriblefire »

arkadiusz.makarenko wrote: 28 Oct 2020 20:31
EDIT
I still have address reads to do.
Sweet. I think so long as you are not doing the full GPIO init inside the interrupt handler you'll see a massive speed up. You're probably also running code compiled for debug. Switching to release + optimized may give further gains.
———
"It is not necessarily a supply voltage at no load, but the amount of current it can provide when touched that
indicates how much hurting you shall receive."
User avatar
arkadiusz.makarenko
Moderator Team
Moderator Team
Posts: 1371
Joined: 19 Jun 2019 07:36
Location: Edinburgh

Re: TF CD32 Riser Revision 2 Design Complete

Post by arkadiusz.makarenko »

terriblefire wrote: 28 Oct 2020 20:53
arkadiusz.makarenko wrote: 28 Oct 2020 20:31
EDIT
I still have address reads to do.
Sweet. I think so long as you are not doing the full GPIO init inside the interrupt handler you'll see a massive speed up. You're probably also running code compiled for debug. Switching to release + optimized may give further gains.
Yes I have as it is convenient just now. I have created profile for compiling with -Ofast flag, will properly test it when I will have all basics done.
Do not trust people. They are capable of greatness.
~ Stanislaw Lem
User avatar
arkadiusz.makarenko
Moderator Team
Moderator Team
Posts: 1371
Joined: 19 Jun 2019 07:36
Location: Edinburgh

Re: TF CD32 Riser Revision 2 Design Complete

Post by arkadiusz.makarenko »

Now both ReadData and WriteData are static inline functions.
Do not trust people. They are capable of greatness.
~ Stanislaw Lem
terriblefire
Admin sponsor
Admin sponsor
Posts: 5686
Joined: 28 Aug 2017 22:56
Location: Glasgow, UK

Re: TF CD32 Riser Revision 2 Design Complete

Post by terriblefire »

arkadiusz.makarenko wrote: 28 Oct 2020 21:18 Now both ReadData and WriteData are static inline functions.
Sweet. You should be down to roughly 300ns for the transfer now.
———
"It is not necessarily a supply voltage at no load, but the amount of current it can provide when touched that
indicates how much hurting you shall receive."
User avatar
arkadiusz.makarenko
Moderator Team
Moderator Team
Posts: 1371
Joined: 19 Jun 2019 07:36
Location: Edinburgh

Re: TF CD32 Riser Revision 2 Design Complete

Post by arkadiusz.makarenko »

Address reads are directly on registers as well. I don't think it is massive gain, but every little helps.

Code: Select all

static inline uint8_t ReadAddress() {
	uint8_t address = 0;
	address = ((GPIOC->IDR >> 9) & 1U); //PC9 - INTSIG5
	address = (address << 1) | ((GPIOA->IDR >> 10) & 1U); //PA10 - A4
	address = (address << 1) | ((GPIOA->IDR >> 15) & 1U);//PA15 - INTSIG3
	address = (address << 1) | ((GPIOC->IDR >> 7) & 1U); //PC7 - A2
	address = (address << 1) | ((GPIOC->IDR >> 6) & 1U); //PC6 - A1
	address = (address << 1) | ((GPIOC->IDR >> 4) & 1U); //PC4 - A0
	return address;
}
Do not trust people. They are capable of greatness.
~ Stanislaw Lem

Return to “TF CD32 Riser”

Who is online

Users browsing this forum: ClaudeBot and 2 guests