Hi guys,
I using
keil uvisionV5.35.0.0
arm_compiler : V6.16
We are developing a project on STM32L071CZYx MCU. which has
flash memory: 192kB
RAM: 20KB
The code perfectly works when it is in separate project but we need to combine both the project.
In 1st project We have configured I2C1 has a slave. i have attached code for the irq_handler
void I2C1_IRQHandler(void) { I2C1->CR1 &= ~(I2C_CR1_RXIE |I2C_CR1_ADDRIE | I2C_CR1_STOPIE | I2C_CR1_TXIE); switch((I2C1->ISR &(I2C_ISR_STOPF | I2C_ISR_ADDR |I2C_ISR_RXNE | I2C_ISR_TXIS))) { case 0x08: //address match dev_addr = ((I2C1->ISR >> 16 ) & 0xFE); // assigning Recieved slave address if(I2C1->ISR & I2C_ISR_DIR) { // Slave address with Read bit if(i2c_state == I2C_GOT_CONTROL_WORD_ADDR) { i2c_state = I2C_REPEATED_START; } else { i2c_state = I2C_RD_STARTED; } __HAL_I2C_CLEAR_FLAG(&hi2c1,(I2C_FLAG_ADDR )); I2C1->CR1 |= (I2C_CR1_TXIE); // enabling Transmitter Interrupt //slave Tx } else { // Slave address with write bit i2c_pkt_length = 0; i2c_state = I2C_WR_STARTED; __HAL_I2C_CLEAR_FLAG(&hi2c1,I2C_FLAG_ADDR); I2C1->CR1 |= (I2C_CR1_RXIE); // stopIE is not required //slave Rx } break; case 0x04: //rx data for master if(i2c_state == I2C_WR_STARTED) { CW =I2C1->RXDR; word_addr = CW; i2c_state = I2C_GOT_CONTROL_WORD_ADDR; } else { i2cdatarx[i2c_pkt_length++] = I2C1->RXDR; i2c_state = I2C_DATA_STARTED; } __HAL_I2C_CLEAR_FLAG(&hi2c1,I2C_FLAG_RXNE); I2C1->CR1 |= (I2C_CR1_RXIE | I2C_CR1_ADDRIE | I2C_CR1_STOPIE); // enabling Rx address match and Stop interrupt break; case 0x20: // detected a stop if (dev_addr == 0xB0 ) { if (i2c_state == I2C_DATA_STARTED || i2c_state == I2C_GOT_CONTROL_WORD_ADDR) { F0_write(word_addr); } else { I2C1->ISR |= I2C_ISR_TXE;//Setting flushing the TX buffer for new data transfer } } else { if (i2c_state == I2C_DATA_STARTED || i2c_state == I2C_WR_STARTED) { if (mode == mFACTORY) { A0_write_FM(word_addr); // writting to sram and Eeprom } else { A0_write(word_addr); } } else { I2C1->ISR |= I2C_ISR_TXE;//Setting flushing the TX buffer for new data transfer } } i2c_state = I2C_IDLE; __HAL_I2C_CLEAR_FLAG(&hi2c1,I2C_FLAG_STOPF); I2C1->CR1 |= (I2C_CR1_ADDRIE); // enabling address match break; case 0x02: // Transmit has detected //i2cdatarx = I2C_read_F0(CW); if (dev_addr == 0xB0) { I2C1->TXDR = F0_Read(CW); } else { if (mode == 1) { I2C1->TXDR = A0_read_FM(CW); } else { I2C1->TXDR = A0_read(CW); } } __HAL_I2C_CLEAR_FLAG(&hi2c1,(I2C_FLAG_ADDR)); I2C1->CR1 |= (I2C_CR1_STOPIE | I2C_CR1_TXIE); break; } }
and 1st project alone uses :
==============================================================================
Total RO Size (Code + RO Data) 9188 ( 8.97kB) Total RW Size (RW Data + ZI Data) 3704 ( 3.62kB) Total ROM Size (Code + RO Data + RW Data) 9228 ( 9.01kB)
And the 2nd project alone uses:
stack memory : 10.5kB
Total RO Size (Code + RO Data) 146028 ( 142.61kB) Total RW Size (RW Data + ZI Data) 19440 ( 18.98kB) Total ROM Size (Code + RO Data + RW Data) 146188 ( 142.76kB)
and the combined code uses :
we have removed the 1280 bytes of global variable(array) and we got,
and even increase the stack memory to : 12kB
In the combined project code crashes when we include 1st projects I2C_IRQ_handler but without it works fine with polling method but we can't include all the required features in it. I have many method like increasing stack size and reducing global variable but nothing worked. I will be thankful if I get an information. and even attached an error pic.
Hey, did you have to implement the Driver_I2C.c manually ? Or did you just import the Driver_I2C.h file and it worked ?
Hi Uodami Thank you for reply,
I have add all the required files in the project folder.