Program stm32g474re from Bootloader via I2C
Good afternoon.
I am trying to program STM32G47X through the built-in bootloader using a protocol I2C from another microcontroller.
Document 2606 on page 212 indicates the slave address 0b1010100x. I managed to get through only at 0b1010011x. Is this a bug in the documentation?
Document 4221 also has very little information. I enter bootloader mode by setting boot1 to 1 and releasing the reset.
//i2c 100kHz
HAL_StatusTypeDef status;
uint8_t tmp[2];
uint8_t dat[21];
uint8_t ACK;
while(HAL_I2C_GetState(hi2c) != HAL_I2C_STATE_READY);
status = HAL_I2C_Master_Transmit_IT(I2cHandle, 0xa6, dat, 1);
while (HAL_I2C_GetState(hi2c) != HAL_I2C_STATE_READY) ;
status = HAL_I2C_Master_Receive_IT(I2cHandle, 0xa7, &ACK, 1);
while(1)
{
tmp[0] = 1;
tmp[1] = 0xfe;//XOR tmp[0]
while (HAL_I2C_GetState(hi2c) != HAL_I2C_STATE_READY) ;
status = HAL_I2C_Master_Transmit_IT(I2cHandle, 0xa6, tmp, 2);
memset(dat, 0, sizeof(dat));
while (HAL_I2C_GetState(hi2c) != HAL_I2C_STATE_READY) ;
status = HAL_I2C_Master_Receive_IT(I2cHandle, 0xa7, &ACK, 1);
if (ACK == 0x79)
{
while (HAL_I2C_GetState(hi2c) != HAL_I2C_STATE_READY) ;
status = HAL_I2C_Master_Receive_IT(I2cHandle, 0xa7, dat, 2);
//I accept only zeros!
}
else if (ACK == 0x1f)//nack
{
//Sometimes I get here
}
else if(ACK == 0x76)//busy
{
}
else
{
}Often, the slave controller presses the SCL line to the ground. And you have to wait up to 10 seconds.
Maybe someone has an example working?
I don’t understand how to receive data after the response ACK == 0x79
