Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
11 years, 1 month ago.
What do I have to do to my project to get lines like this to compile? They all are undefined.
#include "mbed.h" ... void pit_init(void) { // PIT Initialization SIM_SCGC6 |= SIM_SCGC6_PIT_MASK; // Enable the clock to the PIT module PIT_LDVAL0 = 8000000; // Default start value PIT_MCR = PIT_MCR_FRZ_MASK; // Enable clock for timer, freeze timer in debug mode PIT_TCTRL0 = PIT_TCTRL_TIE_MASK | PIT_TCTRL_TEN_MASK; // Enable timer and timer interrupt // Initialize the NVIC to enable the PIT interrupt NVIC_ICPR |= 1 << ((INT_PIT - 16) % 32); NVIC_ISER |= 1 << ((INT_PIT - 16) % 32);
1 Answer
11 years, 1 month ago.
Hello Herschell Hall,
use code highlighting, first of all.
Where did you get that code? I believe you are using Freescale header file for MCU, not CMSIS, please open a file I'll paste below.
Follow the naming which is in this file, that one should not cause any undefined error.
Regards,
0xc0170
Thanks so much. You are right, This code came from a Freescale example. I have had a hard time finding a good example of how to use the PIT. I knew there was something missing. I thought it might be in mbed.h and that there was some switch I needed to turn on. Do I put the KL25Z CMSIS header file in place of the mbed.h file, or before/after it?
posted by 04 Nov 2013Don't need to include it, it should be already. Just try to change your syntax.
posted by 04 Nov 2013Finally got back to this. I have made the syntax changes to correspond to the file you sent and that part is compiling ok now. I do need some help with how to assign the PIT interrupt. I have a example, that is probably wrong, that uses the NVIC. But it looks like the file you sent doesn't have a NVIC component? Can you please point me in the right direction for this? Thanks so much.
posted by 06 Nov 2013NVIC is in another file since it is equal for all M0s.
Interrupt handlers have default names, they are hidden in startup files: https://github.com/mbedmicro/mbed/blob/master/libraries/mbed/targets/cmsis/TARGET_Freescale/TARGET_KL25Z/TOOLCHAIN_GCC_ARM/startup_MKL25Z4.s
However generally I prefer to just assign them at runtime:
NVIC_SetVector(ADC0_IRQn, (uint32_t)your_function); //Also not to forget: NVIC_EnableIRQ(ADC0_IRQn);
IRQ names are defined in the file linked by Martin.
posted by 06 Nov 2013