AnsweredAssumed Answered

FRDM-KL05Z / MKL05Z32VFM4 Hard-fault with mbed ticker function

Question asked by Tom Overton on Jan 20, 2016

Hello,

 

I am currently working with the Freescale FRDM-KL05Z development board. It features a MKL05Z32VFM4 IC with 32 KB flash & 4KB SRAM.

 

I am currently using the mbed libraries and I am using Keil to write and debug.

 

The current memory location/size:

IROM1: start: 0x0 Size: 0x800

IRAM1: start: 0x1FFFFC00 size: 0x400

IRAM2: start: 0x20000000 size: 0xC00

 

 

The problem:

The mbed libraries feature a 'ticker' which I am using to create a sample rate. However to ensure that it is continuously sampling, on this occasion I have created a square wave which is being outputted to the DAC.

 

The code works well when it runs. I can increase the sample time and it still works well. The problem arises when I try to debug the firmware. The code starts and the square wave output is as expected. When I stop/pause the program a hardfault is produced and the debug has to be terminated.

If I use a simple for loop in place of the ticker it can be started and stopped until the cows come home (however I cant use a for loop on this occasion.. the ticker is a must).

Has anyone expereienced this problem? What could be causing this hardfault? If so... please help!

 

#include "mbed.h"

#define SAMPLE_RATE  0.250           // samples the data ready every 250ms

 

Ticker SAMPLE_DETECTOR;                

AnalogOut DAC_Out_Pulse(PTB1);

 

int data_ready_pulse = 0;

int y = 0;

int i = 0;

 

void DETECTOR_READ_FUNCTION()

{

     data_ready_pulse = 1;

}

 

int main(void)

{

     SAMPLE_DETECTOR.attach(&DETECTOR_READ_FUNCTION, SAMPLE_RATE); 

     while (1) {

     if (data_ready_pulse){

          data_ready_pulse = 0;

 

     if (!y){

          y = 1;

          DAC_Out_Pulse=0;

     }

 

     else{

          y = 0;

          DAC_Out_Pulse=1;

     } 

     } 

     }

}

 

Best regards,

 

Tom

Outcomes