STM32F103R In application Programming

Generic boards that are not Maple or Maple mini clones, and don't contain the additional USB reset hardware
SankarB
Posts: 12
Joined: Thu Oct 04, 2018 7:56 am

STM32F103R In application Programming

Post by SankarB » Sat Jan 12, 2019 6:46 am

Hello,

I am trying to implement in application programming using sd card. my main application is running normally from 0x08000000 address as initialized in the arduino_stm32 library. I wrote my application code in the flash from 0x08010000 address. the code written successfully done. After that I have to jump to my application address and launch my application.
To launch this application I use this function:

Code: Select all

typedef void (fun)(void); //Define a parameter of a function type.
fun AppStart;
void Jump2App(uint32_t Addr)
{
if ((((uint32_t*)Addr) & 0x2FFE0000) == 0x20000000)
{
AppStart = (fun)((uint32_t)(Addr + 4));
__set_MSP((__io uint32_t)Addr);
// nvic_init((uint32_t)0x08010000,0);
// nvic_sys_reset();
AppStart(); //Go to APP.
}
}
but its not taking me to my application. it struck in AppStart();
Im not getting whats going on inside the core library.
Is this AppStart(); is going re initializes our core libraries and sets starting address to 0x08010000
Can you please help me in this program.

User avatar
RogerClark
Posts: 8416
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: STM32F103R In application Programming

Post by RogerClark » Sat Jan 12, 2019 8:41 am

Which Arduino core are you using?

SankarB
Posts: 12
Joined: Thu Oct 04, 2018 7:56 am

Re: STM32F103R In application Programming

Post by SankarB » Sat Jan 12, 2019 9:17 am

I am using arduino_stm32 library which was posted by you on github..
https://github.com/rogerclarkmelbourne/Arduino_STM32

SankarB
Posts: 12
Joined: Thu Oct 04, 2018 7:56 am

Re: STM32F103R In application Programming

Post by SankarB » Tue Jan 15, 2019 3:32 pm

RogerClark wrote:
Sat Jan 12, 2019 8:41 am
Which Arduino core are you using?
I'm using Arduino_stm32 core.. Please help me to get this IAP

stevestrong
Posts: 3053
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany
Contact:

Re: STM32F103R In application Programming

Post by stevestrong » Tue Jan 15, 2019 8:40 pm

How do you upload your sketch?
The starting address is set by the linker depending on the upload method.

Have a look on the CMSIS reset procedure: http://stm32duinoforum.com/forum/viewtopic.ph ... 012#p44928

SankarB
Posts: 12
Joined: Thu Oct 04, 2018 7:56 am

Re: STM32F103R In application Programming

Post by SankarB » Wed Jan 16, 2019 4:52 am

stevestrong wrote:
Tue Jan 15, 2019 8:40 pm
How do you upload your sketch?
Thanks for the replay stevestrong,
By using this eeprom library I am writing my application bin file in specific loctaion starting from 0x08010000
https://github.com/rogerclarkmelbourne/ ... ies/EEPROM
Last edited by SankarB on Wed Jan 16, 2019 6:50 am, edited 1 time in total.

SankarB
Posts: 12
Joined: Thu Oct 04, 2018 7:56 am

Re: STM32F103R In application Programming

Post by SankarB » Wed Jan 16, 2019 6:45 am

stevestrong wrote:
Tue Jan 15, 2019 8:40 pm
The starting address is set by the linker depending on the upload method.

Have a look on the CMSIS reset procedure: http://stm32duinoforum.com/forum/viewtopic.ph ... 012#p44928
How that starting address is set by linker works.?
Im using SD card method to upload my application file.

after having look at cmsis reset procedure

Code: Select all

static __INLINE void NVIC_SystemReset(void)
{
  SCB->AIRCR  = (NVIC_AIRCR_VECTKEY | (SCB->AIRCR & (0x700)) | (1<
this function was already included in my core library as

Code: Select all

void nvic_sys_reset() {
    uint32 prigroup = SCB_BASE->AIRCR & SCB_AIRCR_PRIGROUP;
    SCB_BASE->AIRCR = SCB_AIRCR_VECTKEY | SCB_AIRCR_SYSRESETREQ | prigroup;
    asm volatile("dsb");
    while (1)
        ;
}
i think this is enough for reset the controller. But when i use this nvic_sys_reset() function in my code it is resetting the controller and starts from main code address only that is 0x08000000. im not able change the starting address by keeping this
nvic_set_vector_table(0x08000000, 0x00010000);
I am not getting what i've missed.

stevestrong
Posts: 3053
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany
Contact:

Re: STM32F103R In application Programming

Post by stevestrong » Wed Jan 16, 2019 8:25 am


SankarB
Posts: 12
Joined: Thu Oct 04, 2018 7:56 am

Re: STM32F103R In application Programming

Post by SankarB » Wed Jan 16, 2019 9:49 am

stevestrong wrote:
Wed Jan 16, 2019 8:25 am
http://stm32duinoforum.com/forum/index.php?ti ... g_a_sketch

Again: how do you upload your sketch?
Using Arduino IDE through STlink I use to upload the sketch

stevestrong
Posts: 3053
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany
Contact:

Re: STM32F103R In application Programming

Post by stevestrong » Wed Jan 16, 2019 10:03 am

As far as I understood, you actually want to write a "bootloader" which starts from 0x800000 (CPU reset address), reads code from SD card and writes this code to flash starting from 0x8001000, is this correct?

This will only work if the program loaded from SD card has been linked using the correct starting address of 0x8001000.
Special care has to be taken for irq vector table.
Have a look in at the stm32duino bootloader, as an example, how a jump to user code can be implemented: https://github.com/rogerclarkmelbourne/ ... are.c#L201

Post Reply