STM32L4 Core

Cores are the underlying magic that make the Arduino API possible
User avatar
Posts: 188
Joined: Fri Apr 15, 2016 4:15 pm
Location: Denver, CO

Re: STM32L4 Core

Post by GrumpyOldPizza » Tue Jan 30, 2018 3:37 pm

MGeo wrote:
Tue Jan 30, 2018 11:00 am
Ok, I'll beg for forgiveness on not following directions... :).

I'm more or less following the design philosophy of this ... xtract.pdf

For this high integrity scheduler co-operative scheduler I would want to hook SysTick, and be aware of any higher priority interrupts that may interfere with task timing. So understanding the core workings is part of my learning exercise here. The followings appear to work as expected, very cool:

Code: Select all

  GrumpyOldPizza L4 Core on NUCLEO-L432KC board.
  Test to hook SysTick, incremeent a counter in SysTick callback,
  toogle LED on for one second, then off for one second, repeatedly.
// Pin 13 has an LED connected on most Arduino boards
int led = 13;

volatile bool oneSecFlag = false;
volatile int16_t oneSecCount = 0;

// the setup routine runs once when you press reset:
void setup() {
  Serial.println("Setting up...");
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);
  //armv7m_systick_notify(L4_SYSTICK_Callback, NULL); 
  armv7m_systick_notify( (armv7m_systick_callback_t)L4_SYSTICK_Callback, NULL); 

// the loop routine runs over and over again forever:
void loop() {

  if (oneSecFlag == true) {
    Serial.println("One Second Event has occured, clearing oneSecFlag");
    oneSecFlag = false;
    digitalWrite(led, !digitalRead(led));
  Serial.print("oneSecCount = "); Serial.println(oneSecCount);

armv7m_systick_callback_t L4_SYSTICK_Callback(void) {
  if (oneSecCount >= 1000) {
    oneSecFlag = true;
    oneSecCount = 0;
Please do not use the systick callback directly. The internal timer facility uses this callback to do it's ticking. That one is used in a few places internally, which means if you put your own callback in there you kill parts of the system layer.
For the scheduler implementation I would want to put the processor to sleep at the end of the task list, waking the processor from the SysTick interrupt. Once awake the scheduler scans the task list for ready tasks, execute them and then goes back to sleep until the next 'Tick'. Tick is some integer count of 1msec SysTick.
Usually you put the context switch at the tail of the PendSV handler ...
So my next step is to place the processor to sleep at the end of schedule loop. Would a WFI() or WFE() be recommended? I'm a bit confused between the two. Also, in the above I set context to NULL. I see that _armv7m_systick_control_t struct includes context, but am not yet clear on it's purpose or how it might be used.

Post Reply