Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not run on Blue Pill STM32F103 #12

Open
chrysophylax opened this issue Dec 2, 2020 · 22 comments
Open

Does not run on Blue Pill STM32F103 #12

chrysophylax opened this issue Dec 2, 2020 · 22 comments

Comments

@chrysophylax
Copy link

Trying to run the latest version on the official STM32 Core v 1.9.0 Arduino board gives me a bunch of errors in the IDE.
What's the last known working version?

/home/billy/Arduino/ulisp.cpp/ulisp.cpp.ino: In function 'void FlashSetup()':
ulisp.cpp:383:3: error: 'FLASH_Unlock' was not declared in this scope; did you mean 'HAL_FLASH_Unlock'?
  383 |   FLASH_Unlock();
      |   ^~~~~~~~~~~~
      |   HAL_FLASH_Unlock
ulisp.cpp:386:14: error: 'FLASH_ErasePage' was not declared in this scope
  386 |     Status = FLASH_ErasePage(page);
      |              ^~~~~~~~~~~~~~~
ulisp.cpp:387:19: error: 'FLASH_COMPLETE' was not declared in this scope; did you mean 'FLASH_CR_PER'?
  387 |     if (Status != FLASH_COMPLETE) error2(SAVEIMAGE, PSTR("flash erase failed"));
      |                   ^~~~~~~~~~~~~~
      |                   FLASH_CR_PER
/home/billy/Arduino/ulisp.cpp/ulisp.cpp.ino: In function 'void FlashWrite16(unsigned int*, uint16_t)':
ulisp.cpp:392:21: error: 'FLASH_ProgramHalfWord' was not declared in this scope
  392 |   uint16_t Status = FLASH_ProgramHalfWord((*addr) + Eeprom, data);
      |                     ^~~~~~~~~~~~~~~~~~~~~
ulisp.cpp:393:17: error: 'FLASH_COMPLETE' was not declared in this scope; did you mean 'FLASH_CR_PER'?
  393 |   if (Status != FLASH_COMPLETE) error2(SAVEIMAGE, PSTR("flash write failed"));
      |                 ^~~~~~~~~~~~~~
      |                 FLASH_CR_PER
/home/billy/Arduino/ulisp.cpp/ulisp.cpp.ino: In function 'uint16_t FlashRead16(unsigned int*)':
ulisp.cpp:464:27: error: ISO C++ forbids declaration of 'type name' with no type [-fpermissive]
  464 |   uint16_t data = (*(__IO uint16*)((*addr) + Eeprom));
      |                           ^~~~~~
In file included from /home/billy/.arduino15/packages/STM32/hardware/stm32/1.9.0/system/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xb.h:132,
                 from /home/billy/.arduino15/packages/STM32/hardware/stm32/1.9.0/system/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f1xx.h:131,
                 from /home/billy/.arduino15/packages/STM32/hardware/stm32/1.9.0/cores/arduino/stm32/stm32_def.h:28,
                 from /home/billy/.arduino15/packages/STM32/hardware/stm32/1.9.0/cores/arduino/stm32/clock.h:43,
                 from /home/billy/.arduino15/packages/STM32/hardware/stm32/1.9.0/cores/arduino/wiring_time.h:23,
                 from /home/billy/.arduino15/packages/STM32/hardware/stm32/1.9.0/cores/arduino/wiring.h:38,
                 from /home/billy/.arduino15/packages/STM32/hardware/stm32/1.9.0/cores/arduino/Arduino.h:36,
                 from sketch/ulisp.cpp.ino.cpp:1:
/home/billy/.arduino15/packages/STM32/tools/CMSIS/5.5.1/CMSIS/Core/Include/core_cm3.h:170:21: error: expected primary-expression before 'volatile'
  170 | #define     __IO    volatile             /*!< Defines 'read / write' permissions */
      |                     ^~~~~~~~
/home/billy/Arduino/ulisp.cpp/ulisp.cpp.ino:464:22: note: in expansion of macro '__IO'
  464 |   uint16_t data = (*(__IO uint16*)((*addr) + Eeprom));
      |                      ^~~~
ulisp.cpp:464:22: error: expected ')' before 'volatile'
  464 |   uint16_t data = (*(__IO uint16*)((*addr) + Eeprom));
      |                     ~^
      |                      )
ulisp.cpp:464:54: error: expected ')' before ';' token
  464 |   uint16_t data = (*(__IO uint16*)((*addr) + Eeprom));
      |                   ~                                  ^
      |                                                      )
/home/billy/Arduino/ulisp.cpp/ulisp.cpp.ino: In function 'object* fn_pinmode(object*, object*)':
ulisp.cpp:2880:17: error: 'WiringPinMode' was not declared in this scope
 2880 |   pinMode(pin, (WiringPinMode)pm);
      |                 ^~~~~~~~~~~~~
exit status 1
'FLASH_Unlock' was not declared in this scope; did you mean 'HAL_FLASH_Unlock'?
@technoblogy
Copy link
Owner

The latest version of uLisp for the Blue Pill and Maple Mini is 3.0b. Are you using Roger Clark's core?

@chrysophylax
Copy link
Author

chrysophylax commented Dec 2, 2020

Yes, indeed, I was trying 3.0b but using the STM32 official core, not Roger Clark's. To clarify: I meant which version of the STM32 official Arduino core was last known 'working' :-)

@technoblogy
Copy link
Owner

The official core doesn't have the FLASH EEPROM emulation.

@chrysophylax
Copy link
Author

chrysophylax commented Dec 2, 2020 via email

@chrysophylax
Copy link
Author

Oh, that would make sense then. I was going off the website examples that mention both official and RogerClark cores working.

Thanks for the clarification!

@technoblogy
Copy link
Owner

I was going off the website examples that mention both official and RogerClark cores working.

You're right! I must have written that before I made (save-image) work with emulated EEPROM.

I think if you say you want to use an SD Card for saving images, by uncommenting:

#define sdcardsupport

then it may work on the official core. Let me know and I'll update the documentation.

@chrysophylax
Copy link
Author

chrysophylax commented Dec 2, 2020

No progress sadly with enabling sdcardsupport. I will switch to Roger's core for now but comments on the forums for stm32duino seem to mean that it's a legacy product already.

Only the Official Core from STM is supported. Roger's core is in long-term (limited changes) mode.

I think one might be able to flash the memory using the more direct HAL library calls for the stm32f103 official core but you have to deal with it in pages, not EEPROM style ARMmbed/mbed-os#6380 (an example of calls to HAL_FLASHEx_Erase / cache invalidation)

@technoblogy
Copy link
Owner

I tried implementing the HAL library calls, but it turned out to be a lot of work.

Another workaround would be to stick with the official core, but comment out the body of saveimage() and loadimage() so the errors go away.

Regards,
David

@chrysophylax
Copy link
Author

chrysophylax commented Dec 2, 2020

Hmm,

I tried commenting out the respective bodies of saveimage() and loadimage() but that just gave me a lot of further errors with various flash write int/16 functions with -fpermissive and ISO C++ forbidding the use of no type name. I commented out the bodies of those functions too and now I am left with

/home/billy/Arduino/ulisp-nosaves/ulisp-nosaves.ino: In function 'object* fn_pinmode(object*, object*)':
ulisp-nosaves:2882:17: error: 'WiringPinMode' was not declared in this scope
   pinMode(pin, (WiringPinMode)pm);
                 ^~~~~~~~~~~~~
/home/billy/Arduino/ulisp-nosaves/ulisp-nosaves.ino:2882:17: note: suggested alternative: 'PinMode'
   pinMode(pin, (WiringPinMode)pm);
                 ^~~~~~~~~~~~~
                 PinMode
exit status 1
'WiringPinMode' was not declared in this scope

as the only remaining errors.

Thanks for your patience!
Billy

@chrysophylax
Copy link
Author

@chrysophylax
Copy link
Author

Turns out casting pm to (uint32_t) instead makes it compile! Time to test it out.

@chrysophylax
Copy link
Author

chrysophylax commented Dec 2, 2020

Screenshot from 2020-12-03 00-28-31

Hurrah.

I updated the gist.

@chrysophylax
Copy link
Author

I just ran https:/stm32duino/STM32Examples/blob/master/examples/NonReg/BufferedEEPROM/BufferedEEPROM.ino
on my F103 and it works fine. Could this be used instead to write saveimage/loadimage?

@chrysophylax
Copy link
Author

Should be similar to the ARM32 version I see actually, maybe it'd be worth adding a #define officialstm32 and some #if defined checks in FlashWriteInt to it looks more like

void FlashWriteInt (uint32_t *addr, int data) {
#if defined(officialstm32)
  FlashWriteByte(addr, data & 0xFF); FlashWriteByte(addr, data>>8 & 0xFF);
  FlashWriteByte(addr, data>>16 & 0xFF); FlashWriteByte(addr, data>>24 & 0xFF);
#else 
  FlashWrite16(addr, data & 0xFFFF); FlashWrite16(addr, data>>16 & 0xFFFF);
#endif
}

where FlashWriteByte basically invokes

void eeprom_buffered_write_byte(uint32_t pos, uint8_t value);

and saveimage would need a buffer flush at the end (likewise for loadimage, a buffer fill)

#if defined(officialstm32)
	eeprom_buffer_flush(); //buffered API
#endif
  return imagesize; 

I'll try it out tomorrow unless you beat me to it :)

@technoblogy
Copy link
Owner

I probably won't get round to it, but it will be great if you can get it working. I'll then be able to make the official core the only core we need to support.

@chrysophylax
Copy link
Author

chrysophylax commented Dec 4, 2020

@technoblogy Would it be OK to just be able to read/write 32-bits at a time from flash and be able to control the offset/amount of pages? Using STM32 HAL it seems possible to write full words at a time instead of writing individual bytes or halfwords.

@technoblogy
Copy link
Owner

save-image writes a serial stream of bytes to the EEPROM or SD card, so I'm not sure what the advantage would be.

@chrysophylax
Copy link
Author

chrysophylax commented Dec 4, 2020

Aha, I got the impression that save-image primarily wrote Arduino 32-bit integers and as the HAL seems to expose writing those directly I had an idea it might be more pleasant instead of having to do binary shifts with halfwords or bytes

@technoblogy
Copy link
Owner

You could try it...

@kwccoin
Copy link

kwccoin commented Sep 10, 2021

Screenshot from 2020-12-03 00-28-31

Hurrah.

I updated the gist.

I tied this but unfortunately it failed still:

  1. with TZT STM32F103C8T6 ARM STM32 Minimum System Development Board STM Module For arduino original and add a line
  2. add one line
    #define VARIANT_ARDUINO_STM32
    to avoid various issues

Still have issues with complier:

/Users/ngcchk/Library/Arduino15/packages/STMicroelectronics/tools/xpack-arm-none-eabi-gcc/9.3.1-1.3/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/bin/ld: ulisp_stm32_trySTM32F103C8T6_2.ino.elf section.text' will not fit in region FLASH' /Users/ngcchk/Library/Arduino15/packages/STMicroelectronics/tools/xpack-arm-none-eabi-gcc/9.3.1-1.3/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/bin/ld: ulisp_stm32_trySTM32F103C8T6_2.ino.elf section .bss' will not fit in region RAM' /Users/ngcchk/Library/Arduino15/packages/STMicroelectronics/tools/xpack-arm-none-eabi-gcc/9.3.1-1.3/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/bin/ld: region RAM' overflowed by 5064 bytes
/Users/ngcchk/Library/Arduino15/packages/STMicroelectronics/tools/xpack-arm-none-eabi-gcc/9.3.1-1.3/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/bin/ld: region `FLASH' overflowed by 46956 bytes
collect2: error: ld returned 1 exit status
exit status 1
Error compiling for board Generic STM32F1 series.

`

Any help would be appreciated.

@technoblogy
Copy link
Owner

On the STM32F103 uLisp needs at least 128KBytes of flash memory to run. From the error messages it looks like your STM32F103C8T6 only has 64KBytes; as far as I know there are versions of the chip with both sizes. Do you have a datasheet for the board you are using that you can check?

@kwccoin
Copy link

kwccoin commented Sep 10, 2021

On the STM32F103 uLisp needs at least 128KBytes of flash memory to run. From the error messages it looks like your STM32F103C8T6 only has 64KBytes; as far as I know there are versions of the chip with both sizes. Do you have a datasheet for the board you are using that you can check?

Thanks and I have to try another chip then. Got 4 of those sadly ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants