Skip to content

Commit

Permalink
1.2.0
Browse files Browse the repository at this point in the history
- added: EEPROM support
- added: macro STM32CUBEDUINO_DISABLE_EEPROM
- added: macro STM32CUBEDUINO_DISABLE_PRINTF_FLOAT
- added: macro STM32CUBEDUINO_DISABLE_SCANF_FLOAT
- added: macro STM32CUBEDUINO_DISABLE_STRING
- added: hints for possible flash and speed improvement options to FAQ
- added: STM32L053C8T6 (GreenPill) blinky example
- fixed: OpenOCD target name creation in BuildScript.py for STM32L0, STM32L1 and STM32W108
- fixed: missing transfer flag handling in USB_Send()

Signed-off-by: Daniel Starke <[email protected]>
  • Loading branch information
daniel-starke committed May 29, 2022
1 parent d447a03 commit 28c5c30
Show file tree
Hide file tree
Showing 21 changed files with 987 additions and 142 deletions.
38 changes: 34 additions & 4 deletions BuildScript.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@author Daniel Starke
@copyright Copyright 2020-2022 Daniel Starke
@date 2020-10-20
@version 2022-03-27
@version 2022-05-29
"""

import os
Expand Down Expand Up @@ -1615,6 +1615,25 @@ def getMcuVariant(boardId, cpu, mcu):
return {"error": "Invalid value in CPU field for board %s. Possible values for %s are: %s." % (boardId, result["partNumber"] + result["variant"], cores)}
return result

def getOpenOcdTarget(mcu, warn = False):
""" Returns the PlatformIO OpenOCD target name for the given MCU. """
# dual bank firmware download is not support
from platformio.project.config import ProjectConfig
projectConfig = ProjectConfig()
corePath = projectConfig.get_optional_dir("core")
if corePath:
targetPath = os.path.join(corePath, "packages", "tool-openocd", "scripts", "target")
pattern = re.compile("^stm32[^_]+\.cfg$", re.I)
files = [f for f in os.listdir(targetPath) if os.path.isfile(os.path.join(targetPath, f)) and pattern.match(f)]
lowerMcu = mcu.lower()
for file in files:
target = file.replace(".cfg", "")
if re.match("^" + target.replace("x", ".*") + ".*$", lowerMcu, re.I):
return target;
if warn:
print("Warning: OpenOCD target not found for: " + mcu, file=sys.stderr)
return None

def getSvdFile(mcu, warn = False):
""" Returns the PlatformIO SVD file name for the given MCU. """
from platformio.project.config import ProjectConfig
Expand All @@ -1632,12 +1651,15 @@ def getSvdFile(mcu, warn = False):
if warn:
print("Warning: SVD file name list file not found: " + svdMapPath, file=sys.stderr)
return None


# add target specific pre-processor defines
if __name__ == 'SCons.Script':
Import("env")

if not "stm32cube" in map(str.lower, env.GetProjectOption("framework")):
Return()

global_env = DefaultEnvironment()
board = env.BoardConfig()

Expand All @@ -1649,7 +1671,13 @@ def getSvdFile(mcu, warn = False):
env.Append(CPPDEFINES=userMcu) # for this library
global_env.Append(CPPDEFINES=userMcu) # for all other components
env.Append(CPPDEFINES=[mcu["partNumber"] + mcu["variant"], mcu["partNumber"], mcu["define"], "ARDUINO=" + str(ARDUINO), "ARDUINO_ARCH_STM32"]) # for this library
global_env.Append(CPPDEFINES=[mcu["partNumber"] + mcu["variant"], mcu["partNumber"], mcu["define"], "ARDUINO=" + str(ARDUINO), "ARDUINO_ARCH_STM32"], LINKFLAGS=["-Wl,-u,_printf_float,-u,_scanf_float"]) # for all other components
global_env.Append(CPPDEFINES=[mcu["partNumber"] + mcu["variant"], mcu["partNumber"], mcu["define"], "ARDUINO=" + str(ARDUINO), "ARDUINO_ARCH_STM32"]) # for all other components
# include float support for printf/scanf like functions
cppDefines = env.get("CPPDEFINES", [])
if not "STM32CUBEDUINO_DISABLE_PRINTF_FLOAT" in cppDefines:
global_env.Append(LINKFLAGS=["-Wl,-u,_printf_float"])
if not "STM32CUBEDUINO_DISABLE_SCANF_FLOAT" in cppDefines:
global_env.Append(LINKFLAGS=["-Wl,-u,_scanf_float"])


# helper application to create PlatformIO board ini files
Expand All @@ -1669,6 +1697,7 @@ def getSvdFile(mcu, warn = False):
print("Error: " + mcu["error"], file=sys.stderr)
sys.exit(1)

ocdTarget = getOpenOcdTarget(mcu["partNumber"], True)
svdFile = getSvdFile(mcu["partNumber"], True)

boardName = "<add board name here>"
Expand All @@ -1691,7 +1720,7 @@ def getSvdFile(mcu, warn = False):
"onboard_tools": [
"stlink"
],
"openocd_target": "{mcu:.7s}x",
"openocd_target": "{OCD}",
"svd_path": "{SVD}"
}},
"frameworks": "stm32cube",
Expand All @@ -1717,6 +1746,7 @@ def getSvdFile(mcu, warn = False):
PROD=mcu["define"],
dev=sys.argv[2].lower()[:11],
DEV=sys.argv[2].upper()[:11],
OCD=(ocdTarget if ocdTarget else "<add OpenOCD target name here>"),
SVD=(svdFile if svdFile else "<add SVD file name here>"),
RAM=mcu["ram"] * 1024,
FLASH=mcu["flash"] * 1024,
Expand Down
146 changes: 85 additions & 61 deletions README.md

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion etc/test/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# @author Daniel Starke
# @copyright Copyright 2022 Daniel Starke
# @date 2022-03-20
# @version 2022-03-29
# @version 2022-04-18
#
# Running from within the library root directory.
# The following environment variables are used:
Expand Down Expand Up @@ -56,8 +56,11 @@ done <<"_LIST"
-DSTM32CUBEDUINO_DISABLE_EXTI
-DSTM32CUBEDUINO_DISABLE_I2C
-DSTM32CUBEDUINO_DISABLE_PWM
-DSTM32CUBEDUINO_DISABLE_PRINTF_FLOAT
-DSTM32CUBEDUINO_DISABLE_SCANF_FLOAT
-DSTM32CUBEDUINO_DISABLE_SERIAL
-DSTM32CUBEDUINO_DISABLE_SPI
-DSTM32CUBEDUINO_DISABLE_STRING
-DSTM32CUBEDUINO_DISABLE_TIMER
-DSTM32CUBEDUINO_DISABLE_USB
_LIST
Expand Down
3 changes: 1 addition & 2 deletions examples/BluePill/Blinky/src/bluepill/board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ void initVariant() {
systemErrorHandler();
}
/* Initializes the CPU, AHB and APB buses clocks. */
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
Expand Down
37 changes: 37 additions & 0 deletions examples/GreenPill/Blinky/boards/greenpill.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"build": {
"core": "stm32",
"cpu": "cortex-m0plus",
"mcu": "stm32l053c8t6",
"product_line": "STM32L053xx",
"extra_flags": "-DUSB_VID=0x2341 -DUSB_PID=0x8036"
},
"debug": {
"default_tools": [
"stlink"
],
"jlink_device": "STM32L053C8",
"onboard_tools": [
"stlink"
],
"openocd_target": "stm32l0",
"svd_path": "STM32L053x.svd"
},
"frameworks": "stm32cube",
"name": "greenpill",
"upload": {
"maximum_ram_size": 8192,
"maximum_size": 65536,
"protocol": "stlink",
"protocols": [
"jlink",
"stlink",
"blackmagic",
"serial",
"mbed",
"dfu"
]
},
"url": "https://stm32-base.org/boards/STM32L053C8T6-Green-Pill",
"vendor": "Generic"
}
16 changes: 16 additions & 0 deletions examples/GreenPill/Blinky/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[platformio]
workspace_dir = bin
src_dir = src
lib_dir = ../../../..

[common]
build_flags = -Wall -Wextra -Wformat -pedantic -Wshadow -Wconversion -Wparentheses -Wunused -Wno-missing-field-initializers

[env:greenpill]
platform = ststm32
platform_packages = [email protected]
framework = stm32cube
board = greenpill
build_flags = -fno-strict-aliasing -I${PROJECTSRC_DIR}/greenpill -DNO_GPL
src_build_flags = ${common.build_flags}
debug_tool = stlink
52 changes: 52 additions & 0 deletions examples/GreenPill/Blinky/src/greenpill/board.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* @file board.cpp
* @author Daniel Starke
* @copyright Copyright 2022 Daniel Starke
* @date 2022-05-29
* @version 2022-05-29
*/
#include <Arduino.h>
#include <wiring_irq.h>


/* exported variables */
HardwareSerial Serial1(USART1, getIrqNumFor(USART1), PA_10, PA_9, 4, 4);


/**
* Initializes this board by configuring the system clock base.
*/
void initVariant() {
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};

/* Configure the main internal regulator output voltage */
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
/* Initializes the RCC Oscillators according to the specified parameters in the RCC_OscInitTypeDef structure. */
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLLMUL_12;
RCC_OscInitStruct.PLL.PLLDIV = RCC_PLLDIV_3;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
systemErrorHandler();
}
/* Initializes the CPU, AHB and APB buses clocks */
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) {
systemErrorHandler();
}
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1|RCC_PERIPHCLK_USB;
PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;
PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLL;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) {
systemErrorHandler();
}
}
47 changes: 47 additions & 0 deletions examples/GreenPill/Blinky/src/greenpill/board.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* @file board.hpp
* @author Daniel Starke
* @copyright Copyright 2022 Daniel Starke
* @date 2022-05-29
* @version 2022-05-29
*/
#ifndef __GREENPILL_HPP__
#define __GREENPILL_HPP__

#include <stdint.h>
#include <stm32l0xx.h>
#include <stm32l0xx_hal.h>
#include <stm32l0xx_ll_cortex.h>
#include <stm32l0xx_ll_exti.h>
#include <stm32l0xx_ll_gpio.h>
#include <stm32l0xx_ll_system.h>
#include <stm32l0xx_ll_tim.h>


#ifndef __STM32L053xx_H
#error Missing include of stm32l053xx.h. Please define STM32L053xx.
#endif


#define USB_IRQ_PRIO 0
#define USB_IRQ_SUBPRIO 0

#define UART_IRQ_PRIO 1
#define UART_IRQ_SUBPRIO 0

#define EXTI_IRQ_PRIO 3
#define EXTI_IRQ_SUBPRIO 0

#define TIMER_IRQ_PRIO 4
#define TIMER_IRQ_SUBPRIO 0

#define I2C_IRQ_PRIO 5
#define I2C_IRQ_SUBPRIO 0


/* pin aliases */
/* may be PA_0 for some variants */
#define LED_BUILTIN PA_1


#endif /* __GREENPILL_HPP__ */
38 changes: 38 additions & 0 deletions examples/GreenPill/Blinky/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* @file main.cpp
* @author Daniel Starke
* @copyright Copyright 2022 Daniel Starke
* @date 2022-05-29
* @version 2022-05-29
*
* Simple blinky and EEPROM example with serial output.
*/
#include <Arduino.h>
#include <EEPROM.h>


void setup() {
Serial1.begin(115200);
delay(100);
pinMode(LED_BUILTIN, OUTPUT);
Serial1.println("begin");
/* EEPROM */
Serial1.print("EEPROM size: ");
Serial1.println(EEPROM.length());
/* boot count */
uint32_t bootCount;
EEPROM.get(0, bootCount);
Serial1.print("boot count: ");
Serial1.println(bootCount);
bootCount++;
EEPROM.put(0, bootCount);
}


void loop() {
static bool value = false;
Serial1.println(value ? "LOW" : "HIGH");
digitalWrite(LED_BUILTIN, uint32_t(value));
value = !value;
delay(500);
}
6 changes: 5 additions & 1 deletion keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# @author Daniel Starke
# @copyright Copyright 2022 Daniel Starke
# @date 2022-02-19
# @version 2022-03-20
# @version 2022-05-29
# @see https://arduino.github.io/arduino-cli/0.21/library-specification/
#
# Coloring description:
Expand Down Expand Up @@ -35,11 +35,15 @@ STM32CUBEDUINO_MAP_ALL_IRQS LITERAL1
STM32CUBEDUINO_DISABLE_ADC LITERAL1
STM32CUBEDUINO_DISABLE_CDC LITERAL1
STM32CUBEDUINO_DISABLE_DAC LITERAL1
STM32CUBEDUINO_DISABLE_EEPROM LITERAL1
STM32CUBEDUINO_DISABLE_EXTI LITERAL1
STM32CUBEDUINO_DISABLE_I2C LITERAL1
STM32CUBEDUINO_DISABLE_PWM LITERAL1
STM32CUBEDUINO_DISABLE_PRINTF_FLOAT LITERAL1
STM32CUBEDUINO_DISABLE_SCANF_FLOAT LITERAL1
STM32CUBEDUINO_DISABLE_SERIAL LITERAL1
STM32CUBEDUINO_DISABLE_SPI LITERAL1
STM32CUBEDUINO_DISABLE_STRING LITERAL1
STM32CUBEDUINO_DISABLE_TIMER LITERAL1
STM32CUBEDUINO_DISABLE_USB LITERAL1

Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stm32cubeduino",
"version": "1.1.0",
"version": "1.2.0",
"description": "Port of the Arduino API for the STM32 Cube framework.",
"keywords": "arduino, stm32, stm32cube, stm32cubeduino",
"platforms": "ststm32",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=STM32CubeDuino
version=1.1.0
version=1.2.0
author=Daniel Starke
maintainer=Daniel Starke
sentence=Port of the Arduino API for the STM32 Cube framework.
Expand Down
Loading

0 comments on commit 28c5c30

Please sign in to comment.