Skip to content

Commit

Permalink
Added stm32 app.
Browse files Browse the repository at this point in the history
  • Loading branch information
o7-machinehum committed Aug 18, 2023
1 parent b0e4c45 commit 5a0be70
Show file tree
Hide file tree
Showing 9 changed files with 448 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "libopencm3"]
path = libopencm3
url = https://github.com/libopencm3/libopencm3.git
1 change: 1 addition & 0 deletions libopencm3
Submodule libopencm3 added at 32a169
16 changes: 15 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ cd pl02-fw
west update
```

### Build & Run - ESP32
### Build & Run - ESP32/RP2040
The application can be built by running:

```shell
Expand All @@ -31,3 +31,17 @@ west flash --runner jlink --build-dir build/rp2040
# If you don't have a jlink (programmer). You can use this.
sudo picotool load build/rp2040/zephyr/zephyr.elf
```

### Build & Run - STM32
The STM32 doesn't not used zephyr, it's a libopencm3 project.
```shell
git submodule init
git submodule update
```

Building and flashing
```shell
cd stm32-app
make
make flash
```
1 change: 0 additions & 1 deletion rp2040-app/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ void buckboost(void)
first = false;
}


// Read vbat in mA
vbat = adc.read_vbat();
if(vbat > 20000.0) {
Expand Down
47 changes: 47 additions & 0 deletions stm32-app/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
##
## This file is part of the libopencm3 project.
##
## Copyright (C) 2009 Uwe Hermann <[email protected]>
##
## This library is free software: you can redistribute it and/or modify
## it under the terms of the GNU Lesser General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This library is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU Lesser General Public License for more details.
##
## You should have received a copy of the GNU Lesser General Public License
## along with this library. If not, see <http://www.gnu.org/licenses/>.
##

BINARY = main
CSTD = -std=gnu99

LDSCRIPT = nucleo-g030f6.ld
LIBNAME = opencm3_stm32g0
DEFS += -DSTM32G0

FP_FLAGS ?= -msoft-float
ARCH_FLAGS = -mthumb -mcpu=cortex-m0 $(FP_FLAGS)

################################################################################
# OpenOCD specific variables

OOCD ?= openocd
OOCD_INTERFACE ?= stlink
OOCD_TARGET ?= stm32g0x

################################################################################
# Black Magic Probe specific variables
# Set the BMP_PORT to a serial port and then BMP is used for flashing
BMP_PORT ?=

################################################################################
# texane/stlink specific variables
#STLINK_PORT ?= :4242


include rules.mk
12 changes: 12 additions & 0 deletions stm32-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# README

This example program sends a message "Pass: n" with increasing number n
from 0 to 200 on USART2 serial line of ST NUCLEO-G031K8 eval board.

The sending is done using newlib library in a blocking way.

## Board connections

| Port | Function | Description |
| ----- | ------------- | --------------------------------- |
| `PA2` | `(USART2_TX)` | TTL serial output `(115200,8,N,1)` |
69 changes: 69 additions & 0 deletions stm32-app/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/gpio.h>
#include <libopencm3/stm32/usart.h>

#include <stdio.h>

#define PORT_LED GPIOA
#define PIN_LED1 GPIO5
#define PIN_LED2 GPIO7

void uart_out(char* data);

static void clock_setup(void)
{
/* Enable GPIOC clock for LED & USARTs. */
rcc_set_sysclk_source(RCC_CLOCK_CONFIG_HSI_PLL_64MHZ);
rcc_periph_clock_enable(RCC_GPIOA);
// rcc_periph_clock_enable(RCC_GPIOC);

/* Enable clocks for USART. */
// rcc_periph_clock_enable(RCC_USART1);
}

static void usart_setup(void)
{
/* Setup USART parameters. */
usart_set_baudrate(USART1, 115200);
usart_set_databits(USART1, 8);
usart_set_parity(USART1, USART_PARITY_NONE);
usart_set_stopbits(USART1, USART_CR2_STOPBITS_1);
usart_set_mode(USART1, USART_MODE_TX);
usart_set_flow_control(USART1, USART_FLOWCONTROL_NONE);

/* Finally enable the USART. */
usart_enable(USART1);
}

static void gpio_setup(void)
{
gpio_mode_setup(PORT_LED, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, PIN_LED1 | PIN_LED2);

// gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO9);

// gpio_set_af(GPIOA, GPIO_AF1, GPIO9);
}

void uart_out(char* data) {
while(*data) {
usart_send_blocking(USART1, *data++); /* USART2: Send byte. */
}
}

int main(void)
{
int i = 0;
// char buf[256];

clock_setup();
gpio_setup();
// usart_setup();
// sprintf(buf, "Hello world\r\n");
// uart_out(buf);

while(1) {
gpio_set(PORT_LED, PIN_LED1 | PIN_LED2);
}

return 0;
}
32 changes: 32 additions & 0 deletions stm32-app/nucleo-g030f6.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* This file is part of the libopencm3 project.
*
* Copyright (C) 2009 Uwe Hermann <[email protected]>
* Copyright (C) 2011 Stephen Caudle <[email protected]>
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/

/* Linker script for ST NUCLEO-G030F6 (STM32G030F6, 32K flash, 8K RAM). */

/* Define memory regions. */
MEMORY
{
rom (rx) : ORIGIN = 0x08000000, LENGTH = 32K
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 8K
}

/* Include the common ld script. */
INCLUDE cortex-m-generic.ld

Loading

0 comments on commit 5a0be70

Please sign in to comment.