STM32, Maple and Maple mini port to IDE 1.5.x

Quote from: bobcousins on Today at 12:23 am
I get the feeling the F1 code is nearly ready for a wider audience, and with a little work on the wiki to provide some guidance

I suggest we be cautious ... I am sure Roger wants users to stress the code, but users must understand that only Roger can prioritize and correct unless a pull-request is provided... Even then, there is an indefinite time to cycle the request. I'm just concerned about Roger's bandwidth since he has a consulting business and real customers!

Ray

So I reboot the computer, and restart the Arduino IDE, and now the STM boards have simply disappeared as an option under "Boards" in the IDE.

Does this issue sound familiar ?

Which version of the IDE are you running.

Check you are running 1.5.x or 1.6.x

The only reason the boards are not appearing is if you are using a different version of the IDE or you have changed something in MyDocuments/Arduino/hardware/Arduino_ST32

As far as I can see the code is usable, but its hard very little testing, its hard to know what is still missing and what doesn't work.

e.g. yield() is something new that I've only just noticed.

The amount of time I can spend on this varies a lot depending on my business workload, which ebbs and flows, and is impossible to predict.

Doing handling pull requests isn't much of a problem, but testing pull requests is.

Alexey is already reporting having issues with DFU uploads in the latest release. I can't replicate them, but it doesn't mean they don't exist.

I think organic growth is probably the way to go at the moment

Overall, the codebase is quite messy really. Some of the newer ports

Hi Bob.

I guess you have "Maple Mini generic" selected, which uses upload_router. This option should be used for non-Maple compatible boards. Actually I'm not sure why that was added or what it is for.

This is(upload_router) need for "Debugging mode ON"

http://forum.arduino.cc/index.php?topic=265904.msg2006494#msg2006494

Edit: hmm, now I look at it, some of those board options are a bit confusing.

What confuses you specifically ? :slight_smile:

Following Chillitronix's issue with RadioHead, I've added a page on the wiki about which libraries do or don't work

This is very much a work in progress

Edit

I just had another look at why RadioHead won't compile and SPI.attachInterrupt() and SPI.detachInterrupt() are missing

They don't seem to have been part of the original Maple HardwareSPI code :frowning:

So they will need to be written.

I also noticed that Paul Stoffregen (Teensy) has a special version of RadioHead which looks like it is designed to support Transactional SPI see RadioHead/RHHardwareSPI.cpp at master · PaulStoffregen/RadioHead · GitHub

I will take a look at SPI.interrupt() etc

I Fixed the problem I posted an hour ago.

My current goal is to get Wire and Serial working for me on the STM32F4 discovery board.

Here's another question:

in the "boards.txt" under Arduino_STM32-master/STM32F4 is there any particular reason why the line is there:

"discovery_f407.build.extra_flags=-DMCU_STM32F406VG -mthumb -DSTM32_HIGH_DENSITY -march=armv7-m -DSTM32F2 -DBOARD_discovery_f4"

The actual question is, why the 406VG mcu and not the 407VG chip which I believe this device has.

The actual question is, why the 406VG mcu and not the 407VG chip which I believe this device has.

I suspect bob has set it to 406 because of this line in libmaple.h

#if defined(MCU_STM32F103VE) || defined(MCU_STM32F205VE) || defined(MCU_STM32F406VG)

i.e the code is taken from the AeroQuad build for Maple and its not specifically designed for the ST Discovery boards, but the 406 is close enough to the 407 for it to mostly work.

rogerClark:
Which version of the IDE are you running.

Check you are running 1.5.x or 1.6.x

The only reason the boards are not appearing is if you are using a different version of the IDE or you have changed something in MyDocuments/Arduino/hardware/Arduino_ST32

I installed this morning the latest IDE version 1.6 according to your instructions at github. I think I was using 1.5.4 before that.

The reason I got that failure, is that I created a directory for my sketches, like /User/Arduino/MySketches/Sketch1/Sketch1.ino, instead of having the individual directories for each sketch directly in User/Arduino. I've always done it that way, I have hundreds of sketches.

Apparently, this causes the process of reading boards.txt to fail. When I made this change, it didn't fail right away, it failed several hours later when I restarted the computer.

Looking at STM's document, I am unsure that there even is a model 406. I can only see 405 and 407.

http://www.digikey.com/web%20export/supplier%20content/stmicroelectronics_497/mkt/stm32/brstm32.pdf?redirected=1

Looking at STM's document, I am unsure that there even is a model 407. I can only see 405 and 407.

There is definitely a 407. I have one on my desk.

Sorry. My last post was supposed to read "I am unsure if there even is a model 406".

The boards.txt file appears to refer to a model 406 but it doesn't seem to be listed in STM's table of different microcontrollers that they make.

Code for my 407 chip seems to compile and run OK, with that -dmcu=.... 406 ... there in the compiler options.

@chillitronix

I've opened an issue for RadioHead

See

I also started to change the code to add functions that were missing from the STM32 code, but we really need to make a copy of the library and work on it - which is what I've written in the issue :wink:

michinyon:
Sorry. My last post was supposed to read "I am unsure if there even is a model 406".

The boards.txt file appears to refer to a model 406 but it doesn't seem to be listed in STM's table of different microcontrollers that they make.

Code for my 407 chip seems to compile and run OK, with that -dmcu=.... 406 ... there in the compiler options.

I couldn't find an F406 at ST website either, so I think it must be a typo in the AeroQuad code.

My general approach to porting is to get a clean build first, then start making changes. It seems like it should be F407 and the code changed accordingly.

@bobc

@hiddenpilot pm'ed me about an issue, with the maple mini after upload it doesn't run the code, and it generally seems to have screwed up the Serial USB

I've spent some time going back though the commits and ...

I think something strange has happened at commit a3065b0c0042d5f90d85ed90d88e7aeaccf8aeb9 which is the pull for bob's change to remove redundant files by moving a lot of the files from variants into core

On the Maple mini, from this version onwards, after the upload is complete, the program doesn't run and also the serial USB device doesnt re-appear

The only way to fix this is to disconnect the board, go back to commit 1eb90acf81b7e9d94d533dc0af300008d1aaef92

and manually go into perpetual bootloader mode (using the button sequence) and then upload again.

But I can't see how this change has done what it appears to have done.

I've run BeyondCompare on the libmaple folders for maple-mini maple and microdino and they are all basically identical (maple had 2 extra empty lines in one file)

You can easily replicate this bug. Just upload the maple blink (well this is the one I'm using as it also writes some serial debug)

char strBuf[64];


void setup() {
    // Set up the built-in LED pin as an output:
    pinMode(BOARD_LED_PIN, OUTPUT);
    pinMode(PC13, OUTPUT);
    Serial.begin(115200);
}

void loop() 
{
    toggleLED();          // Turn the LED from off to on, or on to off
    togglePin(PC13);

    sprintf(strBuf,"Mills in seconds is  %g\n",millis() / 1000.0);
  //  Serial.print(strBuf);
    delay(50);        
}

After, upload the program doesn't run and the serial USB device is missing

The only way to get it to work again is to go back to 1eb90acf81b7e9d94d533dc0af300008d1aaef92 disconnect and reconnect the maple mini, manually go into perpetual upload mode
quit and restart the IDE so it picks up the changes and then upload again.

It seems to be OK again and you can upload again etc

Edit.
To get to go wrong, you need to switch to anything newer than 1eb90acf81b7e9d94d533dc0af300008d1aaef92 restart the ide upload
then upload again. The first upload works OK (I presume its using code from 1eb90...) but if you upload again its screwed :frowning:

Do you have any ideas what has happened ?

I finally got around to looking at the F4 port that bob did, and it uploads onto my 407VGT and the clock PLL seems OK as the flash speed of the LED seems about right

However I can only get GPIO to work.

Neither Serial1 or Serial2 appear to work. I connected a USB to Serial to PA9 and PA10 and didnt get any output, and I also tried on PA2 and PA3 (Serial 2) but no joy either

But I guess at least it compiles and uploads via STLink (onboard) and GPIO works !

Which is more than that I managed to get working :wink:

rogerClark:
@bobc

@hiddenpilot pm'ed me about an issue, with the maple mini after upload it doesn't run the code, and it generally seems to have screwed up the Serial USB

I've spent some time going back though the commits and ...

I think something strange has happened at commit a3065b0c0042d5f90d85ed90d88e7aeaccf8aeb9 which is the pull for bob's change to remove redundant files by moving a lot of the files from variants into core

On the Maple mini, from this version onwards, after the upload is complete, the program doesn't run and also the serial USB device doesnt re-appear

The only way to fix this is to disconnect the board, go back to commit 1eb90acf81b7e9d94d533dc0af300008d1aaef92

and manually go into perpetual bootloader mode (using the button sequence) and then upload again.

But I can't see how this change has done what it appears to have done.

I am afraid you are right Roger and I apologise! I had thought this problem was fixed but my testing was clearly inadequate.

The immediate resolution is to revert 'ccf8aeb9 which will put libmaple back into the variant folders.

Previously I found the problem was intermittent, but when it gets "stuck", it seems to stay stuck. Power cycling the board appears to work correctly, so it appears something in a volatile location is getting set after going through the bootloader, and a subsequent (soft) reset causes a hang somewhere.

The problem seems to only manifest when the libmaple code is built into a library (all the files in cores are built into "core.a"). I raised a query on the LeafLabs forum about this, it seems a few people have the same problem but no-one has a definite answer.

I suspected that weak symbols are not being resolved correctly, adding the --whole-archive flag to the linker should force it to examine all symbols. It seems there is more to it.

Possibly there is some interaction between the bootloader, user sketch and linker that causes the problem, so it could be tough to narrow down. I think to solve this I will need to get a debug environment going and find exactly where it is hanging.

If anyone can get libmaple to work correctly when built to a library it is worth a beer or three!

Hi bob

I've made some changes since I did that pull, so I'm to sure I can simply pull that version.

I'd also like or retain the F4 stuff, which I think you put in afterwards

So the easiest solution I think is for me to copy out the variants libmaple folders from the last working commit I.e 1eb90... Into a folder outside source control, And then checkout master, and move those folders back to variants.

But I can't do that until later your time, basically tomorrow morning for me.

In the mean time if anyone has issues they will need to grab the zip of the 1eb90.. commit

I PMed Alexey the link, so perhaps he can post it, as I can't get to it at the moment from my iPad

rogerClark:
Hi bob

I've made some changes since I did that pull, so I'm to sure I can simply pull that version.

Actually git makes it easy to reverse a specific commit:

git revert a3065b0c0042d5f90d85ed90d88e7aeaccf8aeb9

creates a new commit which reverses the specified one, keeping everything else.

I can't see any changes you have made to libmaple after this commit, unless you have some local changes?

I will create a pull request... seems like I should clean up my own blunder :slight_smile:

About this issue: STM32, Maple and Maple mini port to IDE 1.5.x - #838 by HiddenPilot - Microcontrollers - Arduino Forum
To better understand this problem, I'm a little remade library:

#ifndef MYLIB_H
#define MYLIB_H
#include "Arduino.h"

#define digitalPinToBitMask(pin)     (BIT(PIN_MAP[pin].gpio_bit))
#define digitalPinToPort(pin)        PIN_MAP[pin].gpio_device

#define portCRLRegister(Port)           (&(Port->regs->CRL))
#define portOutputRegister(Port)        (&(Port->regs->ODR))

class myLib
{ public:
  myLib();
  myLib(int RST_pin);
  int myPin;
  void setPortsReg();
  void serialPrint();
  __io uint32 *init_gpio_device, *init_timer_device, *init_adc_device, *set_gpio_device, *set_timer_device, *set_adc_device;
  uint32 init_gpio_bit, init_timer_channel, init_adc_channel, set_gpio_bit, set_timer_channel, set_adc_channel;
  uint32 init_RCC_val, set_RCC_val;
};
#endif
#include "myLib.h"
#include <pins_arduino.h>

myLib::myLib() {}

myLib::myLib(int RST_pin)
{ 
  myPin = RST_pin;
  init_gpio_device =   &(PIN_MAP[3].gpio_device->regs->CRL);
  init_timer_device = &((PIN_MAP[3].timer_device->regs).adv->CR1);
  init_adc_device =    &(PIN_MAP[3].adc_device->regs->SR);
  init_gpio_bit =        PIN_MAP[3].gpio_bit;
  init_timer_channel =   PIN_MAP[3].timer_channel;
  init_adc_channel =     PIN_MAP[3].adc_channel;
  init_RCC_val = RCC_BASE->APB2ENR;
  }

void myLib::setPortsReg(){
  set_gpio_device =    &(PIN_MAP[3].gpio_device->regs->CRL);
  set_timer_device =  &((PIN_MAP[3].timer_device->regs).adv->CR1);
  set_adc_device =     &(PIN_MAP[3].adc_device->regs->SR);
  set_gpio_bit =         PIN_MAP[3].gpio_bit;
  set_timer_channel =    PIN_MAP[3].timer_channel;
  set_adc_channel =      PIN_MAP[3].adc_channel;
  set_RCC_val = RCC_BASE->APB2ENR;
}

void myLib::serialPrint(){
  Serial.print("                   INIT         ");                                  Serial.println("                  SET");

  Serial.print(" init_gpio_device   = 0x");Serial.print((uint32)init_gpio_device,16);  Serial.print(" set_gpio_device   = 0x");Serial.println((uint32)set_gpio_device,16);
  Serial.print(" init_timer_device  = 0x");Serial.print((uint32)init_timer_device,16); Serial.print(" set_timer_device  = 0x");Serial.println((uint32)set_timer_device,16);
  Serial.print(" init_adc_device    = 0x");Serial.print((uint32)init_adc_device,16);   Serial.print(" set_adc_device    = 0x");Serial.println((uint32)set_adc_device,16);
  Serial.print(" init_RCC->APB2ENR  = B");Serial.print((uint32)init_RCC_val,2); Serial.print("      set_RCC->APB2ENR  = B");Serial.println((uint32)set_RCC_val,2);
  Serial.print("                   INIT  ");                                       Serial.println("                    SET");
  Serial.print(" init_gpio_bit      = ");Serial.print((uint32)init_gpio_bit,16);     Serial.print("   set_gpio_bit      = ");Serial.println((uint32)set_gpio_bit,16);
  Serial.print(" init_timer_channel = ");Serial.print((uint32)init_timer_channel,16);Serial.print("   set_timer_channel = ");Serial.println((uint32)set_timer_channel,16);
  Serial.print(" init_adc_channel   = ");Serial.print((uint32)init_adc_channel,16);  Serial.print("   set_adc_channel   = ");Serial.println((uint32)set_adc_channel,16);
  Serial.println("----------------------------------------------------");
}

Result:

                   INIT                           SET
 init_gpio_device   = 0x20005000 set_gpio_device   = 0x40010C00
 init_timer_device  = 0x20005000 set_timer_device  = 0x40000400
 init_adc_device    = 0x20005000 set_adc_device    = 0x40012400
 init_RCC->APB2ENR  = B1000      set_RCC->APB2ENR  = B111000111101
                   INIT                      SET
 init_gpio_bit      = 0   set_gpio_bit      = 0
 init_timer_channel = 3   set_timer_channel = 3
 init_adc_channel   = 8   set_adc_channel   = 8

GPIOB variable is initialized in the file "gpio_f1.c"GPIOB  |0800b3cc|  R  |  OBJECT|00000004|    |.rodata C:\Intel\ARDU\hardware\Arduino_STM32\STM32F1XX\variants\maple_mini\libmaple/gpio_f1.c:53

So, when object "TestIt" of the class "myLib" is created, the file \hardware\Arduino_STM32\STM32F1XX\variants\maple_mini\libmaple/gpio_f1.c is not running yet?
(the variable "init_RCC->APB2ENR" сonfirms this guess. Function gpio_init_all(void) is not runnig yet)

Who know how to fix this problem in Arduino_STM32? :frowning: