Help me design a board around an STM32L4 - Page 1
Forum section: electronics / projects

author: IamSynthetiC
author_rank: Regular Contributor
timestamp: February 11, 2021, 08:54:11 pm
content: Greetings, I am designing a very simple Nixie Tube Clock, and decided to use and STM32L4 as the brain. I have never previously used an STM32 and I am not fully certain whether what I am doing is correct. Hence, i would appreciate a second, experienced, look on my design.The plan is for an external RTC (DS3231) to interupt the STM32 through its PPS, and the STM32 to load the time onto the Nixies through 2xHV5122. Along with an ambient light sensor, the STM32 must turn the nixies off when it is late, and there is no light in the room.Any tips, hints, flaws, or mistakes you might point out are more than welcome.Thanks in advance.

author: thm_w
author_rank: Super Contributor
timestamp: February 12, 2021, 12:00:21 am
content: - STM32L4 has internal RTC (just need 32.768kHz crystal) if you want. You already seem to have wired it up, although you labeled it "32MHz".- Your 3.3V rail is going to dump power into your battery, if its not rechargeable you may not want that- Not sure how your level shifters work, you can google "fet level shifter" and find existing circuits to copy (egthis article)

author: SiliconWizard
author_rank: Super Contributor
timestamp: February 12, 2021, 12:26:49 am
content: Never used Nixie tubes, so I can't comment on that part.Adding to what thm_w said:* Yes, this MCU has an internal RTC, so you could save the DS3231, although I'm guessing you chose it for better accuracy, and you'll indeed get better than the internal RTC and an external 32kHz crystal. But if the accuracy/drift you'd get with the internal RTC is adequate for your needs, something to consider to save some parts. This STM32L4 is a very low power MCU, and in the appropriate stop or standby mode, it would draw no more power than then DS3231 - maybe actually less. So you can absolutely use it as a permanent RTC, and wake up the CPU every second (if your clock is displaying seconds) or even every minute if not, update the display, and get back to sleep.* You don't need all those oscillators. Since you're not using the internal RTC, you can do without the 32kHz crystal. Yes I suppose 32 "MHz" is a typo. The secondary oscillator can't oscillate that fast anyway, it's really made for 32kHz crystals. You can even do without the other oscillator (HSE). Why a full-blown oscillator anyway and not a crystal? (Could be to save a pin on the MCU, but you're not even using all of them...) The system could absolutely do without the two, the internal oscillator would be more than adequate for what the MCU has to do. But, I see you have an USB connection, and USB will be more stable with a crystal - although I've heard people getting USB to work fine only from the internal oscillator. Anyway, USB seems the only reason here to use a crystal. I'd get rid of the secondary oscillator and the 32kHz crystal and would keep only one crystal using the HSE oscillator, not a full external oscillator. That'll be less expensive. I think 12MHz would be adequate to generate the proper internal frequency for USB. The MCU has internal oscillators, so you can use them coupled to timers to wake-up the device even when the HSE is stopped (to save power).* Not sure what the JTDI signal is for (JTAG interface.) This MCU supports SWD, and the only required signals are SWDIO and SWCLK, NRST ideally as well (so the probe can reset the CPU, required if it's in low-power mode), and SWO for debugging purposes, although this last one is optional.* Rotary switch: I suppose this is a rotary encoder? I'd suggest doing some analog filtering with capacitors. Sure you can debounce in software, but without this analog filtering, the signals will be very bouncy, and may give you some headaches software-wise. Look that up in any datasheet for a rotary encoders, most of them include a small schematic showing how to do this.* I also don't think your 'level shifters' will work properly as is.

author: pigrew
author_rank: Frequent Contributor
timestamp: February 12, 2021, 04:13:30 am
content: ST suggests putting a 100nF capacitor from nRST to GND for better noise immunity. It's probably not required, but not a bad idea.The Zeners on the current sense lines won't work as drawn. They'll try to pull the power rails down to 3.5V, got hot, and release smoke. You may want to put a filter capacitor on the amplifers' outputs. Add decoupling capacitor for the INA138's power supply pins.Since you might be doing "self-powered" USB, it's a good idea to route VBUS to the MCU (through a voltage divider), so the MCU can tell if a USB host is connected. Some MCUs will have a special pin for this use.Did you get the MCU wrong? The STM32L431 does not have USB. Anyway.... why do you need a STM32L4? Why not use a STM32L0? Does low-power matter? Probably not, tube heaters and all....I would normally use the RTC internal to the MCU (instead of the external one), except this package doesn't provide a VBAT pin, so you can't power it in the background without the rest of the MCU being power. Then again... the MCU might be so low power that it's OK to keep the whole thing powered.

author: IamSynthetiC
author_rank: Regular Contributor
timestamp: February 12, 2021, 04:53:49 pm
content: I have corected the level shifter circuit and checked it with LTspice just to be sure.I have also added HW filtering to the rotary switch. A simple RC filter should do the trick.Quote from: SiliconWizard on February 12, 2021, 12:26:49 amI first selected my microcontroller through STM32CubeMX, and then followed the pinout from there.When i select the HSE on the RCC tab, the only pin that comes up is the RCC_CK_IN (pin 6) and nothing else. I assumed it needed an oscilator instead of a crystal. PC14 and PC15 where for the LSE which i now disabled.Quote from: SiliconWizard on February 12, 2021, 12:26:49 amoops, i meant to use SWD, with SWO, but i messed up at the very start, and followed all the way through. Thanks for the catch.Quote from: pigrew on February 12, 2021, 04:13:30 amoops again, i though of the differential pair as one voltage away from GND. I removed the zenners and added the capacitors.Quote from: pigrew on February 12, 2021, 04:13:30 amI wanted to familiarize my self with them for future projects (some sensors i want to add to my bicycle). And also they were the cheapest to find

author: SiliconWizard
author_rank: Super Contributor
timestamp: February 12, 2021, 06:38:08 pm
content: * As pigrew said, the STM32L431 doesn't support USB. So if you really want USB, you need to select something else. The closest match would be the STM32L432.* Are you sure you want/need USB? That looks overkill for just a clock. If you don't implement USB, you'll save a few parts, significant code as well, and then you definitely won't need any external crystal or oscillator. The internal oscillators would be adequate.* From the DS, the L431 definitely allows you to use a crystal for the HSE oscillator (OSC_IN and OSC_OUT pins). The schematic mentions "STM32L412" on the frame around the MCU. Are you sure you didn't mixed up MCUs at some point?Anyway, unless you did something wrong, I wouldn't trust this CubeMX for selecting the part, especially if you're new to this line of MCUs. Apparently it didn't even help you see that there was no USB controller inside the L431. You should definitely check out the datasheets, and start here:https://www.st.com/en/microcontrollers-microprocessors/stm32l4-series.html

author: IamSynthetiC
author_rank: Regular Contributor
timestamp: February 12, 2021, 08:29:48 pm
content: It seems i somehow deleted the last part of my previous reply where i was mentioning this. I was deisgning around the STM32L412 not the STM32L431. KiCAD had no symbol for the L412, but i noticed the L431 is similar enough to the L412 that it would suffice. But as pigrew mentioned :Quote from: pigrew on February 12, 2021, 04:13:30 amL series STM32 doesnt make much sense here. So after a short search, i found the STM32F031K, which has all the conectivity and IO i need, and also come at around 0.9$.As for the USB, you are definitely right, it seems out of place. So to program the STM32F031, without a USB port, i would need to expose the UART pins, and then connect them through a USB-to-TTL to my PC, right ? no extra fuss ?

author: SiliconWizard
author_rank: Super Contributor
timestamp: February 12, 2021, 08:40:27 pm
content: Quote from: IamSynthetiC on February 12, 2021, 08:29:48 pmThis would explain the confusion as to the specs. (Edit: I miscounted the pins on your CubeMX capture. There are 32 pins)But the very limited number of pins on this L412 would explain why you can't use a crystal for HSE here. Which is a pain. I'd suggest using a version with a bit more pins (and in this case, you'll be able to use a crystal instead of the external oscillator). The L412 seems to be only available with 32 pins. Maybe going for a L432 instead (with more package options) would make more sense. It may be a little more expensive, but frankly, in a circuit with Nixie tubes, the cost of the MCU is probably negligible...Regarding your level shifters, they look correct now. The fact they are inverting should of course be taken into account, I suppose you have.Regarding the rotary encoder, I think it's more common to tie the "C" pin to ground, and add pull-up resistors to Vcc at the "A" and "B" pins. The way you did it here, with the filtering, I'm not sure the signal will ever really get to a logic "low" at the MCU inputs?

author: IamSynthetiC
author_rank: Regular Contributor
timestamp: February 12, 2021, 10:18:02 pm
content: Quote from: SiliconWizard on February 12, 2021, 08:40:27 pmI was thinking of using the microcontroller to pull-up or pull-down the signals. Out of curiocity i wanted to do some research on this. Something tells me though that for 2 resistors, worth a few cents, the risk involved isn't worth it.Quote from: SiliconWizard on February 12, 2021, 08:40:27 pmI have, it should be easy enough to invert the data in software. After all i am merelyshifting dataout.Regarding the cost, i found a friend who was selling some Nixies, and sold me 50 tubes for 60 euros and a fewbearsbeers, obviously;D. It was a good deal. As for the boards, i want to build at least 6 of them to give out to loved ones and relatives, so the cost can quickly add up.