embedded

printf() results in gibberish

你说的曾经没有我的故事 提交于 2019-12-01 12:07:56
I have this code: unsigned char *command = "0000"; unsigned char foo = (hex_char_to_int(command[0]) << 4) | hex_char_to_int(command[1]); unsigned char bar = (hex_char_to_int(command[2]) << 4) | hex_char_to_int(command[3]); printf("foo: %02x, bar: %02x\r\n", foo, bar); It uses this function: unsigned char hex_char_to_int(unsigned char ch) { switch (ch){ case '0': return 0; case '1': return 1; case '2': return 2; case '3': return 3; case '4': return 4; case '5': return 5; case '6': return 6; case '7': return 7; case '8': return 8; case '9': return 9; case 'A': return 0xA; case 'B': return 0xB;

GCC - How to stop malloc being linked?

巧了我就是萌 提交于 2019-12-01 12:03:14
I am struggling to get my code down to minimal bare bones size! I am using a STM32F0 with only 32k flash and need a good part of the flash for data storage. My code is already at approx 20k flash size! Some of this is due to use of the STM32 HAL functions which I can account for and optimise later if needed. However, my biggest consumer of flash is all the implicitly included library routines. I can not seem to remove these functions. They are not called anywhere in my code or any HAL code. Functions such as _malloc_r (1.3k Bytes), and __vfiprintf_r (3kB) and many others are using a large part

Allocating an object for C / FFI library calls

白昼怎懂夜的黑 提交于 2019-12-01 11:52:23
问题 I have a C library, which has gpio implementation. There's gpio_type which is target specific, each MCU has different definition for gpio_type. One of the functions in the library: void gpio_init(gpio_type *object, int32_t pin); I want to write abstraction of Gpio object in Rust, using C library functions. Therefore need something like opaque pointer type (in C++ I would just create a member variable with type: gpio_type). I figured I would create an empty enum (or struct), allocate a space

How do you call an assembly function from C program?

亡梦爱人 提交于 2019-12-01 11:42:44
问题 I am very new to Microcontroller programming particularly PIC18F87J11, and I am using MPLAB C18 compiler. I was reading the datasheet for various topics such as saving to memory or working with timers. I noticed the examples are written in assembly language, but I have minimum experience with it. Is there a way to use the power of Assembly and C together in my project? I do not understand assembly that good or else I would try to convert the code to C, in this case, I rather just use the

GCC - How to stop malloc being linked?

空扰寡人 提交于 2019-12-01 11:09:17
问题 I am struggling to get my code down to minimal bare bones size! I am using a STM32F0 with only 32k flash and need a good part of the flash for data storage. My code is already at approx 20k flash size! Some of this is due to use of the STM32 HAL functions which I can account for and optimise later if needed. However, my biggest consumer of flash is all the implicitly included library routines. I can not seem to remove these functions. They are not called anywhere in my code or any HAL code.

printf() results in gibberish

笑着哭i 提交于 2019-12-01 10:55:41
问题 I have this code: unsigned char *command = "0000"; unsigned char foo = (hex_char_to_int(command[0]) << 4) | hex_char_to_int(command[1]); unsigned char bar = (hex_char_to_int(command[2]) << 4) | hex_char_to_int(command[3]); printf("foo: %02x, bar: %02x\r\n", foo, bar); It uses this function: unsigned char hex_char_to_int(unsigned char ch) { switch (ch){ case '0': return 0; case '1': return 1; case '2': return 2; case '3': return 3; case '4': return 4; case '5': return 5; case '6': return 6;

Android 4.0+ Bluetooth connection error to an embedded device: “Permission Denied”

落爺英雄遲暮 提交于 2019-12-01 10:19:16
问题 I have the following setup: An Android device uses a 'Client' socket to connect to a remote embedded device, The Android application uses the following code snippet to connect to the embedded device. On the embedded device uses MindTree BT stack, where server serial socket is prepared according to some properties in the device, which the Android application is familiar with, the connection defined on the embedded device, is not secured!! The combination of both applications works on: 2 LG

How do we trouble shoot a long-running NETMF program that stops in production?

浪尽此生 提交于 2019-12-01 10:14:37
问题 Situtation I have a FEZ Cobra II NET running test code. It sends data every second to a server on the LAN. The server writes the data to a text file. After 27 hours and 97,200 successful sends, the Cobra stops sending. Clearly I am not going to debug for 27 hours, and I am not sure how else to trouble shoot, because standard software trouble shooting approaches do not apply. Question If I were to write to log errors on the Cobra, how would I access them? Does NETMF have application logs? How

C/C++ linker CALL16 reloc at xxxxx not against global symbol

元气小坏坏 提交于 2019-12-01 08:53:11
I'm getting these errors while linking, both messages have to do with the same object file. CALL16 reloc at 0x5f8 not against global symbol and could not read symbols: Bad value The 2nd message seems to be the reason I'm getting the CALL16 error, but the file compiles just fine. Any tips on fixing this? FYI, I'm cross compiling for a MIPS target and using gcc 4.1.2 EDIT: No luck so far: Here are my flags used: -fPIC,-Wl,-rpath,-Wl,-O1 I've also tried the following without success: -mno-explicit-relocs -mexplicit-relocs -mlong-calls -mno-long-calls -mxgot -mno-xgot Meanwhile, I'll go back to

cost of fprintf

谁说我不能喝 提交于 2019-12-01 08:10:50
问题 I am developing an embedded application in C++ for a platform with limited code/data RAM, but rather unlimited RAM for filesystem usage. While looking for reducing the code size, I realized that excluding fprintf() lines contributed a lot to the size of generated code. My questions are : 1. Why is the cost of fprintf so high ? 2. If I exclude the fprintf functionality, what would be the alternative to generate log files describing the occurances through the application run ? 回答1: The answer