New Project - too ambitious for someone between beginner and intermediate? - Page 1
Forum section: electronics / beginners

author: mortrek
author_rank: Contributor
timestamp: July 06, 2020, 09:52:28 pm
content: I finished a project and it works fine, but it's using a lot of premade modules and utilizes a bare AtMega328P which controls everything and sometimes uses a Raspberry Pi to do some more complex stuff.I was considering trying to create a completely new version of the project that uses an STM32 exclusively and eliminates as many external modules (voltage regulators, external ADCs and RTCs, etc) as possible. It'd need to interface w/a device as a USB host, connect to an LTE chip via a serial interface (if USB, it'd need a hub chip), store files on an SD card, and do so with minimal current consumption. I'd want to use a project with a bare STM32, at least in the final version, and not a dev board. I was considering trying HAL with a full STM32Cube stack to accomplish all of this, with a higher-end STM32L4 QFP64 chip. It'd basically be a clean, streamlined version of my old project.I'm not advanced, but not I'm not quite a beginner, but definitely closer to being a beginner. Is this too ambitious? I often slog through projects, fighting to get them working, but sometimes that drive isn't enough. Is this the sort of project that generally requires a professional engineer or even a team of engineers? Is it too ambitious for someone who isn't terribly advanced?Thank you.

author: garethw
author_rank: Regular Contributor
timestamp: July 07, 2020, 05:59:55 am
content: Definitely sounds like a good time to learn a new system. CubeMX is a good way to get you started but its quite easy to get reliant on it as you don't know what its doing. Some folks hate CubeMX but I found it to be a useful learning tool by using the LL drivers not the HAL ones.I made the jump from PIC to STM32 about 18 months ago. I went down the route of bare IC i.e. not a dev board, and designed my own basic board. My project uses a Bosch BME680 environment sensor which comes with a pre-compiled library for calculating the results from the sensor and it also configures the sensor for each read. It can measure air quality. There is also an LCD display, a dual digital potentiometer and an EEPROM for which I wrote all the drivers from scratch. The way that I write embedded software has changed dramatically during this project by using abstraction to separate the drivers from the interfaces etc and performing unit testing.Personally I think you will learn huge amounts taking on the project you described. If it sounds easy, you probably won't learn much.

author: tggzzz
author_rank: Super Contributor
timestamp: July 07, 2020, 06:44:19 am
content: I won't comment on the specific technology, nor your experience.Key questions for you to think about:what do you want to get from doing this (i.e. benefit)what are you prepared to lose by doing this (i.e. cost)if you stop halfway, do you have zero benefit, all the benefit, or somewhere in betweenwill this help you on the journey to whatever destination you chooseIn general it is good to choose a "stretch" goal that you have some chance of achieving. You will learn a lot, and will be able todemonstrategoal setting, learning, hard work, achievement, and the ability to assess how you would do better next time. Decent employers like that.

author: mortrek
author_rank: Contributor
timestamp: July 07, 2020, 01:46:12 pm
content: How hard is it to work with more advanced peripherals like USB over LL? Part of my problem is that I have limited free time to work on it, so I thought HAL might be a nice way to speed up development.While I wouldn't learn as much with HAL, does it still produce a good result? Also HAL/Cube has a ton of libraries that would prevent me from having to reinvent the wheel, like CDC and MTP libraries. I'm not sure how much work those would be with LL.Really my end-goal is to produce the final project. I'd love to have the time to get deep into low level stuff, but I doubt that I will any time soon. I'm not expecting to get employed as an engineer, but I do want to produce a project that isn't a total kludge. Would you still recommend I eschew HAL?

author: rstofer
author_rank: Super Contributor
timestamp: July 07, 2020, 01:55:48 pm
content: I would think that implementing USB Host would be a real challenge whether the factory provides some code or not. You probably need to come up with some kind of real time operating system, like FreeRTOS, and a port is often included in factory code. I would think the project to be so challenging that I would probably pass. I'm interested in the results, not the approach. If I can get something to work using a Raspberry Pi or an Arduino, that's the way I will go.If I decided to do something like this, I would start with the hard part (USB Host) and work toward the easy part.

author: robca
author_rank: Frequent Contributor
timestamp: July 07, 2020, 05:59:16 pm
content: I have programmed the STM32 chips using a lot of options: CubeMX with HAL, LL and changing registers directly. The new STM32CubeIDE is pretty good as a fully integrated environment, mostly based on Eclipse and with good debugging using either STLink or J LinkThere is no USB LL, though, only HAL. But the USB support is pretty solid, last I tried. And ST supports FreeRTOS (even if I'm not a big fan of it). ChibiOS also is well supported on the STM32 familyYou can freely mix HAL, LL and direct register access. I was working with a STM32H743 and needed to have very high performance ADC (6 Channels, 2MSPS per channel), so that portion of the code was written to directly access the ADC and DMA registers, other parts were using the HAL (even if I'm not a big fan of HAL, some parts are easier when using the HAL)As an alternative, Platformio with the Arduino core libraries (supported by ST directly) is probably the easiest way to get started. The ST Arduino core is based on the HAL, but has good performance. Also, given the relative low cost of most SM32 chips, sometimes it's easier to use a more powerful chip and write less efficient code. For example, the STM32H743 is so fast, that most optimization produces negligible gains (not all, clearly there are critical areas that can benefit from good, optimized code)

author: mortrek
author_rank: Contributor
timestamp: July 08, 2020, 01:24:41 am
content: QuoteWould FreeRTOS really make things easier, and not just complicate things? I don't really *need* processes AFAIK, it could be strictly single-process especially w/DMA and interrupts, although maybe having a scheduler/basic OS would make some things more efficient overall.I'm glad that it's easy to mix the code between register access/LL/HAL. They don't step on each others' toes too much then?QuoteSo the Arduino core is actually usable for more advanced stuff like USB? I was worried it was more of a kludge than a fully featured stack. Still, I'd kind of like to move away from Arduino coding a bit into something more professional, even if it's just HAL.--I have another somewhat-related question. Have you had any experience with high baudrate/bitrate USART/UART? Lilke 2Mbps or so? The datasheets say STM32L4 can handle up to 10Mbps, but I realize that may be hard to realize. I need to interface with a chip that has only low-speed i2c, USB over CDC-ACM (on the L4 that'd easiest at FS) or UART at speeds up to 3Mbps or so.I'd probably need to either hand-trim the internal clock (not good if I ever wanted to produce more of them...) or use a low-ppm trimming 32.728khz LSE to achieve such high rates, in addition to impedance matching, correct? By default the HSI16 clock is only 1% accurate, which I think isn't good enough for multi-megabit UART, right? If I don't use UART I'd have to use USB CDC-ACM, but I already have another USB device, so it'd mean using a hub, which adds complexity, so I'd like to try UART first.

author: tggzzz
author_rank: Super Contributor
timestamp: July 08, 2020, 07:31:43 am
content: Quote from: mortrek on July 08, 2020, 01:24:41 amLook at structuring the top-level design as a formal finite state machine. The single process waits until an event occurs, then processes it as defined by the current state, and changes the state if appropriate.Events are either caused by an interrupt, or a message arriving from some other entity.

author: robca
author_rank: Frequent Contributor
timestamp: July 08, 2020, 05:21:53 pm
content: Quote from: mortrek on July 08, 2020, 01:24:41 amHAL and LL can step on each other if you use both for the same peripheral (e.g. I2C using both HAL and LL, which is not recommended and hard to do by mistake anyway). If you use LL for, say, I2C and HAL for USB, there should be no problem at all. Most HAL functions call LL anyway, so they are compatible. The STM32CubeIDE allows you to choose what version to use on a component by component level. From the project manager tab, you select HAL or LL for each of the enabled peripherals. For USB, the only available option is HAL, for things like I2C, you can select HAL or LL from a drop downThe Arduino ST core is really mature by now, and officially supported by ST. It's on github, and if you find problems you can open an issue, they are pretty responsivehttps://github.com/stm32duino/Arduino_Core_STM32.I haven't used it that much recently, so can't answer specific questions. And Arduino gets a bad rap as a toy development environment, but modern Arduino development using Platformio is just like any other modern development environment with the advantage of a huge set of ready libraries. For example, if you need to use an LCD screen for your project, finding a native STM32 library is most of the times impossible, readily available for Arduino. And given how the ST core is developed, you can also use native CMSIS (e.g. DSP libraries) without problems. Here is the community forumhttps://www.stm32duino.com/For any specific UART question, you are better off searching and/or asking on the ST forumshttps://community.st.com/s/topic/0TO0X000000BSqSWAW/stm32-mcus.I'm sure I saw something about high speed UARTS. Please keep in mind that different STM32 families behave very differently in some case, so be sure to select a CPU based on your needs