Crash on configuring the ADC pin

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Crash on configuring the ADC pin

Jump to solution
798 Views
gauravbanyal
Contributor IV

Hello,

I am using this device MKL03Z32VFG4. Everything else that I want to use on the MCU works but as soon as I add the following line to the pin-mux setting, the system always crashes at this line.

==========

PORT_SetPinMux(PORTA, PIN0_IDX, kPORT_PinDisabledOrAnalog); /* PORTA0 (pin 14) is configured as ADC0_SE15 */

=================

Please help me. I need to use this pin as the analog pin.

The function where this line is added is given below. (all the settings are done using the pins tool)

===========

void BOARD_InitPins(void) {
CLOCK_EnableClock(kCLOCK_PortA); /* Port A Clock Gate Control: Clock enabled */
CLOCK_EnableClock(kCLOCK_PortB); /* Port B Clock Gate Control: Clock enabled */

#if defined(BATT_MEASUREMENT_IMPLEMENTED) && BATT_MEASUREMENT_IMPLEMENTED == 1
PORT_SetPinMux(PORTA, PIN0_IDX, kPORT_PinDisabledOrAnalog); /* PORTA0 (pin 14) is configured as ADC0_SE15 */
#endif
PORT_SetPinMux(PORTA, PIN3_IDX, kPORT_PinDisabledOrAnalog); /* PORTA3 (pin 3) is configured as EXTAL0 */
PORT_SetPinMux(PORTA, PIN4_IDX, kPORT_MuxAsGpio); /* PORTA4 (pin 4) is configured as PTA4 */
PORT_SetPinMux(PORTA, PIN5_IDX, kPORT_MuxAsGpio); /* PORTA5 (pin 5) is configured as PTA5 */
PORT_SetPinMux(PORTA, PIN6_IDX, kPORT_MuxAsGpio); /* PORTA6 (pin 6) is configured as PTA6 */
PORT_SetPinMux(PORTA, PIN7_IDX, kPORT_MuxAsGpio); /* PORTA7 (pin 7) is configured as PTA7 */

PORT_SetPinMux(PORTB, PIN0_IDX, kPORT_MuxAsGpio); /* PORTB0 (pin 8) is configured as LLWU_P4 */
PORT_SetPinMux(PORTB, PIN1_IDX, kPORT_MuxAlt2); /* PORTB1 (pin 13) is configured as LPUART0_TX */
PORTB->PCR[1] = ((PORTB->PCR[1] &
(~(PORT_PCR_PE_MASK | PORT_PCR_ISF_MASK))) /* Mask bits to zero which are setting */
| PORT_PCR_PE(PCR_PE_ENABLED) /* Pull Enable: Internal pullup or pulldown resistor is enabled on the corresponding pin, if the pin is configured as a digital input. */
);
PORT_SetPinMux(PORTB, PIN2_IDX, kPORT_MuxAlt2); /* PORTB2 (pin 14) is configured as LPUART0_RX */
PORT_SetPinMux(PORTB, PIN3_IDX, kPORT_MuxAlt2); /* PORTB3 (pin 11) is configured as I2C0_SCL */
PORT_SetPinMux(PORTB, PIN4_IDX, kPORT_MuxAlt2); /* PORTB4 (pin 12) is configured as I2C0_SDA */
PORT_SetPinMux(PORTB, PIN5_IDX, kPORT_MuxAsGpio); /* PORTB5 (pin 13) is configured as PTB5 */
SIM->SOPT5 = ((SIM->SOPT5 &
(~(SIM_SOPT5_LPUART0RXSRC_MASK))) /* Mask bits to zero which are setting */
| SIM_SOPT5_LPUART0RXSRC(SOPT5_LPUART0RXSRC_LPUART_RX) /* LPUART0 Receive Data Source Select: LPUART_RX pin */
);
}

===========

 

Best regards,

Gaurav.

Labels (1)
0 Kudos
1 Solution
583 Views
mjbcswitzerland
Specialist V

Hi Gaurav

I used the uTasker project to test this ADC input on the FRDM-KL03Z and didn't have any problems. With debugger connected it disconnects as soon as the port is reconfigured for its analog utilisation, which is as expected, but otherwise (with or without debugger) all works identically and normally.

Attached you can find the binary that you can load to the FRDM-KL03Z.

The output (115200 Baud on the VCOM OpenSDA port) shows the board starting and printing out the ADC value every second:

Hello, world... KINETIS
OS Heap use = 0x014d from 0x0400
ADC triggered: 0x0379
ADC triggered: 0x0383
ADC triggered: 0x037c
ADC triggered: 0x02d6
ADC triggered: 0x02de
ADC triggered: 0x02ec
ADC triggered: 0x02d8
ADC triggered: 0x0373
ADC triggered: 0x0326
ADC triggered: 0x040b
ADC triggered: 0x02cf
ADC triggered: 0x02a5
ADC triggered: 0x0366

This is the code that is used to perform the pin configuration:

_CONFIG_PERIPHERAL(A, 0, PA_0_ADC0_SE15); // ensure that the ADC pin is configured (warning: this changes the default SWD_CLK configuration, losing any debug support!)

which equates simply to:
SIM_SCGC5 |= SIM_SCGC5_PORTA;
PORTA_PCR0 = 0;

so you can compare with the code that is executed by the routines you use, but I don't expect any difference.

I suspect that the real problem is not with this line of code but the fact that the debugger can't be used after setting it is causing confusion as to the actual problem.

In case this doesn't help and you need a fast solution you can request professional help at http://www.utasker.com/support.html

Regards

Mark

http://www.utasker.com/kinetis/FRDM-KL03Z.html

View solution in original post

0 Kudos
3 Replies
583 Views
mjbcswitzerland
Specialist V

Hi Gaurav

PTA0 defaults to SWD_CLK so when you configure it to an analog function the debugger will no longer be able to communicate.
Are you thus sure that it is a crash of loss of contact with the debugger?

Regards

Mark

0 Kudos
583 Views
gauravbanyal
Contributor IV

Hello Mark,

The crash happens even when the debugger is not attached. I keep seeing prints on UART debug terminal, that are coded before the pin mux setting function call over and over again when running without the debugger.

Any other reason why it crashes?

Best,

Gaurav.

0 Kudos
584 Views
mjbcswitzerland
Specialist V

Hi Gaurav

I used the uTasker project to test this ADC input on the FRDM-KL03Z and didn't have any problems. With debugger connected it disconnects as soon as the port is reconfigured for its analog utilisation, which is as expected, but otherwise (with or without debugger) all works identically and normally.

Attached you can find the binary that you can load to the FRDM-KL03Z.

The output (115200 Baud on the VCOM OpenSDA port) shows the board starting and printing out the ADC value every second:

Hello, world... KINETIS
OS Heap use = 0x014d from 0x0400
ADC triggered: 0x0379
ADC triggered: 0x0383
ADC triggered: 0x037c
ADC triggered: 0x02d6
ADC triggered: 0x02de
ADC triggered: 0x02ec
ADC triggered: 0x02d8
ADC triggered: 0x0373
ADC triggered: 0x0326
ADC triggered: 0x040b
ADC triggered: 0x02cf
ADC triggered: 0x02a5
ADC triggered: 0x0366

This is the code that is used to perform the pin configuration:

_CONFIG_PERIPHERAL(A, 0, PA_0_ADC0_SE15); // ensure that the ADC pin is configured (warning: this changes the default SWD_CLK configuration, losing any debug support!)

which equates simply to:
SIM_SCGC5 |= SIM_SCGC5_PORTA;
PORTA_PCR0 = 0;

so you can compare with the code that is executed by the routines you use, but I don't expect any difference.

I suspect that the real problem is not with this line of code but the fact that the debugger can't be used after setting it is causing confusion as to the actual problem.

In case this doesn't help and you need a fast solution you can request professional help at http://www.utasker.com/support.html

Regards

Mark

http://www.utasker.com/kinetis/FRDM-KL03Z.html

0 Kudos