64 lines
1.5 KiB
C++
64 lines
1.5 KiB
C++
#include <cstring>
|
|
#include <cstdint>
|
|
#include <cstdio>
|
|
|
|
#include "delay.h"
|
|
#include "platform/stm32g0xx/Gpio.h"
|
|
#include "platform/stm32g0xx/Uart.h"
|
|
#include "platform/stm32g0xx/IndependentWatchdog.h"
|
|
|
|
// 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
|
|
|
|
using namespace perinet::platform::stm32g0xx;
|
|
|
|
Gpio green_led(Gpio::Port::PORT_A, 5, Gpio::Mode::MODE_OUTPUT_PP);
|
|
Uart uart(Uart::UartDevice::UART_2, 115200);
|
|
|
|
#ifndef JTAG_DEBUG
|
|
IndependentWatchdog watchdog(4095, 4095);
|
|
#endif
|
|
|
|
int main(void)
|
|
{
|
|
unsigned int i = 1, j = 40;
|
|
char tx_buf[80];
|
|
|
|
#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;
|
|
}
|
|
sprintf(tx_buf, "%u: Hello World\r\n", i++);
|
|
uart.sync_send((const uint8_t *)tx_buf, strlen(tx_buf));
|
|
green_led.toggle();
|
|
delay_ms(j);
|
|
|
|
#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 */
|