You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the lgt8f328p is 100% compatible with the ATmega328p then there should be no problems. Just install the board support packages and load the library as usual. The sketch upload mechanism is different to the ATmega328p, but this won't affect the building of binary files.
But I'm thinking that there may be some issues with the WDT triggering options, if it is not actually 100% compatible, as noted here. It may just be a fuse setting issue for the individual boards, which can be corrected in boards.txt (by comparison with the lgt8f328p datasheet), but it may be a hardware implementation issue. And if so then one of the other Timers will need to be configured to provide the System Tick.
I have noticed that the lgt8f328p has four timers (one more than the ATmega328P), so it might be possible to use Timer3 (8 bit 16 bit timer) for tick generation ...
Maybe it's possible to use THIS tool to generate the appropriate code for timer3.
Yes. Did not know that. That is good as it won't break Arduino code. And it will be more configurable for different intervals.
Further examples at avrfreertos, show how Timer0 (an 8 bit Timer) can be configured for ATmega328p. Timer3 will probably be no more difficult than exchanging 0 for 3 in the code in this case.
Note that ATmega1284p Timer3 is 16 bit so is not a good example here.
thanks all for your feedback. Not sure I am following. Finally what would be your recommendation to make it work? I confirm that the code as it is not working.
Here are the constants for Timer0 which may be the same as Timer3.
Here is the interrupt configuration. And here the interrupt needs to be adjusted too.
Basically read the FreeRTOS10 code and replace Timer0 with Timer3 (assuming that it is configured the same, confirmed by reading the data sheet). These relevant functions need to be added (or exchanged) into the library code to implement the special 8 bit Timer.
Regarding my previous post, upon closer inspection of the various "translations from Chinese" of the datasheet, it appears that Timer 3 of the LGT8F328 is a 16-bit timer, not an 8-bit timer.
From the datasheet:
Overview
TC3 is a general purpose 16-bit Timer/Counter module, with PWM support. It allows accurate wave generation.
Some news ...
... using the "dbuezas" Arduino core for LGT8F328 we have the capability to use the WDT in "interrupt" mode (see the wdt_interrupt example).
Unfortunately, the WDT basically works with an internal clock of 32 KHz and the shortest interrupt time that can be achieved with this clock is 64 ms.
I am working on modifying the library (WDT.h) so that it has the ability to have the wdt work both at 32 KHz and at (32 MHz / 16), thus being able to have the possibility of interrupts at 16 ms (and even less: 8, 4, 2, 1).
Once this is done, I will try to modify the port.c to use the wdt in this way ...
Any suggestions?
Sorry Phillip,
but all the suggestions I see you making are related to avrfreertos ... however, I believe that both the OP and I, we are interested in changing the Arduino_FreeRTOS_Library library ...
Can you make any suggestions and refer to the files of the said library?
Thanks in advance,
I'm providing avrfreertos as an example or reference, as the kind of thing you are trying to achieve has been done there already. Specifically alternate MCUs, alternate boards, and alternate Timers. Just treat it as reference material.
Arduino_FreeRTOS is simple by design with one Timer setup and all the potential alternatives and definitions are not present. So there's no examples there to see, unfortunately.
In an Arduino Library, it also difficult to make things configurable. And all the MCU resources are normally utilised by Arduino, so it becomes quite tricky not to break something a new or less technical user would expect to "just work".
I've pushed an update that might make things work, provided the board definitions are installed correctly.
I'm a bit confused at to what the most generic term for the LGT8F328P is. It is referred to in the variant files under different definitions, and there doesn't seem to be a hierarchy present so I went with below.
Please test it to see what happens. I'm not holding my breath though.
Yes, actually it is not going to work properly, as the WDTO_15MS definition doesn't match what's provided, and so the timing will be completely out.
There are many further changes required to how the WDT is configured, as you point out @gpb01. It would be best to get the fast WDT interrupt code sorted out by PR into the Library first, then I can pick that up and continue here. Otherwise I end up replicating what should be device specific library code.
Thanks, I'll modify to use that definition soon.
I also need to add the lgtwdt.begin() function to the startup() code too.
It would be ideal if your core WDT improvement PR could define similarly named functions for use of the WDT as are in use with the 'avr-libc/wdt.h` file and the additional interrupt function and interrupt+reset function I've added, that way only the correct header would need to be selected and defined, rather than needing to define alternate functions too.
I don't know if that would create namespace issues, but I think not.
Phillip,
thinking about it, to avoid modifications with the WDT and make the library independent of a specific core, would perhaps be better to use Timer 3, which, by the way, does not exist on the ATmega328P and is therefore normally free ...
This is the initialization routine to get an interrupt every 15 msec:
thinking about it, to avoid modifications with the WDT and make the library independent of a specific core, would perhaps be better to use Timer 3, which, by the way, does not exist on the ATmega328P and is therefore normally free.
Rather than put more definitions in the main code base for just one clone MCU, I would prefer to have a PR suggestion to add the LGT8F Timer 3 using the mechanism documented. Then we can add code examples specifically for the LGT8F without clouding the code for all other (formerly) AVR devices.
If you could test the suggested PR and add some notes or documentation so that people can follow along, I can add that much more quickly I believe.
Hi Phillip,
I looked the example you provide for Timer 0 and ...
I did not understand how and who includes the .cpp file you provide (tick_sources_timer0.cpp) in the project.
In the above file I see the function "prvSetupTimerInterrupt", I see the definition of the ISR, but I do NOT see:
2.1 vPortEndScheduler ... which, obviously, in the case of using a Timer, must be provided.
2.2 I don't understand how to connect the ISR defined in "tick_sources_timer0.cpp" with the various conditions where "configUSE_PREEMPTION" is 0 or is 1 (different things need to be done inside the ISR)
Can you provide clarification ...
Thank you,
Guglielmo
P.S.: Another strange thing ... If I compile the program that I indicated HERE everything is fine and there are no errors; if I try to include Timer 3 related definitions directly inside "FreeRTOSVariant.h" or inside "port.c" I get errors as if it no longer recognizes the existence of Timer 3 ... what am I doing wrong?
Now I have an Arduino_FreeRTOS library working on LGT8F328 using Timer 3 for ticks :-) , but ... I inserted the code inside "port.c" because I am not clear on how to use the external .cpp as you have indicated :-\
Activity
feilipu commentedon Aug 4, 2023
If the lgt8f328p is 100% compatible with the ATmega328p then there should be no problems. Just install the board support packages and load the library as usual. The sketch upload mechanism is different to the ATmega328p, but this won't affect the building of binary files.
But I'm thinking that there may be some issues with the WDT triggering options, if it is not actually 100% compatible, as noted here. It may just be a fuse setting issue for the individual boards, which can be corrected in
boards.txt(by comparison with the lgt8f328p datasheet), but it may be a hardware implementation issue. And if so then one of the other Timers will need to be configured to provide the System Tick.feilipu commentedon Aug 17, 2023
Any luck? If so, please let me know.
mchacher commentedon Aug 17, 2023
Hi I didn’t dig further since I don’t have the tech skills. I would be still interested having support. I can do some testing to help
gpb01 commentedon Aug 17, 2023
I have noticed that the lgt8f328p has four timers (one more than the ATmega328P), so it might be possible to use Timer3 (
8 bit16 bit timer) for tick generation ...Maybe it's possible to use THIS tool to generate the appropriate code for timer3.
Guglielmo
feilipu commentedon Aug 18, 2023
Yes. Did not know that. That is good as it won't break Arduino code. And it will be more configurable for different intervals.
Further examples at avrfreertos, show how Timer0 (an 8 bit Timer) can be configured for ATmega328p. Timer3 will probably be no more difficult than exchanging 0 for 3 in the code in this case.
Note that ATmega1284p Timer3 is 16 bit so is not a good example here.
mchacher commentedon Aug 18, 2023
thanks all for your feedback. Not sure I am following. Finally what would be your recommendation to make it work? I confirm that the code as it is not working.
feilipu commentedon Aug 18, 2023
Here are the constants for Timer0 which may be the same as Timer3.
Here is the interrupt configuration. And here the interrupt needs to be adjusted too.
Basically read the FreeRTOS10 code and replace Timer0 with Timer3 (assuming that it is configured the same, confirmed by reading the data sheet). These relevant functions need to be added (or exchanged) into the library code to implement the special 8 bit Timer.
gpb01 commentedon Aug 20, 2023
Regarding my previous post, upon closer inspection of the various "translations from Chinese" of the datasheet, it appears that Timer 3 of the LGT8F328 is a 16-bit timer, not an 8-bit timer.
From the datasheet:
Guglielmo
gpb01 commentedon Aug 23, 2023
Some news ...
... using the "dbuezas" Arduino core for LGT8F328 we have the capability to use the WDT in "interrupt" mode (see the wdt_interrupt example).
Unfortunately, the WDT basically works with an internal clock of 32 KHz and the shortest interrupt time that can be achieved with this clock is 64 ms.
I am working on modifying the library (WDT.h) so that it has the ability to have the wdt work both at 32 KHz and at (32 MHz / 16), thus being able to have the possibility of interrupts at 16 ms (and even less: 8, 4, 2, 1).
Once this is done, I will try to modify the port.c to use the wdt in this way ...
Any suggestions?
Thanks a lot,
Guglielmo
feilipu commentedon Aug 23, 2023
Good to hear. I suggest following the conventions in avrfreertos
port.cfor naming the System Tick source.For example
portUSE_WDTOis used for the standard WDT. Perhaps useportUSE_WDT_LGT8F328or similar.These definitions are selected in
FreeRTOSBoardDefs.hbased on the Board being used, from compiler provided definitions.gpb01 commentedon Aug 24, 2023
Sorry Phillip,
but all the suggestions I see you making are related to avrfreertos ... however, I believe that both the OP and I, we are interested in changing the Arduino_FreeRTOS_Library library ...
Can you make any suggestions and refer to the files of the said library?
Thanks in advance,
Guglielmo
feilipu commentedon Aug 24, 2023
I'm providing
avrfreertosas an example or reference, as the kind of thing you are trying to achieve has been done there already. Specifically alternate MCUs, alternate boards, and alternate Timers. Just treat it as reference material.Arduino_FreeRTOSis simple by design with one Timer setup and all the potential alternatives and definitions are not present. So there's no examples there to see, unfortunately.In an Arduino Library, it also difficult to make things configurable. And all the MCU resources are normally utilised by Arduino, so it becomes quite tricky not to break something a new or less technical user would expect to "just work".
feilipu commentedon Aug 24, 2023
I've pushed an update that might make things work, provided the board definitions are installed correctly.
I'm a bit confused at to what the most generic term for the LGT8F328P is. It is referred to in the variant files under different definitions, and there doesn't seem to be a hierarchy present so I went with below.
Please test it to see what happens. I'm not holding my breath though.
Yes, actually it is not going to work properly, as the
WDTO_15MSdefinition doesn't match what's provided, and so the timing will be completely out.There are many further changes required to how the WDT is configured, as you point out @gpb01. It would be best to get the fast WDT interrupt code sorted out by PR into the Library first, then I can pick that up and continue here. Otherwise I end up replicating what should be device specific library code.
gpb01 commentedon Aug 28, 2023
Hi Phillip,
just a point of clarification ... looking at the detail of the compilation string used by core of "dbuezas" I see:
-mmcu=atmega328p -DSERIAL_RX_BUFFER_SIZE=64 -DCLOCK_SOURCE=2 -DF_CPU=(16000000L/1) -DF_OSC=16000000L -DF_DIV=1 -DARDUINO=10819 -DARDUINO_AVR_LARDU_328E -DARDUINO_ARCH_AVRso ... no reference to the id referenced in your previous post (maybe they are automatically defined by the compiler).
In any case, since the change to WDT is only present in the core of "dbuezas" and not in other cores for LGT8F328P, I suggest using:
...what I believe is unique to the above core :-)
Guglielmo
feilipu commentedon Aug 28, 2023
Thanks, I'll modify to use that definition soon.
I also need to add the
lgtwdt.begin()function to thestartup()code too.It would be ideal if your core WDT improvement PR could define similarly named functions for use of the WDT as are in use with the 'avr-libc/wdt.h` file and the additional interrupt function and interrupt+reset function I've added, that way only the correct header would need to be selected and defined, rather than needing to define alternate functions too.
I don't know if that would create namespace issues, but I think not.
gpb01 commentedon Aug 28, 2023
Phillip,
thinking about it, to avoid modifications with the WDT and make the library independent of a specific core, would perhaps be better to use Timer 3, which, by the way, does not exist on the ATmega328P and is therefore normally free ...
This is the initialization routine to get an interrupt every 15 msec:
and this is the definition of ISR being called:
... could make it simpler and more generic (not tied to a specific core)?
Guglielmo
feilipu commentedon Aug 28, 2023
Recently an alternate configuration of Timer 0 was removed from the main code and moved to an external definition, together with documentation on how to define alternative System Tick Timer sources.
Rather than put more definitions in the main code base for just one clone MCU, I would prefer to have a PR suggestion to add the LGT8F Timer 3 using the mechanism documented. Then we can add code examples specifically for the LGT8F without clouding the code for all other (formerly) AVR devices.
If you could test the suggested PR and add some notes or documentation so that people can follow along, I can add that much more quickly I believe.
What I would find really nice is using the Timer defines mechanism from avrfreertos so that the configuration of Timers is then generalised as shown here. Though that may be too extensive for what we need to achieve here.
gpb01 commentedon Aug 30, 2023
Hi Phillip,
I looked the example you provide for Timer 0 and ...
I did not understand how and who includes the .cpp file you provide (tick_sources_timer0.cpp) in the project.
In the above file I see the function "prvSetupTimerInterrupt", I see the definition of the ISR, but I do NOT see:
2.1 vPortEndScheduler ... which, obviously, in the case of using a Timer, must be provided.
2.2 I don't understand how to connect the ISR defined in "tick_sources_timer0.cpp" with the various conditions where "configUSE_PREEMPTION" is 0 or is 1 (different things need to be done inside the ISR)
Can you provide clarification ...
Thank you,
Guglielmo
P.S.: Another strange thing ... If I compile the program that I indicated HERE everything is fine and there are no errors; if I try to include Timer 3 related definitions directly inside "FreeRTOSVariant.h" or inside "port.c" I get errors as if it no longer recognizes the existence of Timer 3 ... what am I doing wrong?
gpb01 commentedon Aug 30, 2023
Ok ... problem solved ... I had to add the following:
to include the definition file lgtx8p.h
Now I have an Arduino_FreeRTOS library working on LGT8F328 using Timer 3 for ticks :-) , but ... I inserted the code inside "port.c" because I am not clear on how to use the external .cpp as you have indicated :-\
Guglielmo
feilipu commentedon Aug 30, 2023
Good news.
Please prepare a PR so I can see exactly how you did it. I will use that as a guide, and further clarify the instructions for next time.
I'm AFK until late next week, so no rush. So I'll sort it when I'm back.
gpb01 commentedon Sep 12, 2023
PR is waiting ... :-)
Guglielmo
feilipu commentedon Jan 2, 2024
Closed by #121