There is those lines in hal.c
Code: Select all
void halInit() {
...
palInit(&pal_default_config);
...
}
Where pal_default_config is defined in
board.c file as
Code: Select all
const PALConfig pal_default_config = {...
and in hal_pal_lld.h as
Code: Select all
extern const PALConfig pal_default_config;
My idea is to modify pal_default_config in main.c before calling halInit(). So basically some conf is readout from flash which tells if one particular pin should be defined LOW or HIGH during palInit(1). Something like this in main.c:
Code: Select all
stm32_gpio_setup_t portb = {VAL_GPIOB_MODER, VAL_GPIOB_OTYPER, VAL_GPIOB_OSPEEDR, VAL_GPIOB_PUPDR, VAL_GPIOB_ODR | 0x01, VAL_GPIOB_AFRL, VAL_GPIOB_AFRH};
PALConfig* config = (PALConfig*)&pal_default_config; // do not use const qualifier
if (conf == 1) {
memcpy(&config->PBData, &portb, sizeof(stm32_gpio_setup_t));
}
halInit();
chSysInit();
It works fine if I modify const PALConfig pal_default_config (hal_pal_lld.h and board.c) to be not const. But I would prefer if hal_pal_lld.h is not touched, however it is ok to modify board.c file.
What I tried to do was to modify where this variable is linked. So I came up with this in board.c.
Code: Select all
const PALConfig pal_default_config __attribute__((section(".ram0"))) = {
But I guess section name should be something different or I have to actually modify .ld file to accomplish this.
I am using STM32F030x8
Current .ld is something like that (I remember that old ld scripts were different):
Code: Select all
/*
* STM32F030x8 memory setup.
*/
MEMORY
{
flash : org = 0x08000000, len = 28k
newapp : org = 0x08009000, len = 28k
ram0 : org = 0x20000000, len = 8k
ram1 : org = 0x00000000, len = 0
ram2 : org = 0x00000000, len = 0
ram3 : org = 0x00000000, len = 0
ram4 : org = 0x00000000, len = 0
ram5 : org = 0x00000000, len = 0
ram6 : org = 0x00000000, len = 0
ram7 : org = 0x00000000, len = 0
}
/* For each data/text section two region are defined, a virtual region
and a load region (_LMA suffix).*/
/* Flash region to be used for exception vectors.*/
REGION_ALIAS("VECTORS_FLASH", flash);
REGION_ALIAS("VECTORS_FLASH_LMA", flash);
/* Flash region to be used for constructors and destructors.*/
REGION_ALIAS("XTORS_FLASH", flash);
REGION_ALIAS("XTORS_FLASH_LMA", flash);
/* Flash region to be used for code text.*/
REGION_ALIAS("TEXT_FLASH", flash);
REGION_ALIAS("TEXT_FLASH_LMA", flash);
...
In short, how pal_default_config must be defined in board.c and what should be modified in .ld file to accomplish this.