-
Notifications
You must be signed in to change notification settings - Fork 1.3k
add port for ATMega328P #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I note this is very similar to the ATMega323 port, the only difference being the constants used to access peripherals. For example, the ATMega323 uses TIMSK presumably because it only has one, whereas the ATMega328 uses TIMSK1 presumably because it has more than one TIMSK. Would your x328 port also work for the x323 if the x323 were built with the latest WinAVR tools? That way we could just have one port. If not, could the port be generalised in some way so it works for both? |
I have not checked the 323 datasheet, but different timers might be used. |
well, this might be more confusing than I intended .... Most of ATmega UCs seem to have 3 timers: Timer0 (8-bit), Timer1 (16-bit) and Timer2 (8-bit)
Note 1 Note 2: Now, I am more of a HW designer and I am willing to help have AVR supported by FreeRTOS, but I don't think I know enough about the project to make SW architecture suggestions. |
I will take a look at this and come up with a suggestion over the next week somewhere. |
It may be useful to note that all modern ATmega devices use the same watchdog timer configuration, irrespective of their Timer characteristics. I exploited this characteristic to build an Arduino_FreeRTOS library that is completely agnostic^. So it may be a useful step to make a generic ATmega port using a WDT Tick rather than a proliferation of different Timer Tick versions. Just also to note that all of the Timers are configured by the Arduino platform under the covers (eg. when using ^of course the ATmega2560 devices (3 byte PC) need to have a different |
I compared
TL;DR -- Similar to Richard's original comment, is it possible to
Open to suggestions. Also ref -- "AVR084: Replacing ATmega323 by ATmega32" http://ww1.microchip.com/downloads/en/AppNotes/doc2518.pdf ---------------- Details ---------------- 1. Registers and bit mapping.
From ATmega328P data sheet, about From ATmega323 data sheet, about So there's no functional change to From ATmega328P data sheet, about From ATmega323 data sheet, about So the changes related to **2. Vector name. **
https://www.nongnu.org/avr-libc/user-manual/group__avr__interrupts.html |
@jonsnow1357 On a minor comment, apologies for the extra long review cycle... I attempted to rebase this PR, but it seems a lot of effort. If it's too much trouble, could open another PR and cherry-pick your two commits. |
If you’re going to go to the trouble of integrating the 328p into the mainline code, then it would make a lot more sense to add the 1284p and 2560 devices which have enough RAM to enable multiple useful threads to operate successfully. The 328p simply doesn’t have enough RAM (2kB) to allow (for example) a network interface and a data logging device to operate in the same build. It is useful for an introduction to FreeRTOS, but not much else. I’ve had another repository of AVR ports available for some years, and this is the port.c file, which covers 8u2, 16u2, 32u2, 16u4, 32u4, 168, 328p, 640, 1280, 1281, 1284p, and the two devices with 3 byte program counters 2560, 2561. Any relevant timer, 8 bit (Timer 0), 16 bit (Timer 1, 2, 3), or Watch Dog Timer, can be used to trigger the System Tick. Timer controls are generalised depending on the MCU selected. What would you like to achieve as an outcome from this PR? You mention there are at least two other PRs around 328p. Are there any PRs open which cover all the (relevant) AVR platforms? Happy to contribute if that is seen as a better outcome? |
Thank you for the details. To the most important question first:
My thought is to make the port extensible enough while provide as much as we could. And the PRs could be incremental that it’s easier to review. I’d propose getting 328P in first, and this would cover ATmega48A/PA/88A/PA/168A/PA/328/P data sheet. The RAM size of this series is 512/1K/1K/2KBytes, as you pointed out the use case may be very limited. In the following PRs, could further extend the port to cover ATmega640/V-1280/V-1281/V-2560/V-2561/V, ATmega164A/PA/324A/PA/644A/PA/1284/P, and … (And it’s very likely that less and less needs to be done to cover a new port.) An assumption we made so far is that all the ATmega32 ports are based on the existing ATmega323, in which the port.c file only concerns tick timer related and task stack operation related. To carry out that assumption in the new ports, I think it would make sense to branch based on devices (e.g. in your code So in your [port.c],(https://github.com/feilipu/avrfreertos/blob/master/freeRTOS10xx/portable/port.c)
From ATmega640/V-1280/V-1281/V-2560/V-2561/V data sheet -- From ATmega164A/PA/324A/PA/644A/PA/1284/P data sheet -- Does not necessarily hurt, but I'd rather not make the assumption on behalf of chip vendor. ps: I'm not sure if you and jonsnow are working together on this port. Above comment is based on "no". Throw PRs at us anytime. Could enable "allow edits from maintainer" when submitting, that I could rebase for you if needed. |
Generalised PR #48 done as requested. 👍 |
@feilipu Thank you! Will review as soon as possible, and will post questions/feedback in #48. @jonsnow1357 I may end up closing this PR, depends on how #48 works out. Apologies. |
sorry, missed a couple of days to the exchange :( I will wait for #48 resolution ... |
@jonsnow1357 I'd like to close this PR for now, since PR #48 seems to have a better coverage on ATmega family. Planning to merge #48 first, then having incremental changes there. If that interests you could play with the port and the simulator project linked one of the comments from me. We'll try to have timely feedback moving forward... Thanks again for the contribution. |
No description provided.