"USBSerial" has no member "printf" on STM32F411CEU6 in PlatformIO / ststm32 - c++

Trying to run this USB Serial example (bottom) to learn MBED, but I get the following compilation error:
class "USBSerial" has no member "printf"
Is it possible it isn't implemented for the STM32F411? Or is this a problem with MBED itself?
Seems like this should be basic functionality. Not finding much useful info on google when searching for this error. Has anyone else seen this error before?
potentially useful details:
IDE: vscode/platformIO
platformio.ini:
[env:nucleo f411re]
platform = ststm32
framework = mbed
board = nucleo_f411re
monitor_speed = 115200
MBED version: 6.2 (as I recall from memory, though I doubt it matters since I checked the docs for a few versions and the API and example appears unchanged)

The method printf() (which is a C, not C++ concept anyway) does not exist, simple as that. Use sprintf() if that's what you're familar with, then USBSerial.write(), perhaps.

Related

Creating ECDSA keys with OpenSSL 3 (migration problem)

I need to create ECDSA keys and used old OpenSSL code until now, which dosn't compile any more under OpenSSL3, there are now lots of deprecation errors. I invested now several days with search & try, but I can't solve it. I am trying the simple example [https://fm4dd.com/openssl/eckeycreate.shtm][1], but already the first lines create these errors:
WorkerThread.cpp(34,2): error C4996: 'ERR_load_BIO_strings': Since OpenSSL 3.0
WorkerThread.cpp(47,19): error C4996: 'EC_KEY_new_by_curve_name': Since OpenSSL 3.0
WorkerThread.cpp(54,2): error C4996: 'EC_KEY_free': Since OpenSSL 3.0
So the first idea would be to eliminate these compiler errors somehow. I found the switches
#define OPENSSL_API_COMPAT 30000
#define OPENSSL_NO_DEPRECATED
but they create even more errors, because now suddenly even the EC_KEY is unknown to the compiler. No solution.
So there stays the hard way to try to migrate the code somehow to OpenSSL3, because there seems to be no example code in the whole internet for simply creating an ECDSA key with OpenSSL3, and extract the private and public part. But just changing single functions with an OpenSSL3 matching function doesn't solve it, because the whole concept changes (switching from low level API to high level, with a completely different programming model).
I have tried fiddling around with lots of examples, but it looks like my programming task that seems so simple is a very complicated thing. Any help is appreciated, but I want to stay in C/C++ because my application is performance critical.
Environment: MS Win10, MS Visual Studio 2019, latest OpenSSL 3
[1]: https://fm4dd.com/openssl/eckeycreate.shtm
WorkerThread.cpp(34,2): error C4996: 'ERR_load_BIO_strings': Since OpenSSL 3.0
You don't need to call any of those initialisation functions. Just remove them from your code. They are not needed with any version of OpenSSL from 1.1.0 onwards.
In the example, all of the code for getting an EC_GROUP, creating an EC_KEY, generating a key, setting the OPENSSL_EC_NAMED_CURVE flag and assigning it to an EVP_PKEY can be completely removed. Replace it with a simple call to EVP_EC_gen(). See the man page here:
https://www.openssl.org/docs/man3.0/man3/EVP_EC_gen.html
E.g. all of that code can be replaced with something like
pkey = EVP_EC_gen("secp521r1");
if (pkey == NULL) {
BIO_printf(outbio, "Error generating the ECC key.");
abort();
}

ArrayFire convolution issue with Cuda backend

I've been having an issue with a certain function call in the
dphaseWeighted = af::convolve(dphaseWeighted, m_slowTimeFilter);
which seem to produce nothing but nan's.
The back ground is we have recently switched from using AF OpenCL to AF Cuda and the problem that we are seeing happens in the function.
dphaseWeighted = af::convolve(dphaseWeighted, m_slowTimeFilter);
This seems to work well when using OpenCL.
Unfortunatley, I can't give you the whole function because of IP. only a couple of snippets.
This convolve lies deep with in a phase extract piece of code. and is actualy the second part of that code which uses the af::convolve funtion.
The first function seems to behave as expected, with sensible floating point data out.
but then when it comes to the second function all I'm seeing is nan's coming out ( I view that with af_print amd dumping the data to a file.
in the CMakeList I include
include_directories(${ArrayFire_INCLUDE_DIRS})
and
target_link_libraries(DASPhaseInternalLib ${ArrayFire_CUDA_LIBRARIES})
and it builds as expected.
Has anyone experience any think like this before?

Migrating flex 2.5.4a to 2.6 (lexical analyser generator)

I have a file that generates cc code using flex. When I use the version 2.5.4a-10 the codes works as expected.
If I use bit more recent version 2.5.37 or even newer like 2.6 the generated code seems not to allocate anything. It uses some pointers defined with nullptr and crashes.
I think the syntax has changed in between these versions. I find it also strange that Debian/Ubuntu have a package called flex-old saying:
flex is a tool for generating scanners: programs which recognize lexical
patterns in text. This is the old 2.5.4a version, which is no longer
being developed. You should normally choose flex, unless you have
legacy lexer files that do not work with a modern flex.
This product includes software developed by the University of California,
Berkeley and its contributors. The upstream source code can be found at
http://flex.sourceforge.net/
(Editor's note: Flex has moved to Github but v2.5.4a is not there.)
That version seems to be a big deal for others I suspect. Getting to my question:
Is there any manual or guide of what I have to do in order to port that code to generate some c++ code that works in more recent versions of flex?
EDIT: Here is my simple example taken from something larger:
int num_lines = 0, num_chars = 0;
%%
\n ++num_lines; ++num_chars;
. ++num_chars;
%%
int main()
{
yy_init=1;
yylex();
printf( "# of lines = %d, # of chars = %d\n",
num_lines, num_chars );
return 0;
}
flex it with flex file.l and build it with gcc lex.yy.c -lfl. Now, if you used version 2.5.4 it will work. With later versions it translates and compiles just fine, but when you run the program you will get segmentation fault.
I found the problem myself. The variable yy_init can be explicitly set in that old version. In newer versions it is not allowed. I'm not sure if that is intended, maybe someone can explain why this behavior is observed. I find it a bit strange.
If someone has a similar problem, you might want to take a look at the yy_init variable. Other than that I had no issues.

What are those folders in SDL-1.2.15

I'm trying to understand source code of SDL-1.2.15, and to find out how it renders stuff on windows. But I can't find where the rendering is happening. I looked inside SDL-1.2.15/src/video folder, and there is a ton of subfolders, and I don't know what any of these stands for. See for yourself.
aalib/ directfb/ ipod/ os2fslib/ quartz/ windib/
ataricommon/ dummy/ maccommon/ photon/ riscos/ windx5/
bwindow/ fbcon/ macdsp/ picogui/ svga/ wscons/
caca/ gapi/ macrom/ ps2gs/ symbian/ x11/
dc/ gem/ nanox/ ps3/ vgl/ xbios/
dga/ ggi/ nds/ qtopia/ wincommon/ Xext/
Is this documented somewhere? This is a pretty popular library, so it probably is documented, right? Right? What's the point of having source code if you can't even understand it, if you can't find functions you are using.
While not all the names are self-explanatory, they contain some hints.
directfb, fbcon (framebuffer console) and X (x11, Xext) are output layers on Linux (unix).
The ones starting with win indicate they are for Windows. More specifically, windib should be about device independent bitmaps (DIBs), dx5 about DirectX 5, and wincommon about some common stuff. Indeed, using grep shows that (only) these folders contain Windows-specific code:
grep -r windows.h src/video/*
[ lists files in the win* folders ]
You could also just compile the package on Windows and see which files were compiled (which folders contain object files)
However, to find out what it actually does, you should rather study the function you're interested in (e.g. SDL_BlitSurface), look at it's implementation, and then look at the implementation of the functions it uses. Start in SDL_video.h (and notice that SDL_BlitSurface is just a define).
You should use some tool to search the code base. Grep or some IDE. Or both.
First of all, why not SDL2?
These are different SDL's video drivers. You can get what driver is used by your program by calling SDL_VideoDriverName. Which driver will be used determined by target platform (e.g. operating system - most drivers are platform-specific), environment variable SDL_VIDEODRIVER, or calling side.

What is the difference between fcgi_stdio and fcgiapp?

I am trying to get started with fastcgi development, therefor I download the reference implementation of libfcgi and tried to get a testprogram to run with lighttpd. Since fcgi_stdio allows for cgi backwards compatibility, I decided to start with that.
However I could not get the examples/tiny-fcgi.c to work with lighttpd, it yielded an internal server errror 500, the same configuration allows to run the lighttpd example program (http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_ModFastCGI, below C/C++ FastCGI on lightty named socket) flawless. However it is totally unclear to me why the default supplied example would not work.
Questions:
What is wrong with the examples/tiny-fcgi.c example from the reference implementation causing lighttpd to return error 500?
Which implementation of fastcgi is preferable for c++ development (fcgi_stdio, fcgiapp, Other)? (There is something for streams in the fcgi pack, however I failed to find good/any documentation)
I have tested the unmodified example (Ubuntu/13.10/amd-64, Apache/2.4.6, libapache2-mod-fastcgi/2.4.7~0910052141-1.1, libfcgi-dev/2.4.0-8.1ubuntu4) and it runs ok:
manuelz#garibaldi:~$ curl habrich/tiny-fcgi
<title>FastCGI Hello! (C, fcgi_stdio library)</title>
<h1>FastCGI Hello! (C, fcgi_stdio library)</h1>
Request number 2 running on host <i>habrich</i>
Answers:
Hard to tell without knowing your configuration, but here's a shot in the dark: getenv will return NULL if SERVER_NAME is undefined.
fcgiapp is the base implementation: I would use that one for new development. fcgi_stdio is a wrapper for compatibility with CGI: use that for migrating legacy CGI projects. Quote:
fcgi_stdio is implemented as a thin layer on top of fcgiapp
You can find decent documentation for fcgiapp in the fcgiapp.h header.
I do not know whether your problem has the same origin as mine had, but at least it has the same symptoms.
There are different versions of the tiny-fcgi example. I first tried the one given here (example 1). This failed with an internal server error. However, the example given here (which does basically the same) works. The small but crucial difference is that the working code uses
getenv("SERVER_NAME")
instead of
getenv("SERVER_HOSTNAME")
not exactly the same for me, but if i avoid using getenv the example runs without errors, have to discover why getenv leads into error