Espruino on STM32F4 discovery board

Posted on
  • Hi to all.

    I flash Espruino firmware on STM32F4 discovery board
    with success. Also I installed Virtual COM port drivers with success
    but I have problem to connect my board with Espruino Web IDE, I can't see
    COM port of my board. What is the problem?
    Thanks in advance
    BR
    IvanJ

  • I not mention that I use Win 7 64-bit.

  • Hello,

    I'm trying to flash firmware on popular "blackpill" board.
    I tried espruino_2v08_nucleof411re.bin firmware and flash via Espurino IDE.
    I event can't flash firmware ...
    Tried via UART cable, STLinkV2 and USB bootloader ... :(

    @IvanJ - how did you managed to flash firmaware?

  • Hi did you find good .bin file for microcontroler on black pill board on Espruino download list of firmvers?
    If you do/can I will be glad to describe you whole flash process I will add pictures too but you must have right firmvare aka .bin file.

  • When I mean good I mean right .bin file for this microcontroler on board.

  • I'm trying to flash firmware on popular "blackpill" board.

    Black Pill was always called this one https://stm32-base.org/boards/STM32F103C­8T6-Black-Pill.html - a variant of blue pill.

    But you most probably mean these ones - two variants STM32F401 or STM32F411
    https://www.cnx-software.com/2019/12/24/­stm32-black-pill-board-features-stm32f4-­cortex-m4-mcu-optional-spi-flash/ ? The author probably didn't know about black pill and created confusion.

    EDIT: looks like there are even more of those boards -
    Their github project https://github.com/WeActTC/MiniF4-STM32F­4x1 links to
    https://www.aliexpress.com/item/40003466­95587.html which has 3.0 boards upgraded to 96/512KB for 401. So now there are 3 variants of ram/flash sizes - 64/256 96/512 (401) 128/512 (411)

  • Hi Guys,

    1. first you need to download STM32 Cube Programmer from STM site
    2. then you need connect STM32F4 discovery board with both USB connectors
    3. if you install STM32 Cube Programmer then start it (with board plugged on both USB's)
      you will see this picture after it starts up...

    4. click Connect (upper right corner)
    5. if you are lucky you will see this picture

    6. then you click button Erasing & Programming (it is one on the left with arrow pointing hard drive or soething...) the you will see next picture

    7. click Browse and find File path to you .bin file, your firmware for board
    8. when you find it first click Full Chip Erase when it finish then click option Start programming
    9. then you need to install Virtual COM port drivers from STM site when you finish installation of
      it then find on which virtual com port is your board (my is on COM30)
    10. open Putty or similar program, and open com port after that you must see picture
      after you RESET your board

    11. write reset() command in Putty window and press Enter
    12. if you lucky you will see picture


    that it is

    note: also you need ST LINK drivers !!!

    I have problem with COM port on Espruino Web IDE, I can't connect my board with IDE

  • Which web-ide you use? There is (at least) the in-browser version at https://www.espruino.com/ide/ You need to enable web-serial, and that requires a recent chrome-based browser (for example Edge and Vivaldi does work)

    There is the Chrome web app https://chrome.google.com/webstore/detai­l/espruino-web-ide/bleoifhkdalbjfbobjack­fdifdneehpo (should work without any extra steps)

    And there is the native NWJS based app (that should also work without extra steps)

  • hi
    yes I do it but it still does not working


    image upload

  • But Native is working I am so excited!!!
    How can I upload my code to the board?

    image upload

  • I get it...this button in IDE with arrow pointing up is upload...ok
    silly me

  • Upload button in the middle!
    Or you can just type in the left side, and your code is executed right away on the Discovery board.


    1 Attachment

    • upl.png
  • Thanks!

  • I have board with STM32F411CEU6. Not sure which firmware to use -> I'm trying now with espruino_2v08_nucleof411re.bin

  • Thank you @IvanJ - I followed your steps, upload firmware via STM Cube went without any issues, installed Virtual COM, see COM7 (STMicroelectronics), but when I try to connect with putty or other terminal - there is nothing (no messages, no prompt).

    I'm currently doing all of this using UART (on PA9/PA10).
    Will try over ST-LINK ...

  • When you open Putty just press Enter on keyboard and type
    reset() and press Enter again.
    You will see...

  • but when I try to connect with putty or other terminal - there is nothing (no messages, no prompt).

    the board file for that fw is here https://github.com/espruino/Espruino/blo­b/master/boards/NUCLEOF411RE.py so it has serial console on pins a2,a3

    virtual com is feature of onboard stlink debugger on the nucleo board so it won't work for your WeAct blackpill board, unless you have external stlink with virtual com too and connect it to pins a2,a3

  • Also, the Nucleo and Espruino boards (Original, Pico and Wifi) have an 8MHz xtal, the WeAct has a 25MHz, so the crystal frequency has to be changed / build tweaked.

  • Had this board in drawer somewhere, haven't used it yet. So I took it, soldered SWD pins, flashed the nucleo fw and indeed it doesn't work, nothing on a2/a3. Then made a build of micropython from https://github.com/mcauser/WEACT_F411CEU­6 and that one works fine so board is OK.

    Then I tried to change timing as per this and it almost worked - the blue led was on after poweron. Took some time to enable USB too but now it sort of works. What doesn't work is setting button and LED as inverted. There is example in NUCLEO411 board file but it does nothing for me. So led is still on and LED1.set() turns it off and for button I need to manually enable pullup and then it works but is still inverted.

    board file
    https://gist.github.com/fanoush/7553104f­a7c8c596fe91f276d3f297fd
    clock frequency patch
    https://gist.github.com/fanoush/db80e8b5­e78f217036cb4fc91fed7b6a
    binary
    https://filebin.ca/5eJ1Xo9M3VQG/espruino­_2v08.5_weact_f411ceu6.bin

  • Just an update about the WeAct board and negated pins - looks like stm32 port does not have support for negated pins. At least not in same way as nrf5x port.
    For nrf5x there is runtime check for pinInfo[pin].port & JSH_PIN_NEGATED and value and possible pull ups/downs are negated. I am not sure if this is actually good solution in NRF code but anyway there is nothing like that in stm32 code.
    So I have extended the patch http://microcosm.app/out/78xji to handle negated pins in get/set value but in NRF code there is more (pull ups, downs in get/set pin state)

    Anyway here is updated binary https://filebin.ca/5hFTUCKr4JA5/espruino­_2v08.5_weactf411.bin where button and led works as expected - button skips startup code if held, LED is off at startup.

    The question about how to handle negated pins remains, should the (extra) nrf5x code be copied to stm32 port? To see more start here https://github.com/espruino/Espruino/blo­b/master/targets/nrf5x/jshardware.c#L966­ and search for JSH_PIN_NEGATED. Similar stm32 code is here https://github.com/espruino/Espruino/blo­b/master/targets/stm32/jshardware.c#L103­6 - check methods jshPinSetValue, jshPinGetValue

    also visible on board file changes https://gist.github.com/fanoush/7553104f­a7c8c596fe91f276d3f297fd/revisions is that there was other inverted flag used for pin configuration (got it from other stm32 board files) but it did not work as expected (or at all) so I removed it and added the nrf5x style NEGATED flag instead

    EDIT: fixed few more bugs and updated to latest
    https://filebin.ca/5hG1r5OvrY9N/espruino­_2v08.82_weactf411.bin

  • Hi - yes, it probably makes sense to pull in the pin negation code. Maybe #ifdef so it's not bloating boards where it isn't used (I should probably have done this on NRF52 too).

    I am not sure if this is actually good solution in NRF code

    Do you have other suggestions? If there's a better way of doing it I'd be interested.

    there was other inverted flag

    Yes, that'll help with things like the bootloader/espruino bootup. It's used when declaring stuff like:

    define LED1_PININDEX 18/* D18 */
    define LED1_ONSTATE 1
    

    But while it works fine when used from the C code, it doesn't work when accessing pins themselves

  • Do you have other suggestions? If there's a better way of doing it I'd be interested.

    Few ideas

    1. ifdef code and enable only if some pins are really negated in board file - you already mentioned it
    2. move this to common code if possible (?) so it is not in each port separately
    3. I am actually not sure what it should do and why and on what level this should be, is this mainly just for buttons and leds? So that in javascript code you can treat button/led in normal way - reading,writing, watching change? Will it work if the pull up/down are left alone and instead the negated flag would be visible flag on the Pin object (so you could even toggle it from js yourself on any pin?) because with such flag I'd left figuring out correct pulls on the user code too. So only value would be negated, not pull up/down, that is lot of complicated code. Also if only the BTN1 or LED1 would be negated but the underlying pin D13 not, it could also make the code handling 'normal' pins clear from this if Led and Button would be special object inherited from Pin. Then also the debouncing magic in setWatch in case of buttons would be more clear - watch on Button object would do it, watch on (same) Pin would not. Then maybe port specific code could drop it altogether and Pin and Led with this pin negation feature could be in common code.

    So to sum it up I think making negated flag on pins completely invisible/transparent including pull up/down is too heavy and too much magic. Letting user know about it and possibly handle it could be better. An also maybe this should not be feature of the pin at all but something more high level - button, led.

  • I'll all for ifdefing the code and maybe making it common...

    is this mainly just for buttons and leds?

    And vibration, heart rate/etc on watches. I'd also considered making some boards with motor drivers and it might get used there if the drivers were inverting.

    So that in javascript code you can treat button/led in normal way

    Yes - but also in Espruino's firmware as well.

    Will it work if the ... negated flag would be visible flag on the Pin object

    This was added because beginners complained a lot about 'why does the LED go off when I do LED.set()' and so on... and you're the first person to complain the other way so far...

    I think a very high percentage of beginners wouldn't want their first command - LED.set() to not work.

    However we could negate anyway, and it makes sense to expose the fact the pin is negated via pin.getInfo

    special object inherited from Pin

    It's not that easy if we want to allow people do use digitalPulse/analogWrite/etc on a LED or screen backlight - which are all pretty common things to want to do.

    While with 'virtual pins' we could handle it a little (at least for 'soft' PWM) that still requires a check inside jshPinSetValue - and is arguably a lot less efficient.

  • This was added because beginners complained a lot about 'why does the LED go off when I do LED.set()' and so on... and you're the first person to complain the other way so far...

    No, not complaining about this. This I would keep, but only this - inverting value. Not pull up/down. If you know what pin.setMode("input_pullup") means you can manage inverted flag and set it as pulldown yourself. beginners won't touch this, they will have their leds,buttons,motors already working. BTW are you inverting PWM duty cycle too?

    It was quite a surprise to me that in board file I must set pull the other way than it is for real, e.g. here https://github.com/espruino/Espruino/blo­b/master/boards/NRF52832DK.py#L70 it is in fact set as pullup! here I would really expect to set it like it really is.

    It's not that easy if we want to allow people do use digitalPulse/analogWrite/etc on a LED or screen backlight - which are all pretty common things to want to do.

    Well , I don't know how hard it is to implement it. As for behavior - when using BTN1, LED1 object it should do the magic (with everything that makes sense for that type of object - digitalPulse/analogWrite), when using underlying pin directly it should not do this. That would be least surprising to me. E.g. I have one board (E104-BT5032A-TB) where buttons and leds are enabled by jumpers and are inverted, if I disable the jumper and use the pin on the header directly as is and refer it by pin number, I would expect the pin to be not inverted.

    However we could negate anyway, and it makes sense to expose the fact the pin is negated via pin.getInfo

    yes

  • When thinking about it more, on one side it would be nice to e.g. add your own button or LED to e.g. MDBT42Q and do

    LED1 = new LED(D16,{inverted:true})
    

    currently those are only hardcoded.

    On the other hand the easiest method with just exposing inverted flag I can still have BTN1 and D27 to be same object and when I disconnect the jumper on that E104 board to use the pin directly I could flip the inverted flag to use pin as ordinary pin in sane way - e.g. as CS pin and pull it low by setting it to 0.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Espruino on STM32F4 discovery board

Posted by Avatar for IvanJ @IvanJ

Actions