-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Hardware SPI implementation on AVR #1954
Comments
my_u8x8_gpio_and_delay: Handling of the delay messages is missing: /~https://github.com/olikraus/u8g2/wiki/Porting-to-new-MCU-platform#template-for-the-gpio-and-delay-callback I think at least DELAY_MILLI should be there, probably also the 100NANO delay. |
I've checked the initialization of SPI and all the registers seem to be right but unfortunately the display doesn't initialize. Could it be related to the fact my display doesn't use all the four wires as in #1949 ? It doesn't use the DC pin. I could give the Arduino version a try and see if this display work in 3-wire mode... |
Not sure whether I can help here. This is uC specific.
I don't exactly which messages are used in your case, but you should probably implement all delay messages listed in the code template to be on the safe side.
I am a little bit confused. Let me start from the beginning: It you choose one of them, you need to:
You have actually asked for 3wire, so I pointed out the code in the C++ part of u8g2 (see #1949), but your above code doesn't seem to include the code. So your code above looks more like a 4-wire code. As a starting point, my suggestion is this: Configure your display for 4-wire communication and then use the existing 4-wire communication in u8g2. |
Oh, it looks like you want to use a ST7920 in serial mode. I think this wasn't mentioned before. |
Ok, so I got everything working following this tutorial. It was very easy. No delay functions to be implemented, just a few pin definitions and a couple of messages that later I made some cleanup removing uneeded code for my setup. Maybe it would be the case of updating documentation to reflect this. A simple hello world code ended like this:
I also had to define some symbols, most important is AVR_USE_HW_SPI and some SPI pin definitions: And that is it! Now I'm facing some problems with the C version of MUI. I'm trying a basic example following the MUIMinimal.ino as a guide but MUIF list is throwing an "initializer element is not constant" error and Form Definition String fds_t do not appear to be a recognized symbol. I'm doing something wrong or it is just untested in C? Should I stick to the Arduino version to use MUI? |
/~https://github.com/olikraus/u8g2/wiki/Porting-to-new-MCU-platform#atmel-avr
In fact the development of MUI happend in C only. Did you include both mui.h and mui_u8g2.h? |
Yes, both are included. I'm trying a very minimal test. It's a form with just a label on it:
|
Oli, I'm still stuck with this initializer element is not constant error. I double checked everything. I have both mui_u8g2.h and mui.h included on my main.c, right above u8g2.h and u8x8_avr.h. Is there anything wrong in here? It was tested on baremetal AVR or just the C on Arduino? I think will test it under Arduino interface and see what happens...
|
I have created a test and it works as expected: u8g2/sys/sdl/mui_issue_1954/main.c Lines 13 to 25 in db3888e
I am not sure whether MUI_PROGMEM is required. I thought that I have moved this into the struct typedef. Maybe try without MUI_PROGMEM. For the SDL code above MUI_PROGMEM is anyways disabled, so the problem might be indeed MUI_PROGMEM. |
I've tried with and without MUI_PROGMEM and even setup an entire new environment in a different machine. After installing Microchip Studio from scratch and creating an entire new project, including the library files etc, still the same error.
|
Hmm... difficult to tell. Not sure how to continue from here. MUI works in unix/SDL and Arduino environment. |
Could it be something specific to AVR-GCC? I could upload a simple project in case someone else want to test it. Anyway, I've just made to switch to the Arduino version until I got it working on Studio. |
Hmm... MUI also works without problems on Arduino UNO |
Different compiler versions, maybe? Or am I barking up the wrong tree? |
I think Arduino 1.8.4 or 1.8.10 did work for me. |
I have the same problem. After spending some time, I found the reason. When using PROGMEM, all values should be constants, but in some defines this is not the case. Example: #define MUIF(id,cflags,data,cb) { id[0], id[1], cflags, 0, data, cb} The problem is in id[0] and id[1]. There are several other similar definitions. |
Usually all provided data are constant. Moreover: This error didn't happen to me. |
However, as a temporary solution, @dolence can make the following changes to the //#if defined(__GNUC__) && defined(__AVR__)
//# define muif_get_id0(muif) mui_pgm_read(&((muif)->id0))
//# define muif_get_id1(muif) mui_pgm_read(&((muif)->id1))
//# define muif_get_cflags(muif) mui_pgm_read(&((muif)->cflags))
//# define muif_get_extra(muif) mui_pgm_read(&((muif)->extra))
//# define muif_get_data(muif) ((void *)mui_pgm_wread(&((muif)->data)))
//# define muif_get_cb(muif) ((muif_cb)mui_pgm_wread(&((muif)->cb)))
//#else
# define muif_get_id0(muif) ((muif)->id0)
# define muif_get_id1(muif) ((muif)->id1)
# define muif_get_cflags(muif) ((muif)->cflags)
# define muif_get_extra(muif) ((muif)->extra)
# define muif_get_data(muif) ((muif)->data)
# define muif_get_cb(muif) ((muif)->cb)
//#endif And accordingly remove |
I am even more confused. I neither understand the original problem nor do I understand how the changes from @kasitoru are related to the original problem. |
As I understand it, the problem is that some versions of the compiler for avr (in this case, we are talking about the official toolchain from Microchip) consider it unacceptable to use calculated values (such as /* assumes that pointers are 16 bit so encapusalte the wread i another ifdef __AVR__ */
#if defined(__GNUC__) && defined(__AVR__) && !defined(MUIF_DISABLE_PGM)
# define muif_get_id0(muif) mui_pgm_read(&((muif)->id0))
# define muif_get_id1(muif) mui_pgm_read(&((muif)->id1))
# define muif_get_cflags(muif) mui_pgm_read(&((muif)->cflags))
# define muif_get_extra(muif) mui_pgm_read(&((muif)->extra))
# define muif_get_data(muif) ((void *)mui_pgm_wread(&((muif)->data)))
# define muif_get_cb(muif) ((muif_cb)mui_pgm_wread(&((muif)->cb)))
#else
# define muif_get_id0(muif) ((muif)->id0)
# define muif_get_id1(muif) ((muif)->id1)
# define muif_get_cflags(muif) ((muif)->cflags)
# define muif_get_extra(muif) ((muif)->extra)
# define muif_get_data(muif) ((muif)->data)
# define muif_get_cb(muif) ((muif)->cb)
#endif When compiling, pass this argument to GCC:
|
But the above get macros are not used in the errors reported by @dolence |
Part of his error messages:
This is because he set |
Ok, understand. But this still doesn't explain the root problem. 🤔 |
I don't understand it either. I think the problem is in the avr-gcc compiler. Because the code looks good. |
It was my mistake. It was necessary to move the functions that are used in muif_list to the global scope. |
#include <stdio.h>
int a = "1234567"[0];
int main(void)
{
printf("%d\n", a);
return 0;
} this code can not compiled before gcc-8, it will report errors in my gcc-7: $ gcc 1.c
1.c:3:9: error: initializer element is not constant
int a = "1234567"[0];
^~~~~~~~~
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.5.0-6ubuntu2' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,ob
j-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-
gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new
--enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multia
rch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver -
-enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 7.5.0 (Ubuntu 7.5.0-6ubuntu2) |
I've been trying to implement hardware SPI on AVR baremetal. IC is an Atmega64 running at 12 MHz. I even tried to hardcode SPI speed but nothing is being showed. This is what I did following the Arduino implementation and avr-libc example:
Any thoughts on this?
The text was updated successfully, but these errors were encountered: