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

I'm not sure if this is relevant but I've noticed this

https://www.microduino.cc/

https://www.microduino.cc/wiki/index.php?title=Microduino-CoreSTM32

Which seems also to use the maple IDE etc.

It looks like they may have just cloned the maple design, and put it in a different form factor.

But I have not tracked down their schematics yet.

Bob,

I’m not sure what I’m doing wrong, but I just thought I’d try to compile in the Arduino 1.5.7 Beta IDE and possibly just upload the bin file to my generic STM32 board, but I get a load of warnings

Build options changed, rebuilding all
In file included from C:\Users\theuser\Documents\Arduino\hardware\maple-asp\Maple\system/libmaple/include/libmaple/stm32.h:70:0,
                 from C:\Users\theuser\Documents\Arduino\hardware\maple-asp\Maple\variants\maple_mini\libmaple\stm32f1\performance\isrs.S:29:
C:\Users\theuser\Documents\Arduino\hardware\maple-asp\Maple\system/libmaple/stm32f1/include/series/stm32.h:86:0: warning: "STM32_MEDIUM_DENSITY" redefined [enabled by default]
 #   define STM32_MEDIUM_DENSITY
 ^
<command-line>:0:0: note: this is the location of the previous definition
In file included from C:\Users\theuser\Documents\Arduino\hardware\maple-asp\Maple\system/libmaple/include/libmaple/stm32.h:70:0,
                 from C:\Users\theuser\Documents\Arduino\hardware\maple-asp\Maple\variants\maple_mini\libmaple\stm32f1\performance\vector_table.S:29:
C:\Users\theuser\Documents\Arduino\hardware\maple-asp\Maple\system/libmaple/stm32f1/include/series/stm32.h:86:0: warning: "STM32_MEDIUM_DENSITY" redefined [enabled by default]
 #   define STM32_MEDIUM_DENSITY
 ^
<command-line>:0:0: note: this is the location of the previous definition

Sketch uses 10,076 bytes (9%) of program storage space. Maximum is 108,000 bytes.

Is this normal ?

Edit.
Tried as a matter of interest, uploading the blink sketch compile in the Arduino, via the UART Flash Loader (ST), but I can’t see any of the GPIO lines toggling.

Note: Please make reference to:

For a summarized version of pertinent information contained in this lengthly
thread. Also, some simple Mini Maple projects with source may be found on
my blog: http://www.hackster.io/rayburne

In Windows, it is in %temp% in a subdirectory shown when the IDE is in verbose mode.

Added…

I wrote a script a long time ago to find and move a file(s) [the most recent nested version of a filename] from the current working directory! You do not need to know where it is as the script will ferret the issues for you. I did the Win version and a few other members chimed in with Linux/osX

Ray

Windows 8.1 script for Arduino 1.0.6

PATH=%path%;C:\Program Files (x86)\Arduino_106\hardware\tools\avr\bin;
C:
CD %TEMP%
MD %PUBLIC%\ELFtemp
for /R %TEMP% %%f in (*.elf) do XCOPY /D /Y %%f %PUBLIC%\ELFtemp\
DIR %PUBLIC%\ELFtemp\*.elf /s /b /O:-D /T:W >ElfRhere
SET /P ELF= <ElfRhere
ECHO %ELF% >MemUsage.txt
AVR-SIZE -C %ELF% >>MemUsage.txt
NOTEPAD MemUsage.txt
CD %PUBLIC%\ELFtemp
ECHO y | DEL *.* \%1
SET ELF=""

MemoryUsage.cmd (388 Bytes)

PaulRB: Arduino ... 1.5 not available on Ubuntu s/w centre yet

That's a bit of a pain - apparently no-one around who simultaneously uses Arduino and is guru for the Update Centre.

@mrburnette

Thanks.

I turned on verbose and found where the bin files were being written, but I cant get the bin files to run by directly uploading them into the Flash of the device, i.e in place of the bootloader.

i.e I tried the Maple blink example, and I have an LED connected to the Maple LED, but I didnt get any flashing. I looked at all the other GPIO pins with my analogue multimeter to see if any of them were toggling, but none were.

Would you expect a bin file that was flashed onto the device using the ST flash uploader tool, to run ? Perhaps this isn't possible because I don't have the Maple bootloader installed any more, i.e I'm overwriting it with the actual sketch (bink), so it could be some sort of memory mapping issue e.g. calls to non-relative function address points.

rogerClark: Would you expect a bin file that was flashed onto the device using the ST flash uploader tool, to run ? Perhaps this isn't possible because I don't have the Maple bootloader installed any more, i.e I'm overwriting it with the actual sketch (bink), so it could be some sort of memory mapping issue e.g. calls to non-relative function address points.

Your hunch is correct, the current Maple targets assume the presence of the Maple bootloader, so the sketch is linked to start at an address above the bootloader. There is a link option for non-bootloader in libmaple, it should be easy to add an option to the boards list in the IDE. I was planning to use the stm32flash tool to download using the UART pins.

Btw, the two warnings about redefined macros are a nuisance but not a problem.

Thanks Bob,

Thank makes sense.

I may need to get back to you about enabling that link option if I can't figure it out myself ;-)

Uploading via the uart works fine for me, but it looks like even with the boot0 pulled high, the board only seems to be listening for serial traffic for less than a second.

I.e if I enable flash uploading with the jump link, the reset, then use the flash uploader straight away, it works. But if I reset and wait a second or two, the ST flash program fails to connect, and I have to reset the STM board again.

I was initially under the impression that with the boot pin pulled high that it was permanently in boot mode, but this doesn't seem to be occurring for me. I will need to re read the docs ;-)

Either way, using the Arduino / Maple libs would make using this board far easier than the alternatives I've looked at. E.g. I downloaded coocox, but couldn't even manage to get a version of blink to work ;-(

I was going t download Keil as I've now seen that you can use Keil with gcc and thence get around the 32k code limitations. But I'm not sure Keil is going to be an easier programming experience than coocox. But its probably worth a look.

However if I could get the Arduino / Maple libs working, it would make porting any existing code to this board far far easier

Thanks again

Roger

PaulRB: Hi bobcousins, how much of that would you expect to work on linux? I use Ubuntu 14.04, Arduino 1.0.5 (1.5 not available on Ubuntu s/w centre yet) and have a Maple Mini clone, which I can program with Maple ide for the moment (but obviously a single app which does Arduino and Maple would be better).

Compiling seems to work ok, I am working on the download, I think it just needs a few changes to the scripts.

It should be possible to use dfu-util from a command line to download the binary if you have run the "install-udev-rules.sh" script, and put the board into perpetual bootloader mode. The command is something like

dfu-util /dev/ttyACM0 -a 1 -R -d 1EAF:0003 -D file.bin

Hi Bob

It should be possible to use dfu-util from a command line to download the binary if you have run the "install-udev-rules.sh" script, and put the board into perpetual bootloader mode.

I can't seem to get the board into perpetual bootloader mode.

The real Maple Mini has a pair of transistors which pull USB D+ to GND under software control, which I presume is use to force the PC to re-enumerate the USB devices.

However the generic board doesnt have this. So I think this is why I can't get it into perpetual bootloader mode.

I will try compiling with that option to link from the base of memory rather than above the bootloader, but I'm not sure whether Serial USB would then still work, as if that functionality is inside the bootloader it won't work. (Unless Serial USB is in the Maple Lib as well as in the bootloader ???)

One other option may be to see if I can get the "sketch" to be uploaded into a different memory address, I noticed some options.

And I've noticed a python based loader https://github.com/jsnyder/stm32loader that seems to have an option for target address.

Do you know the address that the bootloader normally places the code that it receives ?

This would probably be the easiest option to get around the issue of the bootloader being missing and the linker using the wrong addresses

Edit.

I've not tried it yet, but looking in the Maple bootloader source code config.h it has these defines

#define USER_CODE_RAM ((u32)0x20000C00)
#define RAM_END ((u32)0x20005000)
#define USER_CODE_FLASH ((u32)0x08005000)
#define FLASH_END ((u32)0x08020000)

Which looks suspiciously like the address of the flash and also the ram address of program uploads

When I get chance (this evening), I'll reflash the maple bootloder back onto my STM board and then build the maple "blink" example, and try uploading it to 0x08005000 (assuming I select the board definition to upload to flash)

I'll let you know how I get on.

rogerClark: The real Maple Mini has a pair of transistors which pull USB D+ to GND under software control, which I presume is use to force the PC to re-enumerate the USB devices.

However the generic board doesnt have this. So I think this is why I can't get it into perpetual bootloader mode.

That is a good observation! The Maple bootloader scheme hinges around being able to re-enumerate as a DFU device, so disconnecting the USB via the pullup is essential. I think this board has the pullup hardwired (still haven't found a schematic), which would require unplugging the USB cable to re-enumerate.

There is some info on the Maple bootloader here http://static.leaflabs.com/pub/leaflabs/maple-docs/latest/bootloader.html, clearly they had problems with their initial scheme.

Perhaps a simple Arduino style bootloader would be better for this board, using an FTDI serial to reset and enter the STM32 UART bootloader, then use something like stm32loader. Another option is STLINK.

To build a sketch for stm32loader (not using Maple bootloader), change the line in maple-asp/Maple/config.txt

maple_mini.build.ldscript=ld/flash.ld

to

maple_mini.build.ldscript=ld/jtag.ld

which gives it all of Flash and Ram to run in.

Hi Bob,

I think the schematic to the maple mini is here

I don’t have the schematic to my generic STM321 board, but as far as I can see it doesn’t have much apart from jump links for Boot0 and Boot1 and also a connection to an RTC (not sure how the RTC is connected I will need to look to see what device it is)

Re: Uploading

I tried setting the board to “Leaflabs Maple Mini Rev 2 to Flash” built with verbose turned on (So I could see where Arduino put the bin file), then uploaded to flash address 8005000 (using ST’s tool, but after a reboot, the board just flashed the LED like it does when just the bootloader is installed.

However if I checked the option in the upload tool for “Jump to the user program” it started to flash the :LED at one second intervals, so it was definately running the blink sketch

I tried rebooting (with Boot0 not held high), but the maple bootloader doesn’t seem to execute the user program.
Looking at the bootloader code

It has this line

bool no_user_jump = !checkUserCode(USER_CODE_FLASH) && !checkUserCode(USER_CODE_RAM) || readPin(BUTTON_BANK, BUTTON);

So I think the reason its not running my code after boot is because USER_CODE_FLASH has not been set.

I think I can manually set this using the ST Flash Loader tool once I figure out its address (watch this space)

Re:Using FDTI instead of the complex DFU etc

Yes. My thoughts exactly.
It would then behave just like an Arduino Mini etc which need an external serial adaptor, which I’m quite used to using on this size of board.

I’m actually thinking of attempting to recompile the Maple bootloader, but cheat and change the hardware ID of the USB serial, so that it thinks its a serial device from a different manufacturer. However I’m not sure if its just a question of changing the ID’s or whether the maple USB serial code in the bootloader is a non-standard usb serial.

Anyway, first things first, I’m going to see if I can manually set that flag so that the bootloader always thinks there is user code installed :wink:

OK. I figured out why it was not executing by program, its because I don't have a button attache to PB8 (like the maple mini does)

Actually, I looked at those addresses and they are the Flash start and Ram start addresses, so its looking for code not a flag. i.e 0x8005000 for flash. I read back what I"d uploaded and I could see that the program was still in flash after a boot,

and that the first 4 bytes were 00 50 00 20 and the code was looking for 200000 so allowing for memory byte orientation, the pattern was correct

So what I need to do is pull PB8 low all the time, via a resistor to stop it floating.

Then the boot process is quite slow, it flashes 6 times quickly, then does slow flashing for a few seconds and then finally gets around to running the user code

It takes much longer to load than the arduino bootloader

Next step to to see if Serial works (after I reboot to use the unsigned driver)

I tried to use the SerialUSB commands, but the code appeared never to get SerialUSB.available() to be true, and hence it seemed to hang in setup()

This could be something to do with the board not being able to do its re-enumeration stuff because it doesn't have those transistors attached to the USB D+ line.

Anyway, as I'd already got my USB to serial attached to USART1 (pa9 and pa10), I tried using Serial1 instead and it worked fine.

My STM32 board has an led on a different GPIO to the maple mini, it has the led on PC13, and for a while I was struggling to work out the mapping of the STM32 GPIO pin names to the Arduino PIN numbers, but I found there are enums for them, so it was possible to write

pinMode(pc13,OUTPUT); digitalWrite(pc13,HIGH);

To get the maple bootloader to run the code after booting, I had to make sure that pb8 was pulled low, as this is attached to a button on the maple mini. So I pulled low via 1k in case I accidentally drove that pin via digitalWrite

I was not able to test loading into the base flash address (0x800000) as the forum went offline before I wrote down bobs instructions to make a new board config, but I will do that today.

Currently, to upload, I have boot0 pulled high, and am using the ST flash loader tool, as it has an option to load at the correct address 0x8005000 and jump to and run code at this address.

So I build in the Arduino IDE the run the flash tool, press the reset button on the board, and then quickly press Next in the flash loader. This seems to put the board into communications with the flash loader and you can then progress to the other screens in the tool and upload and run the code.

Currently the upload process is a bit of a pain.

I did look at using the st32loader python script, and although it appeared to upload to the board, there is not an option to jump to the user code, and even if I rebooted with Boot0 pulled low, the code uploaded by the python script didn't run.

However I have not had time to figure out why this is.

I'm using the python script that is part of the maple tools, but as far as I can tell is not used by the Arduino build process.

I'm not sure how up to date the version of the script is, so I also need to try the latest version from GitHub

So my next steps will be...

  1. Make a board config that links to addresses starting at 800000 so that there is no need for the Maple bootloader.
  2. See if I can get the python script working
  3. See if I can get the python script to run as part of the Arduino Upload command
  4. Ideally there would need to be some way to automatically put the board into serial upload mode only when required. Probably the best way to do this would be an arduino style bootloader and external USB to serial, e.g I think this is what the Due does. However this sounds like a lot of work, and for the moment I will just fit some additional push buttons to the board so I can do this manually ;-)

Edit. I forgot to mention I'd like to use i2c with this board, but currently the status of the I2c lib seems unclear. I think there may be basic, bit banged support, but it appears that there are some issues with hardware i2c associated with hardware faults in the actual IC.

Anyway, I may try hooking up a simple temperature sensor and see if i can get basic comms going before attempting communication with what I really want to use, which are accelerometers etc I.e mpu9150

In case its of any use to anyone else

I’ve amended Bob’s boards.txt file to add a new board, which builds for flash upload without the bootloader

I’ve tested it using ST’s uploader and its working fine.

I’m now going to try to see if I can get the python upload script working. Watch this space :wink:

boards.txt (4.62 KB)

This is probably a really stupid question, but as the Due is a ARM cortex M3 uP as is the STM32F103 would it be practical to use either the source code for libdue etc for these STM boards rather than using the old Maple code ? i.e libmaple.a I know the Atmel chip has a lot more connections etc, but as its built on the same underpinnings, it seems to make sense to use the Due code, because the maple lib is no longer in development and has issues with various things, specifically I2C

Anyway, just a thought ;-)

Update on my progress or lack of it with my generic STM32 board.

Firstly I can’t get the python upload to work at all, I’ve tied the one that is part of Bob’s maple package, but that didn’t work, and I also tried the latest one on github.

Strangely, the python script seems to upload OK, i.e there is code in the flash, but it doesn’t seem to work.
It seems to be uploading the code, but it is doing something else that prevents the code from running, so currently the only think that works to upload the bin is the ST flash loader tool

With the Flash loader, it also only works if I only erase the necessary pages. Global erase seems not to work.
At the moment I’m really not sure what is going on and why either the Python loader or another windows exe loader I’ve tried, don’t work. Yet the ST one does. :frowning:

would it be practical to use either the source code for libdue etc for these STM boards rather than using the old Maple code ?

No. While ARM-based CPUs from different manufacturers have the came core CPU and instruction sets, they tend to have vastly different peripherals. Since the Arduino core libraries consist mostly of interfacing to the peripherals, they have to be re-written for each different chip vendor (and frequently different for different families of chips.)

@westfm

Thanks. That makes sense.

Back from Disney. :-) (New avatar, if the forum SW ever cooperates!) Here's a pinout diagram I made for the STM32f103c8t6: https://docs.google.com/spreadsheet/ccc?key=0AqdMB5dovDUZdGR6cVprUnkwTV9CMUNybV9VMjF5a0E&usp=drive_web#gid=0 - this includes the BOOTx functionality used by the internal (ROM) bootloader. The (builtin) bootload capabilities are described in http://www.st.com/web/en/resource/technical/document/application_note/CD00167594.pdf - basically, the "small" chips like the 103 contain only a serial bootloader, while some of the larger chips can also boot from USB (via DFU), CAN, or other things. I've been using https://code.google.com/p/stm32flash/ to program my (otherwise different) ST board; it's a rather annoying multi-step process:

  • Set the BOOT0 pin appropriately. (BOOT1 gets to stay in the FLASH/BOOT position, rather than "RAM"
  • Hit the RESET button. On my particular board, the reset button is not very reliable, and it seems to be a very popular style of button on these low-cost boards.
  • run the stm32flash utility. (if it doesn't work, hit reset again and loop...)
  • unset the BOOT0.
  • hit the reset button again (perhaps multiple times.)

Note that the ROM Serial bootloader runs "forever", while the maple bootloader only runs momentarily.

I'll see if I can get the Maple SW/bootloader running on my (not maple-like) board. It should be possible (and useful!)

@westfm
What OS are you running, the only utility that seems to upload and run for me is the ST Flash Uploader.
I looked on that Google repo but couldnt see an exe. I tried to compile in codeblocks on the PC but had issues with missing headers, so I found a precompiled version, but although it uploaded, the program wouldnt run after upload :frowning: