Skip to content

Commit

Permalink
Add RPC conditional
Browse files Browse the repository at this point in the history
  • Loading branch information
cpq committed May 11, 2020
1 parent e31534e commit 01c36d2
Show file tree
Hide file tree
Showing 5 changed files with 317 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
TARGET = bluepill
ARCH = arm-none-eabi
CFLAGS = -W -Wall -g -Os -mcpu=cortex-m3 -mthumb -mabi=aapcs -mfloat-abi=soft
CFLAGS = -W -Wall -g -Os -mcpu=cortex-m3 -mthumb -mabi=aapcs -mfloat-abi=soft $(CFLAGS_EXTRA)
LDFLAGS = -Wl,--gc-sections -march=armv7-m -mabi=aapcs -nostartfiles -nostdlib -lc -lnosys -lgcc
AFLAGS = --warn --fatal-warnings -mcpu=cortex-m3
OBJS = obj/bootstrap.o obj/main.o
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# STM32 BluePill controlled by Cloud Connector
# STM32 BluePill controlled by https://vcon.io

This is a baremetal firmware code for a STM32F103C8T6 "BluePill"
development board. This firmware blinks an LED, and runs a JSON-RPC
Expand Down
13 changes: 13 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
// All rights reserved

#include "stm32f1.h"

#ifndef RPC
#define RPC 1
#endif

#if RPC
#include "mjson.h"

static int uart_write(const char *ptr, int size, void *userdata) {
Expand All @@ -13,9 +19,11 @@ static int uart_write(const char *ptr, int size, void *userdata) {
}
return size;
}
#endif

static int blink_period = 150000;

#if RPC
static void set_cycles(struct jsonrpc_request *r) {
double dv;
if (mjson_get_number(r->params, r->params_len, "$.period", &dv)) {
Expand All @@ -25,6 +33,7 @@ static void set_cycles(struct jsonrpc_request *r) {
jsonrpc_return_error(r, JSONRPC_ERROR_BAD_PARAMS, "Expect period", NULL);
}
}
#endif

int main(void) {
INIT_MEMORY;
Expand All @@ -39,14 +48,18 @@ int main(void) {
UART1->BRR = 0x45; // Set baud rate, TRM 27.3.4
UART1->CR1 = BIT(13) | BIT(2) | BIT(3); // Enable USART1

#if RPC
jsonrpc_init(NULL, NULL); // Init JSON-RPC lib
jsonrpc_export("SetCycles", set_cycles, NULL); // Export custom function
#endif

volatile int count = 0, led_on = 0;
for (;;) {
#if RPC
if (UART_HAS_DATA(UART1)) {
jsonrpc_process_byte(UART_READ(UART1), uart_write, UART1);
}
#endif
if (++count < blink_period) continue;
count = 0;
led_on = !led_on;
Expand Down
Loading

0 comments on commit 01c36d2

Please sign in to comment.