STM32, BOOT0 pin. Could they make it more complicated? - Page 1
Forum section: electronics / beginners

author: PGPG
author_rank: Frequent Contributor
timestamp: January 10, 2025, 03:07:40 pm
content: Hi, Everyone.I want to design first small PCB for our first STM32L082KZT6 experiments (we never used any STM32 uC).I am at the state of defining this uC symbol. And I get into question where to put at symbol the BOOT0 pin. To decide I need to know:- will we have a need to change its state in our end applications?- if not than will it be permanently connected to GND (I will place it next to GND pins) or permanently connected to VCC (will be near VDD pins).In datasheet (page 26) I see that there are 3 boot options (Flash/System memory/RAM) that are selected by 2 bits (BOOT0 pin, and nBOOT1 option bit).I assume our application will be in Flash, bootloader is in System. I don't need boot from RAM so it is possible that I could have BOOT0 permanently connected but have to check which bit switches between Flash and System memory.Until now everything seems simple and logical. Only one simple information to find.Datasheet sends me for details to AN2606.It has 475 pages !!!--------------------------------Note added few days later:I found that I made mistake and following text is not true.In some texts STM32L082.. was referred as STM32L0x2... and I had this 2 in my memory so looking into AN2606 I went to STM32L02 instead of STM32L08.---------------------------------At page 296 I see that running bootloader is initiated by "Pattern 6" from Table 2.In Table 2 (page 31) I see that in Pattern 6 we have not 4 but 32 states because there are 5 bits to consider:- Boot0 (pin),- nBoot0(bit),- nBoot1(bit),- nBoot0_SW(bit),- flash memory empty/not empty.And making a Carnaugh table for these 32 states based on Table2 I will be only able to mark states that run Bootloader = boot from System memory.To find if having BOOT0 pin set to permanent state we will be able to boot from Flash or System it is not enough.I suppose that after reading this AN I will be able to decide what we will be doing with BOOT0 pin.But before reading I decided to ask:Do you know what practically is a function of BOOT0 pin?Can I connect it permanently and to what state?I am doing test PCB and I can just left a way to set its state at PCB, but I prefer to have 'good' symbols allowing to schematic look simply so even I will not connect it permanently now I want to have this pin logically positioned.There is a discovery kit we have got (https://www.st.com/en/evaluation-tools/32l0538discovery.html#documentation) but collecting all pdfs I didn't found any schematic that could may be tell me what they are doing with BOOT0 pin.Last few years we were using Silabs ARM based microcontrollers. I used their kit schematics to check how they are doing this or those.I don't understand why it depends on so many bits.

author: pcprogrammer
author_rank: Super Contributor
timestamp: January 10, 2025, 04:37:12 pm
content: It all depends on how you like to program the MCU.If you are going to use SWD with a ST-linkVx programmer then the boot0 pin can be tied to the correct level to select run from FLASH memory. I think ground, but would have to look at the datasheet and the manual you refer to, to validate this.If you want to program your MCU via serial or USB or whatever method the "bootloader" (system memory) offers, you will need the boot0 pin to be settable, and have it set high during programming, and for run time it has to be set low again. (If these are indeed the correct levels for that)For a blank MCU it will automatically start the "bootloader" despite the level of boot0, and then you can program it via the offered methods, or SWD, which always works after a reset.Why they made it like this, with the additional internal fuse bits, who knows. For a simple prototyping board it is not of much use I guess.

author: mwb1100
author_rank: Frequent Contributor
timestamp: January 10, 2025, 06:48:55 pm
content: Quote from: PGPG on January 10, 2025, 03:07:40 pmFor some reason stmicro removed the schematic from revision 4 of the UM1775 document. You can find revision 3 with the schematic here:-https://www.digikey.jp/htmldatasheets/production/1620007/0/0/1/stm32l0538-discovery-user-manual.html

author: PGPG
author_rank: Frequent Contributor
timestamp: January 10, 2025, 07:37:29 pm
content: I was doing something else so I didn't read this AN in more detail yet.Quote from: pcprogrammer on January 10, 2025, 04:37:12 pmThis sentence makes me thinking that in our case boot0 probably can be set to permanent state.1. When MCU is blank 'bootloader' starts despite the boot0 level.2. Using bootloader via USB we program our software.3. Next time MCU is not blank so starts our software (probably provided boot0 has correct state - what state - will have to find).4. If we need to get everything to beginning as you say SWD always work.I'm not writing microcontroller programs what in this case makes it difficult for me to exactly understand what's going on.We will be using this uC because it has 192kB flash while Silabs one we use has 64kB.Looking through my "production" program I found what we were doing with Silabs uC and I can summarize what we will need:1. Program our test program overwriting bootloader (Silabs USB bootloader reports to PC as COM port and allows to load (XMODEM-CRC) user program over it (destructive mode)).2. Get our Test program running.3. If in point 1. we will be using bootloader than in case something went wrong we need be able to reload original bootloader (Silabs developing boards contain programmer that can reload bootloader (via SWD) to user device.When we have Test program running than everything is under our control. Test program allows for hardware be tested, then allows to load destination device specific data and protect that data against following modifications and access and execute upgrade with the effect of replacing test program with device program).The best would be if I can do point 1. from PC by my program. With Silabs we were trying to do it via SWD and we were able to do almost everything but not everything and decided to use bootloader as it simply worked.At the moment I don't know how we will do 1. This Silabs were first ARM we used so I didn't know if bootloader we used is ARM or Silabs but it looks that ST has something different. Both bootloader and SWD ways are still in the game.Now I have to find how this boot0 pin is related to programming (Silabs don't have anything like that).

author: Siwastaja
author_rank: Super Contributor
timestamp: January 10, 2025, 07:42:00 pm
content: It is only as complicated as you make it.There is ONE pin which controls which of two things run. It can be set either '0' or '1'.Even if you choose to completely ignore what the "two things" are, probably one of them is your application.For a PCB, just add a pin or pad and test what happens when you tie it to GND. Then test what happens if you tie it to Vcc.Problem solved, without reading 475 pages.

author: PGPG
author_rank: Frequent Contributor
timestamp: January 10, 2025, 08:45:43 pm
content: Quote from: Siwastaja on January 10, 2025, 07:42:00 pmI know that such an approach exists, but it is absolutely contrary to my mentality. I always have to know 100% what and why.Already during my studies (long time ago), my friends laughed that if I got involved in something, it had to be 100% (or more) certain.Instead (like normal people) using some crypto library I have written all needed algorithms based directly on NIST documents to be sure that I know what is going on (down to single bit).I sow AES sorce code very speed optimized (everything done by MACRO and no function call) and very hard to read. My is as readable as possible without fighting for those few % speed.

author: Analog Kid
author_rank: Super Contributor
timestamp: January 10, 2025, 09:43:06 pm
content: Quote from: PGPG on January 10, 2025, 08:45:43 pmThink of that first PCB as a breadboard.Then just let people wonder why those 2 extra jumpers are there on the production boards.

author: Smokey
author_rank: Super Contributor
timestamp: January 10, 2025, 11:42:21 pm
content: Welcome to embedded systems...If you make it long enough to stick around, you may find that a technical reference manual with ONLY 475 pages becomes the new problem.

author: DavidAlfa
author_rank: Super Contributor
timestamp: January 10, 2025, 11:48:39 pm
content: BOOT0=1 is mainly used to boot the embedded bootloader and program it by DFU, UART etc.But 99.999% of the time BOOT0 is set to 0 and that's it, will run the code in the flash.You can still program it with any programmer just fine (STLink, JLink, DAPLink....BOOT0=1 is useful sometimes, for example if you disable SWD and reset pins in the firmware and you can't program it normally.

author: pcprogrammer
author_rank: Super Contributor
timestamp: January 11, 2025, 07:09:41 am
content: Quote from: PGPG on January 10, 2025, 07:37:29 pmThe "bootloader" in the STM32 devices can't be overwritten. It is in a separate ROM part of the MCU and is only used when either the FLASH is blank or, like DavidAlfa wrote, boot0 pin is high.You can write your own bootloader, but it will be in the FLASH memory and has to be part of your actual program to be able to use it every time the MCU starts. When you try to overwrite that bootloader with something that does not have code to support FLASH writing it will most likely fail, and you have to revert to using SWD.The simplest solution is to just add a pull down resistor and a jumper or switch to vcc connected to boot0. This way you can always set the MCU to start in system programming mode. The pin is only sampled on reset, so once started in system programming mode the pin can be low again.

author: DavidAlfa
author_rank: Super Contributor
timestamp: January 11, 2025, 08:16:44 am
content: Quote from: pcprogrammer on January 11, 2025, 07:09:41 amMaybe for modern STM32, definitely not in F series.

author: Siwastaja
author_rank: Super Contributor
timestamp: January 11, 2025, 10:50:48 am
content: Quote from: PGPG on January 10, 2025, 08:45:43 pmOf course, but do it iteratively. I mean, you start at 0% anyway. If you get stuck on trying to figure out all the logic behind BOOT0 pin for days, you are not going to ever get anywhere, because even when you master all the bootloader entering logic and BOOT0 evaluation logic behind all STM32 devices, you are now at 0.01% of your whole journey. In the same time, you could have learnt 1% instead. Don't get fixated over tiny details in the beginning. Fill in the gaps later.When you spin out your first board, avoid painting yourself in a corner. If unsure, fan the pins out to header pins or at very least small pads where you can solder a wire later.

author: AndyC_772
author_rank: Super Contributor
timestamp: January 11, 2025, 12:23:42 pm
content: I always just hard wire BOOT0 to ground. My products boot from Flash, and I can debug and program them using my dev tools via SWD using an ST-Link V2. I have my own bootloaders for doing field upgrades.Newer devices allow the effect of BOOT0 to be programmed via option bits, rendering the physical pin redundant once the option bits have been programmed. That might be useful if you really need the pin for something else, but it's not a feature I've found the need to use.

author: PGPG
author_rank: Frequent Contributor
timestamp: January 11, 2025, 03:53:17 pm
content: Quote from: pcprogrammer on January 11, 2025, 07:09:41 amSomething like a week ago I saw (here at EEVBlog) someone writing that in presence of EM field at 1/2 of his STM clock frequency his processor 'jumped' from his program into bootloader. And it was no 'once by accident', but he could get this effect many times. He was changing the field frequency and at other frequencies it didn't happened.If STM bootloader can't be overwritten should we be afraid that it can be someway used to hack our software...Quote from: Siwastaja on January 11, 2025, 10:50:48 amI will not be learning how to program this IC. I only have to know how to design PCB with it. So I need to know:- what I have to do with each non standard pins (some Silabses had for example integrated DCDC),- what quartz I can connect and how (Silabs for example had integrated in IC variable (digitally set) capacitors so you connected quartz alone, other Silabs allowed only for quartz from 38 MHz to 40MHz),- what I should do with Reset pin,- at what pins communications (UARTS, SPI, I2C) can be done,- what is GPIO sink/source max current,- what is the current consumption in RTC mode,- what is the A/D converter range (Silabs we used had planty possibilities, here it looks only VDD can be used),- how to connect to USB (do serial resistances are integrated, do pull-ups are integrated).When I asked I thought I know everything except:- what to do with Boot0 pin,- do I have to place out of IC resistors in USB connection.Both these looks needing to read App Notes.I will probably get back to reading this 475 page App Note on Monday. But yesterday I got a parcel with new version of devices that not passes my test program and I will have to take care of it first (does not pass the test - so much the worse for the test- test will have to be modified) so get back to STM may be Tuesday. I plan to order PCB (I didn't started yet) at Thursday as it is this months special offer day of our local PCB manufacturer (the price for their work with prototype PCB files is reduced from $20 to $0.25).So in my case getting these information is not starting 0.1% but last few % to get 100% of what I have to know.Quote from: AndyC_772 on January 11, 2025, 12:23:42 pmIn 80s when you bought EPROM programmer and new EPROM appeared on the market you had to send you programmer to its manufacturer to upgrade firmware.We (me and my brother) set-up our small company in 1988 and our first product was EPROM programmer. But none of our programmers never had to be send to us to upgrade firmware.When programming algorithm (like Quick-Pulse, if remember well) specified that at pin (say 21) you had to issue 5 pulses 1ms each we parameterized in it everything so we send the order to issue n pulses of t us at pin nr m. Future showed that IC manufacturers never get over of possibilities we integrated in our programmer so users had only to download new PC software.With next device (GAL and serial EEPROM programmer) we went step forward and our programmer had no knowledge of any algorithms. We used 8051 128 bytes RAM to load into it each programmed IC programming program and then do programming under its control. There were microcontroller stack, two working stacks (one for parameters and one for programmed data) and IC programming program - all in 128 bytes.When flash came we could start do things normally - each our device have bootloader.

author: pcprogrammer
author_rank: Super Contributor
timestamp: January 11, 2025, 05:03:06 pm
content: Quote from: DavidAlfa on January 11, 2025, 08:16:44 amThe original post specifically mentions STM32L082KZT6, and according to PGPG his research it has this feature. To find out which devices do have it, a read of the AN2606 document is needed.It mentions a lot of different patterns for a very large number of different MCU's and some of these patterns show the blank FLASH option being used.

author: pcprogrammer
author_rank: Super Contributor
timestamp: January 11, 2025, 05:09:25 pm
content: Quote from: PGPG on January 11, 2025, 03:53:17 pmThere are protection schemes that can be used to deny read back of the FLASH, but I have no idea if these protections also work when the "bootloader" is running. But these protections schemes are not water tight either. Things can be hacked, the question you can ask yourself is "is our software special enough to be targeted for a hack". When the answer is yes, you enter a whole new field of engineering, where you have to work on making your design as hack proof as possible.

author: radar_macgyver
author_rank: Frequent Contributor
timestamp: January 11, 2025, 05:40:21 pm
content: Quote from: AndyC_772 on January 11, 2025, 12:23:42 pmOn all the STM32s I've looked at, BOOT0 is a dedicated pin. BOOT1, if it exists, is often shared with GPIO.ST's documentationon thisis not ideal - instead of showing a simple truth table in the datasheet for a given device, they give you the run-around to look up stuff in the reference manual, then further in AN2606, and even within AN2606 one has to do several table lookups. Also, if you rely on the inbuilt bootloader, be aware that the USART pin mappings should match those in AN2606. Tools like CubeMX do not warn you about this when mapping out I/Os. It seems like the best approach is to get a Nucleo proto board and test your firmware on it before designing a board since there are so many interactions and limitations between the various on-chip subsystems.Just a heads-up in case it helps anyone else, some of the STM32L1xxx devices (Cat.5/Cat.6) provide dual-bank flash that is crippled in a strange way. The boot logic can be made to select the flash bank that's not empty (determined by the initial stack pointer stored at location 0), but unlike larger devices (L4xxx, for example) that offer dual-bank flash, there is no relocation of the flash so anything written to bank 2 must be statically linked to start from 0x08040000.Another example of ST's documentation chicanery: One erases an entire flash page, but programs ahalfpage (at least on an L1xxx).

author: PGPG
author_rank: Frequent Contributor
timestamp: January 11, 2025, 06:38:56 pm
content: Quote from: pcprogrammer on January 11, 2025, 05:09:25 pmI think all connected to net devices being no special in any case can be targeted for a hack nowadays.Imagine for example electric stove with the function that user, with his mobile phone can switch on to have something hot when he will come home (or any other IoT device).How much the manufacturer can pay the attacker for returning to normal situation if suddenly all his stoves all over the world are reported to switch on at random times not controlled by user.Yesterday I sow the information that Slovakia Real Estate Register was encrypted and attacker expect a 7-digit $ amount. In whole country no one can take out a mortgage, no one can sell real estate, etc.We manufacture access control systems. There are for example one our system installation with more than 100 points distributed over whole country managed from one place. So it is clear that we use internet for it.Recently the EU introduced the RS485 access system communication standard that we must meet to remain in the market. Its introduction in some respects means going back 10 years and in others, in our opinion, even to solutions from the 90s.I have read a book written in 2002 by two cryptology experts. They suggested that you should not use any of 4 symmetry cryptography modes that are most popular simply because they were described when DES was published. They suggested to use CTR mode. In their opinion CTR has the fewest flaws. I just believed their arguments and when few years later we introduced encrypted communication in our system we just used CTR mode. Later I sow that in SSL specification the suggested mode was changed from one of those 4 to CTR.And now EU introduces standard which forces us to change CTR to one of those not recommended by NIST modes (at the moment I don't remember which one - my brother has read it).

author: Siwastaja
author_rank: Super Contributor
timestamp: January 11, 2025, 07:12:03 pm
content: Quote from: PGPG on January 11, 2025, 03:53:17 pmOK. Then be careful and work in close co-operation with the one who writes the firmware.So far I have always worked for both PCB and firmware side of things and I have noticed nasty coupling between the two. For example: DMA channel mappings. You have to readvery carefullythrough all the reference manual to see if you canactuallyuse DMA for a peripheral in certain pins. It easily happens you miss the available mappings and design PCB such that it uses e.g. SPI1, UART1, I2C1, whatever, only to later notice when writing software that SPI1 and UART1 both cannot use DMA at the same time, but SPI1 and UART2 can, so you need to either live without DMA, or redesign the board.Also peripheral bugs not documented even in errata do appear.That is why I suggest trying to make quick iterations. I skip the "generic protoboard" phase completely and try to do PCB revision 1 (possibly with something that makes modifications easier like fan-out of extra pins) as early as possible, and while the PCBs are in manufacturing I immediately start writing firmware for which I try to do as complete test of all required peripherals as possible, even if it's just throwaway test code. Then I probably have time for revision 2 with the fixes I noticed while prototyping with revision 1.

author: PGPG
author_rank: Frequent Contributor
timestamp: January 12, 2025, 01:18:36 am
content: Quote from: Siwastaja on January 11, 2025, 07:12:03 pmI think we live without DMA at all.Our devices do not need big data transmissions.Quote from: Siwastaja on January 11, 2025, 07:12:03 pmI'm sure I was writing at EEVBlog that in past (±1992) we failed with one project because of bugs in PIC controller. We found 3 of them and found way around but the fourth one defeated us. We needed to get interrupt on incoming slope and typically once per 3000 slopes interrupt was not generated and we got no answer for fax we send to Microchip. We got errata describing 6 bugs more than year later. Described there way around to that bug was to add external slope synchronization (we just didn't get such idea ourselves, but we had not a big experience those days).With AtXmega only bugs which concerned us were higher brown-out voltages than you set and uC stopped working. To get out of that stage was to connect in paralel to local 3V3 regulator external 3.5V supply and then reprogram uC changing brown-out from 2.8 (really 3.3) down to 2.3 (really 2.8 ) (or something like that). In later uC revisions it was fixed.I expected that STM are so long in production that it should be free of bugs.At Friday I have finished reading this uC datasheet, and I know that I have got also errata, but didn't even opened this file yet.Quote from: Siwastaja on January 11, 2025, 07:12:03 pmIntention of our protoboard is to allow for debugging programs for all devices this processor will be used in, even if in product pin connections will be different.

author: PGPG
author_rank: Frequent Contributor
timestamp: January 14, 2025, 05:32:18 pm
content: When I came back to the subject I suddenly found (after some time being still in error) that I made a mistake in first post.STM32L082KZT6 in some selections (I was doing notes) was identified as STM32L0x2... and I remembered that 2.Because of this looking into AN2606 I have wrongly jumped to STM32L02... instead of STM32L08... and second half of my first post is simply not true.Unfortunately now I can't follow this subject. I am permanently in interrupts. This STM is interrupt to writing some PC application what is interrupt in experiments with several new antennas what is interrupt in one reader designing what was interrupt (several months ago) in some standard investigation and this oldest interrupt just a moment ago got highest priority.I will only write a note of being in error in first post, correct errors I have in my notes and will back to it may be in month time.Short look at Pattern 7 says me line 1 and line 3 should be one line with BFB2 just not listed. Search for BFB2 whole AN explains nothing...Why doesn't this surprise me?

author: silly sausage
author_rank: Regular Contributor
timestamp: January 19, 2025, 02:56:28 pm
content: is this board called a blue pill?.

author: tszaboo
author_rank: Super Contributor
timestamp: January 19, 2025, 04:19:25 pm
content: Quote from: PGPG on January 10, 2025, 03:07:40 pmYou are going to have a very bad time in this industry with this attitude.It's 475 pages long because it is well documented. It's a good thing. You have reference manuals, and reference boards with schematic published. And it's all in a language that you understand. And there are plenty of examples available. Not something that nobody ever built before.

author: Siwastaja
author_rank: Super Contributor
timestamp: January 19, 2025, 04:41:52 pm
content: Quote from: tszaboo on January 19, 2025, 04:19:25 pmYeah. I never understood all the complaining of having a lot of pages. Surely we have things liketable of contents, and nowadays in computer/pdf era stuff liketext search. It's not like you have to read all that 475 pages at once.

author: pcprogrammer
author_rank: Super Contributor
timestamp: January 19, 2025, 06:05:35 pm
content: Quote from: silly sausage on January 19, 2025, 02:56:28 pmThe name blue pill is usually used for the board with a STM32F103C8T6 on it. Black pill is used for the board with either a STM32F401 or STM32F411.There are so many STM32 based boards on the market that it gets confusing though.