My main application breaks up the initialization into two separate
routines. BOARD_InitPins(), and BOARD_InitLEDsPins().
Both of these files are specified in the pin wizard, and affect
different pins.
During initialization, this fails, since the generated code does
not preserve port direction and overwrites the previous port
direction bits for pins set as outputs.
MCUXpresso configuration tools version:
=========================================
product: Pins v6.0
processor: LPC51U68
package_id: LPC51U68JBD64
mcu_data: ksdk2_0
processor_version: 6.0.2
board: LPCXpresso51U68
Application Code:
==================
The main routine call the two generated routines in sequence:
//*******************************************
// Initialize board hardware.
//*******************************************
// Set up basic I/O Pins
// Apply power to and reset both GPIO Ports
GPIO_PortInit(GPIO, 0);
GPIO_PortInit(GPIO, 1);
BOARD_InitPins();
// Set up pins for LEDs
BOARD_InitLEDsPins();
PinMux.c code, generated by Configuration tool:
=================================================
void BOARD_InitPins(void) {
CLOCK_EnableClock(kCLOCK_Iocon);
GPIO->DIR[0] = ((GPIO->DIR[0] &
(~(GPIO_DIR_DIRP_MASK)))
| GPIO_DIR_DIRP(0x0D00u)
);
IOCON->PIO[0][0] = ((IOCON->PIO[0][0] &
(~(IOCON_PIO_FUNC_MASK | IOCON_PIO_DIGIMODE_MASK)))
| IOCON_PIO_FUNC(PIO00_FUNC_ALT1)
| IOCON_PIO_DIGIMODE(PIO00_DIGIMODE_DIGITAL)
);
....etc
void BOARD_InitLEDsPins(void) {
CLOCK_EnableClock(kCLOCK_Iocon);
GPIO->DIR[0] = ((GPIO->DIR[0] &
(~(GPIO_DIR_DIRP_MASK)))
| GPIO_DIR_DIRP(0xE0u)
);
GPIO->DIR[1] = ((GPIO->DIR[1] &
(~(GPIO_DIR_DIRP_MASK)))
| GPIO_DIR_DIRP(0x0800u)
);
Problem Description:
======================
When I execute the application code, BOARD_InitPins() executes
and sets up Port 0 direction register (CPIO->DIR[0]) to 0xD00,
which sets up Port 0, pins 8,10, and 11 as outputs. This is correct.
Next, executing the BOARD_InitLEDsPins() function sets up Port 0
direction register (CPIO->DIR[0]) to 0x0E0. It reads the Port Direction
register, but does not preserve the contents of the DIR[0] register.
Expected result: DIR[0] = 0x0DE0
Actual Result: DIR[0] = 0x00E0
In summary, the code generated by the configuration wizard always
appears to overwrite previously set direction bits, and does not
allow the configuration wizard to be used to set up port direction,
if the pin I/O is separated into sections.
My workaround is to handle pin setup separately in the application,
to ensure the pins are properly configured, but I would like to
clean up the code, and leave this to the configuration tools. Is
there something I need to do to prevent interaction, or do I need to
merge all my GPIO configuration into the single BOARD_InitPins()
function.
Solved! Go to Solution.
Hello Frank,
OK, I know your meaning.
Yes, I recommend you all the GPIO configuration in the BOARD_InitPins() function.
Or you need delete the code of
(~(GPIO_DIR_DIRP_MASK))) /* Mask bits to zero which are setting */
to only exist in one pins init function.
Have a great day,
TIC
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------
I will use this workaround. This limitation prevents using multiple setup functions which set output pin directions, since they will interact with each other. I will merge all the separate setup functions into a BOARD_InitPins() function to allow the pin setup to be correct.
Hello Frank,
OK, I know your meaning.
Yes, I recommend you all the GPIO configuration in the BOARD_InitPins() function.
Or you need delete the code of
(~(GPIO_DIR_DIRP_MASK))) /* Mask bits to zero which are setting */
to only exist in one pins init function.
Have a great day,
TIC
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------
Hello Frank Sundermeyer ,
How do you configuration on Congfig Tool? After finish config the GPIO pins, all the generate code
should be in BOARD_InitPins().
Could you please send your config project to me , I will check it on my side.
Also recommend you use the latest SDK version SDK2.6.
BR
Alice