Sipeed Longan Nano the Non Standard -Win- Way.

First, I’m a Dabbler, Tinkerer in Microcontrollers, I don’t have any aspirations
to become a whiz coder or programmer, I know just enough to get into trouble ~ :o)
Therefore I only have some basic tools, I use Win7 (good grief !) and 32 bit at that.

So I bought a couple of Longan Nano’s to try after seeing the Demo on Seeed.
I installed Visual Studio Code, of which PlatformIO is a plugin for it.
Then installed PlatformIO, but it won’t run without Python, so I installed it also.
Having never used Python before (Win7 & basic tools only remember)
nothing was working, my setup doesn’t like Python.

So virtually everything in the gd32v Tools and Utils packages was useless to me.
Nothing I had on my machine previously even detected the the Longan Nano
in Boot - DFU mode or otherwise, so without Flashing tools I was at a dead-end.

Then I found something that did :wink: ) and in the most unlikely of places.
It was an STM Tool, ’ Flash Loader Demo or Demonstrator ’ I had used the STM-Link
Util and DfuSeDemo many times before but they didn’t even detect the L-Nano.

I was using an FTDI serial dongle (not the USB-C connector) this is the same sort
of thing you would use with an Arduino, I used the 3v3, R0, T0, Gnd pins on the
end, top of the L-Nano board, (not JT pins on the bottom).
Simply connect to the same pins on the FTDI dongle (note: 3v3 not 5v) and use
T0-R0 and R0-T0 changeover between them.
You need to hold the L-Nano Boot button when you plug into the USB for Flashing.
Once inserted you let the button go.

Now I had a Tool that could upload something onto the L-Nano at last.
A very Spartan tool, Select ComX (yours), hit Next, (sees Target) hit Next, shows
memory map, hit Next, Select Download to device, Download from File button, there
are 3 choices of File in a drop-down at bottom, *.s19, *.Hex or *.Bin, select .bin.
Select File (badapple_demo.bin) and upload to the L-Nano, done !

If Flash Loader Demo detects a new COM and you still can’t connect, you may have
to remove - re-insert the USB while holding down the L-nano Boot Button also.

I downloaded the L-Nano Demo ’ badapple_demo.bin ’ from the Sipeed site > Here ~
http://dl.sipeed.com/LONGAN/Nano/Firmware
I Flashed the badapple_demo.bin onto the L-Nano no probs, then put the other two files
logo.bin and bmp.bin onto a small SD Card and inserted it (power off).
Badapple Demo will let you know if the SD Card is missing with an onscreen prompt.
Logo.bin is the Sipeed Logo, bmp.bin holds all of the bmp files for the video.
Badapple Demo was now running. :grin:

It would be very useful if Seeed could supply, e.g a two or three frame Video as a raw
file, just to see the actual formatting of how the BMP files are used on the L-Nano.
The suggested Python BMP tools don’t work for me either at the moment, unfortunately.

So now that part was all working, what next ?
As I can’t get PlatformIO working, I wanted to explore the L-Nano a little further.

Just by coincidence there is a little known / used programming language called FORTH.
It’s been around since the 60’s.
Most C, C++ users put their hands over their ears and run away at the mere mention of
it I’ve heard :wink: )
It is quite different I will admit, and does take a bit to get used to, quite a bit.
But it is very small and very powerful, if you take the time to learn and use it.
And you don’t need any TOOLs, Forth runs directly off the Chip it is loaded onto.
There is no compiler as such, Forth compiles itself as you go, it’s completely
self contained ’ on Chip '.

Forth comes in many flavors, usually for specific hardware or chips.

As it happens there’s a new (experimental) version called Mecrisp Quintus, just
released that has a specific version for the GD32VF device, support and others also.
There’s even some demo files you can play with on the Terminal. You need a terminal
running (using the same FTDI dongle as above) to communicate and use with FORTH.
It will run standalone once programmed, for advanced users, as there are things
required, like a back door, to resume a Terminal connection etc.
You can upload to the L-Nano (unpacked) mecrisp-quintus-gd32vf103cb.bin, just as above.

There are no Library files like Arduino as such (there’s a couple), you make your
own usually, so it’s bare metal mostly. It may not be for everyone, but I like it.
And I can only get a Blinky running, a smidgen more, while sorting out PlatformIO etc.
Mecrisp Quintus V0.25 on SourceForge here > https://sourceforge.net/projects/mecrisp/files/

If you are not a programmer you will get a blinky (supplied) running fairly easily but
probably not a lot more, but you will get access to all of the other pins / ports if
you feel like experimenting with the GD32VF103 or L-Nano board.

So it would be good to see if anyone else had some other Tools or Methods for
programming this Longan Nano other than the recommended, which may not work
for everyone either.

Cheers.

The LCD demo seems to be the same (or very similar) to the badapple demo. You can see it simply reads the frame in two halves, and pushes the bytes to the LCD controller. There are 16 bits (RGB565) per pixel, (160x80 x 2 * 2189 = 56038400, the size of the bin file), so you can easily chop the first few frames just by taking 25600 bytes per frame from the file.

        fr = f_open(&fil, "bmp.bin", FA_READ);
        if (fr) printf("open error: %d!\n\r", (int)fr);
        offset = 0;

        for (int i=0; i<2189;i++)
        {
            fr = f_read(&fil, image, sizeof(image), &br);
            LCD_ShowPicture(0,0,159,39);
            offset += 12800;
            f_lseek(&fil, offset);
            LEDB_TOG;
            fr = f_read(&fil, image, sizeof(image), &br);
            LCD_ShowPicture(0,40,159,79);
            offset += 12800;
            f_lseek(&fil, offset);
            LEDB_TOG;
        }

Thanks kevin,

I managed to get a version of Python that works finally.
And the BMP py tools work, not 100%, I get a lot of errors but they still generate a .bin file.
So I have a couple of short videos that will now play and some DIY, MS-Paint files that are working, well sort of.
The errors are with bin2hex and line 230 or something and the width, but everything is 160x80 that I’m using.
I’ll work on it a bit more.

Cheers

Followup:
The Python tools for BMP .bin, genhex.py and bmp2hex are
actually working fine, it was me that wasn’t, I had some BMP
files that were only 8-bit depth and it was throwing errors
even though the 160x80 was correct. Then later I managed
to get a 32-bit file in there and got the same as above.
If everything is 24-bit depth and 160x80 you shouldn’t get
any errors, I just made an 800 frame .bin no probs this time :smiley:
And File numbering is also very important, they must
start at ‘1’ and + + + til the end, don’t skip any numbers.
Then edit genhex.py with your final frame count total.

Cheers