Program won't execute after reset

Post here first, or if you can't find a relevant section!
Post Reply
babak.d.safa
Posts: 1
Joined: Mon Apr 11, 2022 5:06 pm

Program won't execute after reset

Post by babak.d.safa »

Hi everyone, I am relatively new to stm32duino[Ver 2021.5.31], so this may be a newbie question. I have a blue pill (stm32f103c8t6) and I am using a FT232 FTDI to program it through Arduino IDE [Ver 1.8.16]. at first, I change boot0 to 1 and connect FTDI and upload the program, everything is working fine at this point, but as soon as change boot0 back to 0 and reset the board, it refuses to execute the program and freezes.
I would appreciate it if someone enlighten me on this. thanks in advance.

Connected Modules :
1. SSD1306 OLED Display Module 128x64 (Pins: PB6, PB7)
2. TM1638 8digit 7Seg Driver module (Pins: PB8, PB9, PB13)
3. SHT20 Temperature and Humidity Sensor Module (Pins: PB6, PB7)

Program (A simple test program to read temperature and humidity values from SHT20 and display them on both OLED and 7Segment Modules):

Code: Select all

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306_STM32.h>
#include <TM1638plus.h>
#include "DFRobot_SHT20.h"

#define SCREEN_WIDTH 128 
#define SCREEN_HEIGHT 64 

#define OLED_RESET     4 
#define SCREEN_ADDRESS 0x3C 
Adafruit_SSD1306 display(OLED_RESET);

#define  STROBE_TM PB13 
#define  CLOCK_TM PB8 
#define  DIO_TM PB9 
TM1638plus tm(STROBE_TM, CLOCK_TM , DIO_TM);

DFRobot_SHT20 sht20(&Wire, SHT20_I2C_ADDR);

float humd = 0.0;
float temp = 0.0;

void setup() {  
  tm.displayBegin();
  display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS);
  display.setTextColor(WHITE); // Draw white text
  display.cp437(true);
  display.clearDisplay();
  tm.brightness(5);
  sht20.initSHT20();
  delay(100);
  sht20.checkSHT20();
}

void loop(){
  humd = sht20.readHumidity(); 
  temp = sht20.readTemperature();
  display.clearDisplay();
  display.setTextSize(2);
  display.setCursor(0,0);
  display.print("Temp");
  display.setCursor(64,0);
  display.print("Humd");
  display.setCursor(0,16);
  display.print(temp, 1);
  display.setCursor(64,16);
  display.print(humd, 1);
  display.print("%");
  display.display();
  disp(temp, humd);
  delay(1000);
}

void disp(float temp, float humd){
  char workStr[11];
  uint8_t  digit1, digit2, digit3 , digit4, digit5, digit6, digit7, digit8;
  uint16_t tempint =  temp * 100; // 1245
  uint16_t humdint =  humd * 100; // 1245
  digit1 = (tempint / 1000) % 10;
  digit2 = (tempint / 100) % 10;
  digit3 = (tempint / 10) % 10;
  digit4 =  tempint % 10;
  digit5 = (humdint / 1000) % 10;
  digit6 = (humdint / 100) % 10;
  digit7 = (humdint / 10) % 10;
  digit8 =  humdint % 10;
  sprintf(workStr, "%d%d.%d%d%d%d.%d%d", digit1, digit2, digit3, digit4, digit5, digit6, digit7, digit8);
  tm.displayText(workStr);
}
Console :
Sketch uses 30352 bytes (46%) of program storage space. Maximum is 65536 bytes.
Global variables use 2896 bytes (14%) of dynamic memory, leaving 17584 bytes for local variables. Maximum is 20480 bytes.
C:\Users\Babak\AppData\Local\Arduino15\packages\stm32duino\tools\stm32tools\2021.5.31/win/serial_upload.bat COM8 {upload.altID} {upload.usbID} C:\Users\Babak\AppData\Local\Temp\arduino_build_413246/sketch_mar07a_STM32.ino.bin
stm32flash 0.4

http://stm32flash.googlecode.com/

Using Parser : Raw BINARY
Interface serial_w32: 115200 8E1
Version : 0x22
Option 1 : 0x00
Option 2 : 0x00
Device ID : 0x0410 (Medium-density)
- RAM : 20KiB (512b reserved by bootloader)
- Flash : 128KiB (sector size: 4x1024)
- Option RAM : 16b
- System RAM : 2KiB
Write to memory
Erasing memory
Wrote address 0x08007690 (100.00%) Done.

Starting execution at address 0x08000000... done.
ag123
Posts: 1653
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: Program won't execute after reset

Post by ag123 »

I'd assume you have already reviewed these:
viewtopic.php?f=2&t=301
viewtopic.php?f=2&t=3

and this is the 'formal' core
https://github.com/stm32duino/Arduino_Core_STM32
and the wiki is here
https://github.com/stm32duino/wiki/wiki

first of all you'd need to tell us which core are you using. 'official stm' or 'libmaple (roger's)'.

then come to the main topic. stm32f103c8 has 20k sram. that isn't very much especially if you want to work with a lcd display with graphics etc.

a usual thing to do is to blink a led as part of your codes e.g.

Code: Select all

void setup() {
	pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
	digitalWrite(LED_BUILTIN, ! digitalRead(LED_BUILTIN));
	...
	delay(1);
}
that would give you a hint if your sketch/app is 'alive'.
lcd isn't the easiest to interface, pretty much 'not for novices'
incorrect or missing connections and various things (e.g. incorrect initializations, not passing the CS, CMD, LCD_RESET pins to the library etc) means hours of fruitless troubleshooting.
CharlesBottoms
Posts: 3
Joined: Mon Apr 11, 2022 8:46 pm

Re: Program won't execute after reset

Post by CharlesBottoms »

Thank`s for tread, It helped me a lot.
Post Reply

Return to “General discussion”