Unable to access UART0 in MKE02Z32VLH4 because MCUExpresso init didn't enable clock.

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

Unable to access UART0 in MKE02Z32VLH4 because MCUExpresso init didn't enable clock.

Jump to solution
863 Views
bikenomad
Contributor III

I've designed in an MKE02Z32VLH4 processor into my project. When I started to debug my program, I found that it was ending up in a HardFault exception resulting from a call to a (MCUExpresso-generated) peripheral initialization routine.

When I went to look at the exception, everything looked fine. So I went to examine the peripheral memory of UART0 at 0x4006A000 (UART0_BASE).

In the memory view, I saw only '???????'.

Looking a bit further, I saw that the clock was not enabled in the SIM_SCGC register.

The MCUExpresso initialization code in main() looks like this:

int main() {
  /* Init board hardware. */
  BOARD_InitBootPins();
  BOARD_InitBootClocks();
  BOARD_InitBootPeripherals();

The HardFault happened inside BOARD_InitBootPeripherals() when UART0 was being initialized.

Shouldn't MCUExpresso enable the appropriate peripheral clocks before trying to initialize the peripherals?

I tried to fix this particular problem by adding a line to enable that clock:

int main() {
  /* Init board hardware. */
  BOARD_InitBootPins();
  BOARD_InitBootClocks();
  SIM->SCGC |= SIM_SCGC_UART0_MASK;  // enable UART0 clock
  BOARD_InitBootPeripherals();

But that didn't get much farther; I got another HardFault a bit later when the UART0 interrupt was enabled before the ISR callback was set:

HardFault_Handler() at semihost_hardfault.c:62 0x8c8	
<signal handler called>() at 0xfffffff1	
g_pfnVectors() at 0x0	
UART0_DriverIRQHandler() at fsl_uart.c:1,730 0x164a	
UART0_IRQHandler() at startup_mke02z4.cpp:444 0x1ac	
<signal handler called>() at 0xfffffff9	
__NVIC_EnableIRQ() at core_cm0plus.h:749 0x179c	
EnableIRQ() at fsl_common.h:501 0x3316	
UART0_init() at peripherals.c:200 0x18c4	
BOARD_InitPeripherals() at peripherals.c:211 0x3358	
BOARD_InitBootPeripherals() at peripherals.c:219 0x3366	
main() at main.cpp:115 0x742	

Here, UART0_init() should have set up the ISR using UART_TransferCreateHandle() before enabling the UART0 interrupt.

Is the MCUExpresso-generated initialization code expected to actually work?

I've attached my .mex file.

Labels (1)
0 Kudos
1 Solution
829 Views
gusarambula
NXP TechSupport
NXP TechSupport

Hello Bikenomad,

I’m sorry to hear that you’re having problems with MCUXpresso. It is a great tool, albeit not perfect. When working in a Project in MCUXpresso you would need to call the Peripheral Config Tools to add the UART module and setup clock source, interruptions, and other parameters. Only then the Config Tools will update the code as necessary, for example adding the Transfer_CreateHandle method to the initialization of the UART.

MCUXpresso_UART.jpg

 

I hope that this information helps!

Regards,

View solution in original post

0 Kudos
1 Reply
830 Views
gusarambula
NXP TechSupport
NXP TechSupport

Hello Bikenomad,

I’m sorry to hear that you’re having problems with MCUXpresso. It is a great tool, albeit not perfect. When working in a Project in MCUXpresso you would need to call the Peripheral Config Tools to add the UART module and setup clock source, interruptions, and other parameters. Only then the Config Tools will update the code as necessary, for example adding the Transfer_CreateHandle method to the initialization of the UART.

MCUXpresso_UART.jpg

 

I hope that this information helps!

Regards,

0 Kudos