cancel
Showing results for 
Search instead for 
Did you mean: 

How can i write on flash on STM32 MCU family?

MNoro.2
Associate II

I'm totally new on stm32 mcu's. i was working on a project and i want to update the MCU(The previous MCU was AVR) and i want to encode and decode base64 using Stm32CubeIDE(HAL Driver), so i decide to port my arduino library. The library is attached, but i have a problem in porting library. there is an include and function in the arduino library and i don't know how to port this part of code:

First part:

#include <avr/pgmspace.h>

const char PROGMEM b64_alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

"abcdefghijklmnopqrstuvwxyz"

"0123456789+/";

and this function

pgm_read_byte(&b64_alphabet[a4[i]]).

The original library file is attached. Please help me. i dont know what should i do for this.

1 ACCEPTED SOLUTION

Accepted Solutions

Shouldn't need different memory spaces, compiler/linker should fold things like this in the FLASH/ROM section, without extra direction, and you should be able to access like a normal C array

const char b64_alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

"abcdefghijklmnopqrstuvwxyz"

"0123456789+/";

output[encLen++] = b64_alphabet[a4[j]];

To direct things to different sections described in the linker script you'd use an __attribute__((section("name"))) type construct, or #pragma

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

3 REPLIES 3

Shouldn't need different memory spaces, compiler/linker should fold things like this in the FLASH/ROM section, without extra direction, and you should be able to access like a normal C array

const char b64_alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

"abcdefghijklmnopqrstuvwxyz"

"0123456789+/";

output[encLen++] = b64_alphabet[a4[j]];

To direct things to different sections described in the linker script you'd use an __attribute__((section("name"))) type construct, or #pragma

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
MNoro.2
Associate II

Tnx @Community member​ , but this library doesnt work. can i run any C code on stm32? so i just need to find a base64 library in C and import it in my project? i'm confused (noobie here :). ) some commands are used in base64 algorithms like malloc() . do this work on STM32? or i should modify C codes to run on STM32?

malloc/free are typically available​, but the heap can be fairly small depending on compiler and libraries.

You should be able to port the base 64 code without using the PGMSPACE/PRGMEM stuff.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..