ioc file from the STM32CubeMX
folny opened this issue · 11 comments
Hi
Can you please add the .ioc file from the STM32CubeMX program to the project ?. I would like to modify your project for a different type of processor and it would be easier for me.
Sorry, I don't have it anymore.. It was just an empty CubeProject without any configuration though, as I configured everything in code and just needed the CMSIS and some initalization files. Not sure if that would be of any help even if I had it :/
The biggest change will probably be the usb peripheral though, as the USB-memory works differently on different devices.
For the clocktree you'll just have to make sure to fix the enabled subcircuit-addresses if they change. The USART and DMA-mapping can be altered directly in the usart header/config, without digging in the code (ideally...)
Thank you for your reply
So I will try what I can, I also want to ask which library I can use instead of lwip@bef26c4 because it is unavailable.
Sure. If you have any questions regarding the adjustment of the configuration feel free to ask.
Regarding lwip: It works for me. After cloning the directory will be empty, because it is a submodule (i.e. the git repository is somewhere else). You can initialize the the lwip-submodule by running git submodule update --init
Thanks for the advice, everything is working now. I bought this development board and I would like to modify your project for it, how can I change the processor type in the STM32CubeIDE program as easily as possible ?. I use Keil ARM for my projects and I don't know all the features in STM32CubeIDE. I would like to use your code without LCD dip switches and only use 2 output universes.
https://github.com/WeActStudio/WeActStudio.STM32G474CoreBoard
To do these adjustments, you'll have to do the following to the code.
CubeMX
To get an overview of the necessary changes, open the CubeMX-Tool (which is a separate download - or grab the info from the datasheet, but thats way more work..)
You won't need the generated code, but it's an easy way to reference the configuration and make sure nothing clashes.
-
Select your Processor (STM32G474CEU6)
then double click one of the two entries. -
Enable all Peripherals
Under Connectivity, select two Usarts that are convenient for you and enable them by setting their Mode toAsynchronous
. Also enable the USB.
This will show you which pins to use for which peripheral when wiring things up. Check if the selected ones are also exposed on the breadboard.
-
Enable Clock
Under SystemClock > RCC, set HSE toCrystal/Ceramic Resonator
-
Configure Clock
Go to Clock Configuration and selectNo
. The main clock for this board seems to be 8MHz, so we can leave the Input Frequency. Now adjust the PLL until the sysclock has 144MHz. (M=1, N=36, /R=2, /Q=6 seems fine).
main.c
-
Adjust Clock_Init with the values as displayed in CubeMX. The correct register values for the parameters are in the RCC-Section of the datasheet for the PLLCFGR-Register
-
Adjust peripheral clocks. I don't know if the clocktree is exactly the same or where the peripherals you picked are located, so make sure to enable their respective clock.
-
Adjust GPIO_Init to set the ports and alternate modes correctly
-
Replace ReadPortConfig with a fixed initial value for your input/outputs
usart.c
- Change the first two entries according to your configuration. For DRPort/DRPin, pick any that are free. They go to RE/DE of the RS485-Transceiver.
Regarding only 2 ports
Actually probably a good idea to make that a constant somewhere...
For now, you'll have to search all files for the string ' < 4' and adjust it to ' < 2' to reduce the number of ports. That should be safe, I think...
If you want to adjust the webpage as well, you'll have to adjust the Inc/eth/fs/index.html and replace the ' < 4' in there as well. After that, run the index.html through a minifier, copy that into the min directory and get a copy of the "makefsdata" tool from lwip to run it on that min directory.
Thanks for the great advice, I'll try it all out soon and let you know how it goes.
Hi
I couldn't run your project on this board, so I'm asking if you could take a look at it and write me how to set the clock and GPIO parameters exactly according to the attached file. I will be very grateful for your help.
I don't have a board, so I can't verify anything I say 😅
For the first step, I would comment everything in main.c
starting at GPIO_Init()
, so that only the clock and systick are initialized. In Clock_Init
, I'd comment everything between "Select & Enable IO Clocks" and the while loop. A Breakpoint after Clock_Init
allows you to inspect the variable "SystemCoreClock", which will hold the Sysclk
in Hertz, which should be 144000000
.
Having a quick glance, the value for PLLN seems wrong (23, should be 36 according to cube clock tree). PLLM also seems wrong; by setting RCC_PLLCFGR_PLLM_0
you set the PLLM-Value to 01
, which should be /2
if memory serves me correct. Removing that value to leave PLLM at 00
should set it to /1
.
If you run into the HardFault handler, there is probably something wrong with the high-speed transition (Every HCLK > ~75Mhz or something needs to adjust the flash access speeds). To verify this is the cause, you can then comment the block "Select PLL as main clock...." except for the first line directly following that comment. This will turn of the high speed transition and leave the HCLK at half the SYSCLK. To fix it, you'll have to consult the datasheet for the chip on how to exactly transition into high speed on that chip.
If the SystemCoreClock
-Variable holds the correct value, the clock is configured and working as expected.
The next step will be to enable the peripheral clocks again (the block you commented out after "Select & Enable IO Clocks"). It should work as is, if there are no compile errors. If there are, the register layout changed and needs to be adjusted.
If that works, you can start with the peripherals. I can do another writeup for where in the datasheet the required information for the register configuration is.
Thanks for the advice, but it doesn't work, even if I set the clock correctly, the usb appears as an unknown device.
Hm, that is unfortunate. Debugging USB is always half a pain in the butt.
Some pointers to get started and finding out what's going on:
- Generally don't place any breakpoints after
USB_Init
was called until the enumeration is completed. USB has a pretty tight timing and any breakpoint will result in a failed enumeration. - Now break rule 1 😀. Place a breakpoint in line 348 of
usb.c
, it should be just below thecase 0x05: // Set Address
-line. This breakpoint will verify if communication even works at all.
If you hit the breakpoint, there is probably something wrong with the descriptor. Get a copy of the Thesycon USB Descriptor Dumper and post the log of the enumeration process. This tool will record the enumeration and all the device descriptors and also tell if something is wrong with them.
If you don't hit the breakpoint, my guess is that the clock speed for the USB-Subcircuit is not configured correctly. If your main sysclk is running at the expected 144MHz, check the PPLQ-settings (should divide by 6) and your CK48-Clock Mux (should be set to PLLQ). To verify an issue with your PLLQ-value, you can also temporarly switch the CK48 clock mux to HSI48 (don't forget to enable it in RCC_CRRCR). It's less reliable, but works. If it still doesn't hit that breakpoint, make sure the subcircuit is even enabled (USBEN in one of the RCC_APBxENRx-Registers)
If that doesn't lead to any new data, I'll have to think some more.
The problem is only in the clock settings, when I replaced the 8Mhz resonator with a 25Mhz one, everything started working.