Go Down

Topic: STM32, Maple and Maple mini port to IDE 1.5.x (Read 13636 times) previous topic - next topic


Hi bob

Ok about trying to build the system stuff as a library. I'd not considered the issues with all the weak link stuff that is dotted around the code :-(

I never got around to figuring out the code in the sketch managed to use the serial stuff in the bootloader. Well I presume that's what it does.

Actually I currently have a bug in serial.peek which may be related to my lack of knowledge in this area, which seems to cause a hang on the first serial character arriving after peek was called, when the input buffer contains one or more characters.  But this could be unrelated.

I looked at the F4 stuff for Maple, @mrbrunette posted a link here on the forum last week to a GitHub repo that claimed to do it.

However it dates back to 2012, so is considerable out of sync with even the current version of the Maple IDE, code hierarchy.

Plus... I've changed the code in my repo quite considerably to attempt to bring things up to date, well at least up to Arduino 1.0 API.
which required me to move a load of files around etc. too many changes for me to precisely remember what I had to do or why.

A lot of the organisation / hierarchy changes were to get SPI to work as a library like it does in Arduino, rather than the way you had to declare your own HardwareSPI instance with the Maple IDE.

Btw I also changed SerialUSB to be Serial, and remapped hardwareSerial 1 to Serial 1, like the Leonardo.
Again to make it as close to the Arduino 1.0 API as possible.

I also started to make changes, so that you don't need to setup the pin before you use analogWrite and was going to do something similar for analogRead. But this is incomplete at the moment.

More recently Alexey has been looking at speeding up digitalWrite and digitalRead and using sub menus.

Also, now , there is a new hardware board based on the maple mini, but in a different form factor, called the microduino, and their developer is going to make a new variant for that board, as it has less pins than the maple mini.

However, I don't feel this project has reached critical mass yet, as there are only 3 or 4 people either bug fixing, or testing at the moment.

After an initial spirt of effort about 2 months ago, I have not had time to do very much for at least a month, due to my workload on paid commercial projects

But I may have more time in the New Year


Roger, this is a little OT for this thread, but I was wondering if you had much success with the ESP8266 modules?



Yes. I can now compile (make) for ESP8266

On Windows, I'm using Oracle VirtualBox , with the preconfigured VM image from expressif's website, and the SDK etc also from espressif's site

I use a shared drive, with the VM so that after the compile (make) has made the bin files I can upload using the windows command line python uploader

The only issue is the general lack of documentation. i.e the SDK version is ahead of the docs version (they don't match), and there is also a lot of stuff in the SDK that is undocumented even for the previous version of the SDK which was supposed to match the docs


@hidden pilot

I've been trying to implement the missing functions to set bit order etc

my code is

Code: [Select]
  inline  void setBitOrder(uint8_t bitOrder) {
if (bitOrder)
this->spi_d->regs->CR1 |= SPI_CR1_LSBFIRST;
this->spi_d->regs->CR1 &= !SPI_CR1_LSBFIRST;


#define SPI_CR1_LSBFIRST                (1U << SPI_CR1_LSBFIRST_BIT)


#define SPI_CR1_LSBFIRST_BIT            7

but calling it in either bit order doesn't seem to make any difference

I'm using the reference you quoted


Does it look like I'm doing anything wrong ?

Pehaps this->spi_d is not correct . I will need to check


Just a typo I think, always use ~ rather than for ! for inverting bit masks.
Please don't PM me asking for help. Ask questions in the forum.

may be this:
Code: [Select]

bit 6 - SPE : SPI enabled
0 : Peripheral disabled
1 : Peripheral enable

set SPE_flag = 0 before bitset,
and SPE_flag = 1 after bitset ?

Like this:
Code: [Select]
static void spi_reconfigure(spi_dev *dev, uint32 cr1_config) {
    spi_irq_disable(dev, SPI_INTERRUPTS_ALL);
    dev->regs->CR1 = cr1_config;


Dec 21, 2014, 06:56 pm Last Edit: Dec 21, 2014, 08:51 pm by oric_dan
Thanks for the ESP8266 info, Roger. I'm not using the SDK, but will check for more info on internal commands usable via 'AT'.

I looked all over the SDK page and inside a zillion SDK files, but couldn't find where they even mention AT commands. Do you where this is, or a more extensive list than on the Itead,Elektrodragon sites?


Oric dan.

See my PM.

its probably best not to confuse this thread, there is another thread already started on the Arduino site for the 8266

I think the notifications are starting to work again now, so if you post there I should get notified


Alexey and Bob


I will try both of those changes and let you know

Btw. I'm only going for legacy support with this and not, at the moment, to support the new transactional SPI approach which is in 1.5.x. This is for several reasons.

1 I'd need to understand what the Transaction stuff is doing and why
2. There would need to be working examples of Transactional SPI to compare data from
3. I don't have the time.
4. It works for most things as it stands, and only a handful of people are even using the code ;-)


The source code is a bit messy at the moment.

Maple doesn't compile at all, but no one has had chance to work out why not.

Just copy Maple mini and call it Microduino etc

OK - thanks - will do. I'm not connected with Microduino, BTW, just a customer. (Probably would have been easier to buy something else if I'd known it would become a whole new project...)



Oric dan.

See my PM.

its probably best not to confuse this thread, there is another thread already started on the Arduino site for the 8266

I think the notifications are starting to work again now, so if you post there I should get notified

Thanks, I didn't plan to push this matter over here, but most of those other ESP8266 threads I looked at are kind of short on info. Thanks.




It should be fairly simple to make those changes, just duplicate the variant folder to start with and then change boards.txt to specify the new variant

then when it compiles, change the boards stuff for the pin definitions


Dec 21, 2014, 10:53 pm Last Edit: Dec 21, 2014, 11:57 pm by rogerClark
Bob and Alexey

umm. Still not working.

I changed the code for setBitOrder to disable and then re-enable (see below)

I also return the bit pattern (so I can print it)

Code: [Select]

  inline  uint32 setBitOrder(uint8_t bitOrder) {
 this->spi_d->regs->CR1 &= ~SPI_CR1_SPE_BIT;// disable SPI during this change
 if (bitOrder)
 this->spi_d->regs->CR1 |= SPI_CR1_LSBFIRST;
 this->spi_d->regs->CR1 &= ~SPI_CR1_LSBFIRST;
 this->spi_d->regs->CR1 &= ~SPI_CR1_SPE_BIT;// re-enable SPI during this
 return this->spi_d->regs->CR1;

and I get

1111101000 STM32_LSBFIRST
1101101000 STM32_MSBFIRST

(Note. it looks like I need to modify the print functions to handle 32 bit numbers as the output for Serial.print(xxx,BIN) is probably only doing 16 bit.

I'll need to check how this is handled on the Due )


My test config is to use the SD SPI exmaple Cardino.ino and it still list the contents of the card regardless

So either SD cards have some way to know how they are being addressed i.e MSB or LSB first, or the STM32 is not changing its bit order

I suppose I better fire up my scope / and take a look at the bit patterns that are being sent.

I have not looked in the Erratica document for the STM32, it could be this is not supported or doesnt work or requires some other work around.

Actually, the other thing I can do is to hard code this as part of the CR1 stuff, so it always sets or resets that bit, just in case it needs to be done earlier.

I guess also, I'm not disabling the ISR, perhaps I need to do that as well .

Or I suppose something else in the code is clearing the bit.

umm. More debugging required


OK. I know why this is going wrong.

SPI.begin has an "endianess" flag which is overwriting whatever is set in the bitOrder function.

probably the best fix is to set the bit order when the function is called i.e in CR1 but also store the value, and then in begin() use the stored value, unless the bit order is passed in begin()

I'll need to check if bitorder is part of the normal AVR or SAM arguments for begin() as this could be a Maple specific bit of code that I can remove.

Today at 04:22 am Last Edit: Today at 04:53 am by HiddenPilot
Code: [Select]

void SPIClass::begin(void) {

    this->begin(SPI_1_125MHZ, ((!(this->spi_d->regs->CR1&SPI_CR1_LSBFIRST_BIT))?MSBFIRST:LSBFIRST), 0);

Anyway, I think we need to do a full port SPI from SAM for good compatibility SPI with Arduino liraries

Go Up