Hi Will X-san,
I don't understand correctly what is your intension. Do you make programs from the scratch? It would be a little difficult. I think you can re-use the FRDM-KL25Z Sample Code probably even for KL03. The Sample Code can get from the freescale site (http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=KL2x&fpsp=1&tab=Design_Tools_Tab).
Software Development Tools > Lab and Test Software > KL25_SC
If you use the KL25 Sample Code, you can map SPI/I2C ISRs for each interrupt to modify isr.h file in the sample code as follows.
----[snip]-----
void your_SPI_handler();
void your_I2C_handler();
#under VECTOR_026
#define VECTOR_026 your_SPI_handler
#under VECTOR_024
#define VECTOR_024 your_I2C_handler
----[snip]-----
I am not sure whether the vector number of KL25Z is the same as KL03. From the KL03 reference manual it seems to be the same.
Do this help you?
Best regards,
Yasuhiko Koumoto.
Thanks for your answer Yasuhiko-san!
Yes, I am making a program from scratch. I am not basing it on anything and I am enabling the HW interrupts for I2C and SPI but I don't know how to map a handler function to service those interrupts.
In the snippet you provided, where are VECTOR_024 and VECTOR_026 defined? They are defined anywhere in my project. I am using MKL03Z4.h file that contains all the chip related definitions.
If you download the code sample code Yasuhiko-san pointed you to, you'll see a file named startup_MKL25Z4.s
That file contains a table of interrupt vectors with handy names like SPI0_IRQHandler and I2C0_IRQHandler by default these have a weak link to Default_Handler. What that means is if you don't provide a function with that name in your code, than then Default_Handler() gets called if the interrupt occurs. However if you supply and interrupt handler by simply creating a function of that name, it gets linked instead of the default handler.
Note, I'm not really up on the freescale demo code. Some examples instead of the vector table being defined and an assemble (.s) file, it's defined in a .c file instead. But the effect is exactly the same.
So for an spi handler likely
void SPI0_IRQHandler(void)
{
// your code here
}
This should totally work. Note an easy test is to use a pin change interrupt to toggle and LED.
Good luck, bare metal projects are often a bit painful to get off the ground.
Hello Matthew-san,
thank you for your explanations. they would be almost perfect. Also I would add some comments.
VECTOR_024 and VECTOR_026 are defined in the vector.h at
${PROJ_ROOT}\cpu\vector.h
which is contained in the KL25 Sample Code package.
The vector.h is included by the vector.c at the same directory.
-----[snip]-------
#if (defined(KEIL))
const vector_entry __vector_table[] = //@ ".intvec" =
#elif (defined(IAR))
#pragma location = ".intvec"
const vector_entry __vector_table[] = //@ ".intvec" =
#elif (defined(CW))
const vector_entry __attribute__ ((section(".vectortable"))) __vector_table[] = //@ ".intvec" =
#endif
{
VECTOR_000, /* Initial SP */
VECTOR_001, /* Initial PC */
VECTOR_002,
...........
VECTOR_PADDING,
VECTOR_PADDING,
#ifndef CW
CONFIG_1,
CONFIG_2,
CONFIG_3,
CONFIG_4,
#endif
};
-----[snip]-------
And the above tabe is referred in the startup.c like as fllowing.
-----[snip]-------
#if (defined(KEIL))
extern uint32 Image$$VECTOR_ROM$$Base[];
extern uint32 Image$$VECTOR_RAM$$Base[];
#define __VECTOR_TABLE Image$$VECTOR_ROM$$Base
#define __VECTOR_RAM Image$$VECTOR_RAM$$Base
#elif (defined(IAR))
/* Addresses for VECTOR_TABLE and VECTOR_RAM come from the linker file */
extern uint32 __VECTOR_TABLE[];
extern uint32 __VECTOR_RAM[];
#elif (defined(CW))
#define __VECTOR_TABLE __vector_table
#define __VECTOR_RAM __vector_ram
extern uint32 __VECTOR_TABLE[];
extern uint32 __VECTOR_RAM[];
#endif
/* Copy the vector table to RAM */
if (__VECTOR_RAM != __VECTOR_TABLE)
{
for (n = 0; n < 0x104; n++)
__VECTOR_RAM[n] = __VECTOR_TABLE[n];
}
/* Point the VTOR to the new copy of the vector table */
write_vtor((uint32)__VECTOR_RAM);
-----[snip]-------
The startup.c is located at
${PROJ_ROOT}\common\startup.c.
I wonder why Will X-san don't use the sample code package because KL03 sample codes are re-used from KL25Z on the freescale site (http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=KL02&fpsp=1&tab=Design_Tools_Tab).
Best regards,
Yasuhiko Koumoto.
Hi Will,
Freescale provides KSDK software for KL03 chip.
Please download [Freescale Kinetis SDK_1.0.0 for the FRDM-KL03Z - Windows installer] from below link:
After installation the KSDK for KL03Z software, customer could find example demo at default path:
C:\Freescale\KSDK_1.0.0-KL03Z\demos
Just using [rtc_func] as an example, the interrupt ISR list at <startup_MKL03Z4.s> file with vector table to related ISR function.
The ISR function should with the same name as <startup_MKL03Z4.s>, and customer could find RTC IRQ ISR and RTC second IRQ ISR function located <rtc_func.c> file line 74:
/* override the RTC IRQ handler */
void RTC_IRQHandler(void)
{
if (RTC_DRV_IsAlarmPending(0))
{
gAlarmPending = 1;
/* disable alarm interrupt */
RTC_DRV_SetAlarmIntCmd(0, false);
}
}
/* override the RTC Second IRQ handler */
void RTC_Seconds_IRQHandler(void)
{
gSecsFlag = true;
}
Wish it helps.
best regards
Ma Hui
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------