Programing ic seems not damaged because despite of getting little warm after while
On the contrary, that is clear evidence of damage. Or at least misconnection. If this behavior persists with the target unconnected, then it is damaged.
In normal operation it will not be a noticeable source of heat.
I think the following section explains how to generate the NACK. In order to send the NACK signal, the software must clear the ACK bit after reading second last byte. Hope this will help.
(Image source: STM32F407 Reference Manual RM0090, Section 27.3.3, page 849 in revision 18 of the manual)
It is described in the Reference Manual, not in the datasheet. A NACK is sent when the I2C_CR1_ACK bit in I2C->CR1 is set to 0 before receiving the last byte.
HAL should manage this bit automatically according to the transfer size in the HAL_I2C_..._Receive... functions.
Sending a NAK by itself is pointless. The whole purpose of HAL is to handle the protocol for you, will generate a NAK or ACK bit when necessary. And surely the reference manual gives details how to make the I2C peripheral to transmit ACK or NAK after a byte transfer.
This is an old question but I have a general comment about your code as it might cause bugs (I came across this bug just today, preventing me to use the PWM at all). I am posting it as an answer because I can't use comments yet with my new account.
When using init structs, it is best practise to call their corresponding struct init functions before doing ...
Some pins have alternate functions for the JTAG and SW interfaces. JTAG pins are pulled up or pulled down at reset. To use those pins you have to configure the AFIO_MAPR register, or define a macro according to compiler.
Is it possible to use the GPIOs without interfering with the internal goodies? I mean, if I use a GPIO pin which is also used by the LCD, can it be a problem?
Yes. Unplug the LCD glass from the board -- it's mounted in a DIP-style socket. Once you've done this, the pins are available for use.
There are a few other peripherals on this board which cannot ...