add UART EEPROM

This commit is contained in:
King Kévin 2022-07-11 10:39:09 +02:00
parent 9e865cc0c7
commit f7ed7670f3
1 changed files with 34 additions and 0 deletions

34
main.c
View File

@ -40,6 +40,40 @@ static void wait_10us(uint32_t us10)
while (us10--); // burn energy
}
void putc(char c)
{
while (!UART1->SR.fields.TXE); // wait until TX buffer is empty
UART1->DR.reg = c; // put character in buffer to be transmitted
// don't wait until the transmission is complete
}
void puts(const char* s)
{
if (NULL == s) {
return;
}
while (*s) {
putc(*s++);
IWDG_KR = IWDG_KR_KEY_REFRESH; // reset watchdog
}
}
void putn(uint8_t n)
{
n &= 0x0f; // ensure it's a nibble
if (n < 0xa) {
putc('0' + n);
} else {
putc('a' + (n - 0x0a));
}
}
void puth(uint8_t h)
{
putn(h >> 4);
putn(h & 0x0f);
}
void main(void)
{
sim(); // disable interrupts (while we reconfigure them)