Running my Teensy code on nucleo32

I’m new to PlatformIO, using it for OpenHab and my Teensy projects. I’ve got my Teensy projects running without issue, but I really want to move on to a chip with debugging support.

I have the L432 on a Nucleo-32 board, and was hoping that my code would move over, but this is not the case.
For instance, I am using the SleepyDog watchdog timer, and the PlatformIO installer says it is compatible with STM32, but This board is not supported in the code. The error message is:
Adafruit_SleepyDog.h:23:4: error: #error Unsupported platform for the Adafruit Watchdog library!

In this case, should I modify the library to accept this chip, or do I need to include something in my project that works with this library?

Oh, and if there’s another board that I should be considering as a replacement to the Teensy 3.2, let me know.

Going by the actual readme for the Adafruit_SleepDog library, it doesn’t support the Nucleo-32… basically they just stated in their library.properties file that it works with all architectures, rather than listing the ones it does work with.

You’d need to either modify the library, change to another one that is platform agnostic, or use conditional code so that it uses one when compiled for the Teensy, and another when compiled for the Nucleo-32 or other board.

This library (STM32LowPower) might be worth a look?

Okay, I’m seeing that now. I suppose now that I’m moving farther away from Arduino, there’s more I need to be on the lookout for.

1 Like

That, and that unfortunately when you move away from core Arduino hardware (or well supported third party hardware like the Teensy), some third party stuff tends to be a bit dodgy… as who can test a library on all the hardware platforms that be used with the Arduino platform? Especially when doing stuff (like the watchdogs) which are hardware specific code. I do wonder if guys at Adafruit could have done better though, and specified just samd and avr as supported architectures… not sure how the Teensy can be specified… the library.properties docs are pretty much useless on that point, as it gives no idea as to what architectures are valid, and how to check them! So a library developer is pretty much going to do a "*" meaning all… which can be wrong… :cry:

There is a low power lib GitHub - stm32duino/STM32LowPower: Arduino Low Power library for STM32

1 Like

You are the second to mention this. Am I missing something? That library is for sleeping modes, right? I did not see any watchdog routines in there.

Maybe you find some ideas on Repository Search | Mbed

Just use the two very simple STM32 HAL functions? You have a hardware IWDG (independent watchdog) on your chip. To use it, just…

#include <stm32l4xx.h>

IWDG_HandleTypeDef IwdgHandle;

void main() {
	//Assuming LSI runs on 32kHz and we want the 
	//max watchdog value, we use the highest prescaler of 
	//256 to get 32000 Hz / 256 = 125 Hz (watchdog clock pulses per second)
	//we use the maximum reload value of 0x0FFF = 4095. 
	//meaning that the watchdog has a max timeout of 4095 / 125 = 32.76 seconds.
	//If HAL_IWDG_Refresh() is not called before this timeout expires, the micro-
	//controller resets.
	IwdgHandle.Instance = IWDG;
	IwdgHandle.Init.Prescaler = IWDG_PRESCALER_256;
	IwdgHandle.Init.Reload    = 0x0FFF;
	IwdgHandle.Init.Window    = IWDG_WINDOW_DISABLE;

	if(HAL_IWDG_Init(&IwdgHandle) != HAL_OK)
	{
		/* Initialization Error */
		Error_Handler();
	}
	
	while(1) {
		//do stuff..
		//reset watchdog
		HAL_IWDG_Refresh(&IwdgHandle);
	}
}

See STM32 L4 HAL Reference Manual page 495 following. Also see official reference example and clock trees (HSI, LSI etc).

1 Like

Thank you very much for these references. This is going to help a lot.

I have modified the Adafruit Library, and have it compiling, but I don’t know if I short circuited an include file somewhere.
My includes:

#include <backup.h>
#include <stm32l432xx.h>
#include <stm32l4xx_hal_iwdg.h>
#include “WatchdogStm32L432xx.h”

And then in my platformio.ini file:

[env:nucleo_l432kc]
platform = ststm32
board = nucleo_l432kc
framework = arduino
build_flags =
-DHAL_IWDG_MODULE_ENABLED

Was there supposed to be an include that defined HAL_IWDG_MODULE_ENABLED ?

After reading some more, I have a single include:
#include <stm32l4xx_hal.h>
That gets me all of the dependencies, but I still must define
HAL_IWDG_MODULE_ENABLED

I can see the list of the available modules. Is it up to the programmer to enable only the modules to be used, or is there a header file that turns on all of the default modules?

EDIT: Okay, I found the hal conf template, which answers my question. So, yes, it is up to the programmer to turn on each module in order to keep the binary size small.

Exactly. You didn’t specify which framework you’re programming for (arduino, mbed, stm32cube) so I assumed stm32cube and forgot about the define that enable this module, sry… So, does this fullfil your needs and it works?