Hi
For a minimum project with UART use the configuration (in config.h):
#define HELLO_WORLD // gives the classic first step project with just a message on a UART start and echos back input afterwards [enter key shows memory use] (also blinks LED and is identical with or without BLINKY enabled)
It will have two tasks:
watchdog - called every 200ms to trigger the watchdog and toggle a heat-beat LED
application - which configures the UART and prints a message. It is also scheduled each tie something is received and echoes it back.
It can run with or without low power support
#define SUPPORT_LOW_POWER // a low power task supervises power reduction when possible
which will then also add the low power task, typically halving the current consumption with no other effect on behavior.
The UART can still be used with DMA (although in your case the KL03 doesn't have DMA capabilities) or interrupts.
You can add your own SPI initialisation code in the initialisation part of the application task (or in extern void fnUserHWInit(void) if you prefer it to be done immediately when the processor starts).
Although the SD card interface is probably not the one you need you can use it as reference for any SPI configuration and communication. There is no setup for KL03 since utFAT has never been used with it - it probably has too little memory for such file system use but it is the same as other KL parts - for example (from KL26)
// Configure to suit special connection SPI mode at between 100k and 400k (SPI1)
// - SPI1_CS PTD-4 (J2-6) [VDD J3-4 / 0V J3-14]
// - SPI1_SCK PTD-5 (J2-12)
// - SPI1_MOSI PTD-6 (J2-8)
// - SPI1_MISO PTD-7 (J2-10)
//
#define SPI_CS1_0 PORTD_BIT4
#define INITIALISE_SPI_SD_INTERFACE() POWER_UP_ATOMIC(4, SPI1); \
_CONFIG_PERIPHERAL(D, 5, PD_5_SPI1_SCK); \
_CONFIG_PERIPHERAL(D, 6, (PD_6_SPI1_MOSI | PORT_SRE_FAST | PORT_DSE_HIGH)); \
_CONFIG_PERIPHERAL(D, 7, (PD_7_SPI1_MISO | PORT_PS_UP_ENABLE)); \
_CONFIG_DRIVE_PORT_OUTPUT_VALUE(D, SPI_CS1_0, SPI_CS1_0, (PORT_SRE_FAST | PORT_DSE_HIGH)); \
SPI1_C1 = (SPI_C1_CPHA | SPI_C1_CPOL | SPI_C1_MSTR | SPI_C1_SPE); \
SPI1_BR = (SPI_BR_SPPR_PRE_8 | SPI_BR_SPR_DIV_16); \
(void)SPI1_S; (void)SPI1_D
#define ENABLE_SPI_SD_OPERATION()
#define SET_SD_CARD_MODE()
// Set maximum speed
//
#define SET_SPI_SD_INTERFACE_FULL_SPEED() SPI1_BR = (SPI_BR_SPPR_PRE_1 | SPI_BR_SPR_DIV_2)
#if defined _WINDOWS
#define WRITE_SPI_CMD(byte) SPI1_D = (byte); SPI1_D = _fnSimSD_write((unsigned char)byte)
#define WAIT_TRANSMISSON_END() while (((unsigned char)SPI1_S & (SPI_S_SPRF)) == 0) { SPI1_S |= (SPI_S_SPRF); }
#define READ_SPI_DATA() (unsigned char)SPI1_D
#else
#define WRITE_SPI_CMD(byte) SPI1_D = (byte)
#define WAIT_TRANSMISSON_END() while (((unsigned char)SPI1_S & (SPI_S_SPRF)) == 0) {}
#define READ_SPI_DATA() (unsigned char)SPI1_D
#endif
#define SET_SD_DI_CS_HIGH() _SETBITS(D, SPI_CS1_0) // force DI and CS lines high ready for the initialisation sequence
#define SET_SD_CS_LOW() _CLEARBITS(D, SPI_CS1_0) // assert the CS line of the SD card to be read
#define SET_SD_CS_HIGH() _SETBITS(D, SPI_CS1_0) // negate the CS line of the SD card to be read
#define POWER_UP_SD_CARD() // apply power to the SD card if appropriate
#define POWER_DOWN_SD_CARD()
#define GET_SDCARD_WP_STATE() 0 // never write protect
Note that MOSI is not on A3 of the KL03 but on A7. This means that a suitable setup for the KL03 would be
// - SPI0_CS PTA-5
// - SPI0_SCK PTB-0
// - SPI0_MOSI PTA-7
// - SPI0_MISO PTA-6
//
#define SPI_CS1_0 PORTA_BIT5
POWER_UP_ATOMIC(4, SPI0);
_CONFIG_PERIPHERAL(B, 0, PB_0_SPI0_SCK);
_CONFIG_PERIPHERAL(A, 7, (PA_7_SPI0_MOSI | PORT_SRE_FAST | PORT_DSE_HIGH));
_CONFIG_PERIPHERAL(A, 6, (PA_6_SPI0_MISO | PORT_PS_UP_ENABLE)); \
_CONFIG_DRIVE_PORT_OUTPUT_VALUE(A, SPI_CS1_0, SPI_CS1_0, (PORT_SRE_FAST | PORT_DSE_HIGH));
SPI0_C1 = (SPI_C1_CPHA | SPI_C1_CPOL | SPI_C1_MSTR | SPI_C1_SPE);
SPI0_BR = (SPI_BR_SPPR_PRE_8 | SPI_BR_SPR_DIV_16);
(void)SPI0_S; (void)SPI0_D;
whereby the chip select is controlled as a GPIO output rather than using its peripheral function.
PB_0_SPI0_SCK is ALT3 so one doesn't necessarily need to know the ALT details if the names with integrated pin numbers are used like this.
For transmission and reception you just need to change SPI1 into SPI0.
Regards
Mark
P.S. You can disable the watchdog and remove the watchdog task if you don't need it but it is generally always present since watchdog functionality would normally be the highest priority for reliable equipment (that can recover from serious error situations)