Hello ,
I am writing a small chunk of code on my KL05 (32KB flash).
After building, I have gioven generate .hex option. I am getting a hex file
abt 19KB. My aim is to use this to drive a sensorless BLDC. The LPC2121
uses abt 6KB of its 32KB flash. WHy is Kinetis using 19KB.
How can I look at the flash usage (does code warrior have one, a la MPLAB).
Is the hex file programmed into the controller. Or is it something else.
My code is below
#include "derivative.h" /* include peripheral declarations */
#define uartEnable UART0_C2 |= UART0_C2_TE_MASK| UART0_C2_RE_MASK; // UART is enabled //
#define uartDisable UART0_C2 &= ~ (UART0_C2_TE_MASK| UART0_C2_RE_MASK); // UART is disabled //
#define luvOceansModeStartup
#define normalModeStartup;
#define startupBrakeTime 150
void delaySet(uint8_t timerReg,uint16_t timeValue);
//*********************************************************//
// PWM module //
void pwmInit(){
// PWM //
//timer0 - PWM //
SIM_SOPT2 |= SIM_SOPT2_TPMSRC(1); // clk source for TPM0 and TPM1 as well
SIM_SCGC6 |= SIM_SCGC6_TPM0_MASK; // clk gated for TPM0
TPM0_SC = (1<<2); // 16 prescale factor
//Pins of PWM //
//--- alternate selection (all PWM are ALT2)---//
PORTB_PCR6 |= PORT_PCR_MUX(1); // U1+
PORTB_PCR7 |= PORT_PCR_MUX(1); // U1-
PORTB_PCR10 |= PORT_PCR_MUX(1); // V1+
PORTB_PCR11 |= PORT_PCR_MUX(1); // V1-
PORTA_PCR5 |= PORT_PCR_MUX(1); // W1+
PORTA_PCR6 |= PORT_PCR_MUX(1); // W1-
GPIOB_PDDR |= (1<<6);GPIOB_PDDR |= (1<<7);GPIOB_PDDR |= (1<<10);GPIOB_PDDR |= (1<<11);
GPIOA_PDDR |= (1<<5);GPIOA_PDDR |= (1<<6);
TPM0_C0SC |= (TPM_CnSC_MSB_MASK | TPM_CnSC_ELSB_MASK); // PWM - edge ,...etc //
TPM0_C1SC |= (TPM_CnSC_MSB_MASK | TPM_CnSC_ELSB_MASK);
TPM0_C2SC |= (TPM_CnSC_MSB_MASK | TPM_CnSC_ELSB_MASK);
TPM0_C3SC |= (TPM_CnSC_MSB_MASK | TPM_CnSC_ELSB_MASK);
TPM0_C4SC |= (TPM_CnSC_MSB_MASK | TPM_CnSC_ELSB_MASK);
TPM0_C5SC |= (TPM_CnSC_MSB_MASK | TPM_CnSC_ELSB_MASK);
TPM0_CONF |= TPM_CONF_DBGMODE_MASK; // timer runs even in debug mode //
// TPM0_SC -- turn on timer //
}
// PWM done //
//*********************************************************//
//*********************************************************//
// UART module //
void uartInit(){
//UART configure //
SIM_SOPT2 |= SIM_SOPT2_UART0SRC(1); // clk source for UART
SIM_SCGC4 |= SIM_SCGC4_UART0_MASK; // clk gated for UART0
SIM_SCGC5 |= SIM_SCGC5_PORTA_MASK; // clk gated for PORTA
SIM_SCGC5 |= SIM_SCGC5_PORTB_MASK; // clk gated for PORTB
PORTB_PCR3 = PORT_PCR_ISF_MASK|PORT_PCR_MUX(2); // alternate - 4 //
PORTB_PCR4 = PORT_PCR_ISF_MASK|PORT_PCR_MUX(2); // alternate - 4 //
//uartDisable;
// 8 bits,stop bits,....etc //
//GPIOB_PDDR
UART0_BDH = 0x02;
UART0_BDL = 0x22;
UART0_C4 = 0x0F;
UART0_C1 = 0x00;
UART0_C3 = 0x00;
UART0_MA1 = 0x00;
UART0_MA1 = 0x00;
UART0_S1 |= 0x1F;
UART0_S2 |= 0xC0;
//uartEnable;
}
// UART done //
//*********************************************************//
//*********************************************************//
// timer1 module //
void ptm1Init(){
SIM_SCGC6 |= SIM_SCGC6_TPM1_MASK; // clk gated for TPM0
TPM1_SC = (1<<2); // 16 prescale factor
TPM1_CONF |= TPM_CONF_DBGMODE_MASK; // timer runs even in debug mode //
//TPM1_SC; // start off timer //
}
// timer1 done //
//*********************************************************//
//*********************************************************//
// adc module //
void adcInit(){
}
// adc done //
//*********************************************************//
//*********************************************************//
// LPTMR module //
void lptmInit(){
}
// LPTMR done //
//*********************************************************//
//*********************************************************//
// -- timer register timerData
// bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0
// x x x x 1-ms 1-IE 1-on 1-on
// 0-us 0-ID 0-off 0-off
// startBrake module //
void startBrake(){
uint8_t timerDat;
// ptm1Init(); // done at startup //
// gpios set as output //
PORTA_PCR5 &= ~(PORT_PCR_MUX_MASK);
PORTA_PCR6 &= ~(PORT_PCR_MUX_MASK);
PORTB_PCR5 &= ~(PORT_PCR_MUX_MASK);
PORTB_PCR7 &= ~(PORT_PCR_MUX_MASK);
PORTB_PCR10 &= ~(PORT_PCR_MUX_MASK);
PORTB_PCR11 &= ~(PORT_PCR_MUX_MASK);
PORTA_PCR5 |= PORT_PCR_MUX(0);
PORTA_PCR5 |= PORT_PCR_MUX(0);
PORTA_PCR6 |= PORT_PCR_MUX(0);
PORTB_PCR5 |= PORT_PCR_MUX(0);
PORTB_PCR7 |= PORT_PCR_MUX(0);
PORTB_PCR10|= PORT_PCR_MUX(0);
PORTB_PCR11|= PORT_PCR_MUX(0);
GPIOA_PDDR = (GPIO_PDDR_PDD(5) & GPIO_PDDR_PDD(6));
GPIOB_PDDR = (GPIO_PDDR_PDD(5) & GPIO_PDDR_PDD(7) & GPIO_PDDR_PDD(10) & GPIO_PDDR_PDD(11));
timerDat = 10;
//GPIOA_PSOR = (GPIO_PSOR_PTSO(5) & GPIO_PSOR_PTSO(6));
GPIOB_PSOR = (GPIO_PSOR_PTSO(7) & GPIO_PSOR_PTSO(10));
//delaySet(timerDat,startupBrakeTime);
// brake - PTB7 - off,PTB5,PTB10 and PTA5 - on //
//GPIOB_PCOR = (GPIO_PSOR_PTSO(7) & (GPIO_PSOR_PTSO(11); // U1+ W1+
//GPIOA_PCOR = ((GPIO_PSOR_PTSO(6)); // V+
GPIOB_PSOR = (GPIO_PSOR_PTSO(5) & GPIO_PSOR_PTSO(10));
GPIOA_PSOR = (GPIO_PSOR_PTSO(5));
// -- braking done calibration done -- //
}
// startBrake done //
//*********************************************************//
//*********************************************************//
// -- start up and brake done -- //
// -- ramp up is done next -- //
// open loop module //
void openLoopMotor(){
}
// open loop done //
//*********************************************************//
//*********************************************************//
//*********************************************************//
// Usage - this function will set up the KL04 controller -
// Peripherals - timer0,timer1,LPTMR,ADC, and PWM.
// Pins -
// U1+ - Pin2 - PTB7
// U1- - Pin1 - PTB6
// V1+ - Pin8 - PTA6
// V1- - Pin7 - PTA5
// W1+ - Pin10 - PTB11
// W1- - Pin9 - PTB10
// ADC(U) - Pin11 - PTA7
// ADC(V) - Pin12 - PTB0
// ADC(W) - Pin13 - PTB1
// ADC(Total) - Pin14 - PTB1
// UART //
// Called from - main
// Calls - pwmInit,uartInit,ptm1Init,adcInit,lptmInit
//*********************************************************//
void ucInit(){
// clock initialised to 20.97MHz //
// done //
ptm1Init();
uartInit();
//adcInit();
//lptmInit();
#ifdef luvOceansModeStartup
startBrake();
#endif
pwmInit(); // mask register bits before configuring //
//ADC configure //
//LPTMR configure //
//timer1 - Capture and compare from Atmega //
//LPTMR and commutation timing - ADC capturing //
}
//*********************************************************//
//*********************************************************//
// -- delays -- //
void delaySet(uint8_t timerReg,uint16_t timeValue){
uint8_t mask;
uint8_t countRegTemp;
uint16_t timeValueTemp;
uint16_t rough;
countRegTemp = 0;
if((mask = 1<<countRegTemp+3) == 1){
countRegTemp = 0;
// msecs //
if((mask = 1<<countRegTemp) == 1){
// timer0 on //
TPM0_MOD = 1309;
TPM0_SC &= ~(TPM_SC_CMOD_MASK);
TPM0_SC |= TPM_SC_CMOD(0);
for(timeValueTemp =0;timeValueTemp<=timeValue;timeValueTemp++){
while(TPM0_SC & TPM_SC_TOF_MASK){
TPM0_SC &= ~(TPM_SC_CMOD_MASK);
TPM0_SC |= TPM_SC_TOF_MASK;
TPM0_SC |= TPM_SC_CMOD(0);
}
}
}
else{
// timer 1 //
TPM1_SC &= ~(TPM_SC_CMOD_MASK);
TPM1_SC |= TPM_SC_CMOD(0);
for(timeValueTemp =0;timeValueTemp<=timeValue;timeValueTemp++){
while(TPM0_SC & TPM_SC_TOF_MASK){
TPM1_SC &= ~(TPM_SC_CMOD_MASK);
TPM1_SC |= TPM_SC_TOF_MASK;
TPM1_SC |= TPM_SC_CMOD(0);
}
}
}
}
else{
// usecs - look if its a multiple of 10 //
if(timeValue <10){
timeValue = 10;
}
rough = timeValue%10;
if(rough != 0)
timeValue = ((timeValue/10)*10);
if((mask = 1<<countRegTemp) == 1){
// timer0 on //
TPM0_MOD = 13;
TPM0_SC &= ~(TPM_SC_CMOD_MASK);
TPM0_SC |= TPM_SC_CMOD(0);
for(timeValueTemp =0;timeValueTemp<=timeValue;timeValueTemp++){
while(TPM0_SC & TPM_SC_TOF_MASK){
TPM0_SC &= ~(TPM_SC_CMOD_MASK);
TPM0_SC |= TPM_SC_TOF_MASK;
TPM0_SC |= TPM_SC_CMOD(0);
}
}
}
else{
// timer 1 //
TPM1_SC &= ~(TPM_SC_CMOD_MASK);
TPM1_SC |= TPM_SC_CMOD(0);
for(timeValueTemp =0;timeValueTemp<=timeValue;timeValueTemp++){
while(TPM0_SC & TPM_SC_TOF_MASK){
TPM1_SC &= ~(TPM_SC_CMOD_MASK);
TPM1_SC |= TPM_SC_TOF_MASK;
TPM1_SC |= TPM_SC_CMOD(0);
}
}
}
}
}
// -- timer delay done //
//*********************************************************//
int main(void)
{
// initialise //
ucInit();
//pwmInit();
openLoopMotor();
while(1){
//closedLoopMotor();
}
//return 0;
}
hi karuvat,
Please make sure optimization level chosen by you is optimize size(-Os).
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Please check your project compile generated map file about memory usage.
I suggest to use CodeWarrior GCC compiler, which has higher compile performance for Kinetis product.
Wish it helps.
Best regards,
Ma Hui