STM32F103R In application Programming

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:

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.
}
}


RogerClark
Sat Jan 12, 2019 8:41 am
Which Arduino core are you using?

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
Tue Jan 15, 2019 3:32 pm
[RogerClark – 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
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: https://www.stm32duino.com/viewtopic.ph … 012#p44928


SankarB
Wed Jan 16, 2019 4:52 am
[stevestrong – 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


SankarB
Wed Jan 16, 2019 6:45 am
[stevestrong – 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: https://www.stm32duino.com/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

static __INLINE void NVIC_SystemReset(void)
{
SCB->AIRCR = (NVIC_AIRCR_VECTKEY | (SCB->AIRCR & (0x700)) | (1<<NVIC_SYSRESETREQ)); /* Keep priority group unchanged */
__DSB(); /* Ensure completion of memory access */
while(1); /* wait until reset */
}


stevestrong
Wed Jan 16, 2019 8:25 am
http://wiki.stm32duino.com/index.php?ti … g_a_sketch

Again: how do you upload your sketch?


SankarB
Wed Jan 16, 2019 9:49 am
[stevestrong – Wed Jan 16, 2019 8:25 am] –
http://wiki.stm32duino.com/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
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


SankarB
Wed Jan 16, 2019 10:07 am
[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?

Yes You are right.


SankarB
Wed Jan 16, 2019 1:25 pm
[stevestrong – Wed Jan 16, 2019 10:03 am] –
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

After looking into this bootloader jump function I need to add this function to my existing core Arduino_STM32. Is that right?
or else have write my code only using that bootloader library?


stevestrong
Wed Jan 16, 2019 2:01 pm
The pointed bootloader loads code to be programmed to the flash over the USB interface (DFU protocol).
You could rewrite the whole bootloader code to take the program to be flashed from SD card instead of USB interface.
Or just take parts of interest from it and add them to your existing code.
You must figure out yourself what parts you need.

Your main problem will be to configure Arduino IDE to generate and store your new code (to be programmed) on the SD card.


mrburnette
Wed Jan 16, 2019 3:12 pm
[SankarB – Wed Jan 16, 2019 10:07 am] –

[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?

Yes You are right.

Is this a “school project” because I’m having a difficult time understanding how this is a stm32duino issue?
Writing a bootloader to read SD, load memory, then boot the code is not a simple task, but it has been done
Before: https://www.google.com/search?q=read+SD … bootloader

Ray


SankarB
Thu Jan 17, 2019 5:18 am
[stevestrong – Wed Jan 16, 2019 2:01 pm] –
The pointed bootloader loads code to be programmed to the flash over the USB interface (DFU protocol).
You could rewrite the whole bootloader code to take the program to be flashed from SD card instead of USB interface.
Or just take parts of interest from it and add them to your existing code.
You must figure out yourself what parts you need.

Your main problem will be to configure Arduino IDE to generate and store your new code (to be programmed) on the SD card.

Thank you stevestrong I’ll try as you said.


SankarB
Thu Jan 17, 2019 5:33 am
[mrburnette – Wed Jan 16, 2019 3:12 pm] –
Is this a “school project” because I’m having a difficult time understanding how this is a stm32duino issue?
Writing a bootloader to read SD, load memory, then boot the code is not a simple task, but it has been done
Before: https://www.google.com/search?q=read+SD … bootloader

Ray

Hello mrburnette,
I am going to implement FOTA. through FTP im going to send the .bin file, that could be stored in SD/external Flash. then by using this IAP (bootloader) Im going to write the code in controller flash.

Every time this bootloader have to check there is new .bin file available or not. If available it should replace new code in controller flash. I think you can understand now.
In the given link none of the bootloader+SD done for stm32duino, I think their core different from this.


mrburnette
Thu Jan 17, 2019 5:53 am
[SankarB – Thu Jan 17, 2019 5:33 am] –

I am going to implement FOTA. through FTP im going to send the .bin file, that could be stored in SD/external Flash. then by using this IAP (bootloader) Im going to write the code in controller flash.

Every time this bootloader have to check there is new .bin file available or not. If available it should replace new code in controller flash. I think you can understand now.
In the given link none of the bootloader+SD done for stm32duino, I think their core different from this.

I’m very rarely respond to an inquiry with a specific implementation; rather, I like to think above the implementation and exercise my neurons at the more abstract. In any event, the links showed several attack vectors.

F(irmware)OTA via FTP of the binary is a lots of work when the WiFi IOT groupies have already implemented OTA for the Espressif ESP8266 & ESP32. But suit yourself.

If STM32F103 is a hard requirement, I’d toss the bootloader and use a second uC to stage BT (or WiFi) serial directly to the STM32 on silicon serial loader.

Here in Atlanta, $5 will get a Raspberry Pi Zero-W which is a full Linux implementation and eats Blue Pills for dessert.

Ray


RogerClark
Thu Jan 17, 2019 6:57 am
I agree with Ray

I have some STM32 boards which are connected to a Raspberry Pi, (Note. These are not boards I designed they are boards I use) and the design of the board connects boot0 and reset to GPIO’s on the RPi, as well as Serial UART1

Firmware updates are done using the internal bootloader in the STM32F103, by the RPi driving Boot0 high then toggling the reset pin, before sending the firmware via serial at 56k bps. And its remarkably reliable.

The serial firmware update protocol is well documented by ST and there are open source implementations e.g. STM32Flash, which I suspect would be easier to port to and ESP8266 or ESP32 etc, than to have the complex process you describe of FTP to SD and then SD to firmware in the STM32

I would not use your method to do this.


SankarB
Fri Jan 18, 2019 11:08 am
Thank you Ray & Roger
After looking your posts I want to change my application to Update the firmware using “2 MCU’s+USARTx”. could you provide any path, How to start regarding that.

mrburnette
Fri Jan 18, 2019 8:20 pm
[SankarB – Fri Jan 18, 2019 11:08 am] –
Thank you Ray & Roger
After looking your posts I want to change my application to Update the firmware using “2 MCU’s+USARTx”. could you provide any path, How to start regarding that.

Surely, several approaches have appeared on n this forum in the past. Maybe this one will get you started:
https://www.stm32duino.com/viewtopic.php?t=3003

I found the above by using a site search on google: esp8266 upload OTA site:stm32duino.com

Ray


Leave a Reply

Your email address will not be published. Required fields are marked *