This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSPM0L1304: I want to use the SWCLK-Pin as an GPIO.

Part Number: MSPM0L1304
Other Parts Discussed in Thread: SYSCONFIG,

Tool/software:

Hello!
I am using the MSPM0L1304 and want to use pin PA20 (SWCLK) as a digital output. In the SysConfig() “Debug On SWD Pins” is activated.

My main() looks like this:

int main(void) {                                  
  SYSCFG_DL_init();

  if (DL_GPIO_readPins(BTN_PORT, BTN_DI_SWITCH_PIN)){
    DL_SYSCTL_disableSWD();
    DL_GPIO_enablePower(GPIOA);
    DL_GPIO_initDigitalOutput(IOMUX_PINCM21);
    DL_GPIO_enableOutput(GPIOA, DL_GPIO_PIN_20);
    DL_GPIO_setPins(GPIOA, DL_GPIO_PIN_20);
  }
  while (1) { }
}

In the circuit diagram, I have placed an LED with a series resistor parallel to the SWCLK pin. The LED also pulses during the flash process.


I can't manage to set the SWCLK pin to logic high to supply the LED.
I have read that the debugger may be blocking the interface.
However, I can't manage to set the pin to high even if I just flash.

Perhaps you have a tip for me.

Best regards, C. Zwingmann

  • Hello Christian, 

    Thank you for contacting us. In order to use the SWCLK pin as a GPIO, you will need to uncheck the "Debug Enable On SWD Pins" via SysConfig. Moreover, you can click on the question mark right next to the  "Debug Enable On SWD Pins" for further clarification. Please note that once you disable SWD functionality, the only way to restore this is by triggering a Power-On-Reset (POR). And before that happens, you will need to prevent the application software (which has SWD disabled) from running to buy time in order to trigger the POR. This can be done by either holding the device in a reset state with the NRST pin during a POR or you can also add a delay in the "SYSCONFIG_WEAK void SYSCFG_DL_DEBUG_init" function such as one below: 

    SYSCONFIG_WEAK void SYSCFG_DL_DEBUG_init(void)
    {
    delay_cycles(500000000);
    /* Set the DISABLE bit in the SWDCFG register in SYSCTL along with KEY */
    SYSCTL->SOCLOCK.SWDCFG = (SYSCTL_SWDCFG_KEY_VALUE | SYSCTL_SWDCFG_DISABLE_TRUE);
    }
    For more information on POR, kindly access the technical reference manual linked below (Pg. 196) 

    Regards, Jojo

  • Hello Jojo,

    thank you for the feedback.
    I have deactivated the "Debug Enable On SWD Pins" in the SysConfig and integrated a delay of 15 seconds in the "SYSCONFIG_WEAK void SYSCFG_DL_DEBUG_init".

    void SYSCFG_DL_DEBUG_init(void){
     delay_cycles(500000000);
     SYSCTL->SOCLOCK.SWDCFG = (SYSCTL_SWDCFG_KEY_VALUE | SYSCTL_SWDCFG_DISABLE_TRUE);
    }
    int main(void){
     SYSCFG_DL_init();
     // Code
    }

    I have the following questions:
    1) Your suggestion with the reset (NRST low during a POR) does not work.
    1a) Can you describe exactly when to press and release the reset?
    1b) Is it possible to set somewhere in the IDE that this reset is execute automatically?

    2) Have I implemented the weak function correctly and is it overwritten in "ti_msp_dl_config.c"?

    3) Does the Delay mean that I have 15 seconds after a cold start to flash a program before the SWD interface is disabled?

    4) If I want to use the GPIO PA20 as a digital output, do I have to define the pin as such in the SysConfig or do I do this manually in a separate function?
    4a) If I set the GPIO manually in the main, the output cannot be switched to high:

    void SYSCFG_DL_DEBUG_init(void){
     delay_cycles(500000000);
     SYSCTL->SOCLOCK. SWDCFG = (SYSCTL_SWDCFG_KEY_VALUE | SYSCTL_SWDCFG_DISABLE_TRUE);
    }
    int main(void) {
     SYSCFG_DL_init();
     DL_GPIO_initDigitalOutput(IOMUX_PINCM21);
     DL_GPIO_setPins(GPIOA, DL_GPIO_PIN_20);
     DL_GPIO_enableOutput(GPIOA, DL_GPIO_PIN_20);
     // Code
    }

    4b) When I set the GPIO in the SysConfig, the LED lights up for 15 seconds (as long as the delay) and then goes out again. Debugging access also stops after 15 seconds. (From here on I can only flash the controller via BSL)

    You are welcome to answer my questions.

    Greetings, Christian

  • Hello Christian, 

    Thank you for your questions. Kindly find my answers below:

    1. In order to make this work, you need to ensure that the NRST pin is actually set as such and not a regular GPIO. Is this the case in this scenario?

    1a) For the NRST, essentially this needs to be held for more than 1 sec for the POR. Moreover, for the device to boot successfully, it needs to be held high. This information can be found in Section 2.4.1.1.1  and 2.4.1.3 of the linked document 

    1b) Unfortunately, that option on the IDE does not exist. 

    2. I should have clarified a bit further but that was just an example. In practicality, the way you can go about this with this option is to enable SWD and in your application code, you can manually disable the SWD by adding the delay and then disabling the SWD. Instance of this can be seen below: 

    while(1){

     delay_cycles(500000000);

    SYSCTL->SOCLOCK.SWDCFG = (SYSCTL_SWDCFG_KEY_VALUE | SYSCTL_SWDCFG_DISABLE_TRUE);

    }

    3. Yes, the 15 seconds set is the time allocated before SWD will be disabled 

    4. If you go the route I stated in step2, then you will need to manually configure the PA20 as GPIO manually. 

    4a. Based on the code given, kindly ensure that the internal pull-down resistor is also set to none since the SWCLK pin has an internal pull-down resistor. Kindly let me know how that goes! 

    Regards, Jojo

  • Hello Jojo,

    I have solved the problem.
    I fixed another internal error on my part, then the project ran.

    The “Debug Enable On SWD Pins” is deactivated.
    The following syntax runs:

    void SYSCFG_DL_DEBUG_init(void){
        #ifdef DEBUG_MODE
           delay_cycles(500000000);
        #endif
       SYSCTL->SOCLOCK.SWDCFG = (SYSCTL_SWDCFG_KEY_VALUE | SYSCTL_SWDCFG_DISABLE_TRUE);
     }

    int main(void) {
     SYSCFG_DL_init();

     if (DL_GPIO_readPins(BTN_PORT, BTN_DI_SWITCH_PIN)){
        DL_GPIO_initDigitalOutput(IOMUX_PINCM21);
        DL_GPIO_enableOutput(GPIOA, DL_GPIO_PIN_20);
        DL_GPIO_clearPins(GPIOA, DL_GPIO_PIN_20);
     }

    while(1){
    }

    No pull-down had to be set to "None".

    Many thanks for your help!

  • Hello Christian, 

    Glad to know this is all working now and you are most welcome! Have a great weekend! 

    Regards, Jojo