{
rcc_clock_setup_in_hse_8mhz_out_72mhz();
+ rcc_periph_clock_enable(RCC_GPIOA);
rcc_periph_clock_enable(RCC_GPIOB);
rcc_periph_clock_enable(RCC_GPIOC);
rcc_periph_clock_enable(RCC_USART1);
rcc_periph_clock_enable(RCC_USART3);
+ rcc_periph_reset_pulse(RST_GPIOA);
rcc_periph_reset_pulse(RST_GPIOB);
rcc_periph_reset_pulse(RST_GPIOC);
rcc_periph_reset_pulse(RST_USART1);
systick_interrupt_enable();
}
+#if 0
static void delay_ms(uint ms)
{
u32 start_ticks = ms_ticks;
while (ms_ticks - start_ticks < ms)
;
}
+#endif
static void usart_setup(void)
{
usart_set_baudrate(USART1, 115200);
usart_set_databits(USART1, 8);
usart_set_stopbits(USART1, USART_STOPBITS_1);
- usart_set_mode(USART1, USART_MODE_TX);
+ // usart_set_mode(USART1, USART_MODE_TX);
+ usart_set_mode(USART1, USART_MODE_TX_RX);
usart_set_parity(USART1, USART_PARITY_NONE);
usart_set_flow_control(USART1, USART_FLOWCONTROL_NONE);
// BSB USART
gpio_set_mode(GPIOB, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO_USART3_RX);
- gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART3_TX);
+ gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_OPENDRAIN, GPIO_USART3_TX);
usart_set_baudrate(USART3, 4800);
- usart_set_databits(USART3, 8);
+ usart_set_databits(USART3, 9);
usart_set_stopbits(USART3, USART_STOPBITS_1);
- usart_set_mode(USART3, USART_MODE_RX);
+ usart_set_mode(USART3, USART_MODE_TX_RX);
usart_set_parity(USART3, USART_PARITY_ODD);
usart_set_flow_control(USART3, USART_FLOWCONTROL_NONE);
usart_enable(USART3);
}
+static const byte send_pkt[] = {
+ 0xdc, 0xc2, 0x00, 0x0b, 0x06, 0x3d, 0x2e, 0x11, 0x25, 0x40, 0x78,
+};
+
int main(void)
{
clock_setup();
SCB_VTOR = 0x08000000;
cm_enable_interrupts();
- u32 start_ticks = ms_ticks;
+ debug_printf("Hello, kitty!\n");
+
+ u32 last_ticks = 0;
+ u32 led_ticks = ms_ticks;
+ uint tx_pos = 0;
for (;;) {
+ if (USART_SR(USART1) & USART_SR_RXNE) {
+ uint c = usart_recv(USART1) & 0xff;
+ if (c == '#')
+ tx_pos = 1;
+ }
if (USART_SR(USART3) & USART_SR_RXNE) {
- uint x = usart_recv(USART3);
+ uint x = (usart_recv(USART3) & 0xff) ^ 0xff;
debug_printf("%02x ", x);
+ last_ticks = ms_ticks;
+ }
+ if (tx_pos && (USART_SR(USART3) & USART_SR_TXE)) {
+ if (tx_pos > sizeof(send_pkt)) {
+ tx_pos = 0;
+ debug_putc('.');
+ } else {
+ uint x = send_pkt[tx_pos++ - 1];
+ usart_send(USART3, x ^ 0xff);
+ debug_putc('>');
+ }
+ }
+ if (last_ticks && ms_ticks - last_ticks >= 100) {
+ last_ticks = 0;
+ debug_putc('\n');
}
- if (ms_ticks - start_ticks >= 100) {
- start_ticks = ms_ticks;
+ if (ms_ticks - led_ticks >= 100) {
+ led_ticks = ms_ticks;
debug_led_toggle();
- debug_putc(' ');
}
}