Spark Logic

[libmaple] Black F407VET6

stevestrong

The master branch of my repo contains the latest developments for F4, so I recommend to use this if somebody wants to test it with Arduino IDE or PlatformIO.
Supported board variants: generic F4 (tested), generic F4 mini (tested), disco F407 (compiles but not tested).

Some basic information about the board can be found on wiki: http://wiki.stm32duino.com/index.php?title=STM32F407

Currently working:
– GPIOs + LED toggle
– USB serial and serial 1,2,3. Evaluated USB serial speed, Tx: ~800kBps
– SPI (1,2,3) with DMA (also for SD cards using latest SdFat lib made by Greiman), extended DMA functions
– FSMC (adapted for driving 16 bit parallel LCDs) http://stm32duino.com/viewtopic.php?f=39&t=2298#p31037
– SDIO [non-HAL implementation] (for SD cards using latest SdFat lib made by Greiman) http://stm32duino.com/viewtopic.php?f=39&t=2215
– RTC – reworked, does not need any extra time library
– I2C (Wire) viewtopic.php?f=39&t=2804&p=37376#p37376
– supports W5500-based Ethernet modules (see viewtopic.php?f=13&t=503&p=32063#p32063)
– DAC, see viewtopic.php?f=39&t=1976&p=41564#p41564
– ADC, see http://stm32duino.com/viewtopic.php?f=3 … 720#p42720
– DCMI, see viewtopic.php?f=39&t=3414&p=43358#p43358
– CAN, see: http://stm32duino.com/viewtopic.php?f=3 … 239#p49235

Todo:
– port the new (faster) version of SDIO from Victor (https://github.com/rogerclarkmelbourne/ … 2/pull/474)
– check the on-board W25Q64 SPI flash, maybe add SPIflash lib to repo (where from?) https://github.com/LowPowerLab/SPIFlash
– check/add FPU (http://stm32duino.com/viewtopic.php?f=39&t=2001, http://stm32duino.com/viewtopic.php?f=3 … 048#p31040)
– add support for Seed Arch Max board
– add Ethernet lib (usable with Seeed Arch Max board)

EDIT – 2018.10.02
– added extended SPI DMA functions, see: viewtopic.php?f=15&t=3415

EDIT – 2018.09.12
– working CAN, see: http://stm32duino.com/viewtopic.php?f=3 … 239#p49235 (thanks to @michael_i!)

EDIT – 2018.03.19
– tested ADC, see: http://stm32duino.com/viewtopic.php?f=3 … 720#p42720

EDIT – 2018.02.18
– tested DAC, see: viewtopic.php?f=39&t=1976&p=41564#p41564

EDIT – 2018.01.16
– Added I2C (Wire), see: viewtopic.php?f=39&t=2804&p=37376#p37376

EDIT – 2017.07.10
– RTC lib reworked to be independent from other time libraries. Includes an example sketch to read and set the RTC time, as well as how to use the time elements.
It can be downloaded from here: viewtopic.php?f=39&t=775&p=31218#p31218

EDIT – 2017.06.18
– Implemented SDIO [non-HAL implementation] (for SD cards using latest SdFat lib made by Greiman)
viewtopic.php?f=39&t=2215

EDIT – 2017.06.02

Upload under windows currently only possible with STLink (V2).
When BOOT0=”1″(3.3V) and BOOT1=”0″(GND), the chip is recognized by Win10 as ‘STM Device in DFU mode’ (USB\VID_0483&PID_DF11).
However, there is no working DFU loader for Windows available, yet.

Comments & suggestions are welcome in this thread.
Any bug reports & PRs in Github, please.

————————————————————————————-
Hi all,

I know there is another thread on vet6 & zet6 boards, but there are at least 2 type of boards mixed, with partially different information.
And there is a lot of other information spread over other threads, like this generic implementation from danieleff.
Wiki has some basic stuff, too (thanks, Palmer!).

So, I got my black board today and I though it makes sense to open a separate thread only for the black VET6 board. The title can be edited later if needed, and the useful and tested information can (should) be added to wiki.

First of all, this is the current situation:
Both LEDs blink, but the USB device descriptor failed (VID 0x000 PID 0x0002).
On the serial port (115200Baud, 8N1) I receive after each reset: “LCD ID:ffff”
I can connect with the ST-Link probe, and I could read out the flash (I can attach here or to wiki if wanted). I assume writing would be also possible.

Now would like to start with the sw development.
The question is: how?

I know, there are a lot of alternative options (the official STM32 core, Start Otto github, Koduino, and so on).
But honestly, I like very much the existing Arduino_STM32 repo and I would like to use this for my future work.
I also know, it will be a hard way to go. But I think, with small steps I (we?) can achieve great results.

So, will the Arduino_STM32 provide the basic structure and functionality for a blinky example?
If anyone tried that already and had success, I would appreciate a short description of what and how to do.

For the beginning I intend to use the STlink upload method as the USB DFU seems not (yet?) to work.
Is there any working bootloader available for this board?

Replies20

Wolfie Thu Feb 15, 2018 8:39 am

Thanks for the explanation Steve.

I wasn’t expecting you to change anything, I just wanted to explain what to do in order to get all 32 PWM channels working for anyone that wanted to know, because I have a project that plans to use them all.

As an aside, my W5500 modules arrived yesterday and, late last night, I got a 407VE connected to the LAN, so thanks again for your work.

acronis Sun Feb 18, 2018 12:27 pm

Steve

Please tell me how to do calibration of ADC ?

int channel = PIN_MAP[analogInPin].adc_channel;
adc_set_sample_rate(&ADC1, ADC_SMPR_1_5);
adc_set_reg_seqlen(&ADC1, 1);
(&ADC1)->regs->SQR3 = channel;
(&ADC1)->regs->CR1 |= 0x70000;
(&ADC1)->regs->CR2 |= ADC_CR2_CONT | ADC_CR2_SWSTART;

stevestrong Sun Feb 18, 2018 12:43 pm

You must not and cannot calibrate the ADC of F4.

acronis Sun Feb 18, 2018 12:52 pm

OK. thanks.

stevestrong Sun Feb 18, 2018 9:08 pm

I needed a simple wave generator so I thought why not use the DAC of my F4 board.

The result is a sketch which generates either a sine wave (using a lookup table) or a triangle wave (using the internal wave generator of the F4 chip).
Configurable with some defines in the beginning of the sketch.

As usual, my repo gives the necessary utility functions.

Pito Mon Feb 19, 2018 12:28 am

Any example for a simultaneous regular ADC sampling (2 ADCs sample a channel at the same exact time, no channel’s scan – scan disabled)?

stevestrong Mon Feb 19, 2018 7:54 am

Yes, ADC is the next on the agenda, now that i have a reference signal from the DAC to sample ;)

stevestrong Tue Feb 20, 2018 7:54 pm

This is another wave form generation example using DMA now.
This example allows to configure the output frequency (and amplitude in case internal triangle wave generator).
The example sine wave has 210 samples and 8 bit resolution, with 3.3Vpp.
The generated 20 kHz frequency is quite precise and the signal has a nice shape ;)

Now the next step is ADC.

vitor_boss Fri Feb 23, 2018 1:01 am

[stevestrong – Tue Feb 20, 2018 7:54 pm] –
This is another wave form generation example using DMA now.
This example allows to configure the output frequency (and amplitude in case internal triangle wave generator).
The example sine wave has 210 samples and 8 bit resolution, with 3.3Vpp.
The generated 20 kHz frequency is quite precise and the signal has a nice shape ;)

Now the next step is ADC.

Very nice code, I’m not a skilled programmer like you guys but I have an idea to reduce #ifdefs
#elif GEN_WAVE==TRIANGLE
#if WAVE_AMP==3
const int WAVE_RES = 8192;
#elif WAVE_AMP==2
const int WAVE_RES = 4096;
#elif WAVE_AMP==1
const int WAVE_RES = 2048;
#endif
#endif

stevestrong Fri Feb 23, 2018 8:34 am

Yes, it makes sense.

robca Sat Mar 03, 2018 5:29 pm

I have a long dormant project I’d like to complete (2+ years dormant). It was built on a F103 board, but could not be completed due to limited RAM (only max 64k for the boards I could find) and slow floating point performance.

I happened to find it at the bottom of my pile, and browsing around I see that F4 boards are cheap now, and there is STM32duino support for F4… so I might be able to finish it after all :)

The only thing I’m confused, is that the F4 seems to have a complex memory map, with 112k + 16k + 64K, the latter CCM memory and not DMA enabled. If I were using a different toolchain, I know I could use the proper memory allocators and use all that memory. How about the STM32duino toolchain?

I had a quick look here https://github.com/stevstrong/Arduino_S … eric_f407v and it seems both ram (128k) and ccram (64k) are defined, but not sure how those are made available

If I had a board, it would be easy to test… but before I order (and wait for the slow boat from China), can someone here please help me understand how much free RAM can I reasonably expect to have for my code?

BTW: would this code work on your branch? https://github.com/mpflaga/Arduino-Memo … ryFree.cpp

vitor_boss Sat Mar 03, 2018 5:38 pm

Yes, the freeram code works, also some guys are developing a F405 board with BluePill pinout compatible, is possible to replace only the F1 for the F4.

viewtopic.php?f=19&t=2633&start=580

robca Sat Mar 03, 2018 9:26 pm

Thanks for confirming the freeram code works… but since I don’t have a F4 board, I was kinda hoping someone would be able to tell me how much free RAM I can get with one of the F4 boards ;) (they all have the same amount of RAM, only Flash and pins change)

And it looks as if eBay/Aliexpress F407 boards are the cheapest you can get, at sub-$10… STM32F405 is not any cheaper, actually costs more. F411 has less RAM, slower and single (slow) ADC, so wouldn’t work for me, even if cheaper. Love seeing open hardware and smaller form factors, but for my project it’s not critical. Since I don’t even know if it will ever work, might as well go cheap. But, to be honest, I’m not sure I see the point of custom-designing an F405 or F411 board, given where the market is at

stevestrong Sun Mar 04, 2018 8:23 am

In my repo the stack has been mapped to ccmram, and an example how to map your varibles there is one of the usb buffers. Search the code for that.
But ccmram cannot be used with dma, like the rest of ram.

Regarding the board selection, i find the generic vet6 mini gives a very good starting point including slot for sd cards and i2c flash on board.
If you don’t need those extra hw pieces, any simplier “generic” type would make it, like that one in your other post (named “discovery”).

stevestrong Sun Mar 04, 2018 8:45 am

[Pito – Mon Feb 19, 2018 12:28 am] –
Any example for a simultaneous regular ADC sampling (2 ADCs sample a channel at the same exact time, no channel’s scan – scan disabled)?

You cannot have that, see note in RM0090 chapter 13.9.2.

robca Sun Mar 04, 2018 4:55 pm

[stevestrong – Sun Mar 04, 2018 8:23 am] –
In my repo the stack has been mapped to ccmram, and an example how to map your varibles there is one of the usb buffers. Search the code for that.
But ccmram cannot be used with dma, like the rest of ram.

Regarding the board selection, i find the generic vet6 mini gives a very good starting point including slot for sd cards and i2c flash on board.
If you don’t need those extra hw pieces, any simplier “generic” type would make it, like that one in your other post (named “dicovery”).

That’s great, thanks. I thought I saw the stack mapped to ccram, that was very smart of you, since it frees up more user RAM. Didn’t notice the USB, which is also a great idea. And, yes, I understand the ccram limitations (and I will rely heavily on DMA for a portion of the ADC code), on the other hand it’s faster than the rest of the RAM, so mapping stack and frequently used variables there speeds things up

So I should be able to, in effect, use more than 128Kb RAM in my code, once I figure out how to allocate some variables to ccram. Even (in theory) convert my ADC channels to almost 128Kb RAM using DMA, and stuffing every other variable in ccram. Awesome :)

victor_pv Tue Mar 06, 2018 3:04 am

There is 2 possible approaches about CCM RAM:
  • You can place everything in it by default, and specify when you want to use normal RAM with an attribute.
  • Or you can place everything in normal RAM, and only place things in CCMRAM with an attribute.

I beleive we discussed it on some threads and the PRs, and decided to better leave normal RAM as default, since there is no restrictions on that one (for DMA, or to run code on it), and use CCM RAM only when the attribute is used.
This thread has some of the details:
http://stm32duino.com/viewtopic.php?f=5 … ccm#p32607

Steve would know for sure if the attribute he kept is the one we discussed in that thread, __CCMRAM__, if so, you only need to declare variables with that attribute to place them in CCM RAM, i.e:
uint16_t __CCMRAM__ buffer[256];

robca Tue Mar 06, 2018 6:27 am

Thanks for the extra info. Yes, I looked at the code as suggested by Steve, and with the default settings, you can use the __CCRAM__ to allocate variables in ccram. It makes sense to use the normal RAM as default, since people might want to use DMA and in any case normal RAM is twice as big as ccram. Even in the USB case, there’s an ifdef to put the buffers in normal RAM if DMA is used.

It’s definitely nice to have the ability to decide where the variables are stored, and if speed is a concern, ccram should be used preferentially for anything not dependant on DMA. But I still believe that using normal RAM as default is safer, otherwise people would run into problems with libraries/code relying on DMA and would be very hard to troubleshoot

Since I use ADC with DMA, at a minimum the buffers used by the A/D conversion must be in normal RAM, but I need to see if I can get a faster execution by having some of the cross correlation code using ccram variables

At this point I’m confident that it’s worth starting to experiment with an F407 board. Just will need to wait for the slow boat from China to get here with my board :)

victor_pv Tue Mar 06, 2018 8:46 am

One more piece of advice. The normal RAM is broken out in 2 blocks with separate bus access.
If you need the ultimate performance while doing 2 things in normal RAM at the same time (2DMA transfers or 1 transfer+cpu access), you could do the same we did with the CCMRAM and create a separate region for the top 16KB of ram, that way you can direct the compiler to place some buffer there, and know the DMA can access that region at the same time CPU or another DMA channel are accesing the other normal RAM region without any stalls.
I believe that’s why STM designed the normal RAM in 2 separate blocks.
You could also place some code in that top region, and could execute without being affected by any RAM access, if all other access goes to the other blocks.

robca Tue Mar 06, 2018 5:20 pm

That explains why 128k RAM is usually described as 112k+16k… I was wondering what made that 16k block “special”, and now I know :)

Thanks for the info. Luckily my needs are pretty simple: high speed DMA ADC into a buffer (4 channels), then process the buffer as a single high speed task, sequentially. As such I don’t think that my code would benefit much from wringing out the extra perf of those 16k, since I’m pretty much serializing everything. I can see how it would benefit if I were using real time processing and a circular ADC buffer, processing the ADC buffer while the DMA transfer is active

Sign in to reply