stm32g0xx/Core/main.cc

64 lines
1.5 KiB
C++
Raw Normal View History

2021-01-08 10:58:59 +00:00
#include <cstring>
#include <cstdint>
#include <cstdio>
2021-01-08 10:58:59 +00:00
#include "delay.h"
2020-12-17 09:39:45 +00:00
#include "platform/stm32g0xx/Gpio.h"
2021-01-08 09:21:58 +00:00
#include "platform/stm32g0xx/Uart.h"
2021-01-08 09:50:38 +00:00
#include "platform/stm32g0xx/IndependentWatchdog.h"
2021-01-08 09:50:38 +00:00
// NOTE! The independent watchdog is clocked by a separate clock. this one
// isn't controlled by JTAG. That's why the independent watchdog needs to
// be disabled during JTAG debug sessions.
#define JTAG_DEBUG
2020-12-17 09:51:20 +00:00
using namespace perinet::platform::stm32g0xx;
2021-01-08 09:21:58 +00:00
Gpio green_led(Gpio::Port::PORT_A, 5, Gpio::Mode::MODE_OUTPUT_PP);
Uart uart(Uart::UartDevice::UART_2, 115200);
2021-01-08 09:50:38 +00:00
#ifndef JTAG_DEBUG
IndependentWatchdog watchdog(4095, 4095);
#endif
int main(void)
{
unsigned int i = 1, j = 40;
2021-01-08 09:21:58 +00:00
char tx_buf[80];
2021-01-08 09:50:38 +00:00
#ifndef JTAG_DEBUG
watchdog.enable();
#endif
while (1) {
if (j < 100) {
j += 10;
}
else if (j < 200) {
j += 20;
}
else if (j < 400) {
j += 40;
}
if (j > 800) {
j = 800;
}
2021-01-08 09:21:58 +00:00
sprintf(tx_buf, "%u: Hello World\r\n", i++);
uart.sync_send((const uint8_t *)tx_buf, strlen(tx_buf));
2020-12-17 09:39:45 +00:00
green_led.toggle();
2021-01-08 10:58:59 +00:00
delay_ms(j);
2021-01-08 09:50:38 +00:00
#ifndef JTAG_DEBUG
watchdog.trigger();
#endif
}
}
#ifdef USE_FULL_ASSERT
void assert_failed(uint8_t *file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
}
#endif /* USE_FULL_ASSERT */