Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

boards: add support for bluepill board #7727

Merged
merged 1 commit into from
Oct 27, 2017

Conversation

nmeum
Copy link
Member

@nmeum nmeum commented Oct 12, 2017

This pull request adds support for the stm32 based bluepill board. This board is widely available at a very low cost on sites like AliExpress and others.

Initial work was done by @obgm but his RIOT fork was outdated and incomplete thus we started from scratch based on the nucleon-f103 board. However, we noticed that some peripheral configuration options were missing in the nucleon-f103 periph_conf.h header file. For instance, the general purpose timer four wasn't configured and the cs_pin for the SPI devices wasn't set. In addition to that PWM and ADC support was missing on the nucleon-f103. Compared to the nucleon-f103 we didn't configure i2c in the periph_conf.h file for the bluepill board because we couldn't test it yet, but it is very likely that the i2c configuration from the nucleon-f103 can simply be copied for this board.

All other peripherals were tested using the tests available in tests/. We are also planning to expand support for this board in the future. Apart from i2c we would also like to add support for CAN available on the device.

This was a group effort involving Alexander Kurth, Tristan Bruns, Christian Manal and myself.

@bergzand
Copy link
Member

Is there a difference between this board and the already existing maple mini board? As far as I can see, they look (to the eye) identical and they have the same cpu.

@nmeum
Copy link
Member Author

nmeum commented Oct 12, 2017

It is as similar to the maple-mini as it is to the nucleo-f130. The definitions in board.h differ and the defintions in periph_conf.h are only similar because the boards use the same chip.

It would probably be a good idea to add an stm31f103_common folder to boards which behaves similar to the iotlab_common folder.

@bergzand
Copy link
Member

I was afraid that there would be some duplicate work, but good that it is not the case here.

@jnohlgard jnohlgard changed the title add support for bluepill board boards: add support for bluepill board Oct 14, 2017
@smlng
Copy link
Member

smlng commented Oct 16, 2017

Hi, I tested with my bluepill board, which has a stm32f103c8t6 MCU, not stm32f103cb as configured here. While tests/led is working, I cannot connect to terminal (likely some UART issue), i.e., BOARD=bluepill make term does not work, but if I try BOARD=samr21-xpro make term it runs pyterm but no output is visible.

With #7735 it works as expected ...

@smlng smlng added Area: boards Area: Board ports Type: new feature The issue requests / The PR implemements a new feature for RIOT labels Oct 16, 2017
@kurth1
Copy link

kurth1 commented Oct 16, 2017

The three UART port are in a different order in this PR then in #7735, which means the pins of the UART used for stdout are different. This might explain your issue.

The hardware we used for testing also uses a STM32F103C8T6, the CPU definition uses a STM32F103CBT6 because we are pretty sure that they have 128 KiB Flash anyway, as mentioned here. Since this is not yet 100% conclusive, it would be awesome If people with this hardware could test this.

@smlng
Copy link
Member

smlng commented Oct 16, 2017

@kurth1 thanks for the infos!

Regarding the UART: yes saw that, too - still I think its better to use UART2 (as in #7735) for RIOTs term/shell connection because UART1 lies on the same pins as I2C1, see here.

Regarding the flash size, I don't know wouldn't it be safer to use the lower variant as default until further verification. I guess with those cheap boards it may depend on the production line which it will be, and could lead to some nasty to debug errors, if one has a device with only 64KB flash.

@pyropeter
Copy link
Contributor

I don't really know why make term should work. The bluepill has no internal usb-to-serial-converter. We can make no assumptions at all about how the user chooses to connect the serial ports to a computer.

@smlng
Copy link
Member

smlng commented Oct 17, 2017

@pyropeter you're right, but that's true for many boards.

Still it would be good to have a sensible default, which also allows other periphs to run by default as well. That's why I would recommend to set UART2 as the default for RIOTs primary shell-UART. UART1 and 3 collide with I2C, though I know UART2 collides with some ADC pins, but there are 8 of them so we can manage to loose 2 of them for UART, right?

@jnohlgard
Copy link
Member

I suggest you keep the ordering of the UART modules to match the chip order, and instead define UART_STDIO_DEV in board.h. See boards/mulle/include/board.h for an example.

@nmeum
Copy link
Member Author

nmeum commented Oct 17, 2017

@smlng We adjusted the CPU_MODEL accordingly and defined the UART_STDIO_DEV macro as suggested by @gebart. We also included and configured $(RIOTBOARD)/Makefile.include.serial in Makefile.include.

@nmeum
Copy link
Member Author

nmeum commented Oct 17, 2017

We also copied and tested the saul gpio configuration and changes made to the Makefiles in tests/ and examples/ from #7735 now.

@smlng
Copy link
Member

smlng commented Oct 19, 2017

@nmeum nice work and thanks for adapting to suggestions, I'll close #7735.

@smlng smlng self-assigned this Oct 19, 2017
@smlng smlng added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Oct 19, 2017
@smlng
Copy link
Member

smlng commented Oct 19, 2017

Before merge I'd like to verify that SPI is working with the given configuration, I'll try to test within the next days.

Further, I've some concerns regarding the board name, it might be worth considering to rename it into stm32bluepill (or even stm32f1bluepill) so its more obvious to which family it belongs - its just a thought, any opinions?

@nmeum
Copy link
Member Author

nmeum commented Oct 20, 2017

I don't have a strong opinion on this, the board name is just a string after all. However, the other boards in boards/ using an stm32 are not prefixed with stm32 either. Therefore I would prefer not renaming the board.

@bergzand
Copy link
Member

I'm against rename the board to something with stm32, to me that would make it appear as if there are multiple versions of the bluepill board.

Would a symlink from boards/stm32f103c8 to boards/bluepill work here? I don't know if RIOT-OS has an opinion on using symlinks in the repository.

@jnohlgard
Copy link
Member

We used to have some symlinks in the repo before, but it causes issues for users on windows and using some file systems so we replaced them. I suggest just adding some more information in the board's doxygen page regarding names and what else might be relevant.

@bergzand
Copy link
Member

@gebart I agree with adding information to the doxygen. I can imagine symlinks causing weird issues on different platforms :(

@nmeum
Copy link
Member Author

nmeum commented Oct 20, 2017

We are intending to also write a wiki page about this board. Wouldn't it be better to place this information in the wiki?

@jnohlgard
Copy link
Member

@nmeum sorry for the confusion. This information is perfect for the wiki, but it is also good to have some kind of references for alternate names directly in the source tree as well (Doxygen).

You may put the information wherever you think is best (or both), as long as there is some text describing that this board has several different names across the web, to make it more likely to find the correct page when someone is searching for this board.

There's an ongoing discussion regarding where to put information about the supported platforms (wiki vs. Doxygen). I favor Doxygen because that is where I tend to look first and I think it is easier to keep up to date when things are added or modified, but others favor the wiki because it may be more familiar.

Copy link
Member

@smlng smlng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

verified by testing, basic board supports works.

@smlng
Copy link
Member

smlng commented Oct 27, 2017

fixes #6967

@nmeum
Copy link
Member Author

nmeum commented Oct 27, 2017

We just added a few comments regarding the flash size to the doxygen documentation as suggest by @gebart. Is there anything else we can do to get this merged?

Copy link
Member

@smlng smlng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor nits

#endif

/**
* @brief LED pin definitions and handlers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use @name for doxygen grouping, as done below for xtimer config

* @defgroup boards_bluepill Bluepill board
* @ingroup boards
* @brief Support for the stm32f103c8 based bluepill board.
* @details This board can be bought very cheaply on sides like eBay
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add empty line and omit @details - IMHO its not needed when separated from @brief by an empty line

@smlng
Copy link
Member

smlng commented Oct 27, 2017

you may squash fixes directly.

@nmeum
Copy link
Member Author

nmeum commented Oct 27, 2017

@smlng Done!

@smlng
Copy link
Member

smlng commented Oct 27, 2017

I'm happy and will test later at home, where I have the board ready for testing. If nobody objects until then I tend to merge this. Any further additions etc. can be done in followup PRs.

@smlng
Copy link
Member

smlng commented Oct 27, 2017

Nice work btw.!!!

@smlng
Copy link
Member

smlng commented Oct 27, 2017

ACK & GO!

@smlng smlng merged commit 2e0917c into RIOT-OS:master Oct 27, 2017
@nmeum
Copy link
Member Author

nmeum commented Nov 7, 2017

We are intending to also write a wiki page about this board. Wouldn't it be better to place this information in the wiki?

We just published a wiki page for this board: https://github.com/RIOT-OS/RIOT/wiki/Board:-Bluepill we are intending to improve this because we still don't know how to force OpenOCD to use 128 KB instead of 64 KB flash on this board. In case somebody knows how to do that let us know …

@kYc0o
Copy link
Contributor

kYc0o commented Nov 7, 2017

Is OpenOCD throwing an error when you try to flash it? Or it's at linking? If linking is the problem #7799 can solve it.

However, OpenOCD just gets the size of the ROM by reading it from the chip (through the model), thus even if the mcu has actually more ROM OpenOCD cannot "override" the configuration for the given model.

@nmeum
Copy link
Member Author

nmeum commented Nov 7, 2017

Is OpenOCD throwing an error when you try to flash it? Or it's at linking? If linking is the problem #7799 can solve it.

OpenOCD doesn't throw an error at all. It allows me to flash the binary but the program doesn't work accordingly afterwards.

However, OpenOCD just gets the size of the ROM by reading it from the chip (through the model), thus even if the mcu has actually more ROM OpenOCD cannot "override" the configuration for the given model.

I only looked at this very briefly but there seems to be an OpenOCD flash bank commando: http://www.openocd.org/doc/html/Flash-Commands.html#Flash-Commands which I believe might allow us to override the default flash bank size. Or am I wrong about this?

@kYc0o
Copy link
Contributor

kYc0o commented Nov 15, 2017

Taking more closely a look, this seems to be a "printing" error, since "8" and "B" look quite similar.

Thus, can we assume that bluepill has a stm32f103cb in all cases?

@smlng
Copy link
Member

smlng commented Nov 15, 2017

can we assume that bluepill has a stm32f103cb in all cases

no we cannot (and shouldn't). We lately bought 60 blueppills and for only 3 (that is 5%) openocd reported 128KB flash size the rest was 64KB. Though they might have 128KB too in theory, I wouldn't recommend to count on that in all cases.

@pyropeter
Copy link
Contributor

We lately bought 60 blueppills and for only 3 (that is 5%) openocd reported 128KB flash size the rest was 64KB.

Do those three chips have a stm32f103cb marking? I'm quite curious because from the inside the only way to tell the two chips apart is to read the flash size register, which is what openocd does. (One could also try to detect the flash size by writing and reading the extended flash addresses.)

I only looked at this very briefly but there seems to be an OpenOCD flash bank commando: http://www.openocd.org/doc/html/Flash-Commands.html#Flash-Commands which I believe might allow us to override the default flash bank size. Or am I wrong about this?

@nmeum, after looking at the code, I'm sure this will work. I'm still not sure if the extra flash should be used, though.

@smlng
Copy link
Member

smlng commented Nov 16, 2017

@pyropeter for me all 60 bluebills we bought are marked as stm32f103c8t6 but for 3 or 4 of them openocd reported a flash size of 128KB, all other are reported to have 64KB.

@smlng
Copy link
Member

smlng commented Nov 16, 2017

i.e., also those with 128KB are labeled stm32f103c8t6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: boards Area: Board ports CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants