AnsweredAssumed Answered

Chip_GPIO_SetPortOutHigh() vs Chip_GPIO_SetPinState()

Question asked by Giuseppe Modugno on Jan 27, 2017
Latest reply on Mar 17, 2017 by soledad

I'm using the LPC1768 connected to a ILI9341-based LCD module through a 16-bits data bus and RD/WR/RS control signals. I'm using emWin libraries.

I'm trying to decrease the time the MCU needs to refresh the display. The most important function used by emWin to draw on the display is the following:

void LCD_X_8080_16_WriteM01_16(U16 * pData, int NumWords) {
  //Chip_GPIO_SetPinState(LPC_GPIO, PIN_LCD_RS, 1);
  for (; NumWords; NumWords--) {

As you can see I'm trying to choose the faster function between Chip_GPIO_SetPortOutHigh() and Chip_GPIO_SetPinState(). In theory, Chip_GPIO_SetPortOutHigh()  should be faster because writes directly to .SET register, while Chip_GPIO_SetPinState() reads .SET register, make an OR with a bit, and writes back to .SET.


The output listings demonstrates what I say: the Chip_GPIO_SetPinState() needs an additional instruction.

000009e0 <LCD_X_8080_16_WriteM01_16>: SetPinState
9e0: 4b0a ldr r3, [pc, #40] ; (a0c <LCD_X_8080_16_WriteM01_16+0x2c>)
9e2: 699a ldr r2, [r3, #24]
9e4: f442 7200 orr.w r2, r2, #512 ; 0x200
9e8: 619a str r2, [r3, #24]
9ea: b169 cbz r1, a08 <LCD_X_8080_16_WriteM01_16+0x28>
9ec: b430 push {r4, r5}
9ee: 4d08 ldr r5, [pc, #32] ; (a10 <LCD_X_8080_16_WriteM01_16+0x30>)
9f0: eb00 0141 add.w r1, r0, r1, lsl #1
9f4: f44f 7280 mov.w r2, #256 ; 0x100
9f8: f830 4b02 ldrh.w r4, [r0], #2
9fc: 61da str r2, [r3, #28]
9fe: 4288 cmp r0, r1
a00: 802c strh r4, [r5, #0]
a02: 619a str r2, [r3, #24]
a04: d1f8 bne.n 9f8 <LCD_X_8080_16_WriteM01_16+0x18>
a06: bc30 pop {r4, r5}
a08: 4770 bx lr
a0a: bf00 nop
a0c: 2009c000 .word 0x2009c000
a10: 2009c036 .word 0x2009c036
000009d8 <LCD_X_8080_16_WriteM01_16>: SetPortOut
9d8: 4b09 ldr r3, [pc, #36] ; (a00 <LCD_X_8080_16_WriteM01_16+0x28>)
9da: f44f 7200 mov.w r2, #512 ; 0x200
9de: 619a str r2, [r3, #24]
9e0: b169 cbz r1, 9fe <LCD_X_8080_16_WriteM01_16+0x26>
9e2: b430 push {r4, r5}
9e4: 4d07 ldr r5, [pc, #28] ; (a04 <LCD_X_8080_16_WriteM01_16+0x2c>)
9e6: eb00 0141 add.w r1, r0, r1, lsl #1
9ea: f44f 7280 mov.w r2, #256 ; 0x100
9ee: f830 4b02 ldrh.w r4, [r0], #2
9f2: 61da str r2, [r3, #28]
9f4: 4288 cmp r0, r1
9f6: 802c strh r4, [r5, #0]
9f8: 619a str r2, [r3, #24]
9fa: d1f8 bne.n 9ee <LCD_X_8080_16_WriteM01_16+0x16>
9fc: bc30 pop {r4, r5}
9fe: 4770 bx lr
a00: 2009c000 .word 0x2009c000
a04: 2009c036 .word 0x2009c036

However my oscilloscope says Chip_GPIO_SetPinState() is faster than Chip_GPIO_SetPortOutHigh().

Could you argue what is the reason?